private void SetDefaultOptions() { if (this.options == null) { this.options = new Hashtable(); } this.options.Clear(); // Add default key pairs values this.options.Add("data source", DEFAULT_DATASOURCE); this.options.Add("port number", DEFAULT_PORTNUMBER); this.options.Add("user id", DEFAULT_USERID); this.options.Add("password", DEFAULT_PASSWORD); this.options.Add("role name", DEFAULT_ROLENAME); this.options.Add("catalog", DEFAULT_CATALOG); this.options.Add("character set", DEFAULT_CHARSET); this.options.Add("dialect", DEFAULT_DIALECT); this.options.Add("packet size", DEFAULT_PACKETSIZE); this.options.Add("pooling", DEFAULT_POOLING); this.options.Add("connection lifetime", DEFAULT_CONNECTION_LIFETIME); this.options.Add("min pool size", DEFAULT_MIN_POOLSIZE); this.options.Add("max pool size", DEFAULT_MAX_POOLSIZE); this.options.Add("connection timeout", DEFAULT_CONNECTION_TIMEOUT); this.options.Add("fetch size", DEFAULT_FETCHSIZE); this.options.Add("server type", DEFAULT_SERVERTYPE); this.options.Add("isolation level", DEFAULT_ISOLATIONLEVEL.ToString()); this.options.Add("records affected", DEFAULT_RECORDS_AFFECTED); this.options.Add("context connection", DEFAULT_CONTEXT_CONNECTION); this.options.Add("enlist", DEFAULT_ENLIST); this.options.Add("client library", DEFAULT_CLIENTLIBRARY); }
public void SetIsolationLevel(string typePart, IsolationLevel expected) { var sql = String.Format("SET TRANSACTION ISOLATION LEVEL {0}", typePart); var result = Compile(sql); Assert.IsNotNull(result); Assert.IsFalse(result.HasErrors); Assert.AreEqual(1, result.Statements.Count); var statement = result.Statements.ElementAt(0); Assert.IsNotNull(statement); Assert.IsInstanceOf <SetStatement>(statement); var set = (SetStatement)statement; Assert.AreEqual(TransactionSettingKeys.IsolationLevel, set.SettingName); Assert.IsInstanceOf <SqlConstantExpression>(set.ValueExpression); var value = (SqlConstantExpression)set.ValueExpression; var field = value.Value; Assert.IsInstanceOf <StringType>(field.Type); var s = (SqlString)field.Value; Assert.AreEqual(expected.ToString(), s.ToString()); }
protected virtual System.Data.IsolationLevel GetDataIsolationLevel(IsolationLevel localIsolationLevel) { switch (localIsolationLevel) { case IsolationLevel.Serializable: return(System.Data.IsolationLevel.Serializable); case IsolationLevel.RepeatableRead: return(System.Data.IsolationLevel.RepeatableRead); case IsolationLevel.ReadCommitted: return(System.Data.IsolationLevel.ReadCommitted); case IsolationLevel.ReadUncommitted: return(System.Data.IsolationLevel.ReadUncommitted); case IsolationLevel.Snapshot: return(System.Data.IsolationLevel.Snapshot); case IsolationLevel.Chaos: return(System.Data.IsolationLevel.Chaos); case IsolationLevel.Unspecified: return(System.Data.IsolationLevel.Unspecified); default: System.Data.IsolationLevel level; return(Enum.TryParse(localIsolationLevel.ToString("G"), out level) ? level : System.Data.IsolationLevel.Unspecified); } }
/// <summary> /// Returns a string that represents the current object. /// </summary> /// <returns></returns> public override string ToString() { return(String.Format("Transaction Object using the ConnectionAliasName:[{0}] and the IsolationLevel:[{1}] ", ConnectionAliasName, IsolationLevel.ToString() )); }
public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteAttributeString("transactionId", TransactionId.ToString()); writer.WriteAttributeString("name", _name.ToString()); writer.WriteAttributeString("isolationLevel", IsolationLevel.ToString()); writer.WriteAttributeString("createdOn", CreatedOn.ToString()); writer.WriteAttributeString("transactionState", TransactionState.ToString()); }
/// <summary> /// Initialises a new instance of the <see cref="Transaction" /> class. /// </summary> /// <param name="sessionBase">The session that the transaction is being created for.</param> /// <param name="isolationLevel">The isolation level.</param> internal Transaction(ISessionBase sessionBase, IsolationLevel isolationLevel) { this.sessionBase = sessionBase; if (log.IsDebug) { log.Debug(LogMessages.Transaction_BeginTransactionWithIsolationLevel, isolationLevel.ToString()); } this.transaction = this.sessionBase.Connection.BeginTransaction(isolationLevel); }
/// <summary> /// 开启事务 /// </summary> /// <param name="isolationLevel">事务级别</param> public AfxTransaction BeginTransaction(IsolationLevel isolationLevel) { if (null != this.transaction) { throw new InvalidOperationException("已开启事务,不能重复开启!"); } this.Open(); this.transaction = this.Connection.BeginTransaction(isolationLevel); this.OnLog("-- BeginTransaction " + isolationLevel.ToString()); return(new AfxTransaction(this)); }
static internal ArgumentOutOfRangeException NotSupportedIsolationLevel(IsolationLevel value) { #if DEBUG switch(value) { case IsolationLevel.Unspecified: case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: case IsolationLevel.Snapshot: Debug.Assert(false, "valid IsolationLevel " + value.ToString()); break; case IsolationLevel.Chaos: break; default: Debug.Assert(false, "invalid IsolationLevel " + value.ToString()); break; } #endif return ODBC.NotSupportedEnumerationValue(typeof(IsolationLevel), (int)value); }
/// <summary> /// 开启事务 /// </summary> /// <param name="isolationLevel">事务级别</param> public Transaction BeginTransaction(IsolationLevel isolationLevel) { if (null == this.transaction) { this.Open(); this.transaction = this.Connection.BeginTransaction(isolationLevel); this.OnLog("-- BeginTransaction " + isolationLevel.ToString()); return(new Transaction(this)); } return(Transaction.Current); }
public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new System.ArgumentNullException("info"); } info.AddValue("transactionId", TransactionId); info.AddValue("name", _name); info.AddValue("isolationLevel", IsolationLevel.ToString()); info.AddValue("createdOn", CreatedOn); info.AddValue("transactionState", TransactionState); }
static internal ArgumentOutOfRangeException NotSupportedIsolationLevel(IsolationLevel value) { #if DEBUG switch (value) { case IsolationLevel.Unspecified: case IsolationLevel.ReadCommitted: case IsolationLevel.ReadUncommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: case IsolationLevel.Snapshot: Debug.Assert(false, "valid IsolationLevel " + value.ToString()); break; case IsolationLevel.Chaos: break; default: Debug.Assert(false, "invalid IsolationLevel " + value.ToString()); break; } #endif return(NotSupportedEnumerationValue(typeof(IsolationLevel), (int)value)); }
// IDbConnection.BeginTransaction, OleDbTransaction.Begin internal static ArgumentOutOfRangeException InvalidIsolationLevel(IsolationLevel value) { #if DEBUG switch (value) { case IsolationLevel.Unspecified: case IsolationLevel.Chaos: case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: case IsolationLevel.Snapshot: Debug.Fail("valid IsolationLevel " + value.ToString()); break; } #endif return(InvalidEnumerationValue(typeof(IsolationLevel), (int)value)); }
/// <summary> /// Inizia nuova transazione con specifica dell'isolation level /// </summary> /// <param name="level"></param> public void BeginTransaction(IsolationLevel level) { Exception exLog = null; lock (this._GlobalLock) { //Al di fuori del log imposta eventuale pending della transazione if (!this.IsConnectionOpen) { this.pendingTransSet(level); } else { try { this.OpenConnection(); //Crea la nuova transazione (se il db non supporta annidate lancia eccezione) DbTransaction newTran = this.createNewTransaction(level); //Ok esegue accodamento if (this._command.Transaction != null) { this._tranQ.Push(this._command.Transaction); } //Imposta nuova transazione this._command.Transaction = newTran; //Aggiorna stats this._Stats.Increment(DBStats.EStatement.Begin); } catch (Exception ex) { exLog = ex; throw; } finally { this.TraceStatement("BeginTransaction " + level.ToString(), exLog); } } } }
/// <summary> /// 开启事务 /// </summary> /// <param name="isolationLevel">事务级别</param> public IDisposable BeginTransaction(IsolationLevel isolationLevel) { if (null != this.transaction) { throw new InvalidOperationException("已开启事务,不能重复开启!"); } if (this.connection.State != ConnectionState.Open) { this.Open(); } this.transaction = this.Connection.BeginTransaction(isolationLevel); this.tran_version++; if (this.isLog) { this.OnLog("-- BeginTransaction " + isolationLevel.ToString()); } return(new TranRollback(this, this.tran_version)); }
internal IngresTransaction(IngresConnection conn, IsolationLevel level) { switch(level) { case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: break; case IsolationLevel.Unspecified: level = IsolationLevel.ReadCommitted; // default break; default: throw new NotSupportedException( "IngresTransaction(IsolationLevel."+level.ToString()+")"); } _connection = conn; _isolationLevel = level; }
internal IngresTransaction(IngresConnection conn, IsolationLevel level) { switch (level) { case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: break; case IsolationLevel.Unspecified: level = IsolationLevel.ReadCommitted; // default break; default: throw new NotSupportedException( "IngresTransaction(IsolationLevel." + level.ToString() + ")"); } _connection = conn; _isolationLevel = level; }
public static SessionFactoryConfig Isolation(this SessionFactoryConfig config, IsolationLevel isolation) { return(config.Set(Environment.Isolation, isolation.ToString())); }
public void SetIsolationLevel(string typePart, IsolationLevel expected) { var sql = String.Format("SET TRANSACTION ISOLATION LEVEL {0}", typePart); var result = Compile(sql); Assert.IsNotNull(result); Assert.IsFalse(result.HasErrors); Assert.AreEqual(1, result.Statements.Count); var statement = result.Statements.ElementAt(0); Assert.IsNotNull(statement); Assert.IsInstanceOf<SetStatement>(statement); var set = (SetStatement)statement; Assert.AreEqual(TransactionSettingKeys.IsolationLevel, set.SettingName); Assert.IsInstanceOf<SqlConstantExpression>(set.ValueExpression); var value = (SqlConstantExpression)set.ValueExpression; var field = value.Value; Assert.IsInstanceOf<StringType>(field.Type); var s = (SqlString) field.Value; Assert.AreEqual(expected.ToString(), s.ToString()); }
/// to begin a transaction on an existing TDBTransaction object. public void BeginTransaction(TDataBase ADataBase, IsolationLevel AIsolationLevel, string ATransactionName = "") { FTransactionIdentifier = System.Guid.NewGuid(); FTransactionName = ATransactionName; TLogging.LogAtLevel(DBAccess.DB_DEBUGLEVEL_TRANSACTION, "Begin Transaction " + ATransactionName + " in Connection " + ADataBase.ConnectionName + " with level " + AIsolationLevel.ToString("G")); FWrappedTransaction = ADataBase.BeginDbTransaction(AIsolationLevel); FTDataBaseInstanceThatTransactionBelongsTo = ADataBase; FAppDomainThatTransactionWasStartedIn = AppDomain.CurrentDomain; FThreadThatTransactionWasStartedOn = Thread.CurrentThread; FStackTraceAtPointOfTransactionStart = new StackTrace(true); }
static internal Exception UnsupportedIsolationLevel(IsolationLevel isolevel) { return(Argument(Res.GetString(GetCultureInfo(), Res.Odbc_UnsupportedIsolationLevel, isolevel.ToString()))); }
public static void SetIsolationLevel(this System.Data.SqlClient.SqlConnection connection, IsolationLevel isolationLevel) { if (isolationLevel == IsolationLevel.Unspecified || isolationLevel == IsolationLevel.Chaos) { throw new Exception(string.Format("Isolation Level '{0}' can not be set.", isolationLevel.ToString())); } string isolationLevelSqlName; switch (isolationLevel) { case IsolationLevel.Chaos: isolationLevelSqlName = "CHAOS"; break; case IsolationLevel.ReadCommitted: isolationLevelSqlName = "READ COMMITTED"; break; case IsolationLevel.ReadUncommitted: isolationLevelSqlName = "READ UNCOMMITTED"; break; case IsolationLevel.RepeatableRead: isolationLevelSqlName = "REPEATABLE READ"; break; case IsolationLevel.Serializable: isolationLevelSqlName = "SERIALIZABLE"; break; case IsolationLevel.Snapshot: isolationLevelSqlName = "SNAPSHOT"; break; default: isolationLevelSqlName = "UNSPECIFIED"; break; } IDbCommand command = connection.CreateCommand(); command.CommandText = "SET TRANSACTION ISOLATION LEVEL " + isolationLevelSqlName; command.ExecuteNonQuery(); }
public static Settings BuildSettings(IDictionary properties) { Settings settings = new Settings(); Dialect.Dialect dialect = null; try { dialect = Dialect.Dialect.GetDialect(properties); IDictionary temp = new Hashtable(); foreach (DictionaryEntry de in dialect.DefaultProperties) { temp[de.Key] = de.Value; } foreach (DictionaryEntry de in properties) { temp[de.Key] = de.Value; } properties = temp; } catch (HibernateException he) { log.Warn("No dialect set - using GenericDialect: " + he.Message); dialect = new GenericDialect(); } // TODO: SQLExceptionConverter // TODO: should this be enabled? // int statementFetchSize = PropertiesHelper.GetInt32( Environment.StatementFetchSize, properties, -1 ); // if( statementFetchSize != -1 ) // { // log.Info( "JDBC result set fetch size: " + statementFetchSize ); // } int maxFetchDepth = PropertiesHelper.GetInt32(Environment.MaxFetchDepth, properties, -1); if (maxFetchDepth != -1) { log.Info("Maximum outer join fetch depth: " + maxFetchDepth); } //deprecated: bool useOuterJoin = PropertiesHelper.GetBoolean(Environment.UseOuterJoin, properties, true); log.Info("use outer join fetching: " + useOuterJoin); IConnectionProvider connectionProvider = ConnectionProviderFactory.NewConnectionProvider(properties); ITransactionFactory transactionFactory = new TransactionFactory(); // = TransactionFactoryFactory.BuildTransactionFactory(properties); // TransactionManagerLookup transactionManagerLookup = TransactionManagerLookupFactory.GetTransactionManagerLookup( properties ); // Not ported: useGetGeneratedKeys, useScrollableResultSets bool useMinimalPuts = PropertiesHelper.GetBoolean(Environment.UseMinimalPuts, properties, false); log.Info("Optimize cache for minimal puts: " + useMinimalPuts); string defaultSchema = properties[Environment.DefaultSchema] as string; if (defaultSchema != null) { log.Info("Default schema set to: " + defaultSchema); } bool showSql = PropertiesHelper.GetBoolean(Environment.ShowSql, properties, false); if (showSql) { log.Info("echoing all SQL to stdout"); } // queries: IDictionary querySubstitutions = PropertiesHelper.ToDictionary(Environment.QuerySubstitutions, " ,=;:\n\t\r\f", properties); if (log.IsInfoEnabled) { log.Info("Query language substitutions: " + CollectionPrinter.ToString(querySubstitutions)); } string autoSchemaExport = properties[Environment.Hbm2ddlAuto] as string; if ("update" == autoSchemaExport) { settings.IsAutoUpdateSchema = true; } if ("create" == autoSchemaExport) { settings.IsAutoCreateSchema = true; } if ("create-drop" == autoSchemaExport) { settings.IsAutoCreateSchema = true; settings.IsAutoDropSchema = true; } string cacheClassName = PropertiesHelper.GetString(Environment.CacheProvider, properties, "NHibernate.Cache.HashtableCacheProvider"); log.Info("cache provider: " + cacheClassName); try { settings.CacheProvider = ( ICacheProvider )Activator.CreateInstance(ReflectHelper.ClassForName(cacheClassName)); } catch (Exception e) { throw new HibernateException("could not instantiate CacheProvider: " + cacheClassName, e); } bool useQueryCache = PropertiesHelper.GetBoolean(Environment.UseQueryCache, properties); if (useQueryCache) { string queryCacheFactoryClassName = PropertiesHelper.GetString(Environment.QueryCacheFactory, properties, "NHibernate.Cache.StandardQueryCacheFactory"); log.Info("query cache factory: " + queryCacheFactoryClassName); try { settings.QueryCacheFactory = (IQueryCacheFactory)Activator.CreateInstance( ReflectHelper.ClassForName(queryCacheFactoryClassName)); } catch (Exception cnfe) { throw new HibernateException("could not instantiate IQueryCacheFactory: " + queryCacheFactoryClassName, cnfe); } } string sessionFactoryName = ( string )properties[Environment.SessionFactoryName]; // TODO: Environment.BatchVersionedData // TODO: wrapResultSets/DataReaders string isolationString = PropertiesHelper.GetString(Environment.Isolation, properties, String.Empty); IsolationLevel isolation = IsolationLevel.Unspecified; if (isolationString.Length > 0) { try { isolation = ( IsolationLevel )Enum.Parse(typeof(IsolationLevel), isolationString); log.Info("Using Isolation Level: " + isolation.ToString()); } catch (ArgumentException ae) { log.Error("error configuring IsolationLevel " + isolationString, ae); throw new HibernateException( "The isolation level of " + isolationString + " is not a valid IsolationLevel. Please " + "use one of the Member Names from the IsolationLevel.", ae); } } bool prepareSql = PropertiesHelper.GetBoolean(Environment.PrepareSql, properties, false); int cmdTimeout = PropertiesHelper.GetInt32(Environment.CommandTimeout, properties, 0); // Not ported - settings.StatementFetchSize = statementFetchSize; // Not ported - ScrollableResultSetsEnabled // Not ported - GetGeneratedKeysEnabled // Not ported - settings.BatchSize = batchSize; settings.DefaultSchemaName = defaultSchema; settings.IsShowSqlEnabled = showSql; settings.Dialect = dialect; settings.ConnectionProvider = connectionProvider; settings.QuerySubstitutions = querySubstitutions; settings.TransactionFactory = transactionFactory; // Not ported - TransactionManagerLookup settings.SessionFactoryName = sessionFactoryName; settings.IsOuterJoinFetchEnabled = useOuterJoin; settings.MaximumFetchDepth = maxFetchDepth; settings.IsQueryCacheEnabled = useQueryCache; settings.IsMinimalPutsEnabled = useMinimalPuts; // Not ported - JdbcBatchVersionedData // TODO: SQLExceptionConverter // TODO: WrapResultSetsEnabled // NHibernate-specific: settings.IsolationLevel = isolation; settings.PrepareSql = prepareSql; settings.CommandTimeout = cmdTimeout; return(settings); }
/// <summary> /// Initialises a new instance of the <see cref="Transaction" /> class. /// </summary> /// <param name="sessionBase">The session that the transaction is being created for.</param> /// <param name="isolationLevel">The isolation level.</param> internal Transaction(ISessionBase sessionBase, IsolationLevel isolationLevel) { _sessionBase = sessionBase; if (s_log.IsDebug) { s_log.Debug(LogMessages.Transaction_BeginTransactionWithIsolationLevel, isolationLevel.ToString()); } _transaction = _sessionBase.Connection.BeginTransaction(isolationLevel); }
/// <summary> /// Constructor /// </summary> /// <param name="transactionScopeOption">An instance of the System.Transactions.TransactionScopeOption enumeration that describes the transaction requirements associated with this transaction scope.</param> /// <param name="isolationLevel">the isolation level of the transaction.</param> /// <param name="timeout">the timeout period for the transaction.</param> public TransactionScope(TransactionScopeOption transactionScopeOption, IsolationLevel isolationLevel, TimeSpan timeout) { TransactionOptions options = new TransactionOptions(); options.IsolationLevel = (System.Transactions.IsolationLevel)Enum.Parse(typeof(System.Transactions.IsolationLevel), isolationLevel.ToString()); options.Timeout = timeout; System.Transactions.TransactionScopeOption transactionScopeOptionValue = (System.Transactions.TransactionScopeOption)Enum.Parse(typeof(System.Transactions.TransactionScopeOption), transactionScopeOption.ToString()); this.transactionScope = new System.Transactions.TransactionScope(transactionScopeOptionValue, options); TransactionScopeContext.Increase(); }
void System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter writer) { writer.WriteAttributeString("xmlns", "i", null, Namespaces.SchemaInstance); writer.WriteAttributeString("xmlns", "q", null, Namespaces.Query); writer.WriteAttributeString("Id", _id.ToString()); writer.WriteAttributeString("Method", _method.ToString()); writer.WriteAttributeString("StoredProcedureProvider", _storedProcedureProvider ?? ""); writer.WriteAttributeString("IsSelectDistinct", IsSelectDistinct.ToString()); writer.WriteAttributeString("IgnoreRegisterUserInfo", IgnoreRegisterUserInfo.ToString()); writer.WriteAttributeString("IsolationLevel", IsolationLevel.ToString()); writer.WriteAttributeString("CommandTimeout", CommandTimeout.ToString()); writer.WriteAttributeString("ProviderName", ProviderName.ToString()); writer.WriteAttributeString("IgnoreTypeSchema", IgnoreTypeSchema.ToString()); WriteItem <Projection>(writer, "Projection", _projection); WriteItem <QueryExecutePredicate>(writer, "ExecutePredicate", _executePredicate); writer.WriteStartElement("Entities", Namespaces.Query); if (_entities != null) { foreach (System.Xml.Serialization.IXmlSerializable i in _entities) { writer.WriteStartElement("EntityInfo", Namespaces.Query); i.WriteXml(writer); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteStartElement("Joins", Namespaces.Query); if (_joins != null) { foreach (System.Xml.Serialization.IXmlSerializable i in _joins) { writer.WriteStartElement("JoinInfo", Namespaces.Query); i.WriteXml(writer); writer.WriteEndElement(); } } writer.WriteEndElement(); WriteItem <ConditionalContainer>(writer, "Where", _whereClause); WriteItem <Sort>(writer, "Sort", _sort); WriteItem <GroupBy>(writer, "GroupBy", _groupby); WriteItem <ConditionalContainer>(writer, "Having", _having); WriteItem <TakeParameters>(writer, "TakeParameters", _takeParameters); writer.WriteStartElement("NestedQueries", Namespaces.Query); if (_nestedQueries != null) { foreach (System.Xml.Serialization.IXmlSerializable i in _nestedQueries) { writer.WriteStartElement("QueryInfo", Namespaces.Query); i.WriteXml(writer); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteStartElement("Parameters", Namespaces.Query); if (_parameters != null) { foreach (System.Xml.Serialization.IXmlSerializable i in _parameters) { writer.WriteStartElement("QueryParameter", Namespaces.Query); i.WriteXml(writer); writer.WriteEndElement(); } } writer.WriteEndElement(); WriteItem <StoredProcedureName>(writer, "StoredProcedureName", _storedProcedureName ?? StoredProcedureName.Empty); writer.WriteStartElement("Unions", Namespaces.Query); if (_unions != null) { foreach (System.Xml.Serialization.IXmlSerializable i in _unions) { writer.WriteStartElement("Union", Namespaces.Query); i.WriteXml(writer); writer.WriteEndElement(); } } writer.WriteEndElement(); }
// IDbConnection.BeginTransaction, OleDbTransaction.Begin static internal ArgumentOutOfRangeException InvalidIsolationLevel(IsolationLevel value) { #if DEBUG switch (value) { case IsolationLevel.Unspecified: case IsolationLevel.Chaos: case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: case IsolationLevel.Snapshot: Debug.Fail("valid IsolationLevel " + value.ToString()); break; } #endif return InvalidEnumerationValue(typeof(IsolationLevel), (int)value); }
public IConnectionConfiguration With(IsolationLevel level) { dbc.Configuration.SetProperty(Environment.Isolation, level.ToString()); return(this); }
override internal void ExecuteTransaction( TransactionRequest transactionRequest, string transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, bool isDelegateControlRequest) { if (Bid.AdvancedOn) { Bid.Trace("<sc.SqlInternalConnectionSmi.ExecuteTransaction|ADV> %d#, transactionRequest=%ls, transactionName='%ls', isolationLevel=%ls, internalTransaction=#%d transactionId=0x%I64x.\n", base.ObjectID, transactionRequest.ToString(), (null != transactionName) ? transactionName : "null", iso.ToString(), (null != internalTransaction) ? internalTransaction.ObjectID : 0, (null != internalTransaction) ? internalTransaction.TransactionId : SqlInternalTransaction.NullTransactionId ); } switch (transactionRequest) { case TransactionRequest.Begin: try { _pendingTransaction = internalTransaction; // store this for the time being. _smiConnection.BeginTransaction(transactionName, iso, _smiEventSink); } finally { _pendingTransaction = null; } Debug.Assert(_smiEventSink.HasMessages || null != _currentTransaction, "begin transaction without TransactionStarted event?"); break; case TransactionRequest.Commit: Debug.Assert(null != _currentTransaction, "commit transaction without TransactionStarted event?"); _smiConnection.CommitTransaction(_currentTransaction.TransactionId, _smiEventSink); break; case TransactionRequest.Promote: Debug.Assert(null != _currentTransaction, "promote transaction without TransactionStarted event?"); PromotedDTCToken = _smiConnection.PromoteTransaction(_currentTransaction.TransactionId, _smiEventSink); break; case TransactionRequest.Rollback: case TransactionRequest.IfRollback: Debug.Assert(null != _currentTransaction, "rollback/ifrollback transaction without TransactionStarted event?"); _smiConnection.RollbackTransaction(_currentTransaction.TransactionId, transactionName, _smiEventSink); break; case TransactionRequest.Save: Debug.Assert(null != _currentTransaction, "save transaction without TransactionStarted event?"); _smiConnection.CreateTransactionSavePoint(_currentTransaction.TransactionId, transactionName, _smiEventSink); break; default: Debug.Assert (false, "unhandled case for TransactionRequest"); break; } _smiEventSink.ProcessMessagesAndThrow(); }
override internal void ExecuteTransaction( TransactionRequest transactionRequest, string transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, bool isDelegateControlRequest) { SqlClientEventSource.Log.AdvanceTrace("<sc.SqlInternalConnectionSmi.ExecuteTransaction|ADV> {0}#, transactionRequest={1}, " + "transactionName='{2}', isolationLevel={3}, internalTransaction=#{4} transactionId=0x{5}.", ObjectID, transactionRequest.ToString(), transactionName ?? "null", iso.ToString(), (null != internalTransaction) ? internalTransaction.ObjectID : 0, (null != internalTransaction) ? internalTransaction.TransactionId : SqlInternalTransaction.NullTransactionId); switch (transactionRequest) { case TransactionRequest.Begin: try { _pendingTransaction = internalTransaction; // store this for the time being. _smiConnection.BeginTransaction(transactionName, iso, _smiEventSink); } finally { _pendingTransaction = null; } Debug.Assert(_smiEventSink.HasMessages || null != _currentTransaction, "begin transaction without TransactionStarted event?"); break; case TransactionRequest.Commit: Debug.Assert(null != _currentTransaction, "commit transaction without TransactionStarted event?"); _smiConnection.CommitTransaction(_currentTransaction.TransactionId, _smiEventSink); break; case TransactionRequest.Promote: Debug.Assert(null != _currentTransaction, "promote transaction without TransactionStarted event?"); PromotedDTCToken = _smiConnection.PromoteTransaction(_currentTransaction.TransactionId, _smiEventSink); break; case TransactionRequest.Rollback: case TransactionRequest.IfRollback: Debug.Assert(null != _currentTransaction, "rollback/ifrollback transaction without TransactionStarted event?"); _smiConnection.RollbackTransaction(_currentTransaction.TransactionId, transactionName, _smiEventSink); break; case TransactionRequest.Save: Debug.Assert(null != _currentTransaction, "save transaction without TransactionStarted event?"); _smiConnection.CreateTransactionSavePoint(_currentTransaction.TransactionId, transactionName, _smiEventSink); break; default: Debug.Assert(false, "unhandled case for TransactionRequest"); break; } _smiEventSink.ProcessMessagesAndThrow(); }
/// <summary> /// 开始事务处理功能,之后执行的全部数据库操作语句需要调用提交函数(_commit)生效 /// </summary> internal bool StartTran(IsolationLevel isolationLevel) { //若连接数据库失败抛出错误 if (!ConnectDataBase()) { throw(new ApplicationException("没有建立数据库连接。")); } if (!IsTran) { if (_db.SqlOutputer.HasOutput) { OutMessage(MessageType.OtherOper, "BeginTransaction", null, "Level=" + isolationLevel.ToString()); } _tran = _conn.BeginTransaction(isolationLevel); _comm.Transaction = _tran; return(true); } return(false); }