internal void UseTransaction([InstantHandle] Action <SessionWrapper> action, IsolationLevel?isolationLevel = null) { UseTransaction(session => { action(session); return(true); }, isolationLevel ?? Options.TransactionIsolationLevel); }
public void SaveChanged() { //生成数据库适配器 foreach (var x in p_ComponentServices) { p_ComponentDatabaseContainer.GetDatabaseAdptor(x); } //开始事务 var xxx = p_ComponentDatabaseContainer.GeneratesAdptor; if (xxx != null) { IsolationLevel?al = TransactionLevel; foreach (var g in xxx) { if (al != null && al.HasValue) { g.BeginTransaction(al.Value); } else { g.BeginTransaction(); } } } try { //保存更新 foreach (var x in p_ComponentServices) { SaveChanged(x); x.SuccessUpdate(); } //提交事务 if (xxx != null) { foreach (var g in xxx) { g.CommitTran(); } } } catch (Exception e) { //回滚事务 if (xxx != null) { foreach (var g in xxx) { g.RollbackTran(); } } throw new Exception(e.Message, e); } }
/// <summary> 执行事务(新开连接) </summary> /// <param name="action"></param> /// <param name="level"></param> /// <param name="connectionName"></param> protected void Transaction(Action <IDbConnection, IDbTransaction> action, string connectionName = null, IsolationLevel?level = null) { Transaction((conn, trans) => { action.Invoke(conn, trans); return(true); }, connectionName, level); }
public NoOpTransaction(IsolationLevel?isolation = null) { this.isolation = isolation ?? IsolationLevel.Unspecified; if (isolation != null) { this.isolation = isolation.Value; } }
public SessionConnectionCollection(bool readOnly, IsolationLevel?isolationLevel, ISessionConnectionFactory factory, ISessionExceptionHandler exceptionHandler) { _readOnly = readOnly; _isolationLevel = isolationLevel; _factory = factory; _exceptionHandler = exceptionHandler; InitializedConnections = new Dictionary <Type, ISessionConnection>(); _transactions = new Dictionary <ISessionConnection, IDbTransaction>(); }
public void RunInTransaction( Action <DbConnection, DbTransaction> action, IsolationLevel?isolationLevel = null) { RunInTransaction((connection, transaction) => { action(connection, transaction); return(true); }, isolationLevel); }
public Task RunInTransactionAsync( Func <DbConnection, DbTransaction, Task> func, IsolationLevel?isolationLevel = null) { return(RunInTransactionAsync(async(connection, transaction) => { await func(connection, transaction); return true; }, isolationLevel)); }
public DbContextHolder(bool isReadonly, IsolationLevel?isolationLevel, IDbContextFactory dbContextFactory = null) { _isReadonly = isReadonly; _isolationLevel = isolationLevel; _dbContextFactory = dbContextFactory; _isDisposed = false; _instantiatedDbContextCollection = new Dictionary <Type, DbContext>(); _instantiatedDbContextTransaction = new Dictionary <DbContext, IDbContextTransaction>(); }
internal NonAmbientDbContextScope(DbContextOption.Mode mode, IsolationLevel?isolationLevel, DbTransaction dbTransaction, DbConnection sqlConnection, AmbientDbContextHouseKeeper ambientDbContextHouseKeeper) : base(mode, isolationLevel, dbTransaction, sqlConnection) { _ambientDbContextHouseKeeper = ambientDbContextHouseKeeper; }
/// <summary> /// 开启事务 /// </summary> /// <param name="isolationLevel"></param> public void BeginTransaction(IsolationLevel?isolationLevel = null) { IsBeginCalled(); Transaction = Connection.BeginTransaction(); if (isolationLevel.HasValue) { Transaction = Connection.BeginTransaction(isolationLevel.Value); } }
public IContextBuilder UseTransaction(IsolationLevel il) { if (IsOpen) { throw ExecutionContextException.ConnectionAlreadyOpen(); } _isolationLevel = il; return(this); }
public void RunInTransaction( Action <DbConnection, DbTransaction> action, IsolationLevel?isolationLevel) { RunInTransaction((_1, _2) => { action(_1, _2); return(true); }, isolationLevel); }
public Task RunInTransactionAsync( Func <DbConnection, DbTransaction, Task> func, IsolationLevel?isolationLevel) { return(RunInTransactionAsync((_1, _2) => { func(_1, _2).GetAwaiter().GetResult(); return Task.FromResult(true); }, isolationLevel)); }
public NHibernateTransaction(ISession session, IsolationLevel?isolation = null) { Assertion.NotNull(session); this.session = session; this.transaction = isolation != null?session.BeginTransaction(isolation.Value) : session.BeginTransaction(); this.isolation = isolation ?? IsolationLevel.Unspecified; }
private TransactionScope CreateTransaction(IsolationLevel?isolationLevel) { return(isolationLevel != null ? new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = isolationLevel.Value, Timeout = _options.TransactionTimeout }) : new TransactionScope()); }
public DbContextCollection(IsolationLevel?isolationLevel = null) { _disposed = false; _completed = false; InitializedDbContexts = new Dictionary <Type, DbContext>(); _transactions = new Dictionary <DbContext, DbContextTransaction>(); _isolationLevel = isolationLevel; }
internal T UseTransaction <T>( [InstantHandle] Func <MySqlConnection, T> func, IsolationLevel?isolationLevel) { return(UseConnection(connection => { T result = func(connection); return result; })); }
/// <summary> /// Get system isolation level by data isolation level /// </summary> /// <param name="dataIsolationLevel">Data isolation level</param> /// <returns>Return system data isolation level</returns> internal static IsolationLevel?GetSystemIsolationLevel(DataIsolationLevel?dataIsolationLevel) { IsolationLevel?isolationLevel = null; if (dataIsolationLevel.HasValue && SystemDataIsolationLevelMaps.ContainsKey(dataIsolationLevel.Value)) { isolationLevel = SystemDataIsolationLevelMaps[dataIsolationLevel.Value]; } return(isolationLevel); }
private void Initialize(Database database, String transactionKey, IsolationLevel?isolationLevel) { this.TransactionKey = transactionKey; this.Database = database; DatabaseContext.SetDatabaseContext(this.TransactionKey, this); if (isolationLevel.HasValue == true) { this.BeginTransaction(isolationLevel.Value); } }
internal T UseTransaction <T>([InstantHandle] Func <SessionWrapper, T> func, IsolationLevel?isolationLevel = null) { using (var transaction = CreateTransaction(isolationLevel ?? Options.TransactionIsolationLevel)) { var result = UseSession(func); transaction.Complete(); return(result); } }
private IsolationLevel?FixIsolationLevelForOracle(IsolationLevel?isolationLevel) { if ((ProviderType == ProviderTypeEnum.OracleClient9 || ProviderType == ProviderTypeEnum.OracleClient9Managed || ProviderType == ProviderTypeEnum.OracleClient10 || ProviderType == ProviderTypeEnum.OracleClient10Managed) && (isolationLevel != IsolationLevel.ReadCommitted || isolationLevel != IsolationLevel.Serializable)) { isolationLevel = IsolationLevel.ReadCommitted; } return(isolationLevel); }
/// <summary> /// get system isolation level by data isolation level /// </summary> /// <param name="dataIsolationLevel">data isolation level</param> /// <returns></returns> public static IsolationLevel?GetSystemIsolationLevel(DataIsolationLevel?dataIsolationLevel) { IsolationLevel?isolationLevel = null; if (dataIsolationLevel.HasValue && DataIsolationLevelMapCollection.ContainsKey(dataIsolationLevel.Value)) { isolationLevel = DataIsolationLevelMapCollection[dataIsolationLevel.Value]; } return(isolationLevel); }
public DbContextCollection(bool readOnly = false, IsolationLevel?isolationLevel = null, IDbContextFactory dbContextFactory = null) { _disposed = _completed = false; _initializedDbContexts = new Dictionary <Type, DbContext>(); _transactions = new Dictionary <DbContext, DbContextTransaction>(); _readOnly = readOnly; _isolationLevel = isolationLevel; _dbContextFactory = dbContextFactory; }
internal T UseTransaction <T>([InstantHandle] Func <SqlConnection, T> func, IsolationLevel?isolationLevel) { using (var transaction = CreateTransaction(isolationLevel ?? _options.TransactionIsolationLevel)) { var result = UseConnection(func); transaction.Complete(); return(result); } }
public DbContext NewDbContext(IsolationLevel?level = null) { DbContext dc = new DbContext(this); if (level != null) { dc.Begin(level.Value); } return(dc); }
public static IsolationLevel?GetIsolationLevelFromObject <T>(object obj) { IsolationLevel?isolationLevel = null; if (obj is T) { isolationLevel = ((dynamic)(T)obj).IsolationLevel; } return(isolationLevel); }
public IDbTransaction BeginTransaction(IsolationLevel?isolationLevel = null) { IDbTransaction transaction = isolationLevel.HasValue ? _connection.BeginTransaction(isolationLevel.Value) : _connection.BeginTransaction(); _transactions.Push(transaction); return(new TransactionScope(transaction, () => _transactions.Pop())); }
/// <summary> /// 初始化 <see cref="DbContextBase"/> 类的新实例 /// <param name="connString">数据库连接字符串</param> /// <param name="commandTimeout">执行命令超时时间</param> /// </summary> public DbContextBase(string connString, int?commandTimeout) { XFrameworkException.Check.NotNull(connString, nameof(connString)); _connString = connString; _commandTimeout = commandTimeout; _isDebug = false; _isolationLevel = null; _provider = (DbQueryProvider)this.Provider; }
/// <summary> /// Creates a new <see cref="UnitOfWorkAttribute"/> object. /// </summary> /// <param name="scope">Transaction scope</param> /// <param name="isolationLevel">Transaction isolation level</param> /// <param name="isTransactional"/> /// <param name="timeout">Transaction timeout as milliseconds</param> public UnitOfWorkAttribute(TransactionScopeOption scope, IsolationLevel?isolationLevel, bool isTransactional, int timeout) { Scope = scope; if (isolationLevel.HasValue) { this.IsolationLevel = isolationLevel; } IsTransactional = isTransactional; Timeout = TimeSpan.FromMilliseconds(timeout); }
/// <summary> /// 开启事务 /// </summary> /// <param name="con"></param> /// <param name="level"></param> /// <returns></returns> public static IDbTransaction StartTransaction(this IDbConnection con, IsolationLevel?level = null) { if (level == null) { return(con.BeginTransaction()); } else { return(con.BeginTransaction(level.Value)); } }
public SQLiteWriteOnlyTransaction( IDbConnection connection, IsolationLevel? isolationLevel, PersistentJobQueueProviderCollection queueProviders) { if (connection == null) throw new ArgumentNullException("connection"); if (queueProviders == null) throw new ArgumentNullException("queueProviders"); _connection = connection; _isolationLevel = isolationLevel; _queueProviders = queueProviders; }
public SQLiteConnection( IDbConnection connection, IsolationLevel? isolationLevel, PersistentJobQueueProviderCollection queueProviders, bool ownsConnection) { if (connection == null) throw new ArgumentNullException("connection"); if (queueProviders == null) throw new ArgumentNullException("queueProviders"); _connection = connection; _isolationLevel = isolationLevel; _queueProviders = queueProviders; OwnsConnection = ownsConnection; }
/// <summary> /// Constructor. Sets DBMS type and connection string. /// </summary> /// <param name="dbmsType">DBMS type to which this provider connects to. Only Oracle compatibile values are allowed.</param> /// <param name="connectionString">Connection string.</param> /// <param name="defaultTransactionIsolationLevel">Isolation level for transactions started by the parameterless <see cref="BeginTransaction()"/> method overload.</param> public OracleConnectionProvider(DbmsType dbmsType, string connectionString, IsolationLevel defaultTransactionIsolationLevel) : this(dbmsType, connectionString) { this.defaultTransactionIsolationLevel = defaultTransactionIsolationLevel; }
/// <summary> /// Creates a new instance of <see cref="DatabaseUploadStreamProviderBase" /> class with the specified settings. /// </summary> /// <param name="settings">The <see cref="UploadStreamProviderElement" /> object that holds the configuration settings.</param> protected DatabaseUploadStreamProviderBase(UploadStreamProviderElement settings) : base(settings) { string connectionStringName = Settings.Parameters["connectionStringName"]; if (!string.IsNullOrEmpty(connectionStringName)) _connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString; else _connectionString = Settings.Parameters["connectionString"]; if (string.IsNullOrEmpty(_connectionString)) throw new Exception("uploadStreamProvider connectionString or connectionStringName attribute must be specified."); _table = Settings.Parameters["table"]; _keyField = Settings.Parameters["keyField"]; _dataField = Settings.Parameters["dataField"]; _fileNameField = Settings.Parameters["fileNameField"]; if (string.IsNullOrEmpty(_table)) throw new Exception("uploadStreamProvider table attribute must be specified."); if (string.IsNullOrEmpty(_keyField)) throw new Exception("uploadStreamProvider keyField attribute must be specified."); if (string.IsNullOrEmpty(_dataField)) throw new Exception("uploadStreamProvider dataField attribute must be specified."); // TODO: throw exception for missing parameters bool.TryParse(Settings.Parameters["useInsertTransaction"], out _useInsertTransaction); string isolationLevelString = Settings.Parameters["useInsertTransaction"]; if (!string.IsNullOrEmpty(isolationLevelString)) _isolationLevel = (IsolationLevel)Enum.Parse(typeof(IsolationLevel), isolationLevelString, true); }
public IDbTransaction BeginTransaction(IsolationLevel il) { transaction = new ReplicationTransaction(this, il); this.il = il; return transaction; }