From: Carlos G. Á. <car...@us...> - 2005-09-11 19:46:30
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/PostgreSqlClient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3208/PostgreSql/Data/PostgreSqlClient Modified Files: PgConnection.cs PgConnectionInternal.cs PgConnectionPool.cs Log Message: Updated sources Index: PgConnectionPool.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/PostgreSqlClient/PgConnectionPool.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PgConnectionPool.cs 11 Sep 2005 12:12:31 -0000 1.2 --- PgConnectionPool.cs 11 Sep 2005 19:46:23 -0000 1.3 *************** *** 41,49 **** } ! public static PgConnectionInternal GetConnection(string connectionString, PgConnection owningConnection) { Init(); ! return ((PgConnectionInternal)pool.CheckOut(connectionString, owningConnection)); } --- 41,49 ---- } ! public static PgConnectionInternal GetConnection(PgConnection owningConnection) { Init(); ! return ((PgConnectionInternal)pool.CheckOut(owningConnection)); } *************** *** 83,89 **** #region · Methods · ! public PgConnectionInternal CheckOut(string connectionString, PgConnection owningConnection) { ! PgConnectionInternal newConnection = null; lock (typeof(PgConnectionPool)) --- 83,90 ---- #region · Methods · ! public PgConnectionInternal CheckOut(PgConnection owningConnection) { ! string connectionString = owningConnection.ConnectionString; ! PgConnectionInternal newConnection = null; lock (typeof(PgConnectionPool)) *************** *** 100,106 **** if (this.Validate(connection, connectionString)) { ! if (connection.Lifetime != 0) { ! if ((now - connection.Created) > connection.Lifetime) { this.unlocked.Remove(connection); --- 101,107 ---- if (this.Validate(connection, connectionString)) { ! if (connection.Options.ConnectionLifeTime != 0) { ! if ((now - connection.Created) > connection.Options.ConnectionLifeTime) { this.unlocked.Remove(connection); *************** *** 135,139 **** } ! newConnection = this.Create(connectionString); newConnection.OwningConnection = owningConnection; --- 136,140 ---- } ! newConnection = this.Create(owningConnection); newConnection.OwningConnection = owningConnection; *************** *** 177,189 **** } ! private PgConnectionInternal Create(string connectionString) { try { ! PgConnectionInternal connection = new PgConnectionInternal(connectionString); ! ! return connection; } ! catch (Exception) { throw; --- 178,188 ---- } ! private PgConnectionInternal Create(PgConnection owningConnection) { try { ! return new PgConnectionInternal(owningConnection); } ! catch { throw; *************** *** 195,202 **** try { ! return (connection.ConnectionString == connectionString && ! connection.Verify()); } ! catch (Exception) { throw; --- 194,200 ---- try { ! return (connection.OwningConnection.ConnectionString == connectionString && connection.Verify()); } ! catch { throw; *************** *** 213,217 **** } } ! catch (Exception) { throw new PgException("Error closing database connection."); --- 211,215 ---- } } ! catch { throw new PgException("Error closing database connection."); *************** *** 232,238 **** foreach (PgConnectionInternal connection in list) { ! if (connection.Lifetime != 0) { ! if ((now - connection.Created) >= connection.Lifetime) { this.unlocked.Remove(connection); --- 230,236 ---- foreach (PgConnectionInternal connection in list) { ! if (connection.Options.ConnectionLifeTime != 0) { ! if ((now - connection.Created) >= connection.Options.ConnectionLifeTime) { this.unlocked.Remove(connection); Index: PgConnectionInternal.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PgConnectionInternal.cs 11 Sep 2005 13:29:16 -0000 1.5 --- PgConnectionInternal.cs 11 Sep 2005 19:46:23 -0000 1.6 *************** *** 20,24 **** using System.Data; using System.Text; - using System.Text.RegularExpressions; using PostgreSql.Data.Protocol; --- 20,23 ---- *************** *** 29,33 **** #region · Fields · - private string connectionString; private PgConnection owningConnection; private PgDbClient database; --- 28,31 ---- *************** *** 35,39 **** private PgTransaction activeTransaction; private ArrayList preparedCommands; - private int lifetime; private long created; private bool pooled; --- 33,36 ---- *************** *** 54,68 **** } - public string ConnectionString - { - get { return this.connectionString; } - } - - public int Lifetime - { - get { return this.lifetime; } - set { this.lifetime = value; } - } - public long Created { --- 51,54 ---- *************** *** 88,92 **** if (this.preparedCommands == null) { ! this.preparedCommands = new ArrayList(); } return this.preparedCommands; --- 74,78 ---- if (this.preparedCommands == null) { ! this.preparedCommands = ArrayList.Synchronized(new ArrayList()); } return this.preparedCommands; *************** *** 104,107 **** --- 90,94 ---- public PgConnection OwningConnection { + get { return this.owningConnection; } set { this.owningConnection = value; } } *************** *** 111,127 **** #region · Constructors · ! public PgConnectionInternal(string connectionString) { ! this.options = new PgConnectionOptions(); ! this.connectionString = connectionString; ! this.lifetime = 0; this.created = 0; this.pooled = true; - this.database = new PgDbClient(); - - if (connectionString != null) - { - this.ParseConnectionString(connectionString); - } } --- 98,107 ---- #region · Constructors · ! public PgConnectionInternal(PgConnection owningConnection) { ! this.owningConnection = owningConnection; ! this.options = new PgConnectionOptions(owningConnection.ConnectionString); this.created = 0; this.pooled = true; } *************** *** 134,138 **** try { ! this.database.Options = this.Options; this.database.Connect(); } --- 114,118 ---- try { ! this.database = new PgDbClient(this.options); this.database.Connect(); } *************** *** 240,331 **** #endregion - - #region · Private Methods · - - private void ParseConnectionString(string connectionStirng) - { - Regex search = new Regex(@"([\w\s\d]*)\s*=\s*([^;]*)"); - MatchCollection elements = search.Matches(connectionString); - - foreach (Match element in elements) - { - if (element.Groups[2].Value.Trim().Length > 0) - { - switch (element.Groups[1].Value.Trim().ToLower()) - { - case "data source": - case "server": - case "host": - this.options.ServerName = element.Groups[2].Value.Trim(); - break; - - case "database": - this.options.Database = element.Groups[2].Value.Trim(); - break; - - case "user name": - case "user id": - case "user": - this.options.UserName = element.Groups[2].Value.Trim(); - break; - - case "user password": - case "password": - this.options.UserPassword = element.Groups[2].Value.Trim(); - break; - - case "port": - case "port number": - this.options.ServerPort = Int32.Parse(element.Groups[2].Value.Trim()); - break; - - case "timeout": - case "connection timeout": - this.options.Timeout = Int32.Parse(element.Groups[2].Value.Trim()); - break; - - case "packet size": - this.options.PacketSize = Int32.Parse(element.Groups[2].Value.Trim()); - break; - - case "pooling": - this.options.Pooling = Boolean.Parse(element.Groups[2].Value.Trim()); - break; - - case "connection lifetime": - this.lifetime = Int32.Parse(element.Groups[2].Value.Trim()); - break; - - case "min pool size": - throw new NotImplementedException(); - - case "max pool size": - throw new NotImplementedException(); - - case "ssl": - this.options.SSL = Boolean.Parse(element.Groups[2].Value.Trim()); - break; - } - } - } - - if (options.UserName == String.Empty || options.ServerName == String.Empty || options.ServerPort == 0) - { - throw new ArgumentException("An invalid connection string argument has been supplied or a required connection string argument has not been supplied."); - } - else - { - if (options.PacketSize < 512 || options.PacketSize > 32767) - { - StringBuilder msg = new StringBuilder(); - - msg.AppendFormat("'Packet Size' value of {0} is not valid.\r\nThe value should be an integer >= 512 and <= 32767.", options.PacketSize); - - throw new ArgumentException(msg.ToString()); - } - } - } - - #endregion } } \ No newline at end of file --- 220,223 ---- Index: PgConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PgConnection.cs 11 Sep 2005 12:12:31 -0000 1.3 --- PgConnection.cs 11 Sep 2005 19:46:23 -0000 1.4 *************** *** 53,56 **** --- 53,57 ---- private PgConnectionInternal connectionInternal; + private PgConnectionOptions options; private ConnectionState state; private bool disposed; *************** *** 72,76 **** if (state == ConnectionState.Closed) { ! PgConnectionInternal tmpConn = new PgConnectionInternal(value); this.connectionString = value; } --- 73,77 ---- if (state == ConnectionState.Closed) { ! this.options = new PgConnectionOptions(value); this.connectionString = value; } *************** *** 85,89 **** if (this.connectionInternal != null) { ! return this.connectionInternal.Options.Timeout; } else --- 86,90 ---- if (this.connectionInternal != null) { ! return this.connectionInternal.Options.ConnectionTimeout; } else *************** *** 117,121 **** if (this.connectionInternal != null) { ! return this.connectionInternal.Options.ServerName; } else --- 118,122 ---- if (this.connectionInternal != null) { ! return this.connectionInternal.Options.DataSource; } else *************** *** 311,324 **** this.state = ConnectionState.Connecting; - PgConnectionInternal tmp = new PgConnectionInternal(connectionString); - // Open connection ! if (tmp.Options.Pooling) { ! this.connectionInternal = PgConnectionPool.GetConnection(this.connectionString, this); } else { ! this.connectionInternal = new PgConnectionInternal(this.connectionString); this.connectionInternal.OwningConnection = this; --- 312,323 ---- this.state = ConnectionState.Connecting; // Open connection ! if (this.options.Pooling) { ! this.connectionInternal = PgConnectionPool.GetConnection(this); } else { ! this.connectionInternal = new PgConnectionInternal(this); this.connectionInternal.OwningConnection = this; |