Exemple #1
0
 /// <summary> Called by the <tt>Count</tt> property</summary>
 protected virtual bool ReadSize()
 {
     if (!initialized)
     {
         if (cachedSize != -1 && !HasQueuedOperations)
         {
             return(true);
         }
         else
         {
             ThrowLazyInitializationExceptionIfNotConnected();
             CollectionEntry      entry     = session.PersistenceContext.GetCollectionEntry(this);
             ICollectionPersister persister = entry.LoadedPersister;
             if (persister.IsExtraLazy)
             {
                 if (HasQueuedOperations)
                 {
                     session.Flush();
                 }
                 cachedSize = persister.GetSize(entry.LoadedKey, session);
                 return(true);
             }
         }
     }
     Read();
     return(false);
 }
Exemple #2
0
            void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
            {
                using (new SessionIdLoggingContext(session.SessionId))
                {
                    try
                    {
                        //using (var tx = new TransactionScope(AmbientTransation))
                        {
                            session.BeforeTransactionCompletion(null);
                            if (session.FlushMode != FlushMode.Never && session.ConnectionManager.IsConnected)
                            {
                                using (session.ConnectionManager.FlushingFromDtcTransaction)
                                {
                                    logger.Debug(string.Format("[session-id={0}] Flushing from Dtc Transaction", session.SessionId));
                                    session.Flush();
                                }
                            }
                            logger.Debug("prepared for DTC transaction " + AmbientTransation.TransactionInformation.LocalIdentifier);

                            //tx.Complete();
                        }
                        preparingEnlistment.Prepared();
                    }
                    catch (Exception exception)
                    {
                        logger.Error("DTC transaction prepre phase failed", exception);
                        preparingEnlistment.ForceRollback(exception);
                    }
                }
            }
Exemple #3
0
        /// <summary>
        /// Commits the <see cref="ITransaction"/> by flushing the <see cref="ISession"/>
        /// and committing the <see cref="IDbTransaction"/>.
        /// </summary>
        /// <exception cref="TransactionException">
        /// Thrown if there is any exception while trying to call <c>Commit()</c> on
        /// the underlying <see cref="IDbTransaction"/>.
        /// </exception>
        public void Commit()
        {
            CheckNotDisposed();
            CheckBegun();

            log.Debug("commit");

            if (session.FlushMode != FlushMode.Never)
            {
                session.Flush();
            }
            try
            {
                trans.Commit();
                committed = true;
                AfterTransactionCompletion(true);
                Dispose();
            }
            catch (HibernateException)
            {
                // Don't wrap HibernateExceptions
                throw;
            }
            catch (Exception e)
            {
                log.Error("Commit failed", e);
                AfterTransactionCompletion(false);
                commitFailed = true;
                throw new TransactionException("Commit failed with SQL exception", e);
            }
        }
        protected void EnsureFlushMode(ISessionImplementor session, bool isReadOnly)
        {
            if (session != null)
            {
                // If we're changing the FlushMode on an existing session from Auto,
                // then issue one flush now
                if (session.FlushMode == FlushMode.Auto && isReadOnly)
                    session.Flush();

                session.FlushMode = isReadOnly ? FlushMode.Never : FlushMode.Auto;
            }
        }
        protected void EnsureFlushMode(ISessionImplementor session, bool isReadOnly)
        {
            if (session != null)
            {
                // If we're changing the FlushMode on an existing session from Auto,
                // then issue one flush now
                if (session.FlushMode == FlushMode.Auto && isReadOnly)
                {
                    session.Flush();
                }

                session.FlushMode = isReadOnly ? FlushMode.Never : FlushMode.Auto;
            }
        }
Exemple #6
0
        /// <summary>
        /// Commits the <see cref="ITransaction"/> by flushing the <see cref="ISession"/>
        /// and committing the <see cref="IDbTransaction"/>.
        /// </summary>
        /// <exception cref="TransactionException">
        /// Thrown if there is any exception while trying to call <c>Commit()</c> on
        /// the underlying <see cref="IDbTransaction"/>.
        /// </exception>
        public void Commit()
        {
            using (new SessionIdLoggingContext(sessionId))
            {
                CheckNotDisposed();
                CheckBegun();
                CheckNotZombied();

                log.Debug("Start Commit");

                if (session.FlushMode != FlushMode.Never)
                {
                    session.Flush();
                }

                NotifyLocalSynchsBeforeTransactionCompletion();
                session.BeforeTransactionCompletion(this);

                try
                {
                    trans.Commit();
                    log.Debug("IDbTransaction Committed");

                    committed = true;
                    AfterTransactionCompletion(true);
                    Dispose();
                }
                catch (HibernateException e)
                {
                    log.Error("Commit failed", e);
                    AfterTransactionCompletion(false);
                    commitFailed = true;
                    // Don't wrap HibernateExceptions
                    throw;
                }
                catch (Exception e)
                {
                    log.Error("Commit failed", e);
                    AfterTransactionCompletion(false);
                    commitFailed = true;
                    throw new TransactionException("Commit failed with SQL exception", e);
                }
                finally
                {
                    CloseIfRequired();
                }
            }
        }
Exemple #7
0
 public void Flush()
 {
     _session.Flush();
 }
 public void flush()
 {
     delegat.Flush();
 }