/// <summary> /// Constructor default. /// </summary> public NHSessionWrapper() { log.Debug("Construyendo NHSessionWrapper..."); this.session = null; this.flushMode = FlushMode.Auto; }
public NamedSQLQueryDefinition( string query, INativeSQLQueryReturn[] queryReturns, IList<string> querySpaces, bool cacheable, string cacheRegion, int timeout, int fetchSize, FlushMode flushMode, CacheMode? cacheMode, bool readOnly, string comment, IDictionary<string, string> parameterTypes, bool callable) : base( query.Trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */ cacheable, cacheRegion, timeout, fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes ) { this.queryReturns = queryReturns; this.querySpaces = querySpaces; this.callable = callable; }
public NamedSQLQueryDefinition( string query, string resultSetRef, IList querySpaces, bool cacheable, string cacheRegion, int timeout, int fetchSize, FlushMode flushMode, //CacheMode cacheMode, bool readOnly, string comment, IDictionary parameterTypes, bool callable) : base( query.Trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */ cacheable, cacheRegion, timeout, fetchSize, flushMode, //cacheMode, readOnly, comment, parameterTypes ) { this.resultSetRef = resultSetRef; this.querySpaces = querySpaces; this.callable = callable; }
public void SetUp() { mocks = new MockRepository(); expectedSessionFactory = mocks.StrictMock<ISessionFactory>(); expectedEntityInterceptor = mocks.StrictMock<IInterceptor>(); expectedSingleSession = SessionScopeSettings.SINGLESESSION_DEFAULT; expectedDefaultFlushMode = SessionScopeSettings.FLUSHMODE_DEFAULT; }
public ISession OpenSession(FlushMode flushMode, bool? defaultReadOnly) { var session = SessionProvider.OpenSession(flushMode, defaultReadOnly); sessionRepository.Add(session); return session; }
/// <summary> /// Implementors should start the /// transaction on the underlying resource /// </summary> public void Start() { transaction = session.BeginTransaction(level); if (isReadOnly) { previousFlushMode = session.FlushMode; session.FlushMode = FlushMode.Never; } }
/// <summary> /// Initialize a new instance of <see cref="SessionScopeSettings"/> with default values. /// </summary> /// <remarks> /// Calling this constructor from your derived class leaves <see cref="SessionFactory"/> and <see cref="EntityInterceptor"/> /// uninitialized. See <see cref="ResolveSessionFactory"/> and <see cref="ResolveEntityInterceptor"/> for more. /// </remarks> protected SessionScopeSettings() { this.sessionFactory = null; this.sessionFactoryInitialized = false; this.entityInterceptor = null; this.entityInterceptorInitialized = false; this.singleSession = SINGLESESSION_DEFAULT; this.defaultFlushMode = FLUSHMODE_DEFAULT; }
public PersistenceContainerExtension(bool batch, string connectionName) { // auto allows speed up mass create / update operations // but cause auto database update before each count operation, // so in auto mode we have problem with validation: // change value - validate - validate cause count() operation - auto flush occured - database constraint // that is why in application server we need auto mode this.flushMode = batch ? FlushMode.Auto : FlushMode.Commit; this.connectionName = connectionName; }
/// <summary> /// Allows you to register an interceptor on a new session. This may not be called if there is already /// an open session attached to the HttpContext. If you have an interceptor to be used, modify /// the HttpModule to call this before calling BeginTransaction(). /// </summary> public void RegisterInterceptorOn(string sessionFactoryConfigPath, FlushMode flushMode, IInterceptor interceptor) { var session = (ISession)ContextSessions[sessionFactoryConfigPath]; if (session != null && session.IsOpen) { throw new CacheException("You cannot register an interceptor once a session has already been opened"); } GetSessionFrom(sessionFactoryConfigPath, flushMode, interceptor); }
public ISession OpenSession(FlushMode flushMode, bool? defaultReadOnly) { var result = SessionFactory.OpenSession(new CommonSessionLocalInterceptor()); result.FlushMode = flushMode; if (defaultReadOnly.HasValue) { result.DefaultReadOnly = defaultReadOnly.Value; } return result; }
/// <summary> /// Apply the flush mode that's been specified for this accessor /// to the given Session. /// </summary> /// <param name="session">The current Hibernate Session.</param> /// <param name="existingTransaction">if set to <c>true</c> /// if executing within an existing transaction.</param> /// <returns> /// the previous flush mode to restore after the operation, /// or <code>null</code> if none /// </returns> protected FlushModeHolder ApplyFlushMode(ISession session, bool existingTransaction) { if (TemplateFlushMode == TemplateFlushMode.Never) { if (existingTransaction) { FlushMode previousFlushMode = session.FlushMode; if (previousFlushMode != FlushMode.Never) { session.FlushMode = FlushMode.Never; return(new FlushModeHolder(previousFlushMode)); } } else { session.FlushMode = FlushMode.Never; } } else if (TemplateFlushMode == TemplateFlushMode.Eager) { if (existingTransaction) { FlushMode previousFlushMode = session.FlushMode; if (previousFlushMode != FlushMode.Auto) { session.FlushMode = FlushMode.Auto; return(new FlushModeHolder(previousFlushMode)); } } else { // rely on default FlushMode.AUTO } } else if (TemplateFlushMode == TemplateFlushMode.Commit) { if (existingTransaction) { FlushMode previousFlushMode = session.FlushMode; if (previousFlushMode == FlushMode.Auto) { session.FlushMode = FlushMode.Commit; return(new FlushModeHolder(previousFlushMode)); } } else { session.FlushMode = FlushMode.Commit; } } return(new FlushModeHolder()); }
/// <summary> /// .يک "تراکنش" برمي گرداند. اين نمونه براي تمام زمان زندگي درخواست يکسان خواهد بود /// so it's not thread-safe /// </summary> public ITransaction BeginTransactionOn(FlushMode flushMode, IsolationLevel isolationLevel = IsolationLevel.ReadUncommitted) { ITransaction transaction = (ITransaction)ContextTransaction; IDisposable ds = (IDisposable)transaction; if (transaction == null) { this.GetSession().FlushMode = flushMode; transaction = this.GetSession().BeginTransaction(isolationLevel); ContextTransaction = transaction; } return(transaction); }
protected void After() { if (sessionFlushMode != FlushMode.Unspecified) { Session.FlushMode = sessionFlushMode; sessionFlushMode = FlushMode.Unspecified; } if (sessionCacheMode.HasValue) { Session.CacheMode = sessionCacheMode.Value; sessionCacheMode = null; } }
protected void Before() { if (flushMode != FlushMode.Unspecified) { sessionFlushMode = Session.FlushMode; Session.FlushMode = flushMode; } if (cacheMode.HasValue) { sessionCacheMode = Session.CacheMode; Session.CacheMode = cacheMode.Value; } }
public ISession OpenSession(FlushMode flushMode, bool?defaultReadOnly) { var result = SessionFactory.OpenSession(new CommonSessionLocalInterceptor()); result.FlushMode = flushMode; if (defaultReadOnly.HasValue) { result.DefaultReadOnly = defaultReadOnly.Value; } return(result); }
public void Flush(FlushMode mode) { if (_bufferWritePointer > 0) { Stream.Write(_buffer.AsSpan(0, _bufferWritePointer)); _bufferWritePointer = 0; if (mode == FlushMode.Deep) { Stream.Flush(); } } }
/// <summary> /// Initializes a new instance of the <see cref="UnitOfWork"/> class. /// </summary> /// <param name="dataSessionProvider">The data session provider.</param> /// <param name="activeDataSessionManager">The active data session manager.</param> /// <param name="flushMode">The flush mode.</param> /// <param name="isolationLevel">The isolation level.</param> /// <param name="unitOfWorkBatchMode">The unit of work batch mode.</param> public UnitOfWork( IDataSessionProvider <ISession> dataSessionProvider, IActiveDataSessionManager <ISession> activeDataSessionManager, FlushMode flushMode = FlushMode.Auto, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, UnitOfWorkBatchMode unitOfWorkBatchMode = UnitOfWorkBatchMode.Singular) { this.dataSessionProvider = dataSessionProvider; this.activeDataSessionManager = activeDataSessionManager; this.flushMode = flushMode; this.isolationLevel = isolationLevel; this.UnitOfWorkBatchMode = unitOfWorkBatchMode; }
internal override void ChangeFlushModeOnConversationStopsSpan(IEnumerable <SessionAndTransactionManager> sms) { foreach (SessionAndTransactionManager sm in sms) { FlushMode fm = sm.GetFlushMode(); if (fm != FlushMode.Never) { throw new Exceptions.IllegalFlushModeException( fm + " is illegal in business transaction. " + "When doing Business transaction, you should not change FlushMode."); } sm.SetFlushMode(FlushMode.Auto); } }
public void CanSetCommentBeforeSkipOnOrderedPageQuery( [Values(FlushMode.Always, FlushMode.Auto, FlushMode.Commit, FlushMode.Manual)] FlushMode flushMode) { Sfi.Statistics.Clear(); using (var t = session.BeginTransaction()) { var customer = db.Customers.First(); customer.CompanyName = "Blah"; var unused = db.Customers .OrderBy(c => c.CompanyName) .Skip(5).Take(5) .WithOptions(o => o.SetFlushMode(flushMode)) .ToList(); var expectedFlushCount = 0; switch (flushMode) { case FlushMode.Always: case FlushMode.Auto: expectedFlushCount++; break; } Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(expectedFlushCount), "Unexpected flush count on same entity query"); customer.CompanyName = "Other blah"; var dummy = db.Orders .OrderBy(o => o.OrderId) .Skip(5).Take(5) .WithOptions(o => o.SetFlushMode(flushMode)) .ToList(); switch (flushMode) { case FlushMode.Always: expectedFlushCount++; break; } Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(expectedFlushCount), "Unexpected flush count on other entity query"); // Tests here should not alter data, LinqTestCase derives from ReadonlyTestCase t.Rollback(); } }
public IUnitOfWorkTransaction Begin( IsolationLevel isolationLevel = IsolationLevel.ReadUncommitted, FlushMode flushMode = FlushMode.Commit) { if (this.ThereIsATransactionInProgress) { this.transaction.Dispose(); } this.session = this.sessionBuilder.GetSession(); this.session.FlushMode = flushMode; this.transaction = this.session.BeginTransaction(isolationLevel); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="NHibernateHelper"/> class. /// </summary> /// <param name="factoryName">Name of the factory.</param> /// <param name="flushMode">The flush mode.</param> /// <param name="logger">The logger.</param> public NHibernateHelper(string factoryName, FlushMode flushMode, ILog logger) { try { _disposed = false; _logger = logger; CurrentSession = SessionFactories[factoryName].OpenSession(); CurrentSession.FlushMode = flushMode; } catch (Exception ex) { _logger.Error("Error Hibernate Helper", ex); throw; } }
/// <summary> /// Initializes a new instance of the <see cref="NHibernateHelper"/> class. /// </summary> /// <param name="factoryName">Name of the factory.</param> /// <param name="flushMode">The flush mode.</param> /// <param name="logger">The logger.</param> public NHibernateHelper(string factoryName, FlushMode flushMode, ILog logger) { try { _disposed = false; _logger = logger; CurrentSession = SessionFactories[factoryName].OpenSession(); CurrentSession.FlushMode = flushMode; } catch (Exception ex) { _logger.Error("Error Hibernate Helper", ex); throw; } }
public async Task CanSetCommentOnPagingQueryAsync( [Values(FlushMode.Always, FlushMode.Auto, FlushMode.Commit, FlushMode.Manual)] FlushMode flushMode) { Sfi.Statistics.Clear(); using (var t = session.BeginTransaction()) { var customer = await(db.Customers.FirstAsync()); customer.CompanyName = "Blah"; var unused = await(db.Customers .Skip(1).Take(1) .WithOptions(o => o.SetFlushMode(flushMode)) .ToListAsync()); var expectedFlushCount = 0; switch (flushMode) { case FlushMode.Always: case FlushMode.Auto: expectedFlushCount++; break; } Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(expectedFlushCount), "Unexpected flush count on same entity query"); customer.CompanyName = "Other blah"; var dummy = await(db.Orders .Skip(1).Take(1) .WithOptions(o => o.SetFlushMode(flushMode)) .ToListAsync()); switch (flushMode) { case FlushMode.Always: expectedFlushCount++; break; } Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(expectedFlushCount), "Unexpected flush count on other entity query"); // Tests here should not alter data, LinqTestCase derives from ReadonlyTestCase await(t.RollbackAsync()); } }
public void Flush(FlushMode mode) { switch (mode) { case FlushMode.Input: var temp = new byte[BytesToRead]; Read(temp, 0, temp.Length); break; case FlushMode.Output: outputBuffer.Clear(); break; default: Flush(FlushMode.Input); Flush(FlushMode.Output); break; } }
public IQuery SetFlushMode(FlushMode flushMode) { IQueryEvent queryEvent = new SetFlushModeEvent(flushMode); foreach (IShard shard in shards) { if (shard.GetQueryById(queryId) != null) { shard.GetQueryById(queryId).SetFlushMode(flushMode); } else { shard.AddQueryEvent(queryId, queryEvent); } } return(this); }
public ICriteria SetFlushMode(FlushMode flushMode) { ICriteriaEvent criteriaEvent = new SetFlushModeEvent(flushMode); foreach (IShard shard in shards) { if (shard.GetCriteriaById(criteriaId) != null) { shard.GetCriteriaById(criteriaId).SetFlushMode(flushMode); } else { shard.AddCriteriaEvent(criteriaId, criteriaEvent); } } return(this); }
public ICriteria SetFlushMode(FlushMode flushMode) { ICriteriaEvent criteriaEvent = new SetFlushModeEvent(flushMode); foreach (IShard shard in shards) { if (shardToCriteriaMap[shard] != null) { shardToCriteriaMap[shard].SetFlushMode(flushMode); } else { shardToEventListMap[shard].Add(criteriaEvent); } } return(this); }
public MemoryMapPager(string file, FlushMode flushMode = FlushMode.Full) { _flushMode = flushMode; var fileInfo = new FileInfo(file); var hasData = fileInfo.Exists == false || fileInfo.Length == 0; _fileStream = fileInfo.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); if (hasData) { NumberOfAllocatedPages = 0; } else { NumberOfAllocatedPages = fileInfo.Length / PageSize; PagerState.Release(); PagerState = CreateNewPagerState(); } }
public void AddSqlQuery(HbmSqlQuery querySchema) { mappings.AddSecondPass(delegate { string queryName = querySchema.name; string queryText = querySchema.GetText(); bool cacheable = querySchema.cacheable; string region = querySchema.cacheregion; int timeout = string.IsNullOrEmpty(querySchema.timeout) ? RowSelection.NoValue : int.Parse(querySchema.timeout); int fetchSize = querySchema.fetchsizeSpecified ? querySchema.fetchsize : -1; bool readOnly = querySchema.readonlySpecified ? querySchema.@readonly : false; string comment = null; bool callable = querySchema.callable; string resultSetRef = querySchema.resultsetref; FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema); CacheMode?cacheMode = (querySchema.cachemodeSpecified) ? querySchema.cachemode.ToCacheMode() : null; IDictionary <string, string> parameterTypes = new LinkedHashMap <string, string>(); IList <string> synchronizedTables = GetSynchronizedTables(querySchema); NamedSQLQueryDefinition namedQuery; if (string.IsNullOrEmpty(resultSetRef)) { ResultSetMappingDefinition definition = new ResultSetMappingBinder(Mappings).Create(querySchema); namedQuery = new NamedSQLQueryDefinition(queryText, definition.GetQueryReturns(), synchronizedTables, cacheable, region, timeout, fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes, callable); } else { // TODO: check there is no actual definition elemnents when a ref is defined namedQuery = new NamedSQLQueryDefinition(queryText, resultSetRef, synchronizedTables, cacheable, region, timeout, fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes, callable); } log.Debug("Named SQL query: {0} -> {1}", queryName, namedQuery.QueryString); mappings.AddSQLQuery(queryName, namedQuery); }); }
private void Reset() { ClearParameters(); lockModes.Clear(); selection.FirstRow = RowSelection.NoValue; selection.MaxRows = RowSelection.NoValue; selection.Timeout = RowSelection.NoValue; selection.FetchSize = RowSelection.NoValue; cacheable = false; cacheRegion = null; cacheMode = null; readOnly = false; flushMode = FlushMode.Unspecified; resultTransformer = null; shouldIgnoredUnknownNamedParameters = false; comment = null; }
private void TestFlushMode(ISessionFactory sessionFactory, FlushMode flushMode) { var name = "TestPublisher" + flushMode; using (var session = sessionFactory.OpenSession()) { session.FlushMode = flushMode; using (var tx = session.BeginTransaction()) { var publisher = new Publisher { Name = name }; Console.WriteLine("Saving {0}", name); session.Save(publisher); Console.WriteLine("Searching for {0}", name); var searchPublisher = session .QueryOver <Publisher>() .Where(x => x.Name == name) .SingleOrDefault(); Console.WriteLine(searchPublisher != null ? "Found it!" : "Didn't find it!"); tx.Commit(); } using (var tx = session.BeginTransaction()) { Console.WriteLine( "Searching for {0} again", name); var searchPublisher = session .QueryOver <Publisher>() .Where(x => x.Name == name) .SingleOrDefault(); Console.WriteLine(searchPublisher != null ? "Found it!" : "Didn't find it!"); } } }
protected internal virtual void Flush(FlushMode flushMode) { var logEventsCount = loggingEvents.Count; if (logEventsCount <= 0) { return; } if (logEventsCount <= BufferMaxSize && flushMode == FlushMode.DefaultFlush) { return; } var events = Interlocked.Exchange(ref loggingEvents, new ConcurrentQueue <LoggingEventData>()); SendToCloudAsync(events); }
/// <summary> /// Flushes input and output buffers /// </summary> public void Flush(FlushMode mode) { int queueSelector; if (mode == FlushMode.Input) { queueSelector = Macros.TCIFLUSH; } else if (mode == FlushMode.Output) { queueSelector = Macros.TCOFLUSH; } else { queueSelector = Macros.TCIOFLUSH; } Syscalls.tcflush(_FileDescriptor, queueSelector); }
/// <summary> /// Provides a behavior specific repository for checking if a duplicate exists of an existing entity. /// </summary> public bool DoesDuplicateExistWithTypedIdOf<TId>(IEntityWithTypedId<TId> entity) { if (entity == null) throw new ArgumentNullException("Entity may not be null when checking for duplicates"); ISession session = _sessionFactory.GetCurrentSession(); FlushMode previousFlushMode = session.FlushMode; // We do NOT want this to flush pending changes as checking for a duplicate should // only compare the object against data that's already in the database session.FlushMode = FlushMode.Never; var criteria = session.CreateCriteria(entity.GetType()).Add(Restrictions.Not(Restrictions.Eq("Id", entity.Id))). SetMaxResults(1); AppendSignaturePropertyCriteriaTo(criteria, entity); bool doesDuplicateExist = criteria.List().Count > 0; session.FlushMode = previousFlushMode; return doesDuplicateExist; }
public void Flush(FlushMode mode) { PurgeFlags purgeFlag; if (mode == FlushMode.Input) { purgeFlag = PurgeFlags.RxClear; } else if (mode == FlushMode.Output) { purgeFlag = PurgeFlags.TxClear; } else { purgeFlag = PurgeFlags.RxClear | PurgeFlags.TxClear; } NativeMethods.PurgeComm(serialHandle, (uint)(purgeFlag)); }
public UnitOfWork CreateUnitOfWork(IInterceptor interceptor, FlushMode flushMode) { UnitOfWork uow; if (interceptor == null) { uow = new UnitOfWork(_sessionFactory.OpenSession()); } else { uow = new UnitOfWork(_sessionFactory.OpenSession(interceptor)); } Check.Ensure(uow != null, "The UnitOfWork cannot be NULL"); uow.Session.FlushMode = flushMode; return(uow); }
public MemoryMapPager(string file, FlushMode flushMode = FlushMode.Full) { _flushMode = flushMode; var fileInfo = new FileInfo(file); var hasData = fileInfo.Exists == false || fileInfo.Length == 0; _fileStream = fileInfo.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); if (hasData) { NumberOfAllocatedPages = 0; } else { NumberOfAllocatedPages = fileInfo.Length / PageSize; PagerState.Release(); PagerState = CreateNewPagerState(); } }
private void Flush(FlushMode flushMode) { // If this is the forced flush on Dispose, wait until we acquire the lock. Otherwise, // just check to see if the lock is available, and if not, we are still processing the // last tranche of appends, so bail out and wait for the next flush interval. var lockTimeout = (flushMode == FlushMode.IfIdle ? 1 : Timeout.Infinite); bool acquiredLock = false; Monitor.TryEnter(_lock, lockTimeout, ref acquiredLock); if (!acquiredLock) { return; } try { var file = new FileInfo(_filePath); if (!file.Exists) { return; } var uploadPointer = file.Length; if (uploadPointer <= _flushPointer) { return; } using (var stm = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { stm.Seek(_flushPointer, SeekOrigin.Begin); _blob.AppendFromStream(stm, uploadPointer - _flushPointer); _flushPointer = uploadPointer; } } finally { Monitor.Exit(_lock); } }
public void Transacionar(Action action, FlushMode flushMode = FlushMode.Commit) { using (var trans = this.Begin(flushMode: flushMode)) { try { action(); trans.Commit(); } catch { trans.RollBack(); throw; } finally { trans.Dispose(); } } }
public void Init(HttpApplication context) { context.BeginRequest += ContextBeginRequest; context.EndRequest += ContextEndRequest; if (!SessionFlushModeIsSet) { SessionFlushModeIsSet = true; string fm = ConfigurationManager.AppSettings.Get(SessionFlushModeConfigKey); if (!String.IsNullOrEmpty(fm)) { // // let exceptions bubble through, so developers using this // will see the error // try { SessionFlushMode = (FlushMode)Enum.Parse(typeof(FlushMode), fm, true); Missing.Diagnostics.Log.Information("Session.FlushMode value of '{0}' defined in *.config by appSettings.{1}", SessionFlushMode, SessionFlushModeConfigKey); } catch (Exception ex) { // // found this pattern at // http://stackoverflow.com/a/136092 // if (ex is ArgumentException || ex is OverflowException) { string names = String.Join(", ", Enum.GetNames(typeof(FlushMode))); throw new ArgumentException(String.Format("The value of appSettings.{1} must be one of {2}, but was '{3}'", SessionFlushModeConfigKey, names, fm), ex); } throw; } } } }
public IUnitOfWorkTransaction Begin( int batchSize = 1, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, FlushMode flushMode = FlushMode.Commit) { if (this.ExistTransaction) { throw new InvalidOperationException( "You cannot start more than one unit of work at the same time"); } var transaction = this.transactionFactory.Create(isolationLevel, flushMode); //// TODO: habilitar batch ////if (Database.Provider.SupportBatch) ////{ //// transaction.CurrentSession.SetBatchSize(batchSize); ////} this.store.Current = transaction; return(transaction); }
protected internal AbstractSessionImpl(ISessionFactoryImplementor factory, ISessionCreationOptions options) { SessionId = factory.Settings.TrackSessionId ? Guid.NewGuid() : Guid.Empty; using (BeginContext()) { _factory = factory; Timestamp = factory.Settings.CacheProvider.NextTimestamp(); _flushMode = options.InitialSessionFlushMode; Interceptor = options.SessionInterceptor ?? EmptyInterceptor.Instance; if (options is ISharedSessionCreationOptions sharedOptions && sharedOptions.IsTransactionCoordinatorShared) { // NH specific implementation: need to port Hibernate transaction management. IsTransactionCoordinatorShared = true; if (options.UserSuppliedConnection != null) { throw new SessionException("Cannot simultaneously share transaction context and specify connection"); } var connectionManager = sharedOptions.ConnectionManager; connectionManager.AddDependentSession(this); ConnectionManager = connectionManager; }
/// <summary> /// Provides a behavior specific repository for checking if a duplicate exists of an existing entity. /// </summary> public bool DoesDuplicateExistWithTypedIdOf <IdT>(IEntityWithTypedId <IdT> entity) { Check.Require(entity != null, "Entity may not be null when checking for duplicates"); ISession session = GetSessionFor(entity); FlushMode previousFlushMode = session.FlushMode; // We do NOT want this to flush pending changes as checking for a duplicate should // only compare the object against data that's already in the database session.FlushMode = FlushMode.Never; ICriteria criteria = session.CreateCriteria(entity.GetType()) .Add(Expression.Not(Expression.Eq("Id", entity.Id))) .SetMaxResults(1); AppendSignaturePropertyCriteriaTo <IdT>(criteria, entity); bool doesDuplicateExist = criteria.List().Count > 0; session.FlushMode = previousFlushMode; return(doesDuplicateExist); }
private void DeflateReset(ZLibStream zStream) { zStream.TotalIn = zStream.TotalOut = 0; zStream.Message = null; zStream.DataType = ZUNKNOWN; this.Pending = 0; this.PendingOut = 0; if (this.NoHeader < 0) { this.NoHeader = 0; // was set to -1 by deflate(..., Z_FINISH); } this.status = (this.NoHeader != 0) ? BUSYSTATE : INITSTATE; zStream.Adler = Adler32.SeedValue; this.lastFlush = FlushMode.NoFlush; Trees.Tr_init(this); this.Lm_init(); }
private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode) { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog)); Recreate(); Post.DeleteAll(); Blog.DeleteAll(); DefaultFlushType originalDefaultFlushType = ActiveRecordStarter.ConfigurationSource.DefaultFlushType; try { ((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = flushType; Blog blog = new Blog(); // just for CurrentSession using (new SessionScope()) { Blog.FindAll(); Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode); using (new TransactionScope()) { Blog.FindAll(); Assert.AreEqual(transactionScopeMode, blog.CurrentSession.FlushMode); } // Properly reset? Blog.FindAll(); Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode); } } finally { // Restore Default Flush type we corrupted before. ((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = originalDefaultFlushType; } }
private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode) { using (new SessionScope()) { Post.DeleteAll(); Blog.DeleteAll(); } var originalDefaultFlushType = AR.Holder.ConfigurationSource.DefaultFlushType; try { AR.Holder.ConfigurationSource.Flush(flushType); var blog = new Blog(); // just for CurrentSession using (new SessionScope()) { Blog.FindAll(); Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode); using (new TransactionScope()) { Blog.FindAll(); Assert.AreEqual(transactionScopeMode, blog.GetCurrentSession().FlushMode); } // Properly reset? Blog.FindAll(); Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode); } } finally { // Restore Default Flush type we corrupted before. AR.Holder.ConfigurationSource.Flush(originalDefaultFlushType); } }
public NamedQueryDefinition( string query, bool cacheable, string cacheRegion, int timeout, int fetchSize, FlushMode flushMode, CacheMode? cacheMode, bool readOnly, string comment, IDictionary<string,string> parameterTypes ) { this.query = query; this.cacheable = cacheable; this.cacheRegion = cacheRegion; this.timeout = timeout; this.fetchSize = fetchSize; this.flushMode = flushMode; this.parameterTypes = parameterTypes; this.cacheMode = cacheMode; this.readOnly = readOnly; this.comment = comment; }
/// <summary> /// Initialize a new instance of <see cref="SessionScopeSettings"/> with default values. /// </summary> /// <remarks> /// Calling this constructor from your derived class leaves <see cref="EntityInterceptor"/> /// uninitialized. See <see cref="ResolveEntityInterceptor"/> for more. /// </remarks> public SessionPerConversationScopeSettings() { this.entityInterceptor = null; this.defaultFlushMode = FLUSHMODE_DEFAULT; }
/// <summary> /// Initialize a new instance of <see cref="SessionScopeSettings"/> with the given values and references. /// </summary> /// <param name="sessionFactory"> /// The <see cref="ISessionFactory"/> instance to be used for obtaining <see cref="ISession"/> instances. /// </param> /// <param name="entityInterceptor"> /// Specify the <see cref="IInterceptor"/> to be set on each session provided by the <see cref="SessionScope"/> instance. /// </param> /// <param name="singleSession"> /// Set whether to use a single session for each request. See <see cref="SingleSession"/> property for details. /// </param> /// <param name="defaultFlushMode"> /// Specify the flushmode to be applied on each session provided by the <see cref="SessionScope"/> instance. /// </param> /// <remarks> /// Calling this constructor marks all properties initialized. /// </remarks> public SessionScopeSettings(ISessionFactory sessionFactory, IInterceptor entityInterceptor, bool singleSession, FlushMode defaultFlushMode) { AssertUtils.ArgumentNotNull(sessionFactory, "sessionFactory"); this.sessionFactory = sessionFactory; this.sessionFactoryInitialized = true; this.entityInterceptor = entityInterceptor; this.entityInterceptorInitialized = true; this.singleSession = singleSession; this.defaultFlushMode = defaultFlushMode; }
/// <summary> /// Initializes a new instance of the <see cref="FlushModeHolder"/> class. /// </summary> /// <param name="mode">The flush mode.</param> public FlushModeHolder(FlushMode mode) { Mode = mode; ModeWasSet = true; }
public IAuditQuery SetFlushMode(FlushMode flushMode) { this.flushMode = flushMode; return this; }
public NamedQueryDefinition(string query, bool cacheable, string cacheRegion, int timeout, int fetchSize, FlushMode flushMode, bool readOnly, string comment, IDictionary<string, string> parameterTypes) : this(query,cacheable,cacheRegion,timeout,fetchSize,flushMode,null,readOnly,comment,parameterTypes) {}
private void Reset() { ClearParameters(); lockModes.Clear(); selection.FirstRow = RowSelection.NoValue; selection.MaxRows = RowSelection.NoValue; selection.Timeout = RowSelection.NoValue; selection.FetchSize = RowSelection.NoValue; cacheable = false; cacheRegion = null; cacheMode = null; readOnly = false; flushMode = FlushMode.Unspecified; resultTransformer = null; shouldIgnoredUnknownNamedParameters = false; comment = null; }
public QueryImpl(string queryString, FlushMode flushMode, ISessionImplementor session, ParameterMetadata parameterMetadata) : base(queryString, flushMode, session, parameterMetadata) { }
/// <summary> /// Compares if the flush mode enumerations, Spring's /// TemplateFlushMode and NHibernates FlushMode have equal /// settings. /// </summary> /// <param name="tfm">The template flush mode.</param> /// <param name="fm">The NHibernate flush mode.</param> /// <returns> /// Returns true if both are Never, Auto, or Commit, false /// otherwise. /// </returns> protected bool AreEqualFlushMode(TemplateFlushMode tfm, FlushMode fm) { if ((tfm == TemplateFlushMode.Never && fm == FlushMode.Never) || (tfm == TemplateFlushMode.Auto && fm == FlushMode.Auto) || (tfm == TemplateFlushMode.Commit && fm == FlushMode.Commit)) { return true; } else { return false; } //TODO other combinations. }
public SetFlushModeOpenSessionEvent(FlushMode flushMode) { this.flushMode = flushMode; }
/// <summary> /// Initializes a new instance of the <see cref="SessionScope"/> class. /// </summary> /// <param name="sessionFactory"> /// The <see cref="ISessionFactory"/> instance to be used for obtaining <see cref="ISession"/> instances. /// </param> /// <param name="entityInterceptor"> /// Specify the <see cref="IInterceptor"/> to be set on each session provided by this <see cref="SessionScope"/> instance. /// </param> /// <param name="singleSession"> /// Set whether to use a single session for each request. See <see cref="SingleSession"/> property for details. /// </param> /// <param name="defaultFlushMode"> /// Specify the flushmode to be applied on each session provided by this <see cref="SessionScope"/> instance. /// </param> /// <param name="open"> /// If set to <c>true</c> associate a session with the thread. If false, another /// collaborating class will associate the session with the thread, potentially by calling /// the Open method on this class. /// </param> public SessionScope(ISessionFactory sessionFactory, IInterceptor entityInterceptor, bool singleSession, FlushMode defaultFlushMode, bool open) :this(new SessionScopeSettings(sessionFactory, entityInterceptor, singleSession, defaultFlushMode), open) { // noop }
/// <summary> /// Initialize a new instance of <see cref="SessionPerConversationScopeSettings"/> with the given values and references. /// </summary> /// <param name="entityInterceptor"> /// Specify the <see cref="IInterceptor"/> to be set on each session provided by the <see cref="SessionPerConversationScope"/> instance. /// </param> /// <param name="defaultFlushMode"> /// Specify the flushmode to be applied on each session provided by the <see cref="SessionScope"/> instance. /// </param> /// <remarks> /// Calling this constructor marks all properties initialized. /// </remarks> public SessionPerConversationScopeSettings(IInterceptor entityInterceptor, FlushMode defaultFlushMode) { this.entityInterceptor = entityInterceptor; this.defaultFlushMode = defaultFlushMode; }
public virtual IDetachedQuery SetFlushMode(FlushMode flushMode) { this.flushMode = flushMode; return this; }
public void Flush(FlushMode mode = FlushMode.InputOutput) { lowLevelSerialPort.Flush(mode); }