protected virtual async Task DropTemporaryTableIfNecessaryAsync(IQueryable persister, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (Factory.Dialect.DropTemporaryTableAfterUse()) { IIsolatedWork work = new TmpIdTableDropIsolatedWork(persister, log, session); if (ShouldIsolateTemporaryTableDDL()) { session.ConnectionManager.Transaction.RegisterSynchronization(new AfterTransactionCompletes((success) => { if (Factory.Settings.IsDataDefinitionInTransactionSupported) { Isolater.DoIsolatedWork(work, session); } else { Isolater.DoNonTransactedWork(work, session); } })); } else { using (var dummyCommand = await(session.ConnectionManager.CreateCommandAsync(cancellationToken)).ConfigureAwait(false)) { await(work.DoWorkAsync(dummyCommand.Connection, dummyCommand.Transaction, cancellationToken)).ConfigureAwait(false); session.ConnectionManager.AfterStatement(); } } } else { // at the very least cleanup the data :) DbCommand ps = null; try { var commandText = new SqlString("delete from " + persister.TemporaryIdTableName); ps = await(session.Batcher.PrepareCommandAsync(CommandType.Text, commandText, new SqlType[0], cancellationToken)).ConfigureAwait(false); await(session.Batcher.ExecuteNonQueryAsync(ps, cancellationToken)).ConfigureAwait(false); } catch (Exception t) { log.Warn("unable to cleanup temporary id table after use [" + t + "]"); } finally { if (ps != null) { try { session.Batcher.CloseCommand(ps, null); } catch (Exception) { // ignore } } } } }
protected virtual void DropTemporaryTableIfNecessary(IQueryable persister, ISessionImplementor session) { if (Factory.Dialect.DropTemporaryTableAfterUse()) { IIsolatedWork work = new TmpIdTableDropIsolatedWork(persister, log, session); if (ShouldIsolateTemporaryTableDDL()) { session.ConnectionManager.Transaction.RegisterSynchronization(new AfterTransactionCompletes((success) => { if (Factory.Settings.IsDataDefinitionInTransactionSupported) { Isolater.DoIsolatedWork(work, session); } else { Isolater.DoNonTransactedWork(work, session); } })); } else { using (var dummyCommand = session.ConnectionManager.CreateCommand()) { work.DoWork(dummyCommand.Connection, dummyCommand.Transaction); session.ConnectionManager.AfterStatement(); } } } else { // at the very least cleanup the data :) DbCommand ps = null; try { var commandText = new SqlString("delete from " + persister.TemporaryIdTableName); ps = session.Batcher.PrepareCommand(CommandType.Text, commandText, Array.Empty <SqlType>()); session.Batcher.ExecuteNonQuery(ps); } catch (Exception t) { log.Warn(t, "unable to cleanup temporary id table after use [{0}]", t); } finally { if (ps != null) { try { session.Batcher.CloseCommand(ps, null); } catch (Exception) { // ignore } } } } }
protected virtual void DropTemporaryTableIfNecessary(IQueryable persister, ISessionImplementor session) { if (Factory.Dialect.DropTemporaryTableAfterUse()) { IIsolatedWork work = new TmpIdTableDropIsolatedWork(persister, log, session); if (ShouldIsolateTemporaryTableDDL()) { if (Factory.Settings.IsDataDefinitionInTransactionSupported) { Isolater.DoIsolatedWork(work, session); } else { Isolater.DoNonTransactedWork(work, session); } } else { work.DoWork(session.ConnectionManager.GetConnection(), null); session.ConnectionManager.AfterStatement(); } } else { // at the very least cleanup the data :) IDbCommand ps = null; try { var commandText = new SqlString("delete from " + persister.TemporaryIdTableName); ps = session.Batcher.PrepareCommand(CommandType.Text, commandText, new SqlType[0]); session.Batcher.ExecuteNonQuery(ps); } catch (Exception t) { log.Warn("unable to cleanup temporary id table after use [" + t + "]"); } finally { if (ps != null) { try { session.Batcher.CloseCommand(ps, null); } catch (Exception) { // ignore } } } } }
protected virtual void DropTemporaryTableIfNecessary(IQueryable persister, ISessionImplementor session) { if (Factory.Dialect.DropTemporaryTableAfterUse()) { IIsolatedWork work = new TmpIdTableDropIsolatedWork(persister, log, session); if (ShouldIsolateTemporaryTableDDL()) { if (Factory.Settings.IsDataDefinitionInTransactionSupported) { Isolater.DoIsolatedWork(work, session); } else { Isolater.DoNonTransactedWork(work, session); } } else { work.DoWork(session.ConnectionManager.GetConnection(), null); session.ConnectionManager.AfterStatement(); } } else { // at the very least cleanup the data :) IDbCommand ps = null; try { var commandText = new SqlString("delete from " + persister.TemporaryIdTableName); ps = session.Batcher.PrepareCommand(CommandType.Text, commandText, new SqlType[0]); ps.ExecuteNonQuery(); } catch (Exception t) { log.Warn("unable to cleanup temporary id table after use [" + t + "]"); } finally { if (ps != null) { try { session.Batcher.CloseCommand(ps, null); } catch (Exception) { // ignore } } } } }