Skip to content

Commit

Permalink
DNET-274
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Sep 28, 2009
1 parent bacb579 commit c02ccc7
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 152 deletions.
42 changes: 18 additions & 24 deletions NETProvider/source/FirebirdSql/Data/FirebirdClient/FbCommand.cs
Expand Up @@ -51,7 +51,6 @@ public sealed class FbCommand : DbCommand, ICloneable
private bool implicitTransaction;
private int commandTimeout;
private int fetchSize;
private bool addedToPrepared;

#if (NET_35 && ENTITY_FRAMEWORK)
// type coercions
Expand Down Expand Up @@ -782,31 +781,27 @@ internal void Close()
}
}

internal void Release()
{
// Rollback implicit transaction
this.RollbackImplicitTransaction();
internal void Release()
{
// Rollback implicit transaction
this.RollbackImplicitTransaction();

// If there are an active reader close it
this.CloseReader();
// If there are an active reader close it
this.CloseReader();

if (this.addedToPrepared)
{
// Remove the command from the Prepared commands list
if (this.connection != null && this.connection.State == ConnectionState.Open)
{
this.connection.InnerConnection.RemovePreparedCommand(this);
}
this.addedToPrepared = false;
}
// Remove the command from the Prepared commands list
if (this.connection != null && this.connection.State == ConnectionState.Open)
{
this.connection.InnerConnection.RemovePreparedCommand(this);
}

// Dipose the inner statement
if (this.statement != null)
{
this.statement.Dispose();
this.statement = null;
}
}
// Dipose the inner statement
if (this.statement != null)
{
this.statement.Dispose();
this.statement = null;
}
}

#endregion

Expand Down Expand Up @@ -1157,7 +1152,6 @@ private void Prepare(bool returnsSet)

// Add this command to the active command list
innerConn.AddPreparedCommand(this);
this.addedToPrepared = true;
}
else
{
Expand Down
Expand Up @@ -633,7 +633,7 @@ public override void Close()
this.innerConnection.DisposeTransaction();

// Dispose all active statemenets
this.innerConnection.DisposePreparedCommands();
this.innerConnection.ReleasePreparedCommands();

// Close connection or send it back to the pool
if (this.innerConnection.Pooled)
Expand Down
Expand Up @@ -37,7 +37,7 @@ internal class FbConnectionInternal : MarshalByRefObject, IDisposable

private IDatabase db;
private FbTransaction activeTransaction;
private List<FbCommand> preparedCommands;
private List<WeakReference> preparedCommands;
private FbConnectionString options;
private FbConnection owningConnection;
private long created;
Expand Down Expand Up @@ -84,19 +84,6 @@ public bool HasActiveTransaction
}
}

public List<FbCommand> PreparedCommands
{
get
{
if (this.preparedCommands == null)
{
this.preparedCommands = new List<FbCommand>();
}

return this.preparedCommands;
}
}

public FbTransaction ActiveTransaction
{
get { return this.activeTransaction; }
Expand Down Expand Up @@ -133,7 +120,9 @@ public FbConnectionInternal(FbConnectionString options)
}

public FbConnectionInternal(FbConnectionString options, FbConnection owningConnection)
{
{
this.preparedCommands = new List<WeakReference>();

this.options = options;
this.owningConnection = owningConnection;

Expand Down Expand Up @@ -334,9 +323,12 @@ public void DisposeTransaction()

public void TransactionUpdated()
{
for (int i = 0; i < this.PreparedCommands.Count; i++)
for (int i = 0; i < this.preparedCommands.Count; i++)
{
FbCommand command = this.PreparedCommands[i];
if (!this.preparedCommands[i].IsAlive)
continue;

FbCommand command = this.preparedCommands[i].Target as FbCommand;

if (command.Transaction != null)
{
Expand Down Expand Up @@ -418,54 +410,66 @@ public DataTable GetSchema(string collectionName, string[] restrictions)

public void AddPreparedCommand(FbCommand command)
{
if (!this.PreparedCommands.Contains(command))
{
this.PreparedCommands.Add(command);
}
int position = this.preparedCommands.Count;
for (int i = 0; i < this.preparedCommands.Count; i++)
{
if (!this.preparedCommands[i].IsAlive)
{
position = i;
break;
}
if (this.preparedCommands[i].Target == command)
{
return;
}
}
this.preparedCommands.Insert(position, new WeakReference(command));
}

public void RemovePreparedCommand(FbCommand command)
{
this.PreparedCommands.Remove(command);
}

public void DisposePreparedCommands()
{
if (this.preparedCommands != null)
{
if (this.PreparedCommands.Count > 0)
{
FbCommand[] commands = this.PreparedCommands.ToArray();

for (int i = 0; i < commands.Length; i++)
{
try
{
// Release statement handle
commands[i].Release();
}
catch (System.IO.IOException)
{
// If an IO error occurs weh trying to release the command
// avoid it. ( It maybe the connection to the server was down
// for unknown reasons. )
}
catch (IscException iex)
{
if (iex.ErrorCode != IscCodes.isc_net_read_err &&
iex.ErrorCode != IscCodes.isc_net_write_err &&
iex.ErrorCode != IscCodes.isc_network_error)
{
throw;
}
}
}
}

this.PreparedCommands.Clear();
this.preparedCommands = null;
}
}
for (int i = 0; i < this.preparedCommands.Count; i++)
{
if (this.preparedCommands[i].Target == command)
{
this.preparedCommands[i].Target = null;
this.preparedCommands.RemoveAt(i);
return;
}
}
}

public void ReleasePreparedCommands()
{
for (int i = 0; i < this.preparedCommands.Count; i++)
{
if (!this.preparedCommands[i].IsAlive)
continue;

try
{
// Release statement handle
(this.preparedCommands[i].Target as FbCommand).Release();
}
catch (System.IO.IOException)
{
// If an IO error occurs weh trying to release the command
// avoid it. ( It maybe the connection to the server was down
// for unknown reasons. )
}
catch (IscException iex)
{
if (iex.ErrorCode != IscCodes.isc_net_read_err &&
iex.ErrorCode != IscCodes.isc_net_write_err &&
iex.ErrorCode != IscCodes.isc_network_error)
{
throw;
}
}
}

this.preparedCommands.Clear();
}

#endregion

Expand Down

0 comments on commit c02ccc7

Please sign in to comment.