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:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
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.
23 using System.Runtime.InteropServices;
\r
26 namespace IBM.Data.DB2
\r
28 internal sealed class DB2ConnectionSettings
\r
30 private string connectionString;
\r
31 private string userName = "";
\r
32 private string passWord = "";
\r
33 private string databaseAlias = "";
\r
34 private string server = "";
\r
35 private bool pooling = true;
\r
36 private TimeSpan connectTimeout = new TimeSpan(0, 0, 15);
\r
37 private TimeSpan connectionLifeTime = new TimeSpan(0, 0, 15); // 15 seconds
\r
38 private int connectionPoolSizeMin = 0;
\r
39 private int connectionPoolSizeMax = -1; // no maximum
\r
41 private DB2ConnectionPool pool;
\r
43 private DB2ConnectionSettings(string connectionString)
\r
45 this.connectionString = connectionString;
\r
49 public static DB2ConnectionSettings GetConnectionSettings(string connectionString)
\r
51 DB2ConnectionPool pool = DB2ConnectionPool.FindConnectionPool(connectionString);
\r
54 return pool.ConnectionSettings;
\r
56 DB2ConnectionSettings settings = new DB2ConnectionSettings(connectionString);
\r
57 if(settings.Pooling)
\r
59 settings.pool = DB2ConnectionPool.GetConnectionPool(settings);
\r
64 public DB2OpenConnection GetRealOpenConnection(DB2Connection connection)
\r
68 return pool.GetOpenConnection(connection);
\r
72 return new DB2OpenConnection(this, connection);
\r
76 public DB2ConnectionPool Pool
\r
78 get { return pool; }
\r
81 public string ConnectionString
\r
83 get { return connectionString; }
\r
86 public string UserName
\r
88 get { return userName; }
\r
91 public string PassWord
\r
93 get { return passWord; }
\r
97 /// database alias (for cataloged database)
\r
99 public string DatabaseAlias
\r
101 get { return databaseAlias; }
\r
105 /// server name with optional port number for direct connection (<server name/ip address>[:<port>])
\r
107 public string Server
\r
109 get { return server; }
\r
112 public TimeSpan ConnectTimeout
\r
114 get { return connectTimeout; }
\r
118 /// Connection pooling yes/no
\r
120 public bool Pooling
\r
122 get { return pooling; }
\r
125 public int ConnectionPoolSizeMin
\r
127 get { return connectionPoolSizeMin; }
\r
130 public int ConnectionPoolSizeMax
\r
132 get { return connectionPoolSizeMin; }
\r
135 public TimeSpan ConnectionLifeTime
\r
137 get { return connectionLifeTime; }
\r
142 /// parsed according to IBM DB2 .NET data provider help
\r
144 public void Parse()
\r
146 string[] parts = connectionString.Split(new char[]{';'});
\r
147 foreach(string part in parts)
\r
149 string[] pairs = part.Split(new char[]{'='});
\r
150 switch(pairs[0].ToLower())
\r
154 databaseAlias = pairs[1];
\r
158 userName = pairs[1];
\r
162 passWord = pairs[1];
\r
168 pooling = (pairs[1].ToLower() == "true") || (pairs[1]== "1");
\r
170 case "connect timeout":
\r
172 case "connection timeout":
\r
173 connectTimeout = new TimeSpan(0, 0, int.Parse(pairs[1]));
\r
175 case "min pool size":
\r
176 connectionPoolSizeMin = int.Parse(pairs[1]);
\r
178 case "max pool size":
\r
179 connectionPoolSizeMax = int.Parse(pairs[1]);
\r
181 case "connection lifetime":
\r
182 connectionLifeTime = new TimeSpan(0, 0, int.Parse(pairs[1]));
\r
186 if(connectionLifeTime.Ticks <= 0)
\r
192 public override int GetHashCode()
\r
194 return connectionString.GetHashCode ();
\r
197 public override bool Equals(object obj)
\r
199 return connectionString.Equals (obj);
\r