Mark tests as not working under TARGET_JVM
[mono.git] / mcs / class / System.Data / Test / ProviderTests / Common / ConnectionManager.cs
1 // ConnectionManager.cs - Singleton ConnectionManager class to manage
2 // database connections for test cases.
3 //
4 // Authors:
5 //      Sureshkumar T (tsureshkumar@novell.com)
6 // 
7 // Copyright Novell Inc., and the individuals listed on the
8 // ChangeLog entries.
9 //
10 //
11 // Permission is hereby granted, free of charge, to any person
12 // obtaining a copy of this software and associated documentation
13 // files (the "Software"), to deal in the Software without
14 // restriction, including without limitation the rights to use, copy,
15 // modify, merge, publish, distribute, sublicense, and/or sell copies
16 // of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
26 // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 // SOFTWARE.
30
31 using System;
32 using System.Configuration;
33 using System.Data;
34 using Mono.Data;
35
36 namespace MonoTests.System.Data
37 {
38         public class ConnectionManager
39         {
40                 private static ConnectionManager Instance;
41                 private IDbConnection _connection;
42                 private string _connectionString;
43
44                 static ConnectionManager () 
45                 {
46                         Instance = new ConnectionManager ();
47                 }
48
49                 private ConnectionManager ()
50                 {
51                         string connectionString = ConfigurationSettings.AppSettings ["ConnString"];
52                         if (connectionString == null || connectionString.Equals (String.Empty)) {
53                                 throw new ArgumentException ("Connection string is invalid!");
54                         }
55                         _connection = ProviderFactory.CreateConnectionFromConfig ("ConnString");
56                         _connectionString = Connection.ConnectionString;
57                 }
58
59                 public static ConnectionManager Singleton
60                 {
61                         get {return Instance;}
62                 }
63
64                 public IDbConnection Connection 
65                 {
66                         get {return _connection;}
67                 }
68
69                 public string ConnectionString
70                 {
71                         get {return _connectionString;}
72                 }
73
74                 public void OpenConnection ()
75                 {
76                         if (_connection == null)
77                                 _connection = ProviderFactory.CreateConnectionFromConfig ("ConnString");
78                         if (!(_connection.State == ConnectionState.Closed || _connection.State == ConnectionState.Broken))
79                                 _connection.Close ();
80                         _connection.ConnectionString = _connectionString;
81                         _connection.Open ();
82                 }
83
84                 public void CloseConnection ()
85                 {
86                         if (_connection != null && _connection.State != ConnectionState.Closed)
87                                 _connection.Close ();
88                 }
89                 
90         }
91 }