(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / IBM.Data.DB2 / IBM.Data.DB2 / DB2ConnectionSettings.cs
blob988dcc43189685ce112d98d778c0f369cea16a71
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 using System;
23 using System.Runtime.InteropServices;
24 using System.Text;
26 namespace IBM.Data.DB2
28 internal sealed class DB2ConnectionSettings
30 private string connectionString;
31 private string userName = "";
32 private string passWord = "";
33 private string databaseAlias = "";
34 private string server = "";
35 private bool pooling = true;
36 private TimeSpan connectTimeout = new TimeSpan(0, 0, 15);
37 private TimeSpan connectionLifeTime = new TimeSpan(0, 0, 15); // 15 seconds
38 private int connectionPoolSizeMin = 0;
39 private int connectionPoolSizeMax = -1; // no maximum
41 private DB2ConnectionPool pool;
43 private DB2ConnectionSettings(string connectionString)
45 this.connectionString = connectionString;
46 this.Parse();
49 public static DB2ConnectionSettings GetConnectionSettings(string connectionString)
51 DB2ConnectionPool pool = DB2ConnectionPool.FindConnectionPool(connectionString);
52 if(pool != null)
54 return pool.ConnectionSettings;
56 DB2ConnectionSettings settings = new DB2ConnectionSettings(connectionString);
57 if(settings.Pooling)
59 settings.pool = DB2ConnectionPool.GetConnectionPool(settings);
61 return settings;
64 public DB2OpenConnection GetRealOpenConnection(DB2Connection connection)
66 if(pool != null)
68 return pool.GetOpenConnection(connection);
70 else
72 return new DB2OpenConnection(this, connection);
76 public DB2ConnectionPool Pool
78 get { return pool; }
81 public string ConnectionString
83 get { return connectionString; }
86 public string UserName
88 get { return userName; }
91 public string PassWord
93 get { return passWord; }
96 /// <summary>
97 /// database alias (for cataloged database)
98 /// </summary>
99 public string DatabaseAlias
101 get { return databaseAlias; }
104 /// <summary>
105 /// server name with optional port number for direct connection (<server name/ip address>[:<port>])
106 /// </summary>
107 public string Server
109 get { return server; }
112 public TimeSpan ConnectTimeout
114 get { return connectTimeout; }
117 /// <summary>
118 /// Connection pooling yes/no
119 /// </summary>
120 public bool Pooling
122 get { return pooling; }
125 public int ConnectionPoolSizeMin
127 get { return connectionPoolSizeMin; }
130 public int ConnectionPoolSizeMax
132 get { return connectionPoolSizeMin; }
135 public TimeSpan ConnectionLifeTime
137 get { return connectionLifeTime; }
141 /// <summary>
142 /// parsed according to IBM DB2 .NET data provider help
143 /// </summary>
144 public void Parse()
146 string[] parts = connectionString.Split(new char[]{';'});
147 foreach(string part in parts)
149 string[] pairs = part.Split(new char[]{'='});
150 switch(pairs[0].ToLower())
152 case "database":
153 case "dsn":
154 databaseAlias = pairs[1];
155 break;
156 case "uid":
157 case "user id":
158 userName = pairs[1];
159 break;
160 case "pwd":
161 case "password":
162 passWord = pairs[1];
163 break;
164 case "server":
165 server = pairs[1];
166 break;
167 case "pooling":
168 pooling = (pairs[1].ToLower() == "true") || (pairs[1]== "1");
169 break;
170 case "connect timeout":
171 case "timeout":
172 case "connection timeout":
173 connectTimeout = new TimeSpan(0, 0, int.Parse(pairs[1]));
174 break;
175 case "min pool size":
176 connectionPoolSizeMin = int.Parse(pairs[1]);
177 break;
178 case "max pool size":
179 connectionPoolSizeMax = int.Parse(pairs[1]);
180 break;
181 case "connection lifetime":
182 connectionLifeTime = new TimeSpan(0, 0, int.Parse(pairs[1]));
183 break;
186 if(connectionLifeTime.Ticks <= 0)
188 pooling = false;
192 public override int GetHashCode()
194 return connectionString.GetHashCode ();
197 public override bool Equals(object obj)
199 return connectionString.Equals (obj);