[pgsqlclient-checkins] SF.net SVN: pgsqlclient: [98] trunk/PostgreSqlClient/source/PostgreSql/Data/P
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2006-04-11 20:57:22
|
Revision: 98 Author: carlosga_fb Date: 2006-04-11 13:57:14 -0700 (Tue, 11 Apr 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=98&view=rev Log Message: ----------- 2006-04-11 Carlos Guzman Alvarez (car...@te...) - Implemented Savepoint support. - Added several changes and bug fixes on database schema support. Modified Paths: -------------- trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgTransaction.cs Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-04-11 20:15:14 UTC (rev 97) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-04-11 20:57:14 UTC (rev 98) @@ -254,7 +254,7 @@ #endregion - #region \xB7 Methods \xB7 + #region \xB7 Begin Transaction Methods \xB7 public new PgTransaction BeginTransaction() { @@ -263,7 +263,7 @@ public new PgTransaction BeginTransaction(IsolationLevel level) { - if (this.state == ConnectionState.Closed) + if (this.State == ConnectionState.Closed) { throw new InvalidOperationException("BeginTransaction requires an open and available Connection."); } @@ -271,7 +271,26 @@ return this.connectionInternal.BeginTransaction(level); } - public override void ChangeDatabase(string db) + public PgTransaction BeginTransaction(string transactionName) + { + return this.BeginTransaction(IsolationLevel.ReadCommitted, transactionName); + } + + public PgTransaction BeginTransaction(IsolationLevel level, string transactionName) + { + if (this.State == ConnectionState.Closed) + { + throw new InvalidOperationException("BeginTransaction requires an open and available Connection."); + } + + return this.connectionInternal.BeginTransaction(level, transactionName); + } + + #endregion + + #region \xB7 Methods \xB7 + + public override void ChangeDatabase(string db) { if (this.state == ConnectionState.Closed) { Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs 2006-04-11 20:15:14 UTC (rev 97) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs 2006-04-11 20:57:14 UTC (rev 98) @@ -154,6 +154,27 @@ return this.activeTransaction; } + public PgTransaction BeginTransaction(IsolationLevel level, string transactionName) + { + if (this.activeTransaction != null && !this.activeTransaction.IsUpdated) + { + throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); + } + + try + { + this.activeTransaction = new PgTransaction(this.owningConnection, level); + this.activeTransaction.InternalBeginTransaction(); + this.activeTransaction.Save(transactionName); + } + catch (PgClientException ex) + { + throw new PgException(ex.Message, ex); + } + + return this.activeTransaction; + } + public void DisposeActiveTransaction() { // Rollback active transation Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgTransaction.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgTransaction.cs 2006-04-11 20:15:14 UTC (rev 97) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgTransaction.cs 2006-04-11 20:57:14 UTC (rev 98) @@ -137,26 +137,8 @@ #endregion - #region \xB7 Internal Methods \xB7 - - internal void InternalBeginTransaction() - { - try - { - this.connection.InternalConnection.Database.BeginTransaction(isolationLevel); + #region \xB7 DbTransaction Overriden Methods \xB7 - this.IsUpdated = false; - } - catch (PgClientException ex) - { - throw new PgException(ex.Message, ex); - } - } - - #endregion - - #region \xB7 Methods \xB7 - public override void Commit() { this.CheckTransaction(); @@ -191,6 +173,139 @@ #endregion + #region \xB7 SavePoint Methods \xB7 + + /// <include file='Doc/en_EN/FbTransaction.xml' path='doc/class[@name="FbTransaction"]/method[@name="Save(System.String)"]/*'/> + public void Save(string savePointName) + { + lock (this) + { + if (savePointName == null) + { + throw new ArgumentException("No transaction name was be specified."); + } + else + { + if (savePointName.Length == 0) + { + throw new ArgumentException("No transaction name was be specified."); + } + } + if (this.isUpdated) + { + throw new InvalidOperationException("This Transaction has completed; it is no longer usable."); + } + + try + { + PgCommand command = new PgCommand( + "SAVEPOINT " + savePointName, + this.connection, + this); + command.ExecuteNonQuery(); + command.Dispose(); + } + catch (PgClientException ex) + { + throw new PgException(ex.Message, ex); + } + } + } + + /// <include file='Doc/en_EN/FbTransaction.xml' path='doc/class[@name="FbTransaction"]/method[@name="Commit(System.String)"]/*'/> + public void Commit(string savePointName) + { + lock (this) + { + if (savePointName == null) + { + throw new ArgumentException("No transaction name was be specified."); + } + else + { + if (savePointName.Length == 0) + { + throw new ArgumentException("No transaction name was be specified."); + } + } + if (this.isUpdated) + { + throw new InvalidOperationException("This Transaction has completed; it is no longer usable."); + } + + try + { + PgCommand command = new PgCommand( + "RELEASE SAVEPOINT " + savePointName, + this.connection, + this); + command.ExecuteNonQuery(); + command.Dispose(); + } + catch (PgClientException ex) + { + throw new PgException(ex.Message, ex); + } + } + } + + /// <include file='Doc/en_EN/FbTransaction.xml' path='doc/class[@name="FbTransaction"]/method[@name="Rollback(System.String)"]/*'/> + public void Rollback(string savePointName) + { + lock (this) + { + if (savePointName == null) + { + throw new ArgumentException("No transaction name was be specified."); + } + else + { + if (savePointName.Length == 0) + { + throw new ArgumentException("No transaction name was be specified."); + } + } + if (this.isUpdated) + { + throw new InvalidOperationException("This Transaction has completed; it is no longer usable."); + } + + try + { + PgCommand command = new PgCommand( + "ROLLBACK WORK TO SAVEPOINT " + savePointName, + this.connection, + this); + command.ExecuteNonQuery(); + command.Dispose(); + } + catch (PgClientException ex) + { + throw new PgException(ex.Message, ex); + } + } + } + + #endregion + + #region \xB7 Internal Methods \xB7 + + internal void InternalBeginTransaction() + { + try + { + this.connection.InternalConnection.Database.BeginTransaction(isolationLevel); + + this.IsUpdated = false; + } + catch (PgClientException ex) + { + throw new PgException(ex.Message, ex); + } + } + + #endregion + #region \xB7 Private Methods \xB7 private void CheckTransaction() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |