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
;
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
;
49 public static DB2ConnectionSettings
GetConnectionSettings(string connectionString
)
51 DB2ConnectionPool pool
= DB2ConnectionPool
.FindConnectionPool(connectionString
);
54 return pool
.ConnectionSettings
;
56 DB2ConnectionSettings settings
= new DB2ConnectionSettings(connectionString
);
59 settings
.pool
= DB2ConnectionPool
.GetConnectionPool(settings
);
64 public DB2OpenConnection
GetRealOpenConnection(DB2Connection connection
)
68 return pool
.GetOpenConnection(connection
);
72 return new DB2OpenConnection(this, connection
);
76 public DB2ConnectionPool 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; }
97 /// database alias (for cataloged database)
99 public string DatabaseAlias
101 get { return databaseAlias; }
105 /// server name with optional port number for direct connection (<server name/ip address>[:<port>])
109 get { return server; }
112 public TimeSpan ConnectTimeout
114 get { return connectTimeout; }
118 /// Connection pooling yes/no
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; }
142 /// parsed according to IBM DB2 .NET data provider help
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())
154 databaseAlias
= pairs
[1];
168 pooling
= (pairs
[1].ToLower() == "true") || (pairs
[1]== "1");
170 case "connect timeout":
172 case "connection timeout":
173 connectTimeout
= new TimeSpan(0, 0, int.Parse(pairs
[1]));
175 case "min pool size":
176 connectionPoolSizeMin
= int.Parse(pairs
[1]);
178 case "max pool size":
179 connectionPoolSizeMax
= int.Parse(pairs
[1]);
181 case "connection lifetime":
182 connectionLifeTime
= new TimeSpan(0, 0, int.Parse(pairs
[1]));
186 if(connectionLifeTime
.Ticks
<= 0)
192 public override int GetHashCode()
194 return connectionString
.GetHashCode ();
197 public override bool Equals(object obj
)
199 return connectionString
.Equals (obj
);