Java 类org.hibernate.resource.transaction.spi.TransactionStatus 实例源码

项目:gitplex-mit    文件:DefaultWebSocketManager.java   
@Sessional
@Override
public void render(WebSocketRegion region, @Nullable PageKey sourcePageKey) {
    if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
        dao.doAfterCommit(new Runnable() {

            @Override
            public void run() {
                doRender(region, sourcePageKey);
            }

        });
    } else {
        doRender(region, sourcePageKey);
    }
}
项目:MirServer-Netty    文件:Handler.java   
protected void exce(ChannelHandlerContext ctx, ClientPacket packet) throws Exception {
    session = Session.getSession(ctx);
    if(null == session){
        logger.debug("new session for {}",ctx);
        session = Session.create(ctx);
    }
    DB.getSession().getTransaction().begin();
    try{
        onPacket(packet);
        if(DB.getSession().getTransaction().getStatus().isOneOf(TransactionStatus.ACTIVE))
            DB.getSession().getTransaction().commit();
    }catch(Exception e){
        logger.error("onPacket error, {}", packet.protocol , e);
        if(DB.getSession().isOpen())
            DB.getSession().getTransaction().rollback();
    }

}
项目:ignite    文件:CacheHibernateStoreSessionListener.java   
/** {@inheritDoc} */
@Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
    Session hibSes = ses.attach(null);

    if (hibSes != null) {
        try {
            Transaction tx = hibSes.getTransaction();

            if (commit) {
                if (hibSes.isDirty())
                    hibSes.flush();

                if (tx.getStatus() == TransactionStatus.ACTIVE)
                    tx.commit();
            }
            else if (tx.getStatus().canRollback())
                tx.rollback();
        }
        catch (HibernateException e) {
            throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
        }
        finally {
            hibSes.close();
        }
    }
}
项目:ignite    文件:CacheHibernateBlobStoreSelfTest.java   
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
    super.afterTest();

    Session s = store.session(null);

    if (s == null)
        return;

    try {
        s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName())
                .setFlushMode(FlushMode.ALWAYS).executeUpdate();

        Transaction hTx = s.getTransaction();

        if (hTx != null && hTx.getStatus() == TransactionStatus.ACTIVE)
            hTx.commit();
    }
    finally {
        s.close();
    }
}
项目:dropwizard-jaxws    文件:UnitOfWorkInvokerFactoryTest.java   
@Before
public void setup() {
    exchange = mock(Exchange.class);
    BindingOperationInfo boi = mock(BindingOperationInfo.class);
    when(exchange.getBindingOperationInfo()).thenReturn(boi);
    OperationInfo oi = mock(OperationInfo.class);
    when(boi.getOperationInfo()).thenReturn(oi);
    invokerBuilder = new UnitOfWorkInvokerFactory();
    fooService = new FooService();
    sessionFactory = mock(SessionFactory.class);
    session = mock(Session.class);
    when(sessionFactory.openSession()).thenReturn(session);
    transaction = mock(Transaction.class);
    when(session.getTransaction()).thenReturn(transaction);
    when(transaction.getStatus()).thenReturn(TransactionStatus.ACTIVE);
}
项目:gitplex-mit    文件:DefaultPullRequestManager.java   
@Sessional
@Override
public MergePreview previewMerge(PullRequest request) {
    if (request.getMergeStrategy() != MergeStrategy.DO_NOT_MERGE) {
        MergePreview lastPreview = request.getLastMergePreview();
        if (request.isOpen() && !request.isMergeIntoTarget() 
                && (lastPreview == null || lastPreview.isObsolete(request))) {
            int priority = RequestCycle.get() != null?UI_PREVIEW_PRIORITY:BACKEND_PREVIEW_PRIORITY;         
            if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
                doAfterCommit(new Runnable() {

                    @Override
                    public void run() {
                        batchWorkManager.submit(getMergePreviewer(request), new Prioritized(priority));
                    }

                });
            } else {
                batchWorkManager.submit(getMergePreviewer(request), new Prioritized(priority));
            }
            return null;
        } else {
            return lastPreview;
        }
    } else {
        return null;
    }
}
项目:gitplex-mit    文件:DefaultPullRequestManager.java   
@Sessional
protected void checkAsync(PullRequest request) {
    Long requestId = request.getId();
    Subject subject = SecurityUtils.getSubject();
    if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
        doUnitOfWorkAsyncAfterCommit(newCheckStatusRunnable(requestId, subject));
    } else {
        unitOfWork.doAsync(newCheckStatusRunnable(requestId, subject));
    }
}
项目:gitplex-mit    文件:DefaultMailManager.java   
@Sessional
@Override
public void sendMailAsync(Collection<String> toList, String subject, String body) {
    if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
        dao.doAsyncAfterCommit(newSendMailRunnable(toList, subject, body));
    } else {
        executorService.execute(newSendMailRunnable(toList, subject, body));
    }
}
项目:gitplex-mit    文件:TransactionInterceptor.java   
public Object invoke(MethodInvocation mi) throws Throwable {
    if (persistManager.getSessionFactory() != null) {
        unitOfWork.begin();
        try {
            Session session = unitOfWork.getSession();
            if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
                return mi.proceed();
            } else {
                Transaction tx = session.beginTransaction();
                FlushMode previousMode = session.getFlushMode();
                session.setFlushMode(FlushMode.COMMIT);
                try {
                    Object result = mi.proceed();
                    tx.commit();
                    return result;
                } catch (Throwable t) {
                    try {
                        tx.rollback();
                    } catch (Throwable t2) {
                    }
                    throw t;
                } finally {
                    session.setFlushMode(previousMode);
                }
            }

        } finally {
            unitOfWork.end();
        }
    } else {
        return mi.proceed();
    }
}
项目:Webstore    文件:ProductRepositoryImpl.java   
public List<String> search(String productName){
    try{ if(sessionFactory.getCurrentSession().getTransaction().getStatus() != TransactionStatus.ACTIVE)
        sessionFactory.getCurrentSession().getTransaction().begin();
        Query query = sessionFactory.getCurrentSession().createQuery("select name from Product where name like :name");
        query.setString("name",productName + "%");
        System.out.println(query.list().toString());
        return query.list();
    }catch(Exception e){
        return null;
    }
}
项目:OpenUnison    文件:WorkflowImpl.java   
@Override
public void completeWorkflow() throws ProvisioningException {
    Session session = null;
    try {

        if (this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory() != null) {
            session = this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory().openSession();
            session.beginTransaction();
            DateTime now = new DateTime();
            Workflows wf = session.load(Workflows.class, this.id);
            wf.setCompleteTs(new Timestamp(now.getMillis()));
            session.save(wf);
            session.getTransaction().commit();

        }
    } finally {
        if (session != null) {

            if (session.getTransaction() != null && session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
                session.getTransaction().rollback();
            }

            session.close();
        }
    }


}
项目:livingdoc-confluence    文件:AbstractHibernateMemoryTest.java   
private void rollbackIfNecessary() {
    if (transaction == null) {
        return;
    }
    if(transaction.getStatus() != TransactionStatus.COMMITTED){
        transaction.rollback();
    }
}
项目:elide    文件:HibernateTransaction.java   
@Override
public void close() throws IOException {
    if (session.isOpen() && session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
        session.getTransaction().rollback();
        throw new IOException("Transaction not closed");
    }
}
项目:ignite    文件:CacheHibernateBlobStore.java   
/**
 * Ends hibernate session.
 *
 * @param ses Hibernate session.
 * @param tx Cache ongoing transaction.
 */
private void end(Session ses, Transaction tx) {
    // Commit only if there is no cache transaction,
    // otherwise sessionEnd() will do all required work.
    if (tx == null) {
        org.hibernate.Transaction hTx = ses.getTransaction();

        if (hTx != null && hTx.getStatus() == TransactionStatus.ACTIVE)
            hTx.commit();

        ses.close();
    }
}
项目:robe    文件:WrapperServlet.java   
private void rollbackTransaction(Session session, UnitOfWork uow) {
    if (uow.transactional()) {
        Transaction txn = session.getTransaction();
        if (txn != null && session.getTransaction().getStatus() != TransactionStatus.ACTIVE) {
            txn.rollback();
        }
    }

}
项目:robe    文件:WrapperServlet.java   
private void commitTransaction(Session session, UnitOfWork uow) {
    if (uow.transactional()) {
        Transaction txn = session.getTransaction();
        if (txn != null && session.getTransaction().getStatus() != TransactionStatus.ACTIVE) {
            txn.commit();
        }
    }

}
项目:robe    文件:Transaction.java   
/**
 * If transaction is present and active then commit.
 */
private void success() {
    org.hibernate.Transaction txn = session.getTransaction();
    if (txn != null && txn.getStatus().equals(TransactionStatus.ACTIVE)) {
        txn.commit();
    }
}
项目:robe    文件:Transaction.java   
/**
 * If transaction is present and active then rollback.
 */
private void error() {
    org.hibernate.Transaction txn = session.getTransaction();
    if (txn != null && txn.getStatus().equals(TransactionStatus.ACTIVE)) {
        txn.rollback();
    }
}
项目:ZawodyWeb    文件:HibernateSessionRequestFilter.java   
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        if (req.getContextPath().contains("/error/")) {
            chain.doFilter(request, response);
            return;
        }
    }

    try {
        sf.getCurrentSession().beginTransaction();
        chain.doFilter(request, response);

        sf.getCurrentSession().getTransaction().commit();
    } catch (StaleObjectStateException staleEx) {
        throw staleEx;
    } catch (Throwable ex) {
        try {
            TransactionStatus status = sf.getCurrentSession().getTransaction().getStatus();
            if (status.isOneOf(TransactionStatus.ACTIVE) && status.canRollback()) {
                sf.getCurrentSession().getTransaction().rollback();
            }
        } catch (Throwable rbEx) {
        }
        throw new ServletException(ex);
    }
}
项目:stdlib    文件:TransactionHelper.java   
void addAction(SessionEventListener... listeners) throws HibernateException
{
    final Session session = sessionProvider.get();

    if (session.getTransaction().getStatus() != TransactionStatus.ACTIVE)
        throw new IllegalStateException("Cannot add transaction action with no active transaction!");

    session.addEventListeners(listeners);
}
项目:dropwizard-jaxws    文件:UnitOfWorkInvoker.java   
/**
 * @see io.dropwizard.hibernate.UnitOfWorkAspect#rollbackTransaction()
 */
private void rollbackTransaction(Session session, UnitOfWork unitOfWork) {
    if (unitOfWork.transactional()) {
        final Transaction txn = session.getTransaction();
        if (txn != null && txn.getStatus().equals(TransactionStatus.ACTIVE)) {
            txn.rollback();
        }
    }
}
项目:dropwizard-jaxws    文件:UnitOfWorkInvoker.java   
/**
 * @see io.dropwizard.hibernate.UnitOfWorkAspect#commitTransaction()
 */
private void commitTransaction(Session session, UnitOfWork unitOfWork) {
    if (unitOfWork.transactional()) {
        final Transaction txn = session.getTransaction();
        if (txn != null && txn.getStatus().equals(TransactionStatus.ACTIVE)) {
            txn.commit();
        }
    }
}
项目:spring4-understanding    文件:HibernateTransactionManager.java   
public boolean hasHibernateManagedTransaction() {
    return (this.sessionHolder != null &&
            this.sessionHolder.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE);
}
项目:dropwizard-db-sharding-bundle    文件:TransactionHandler.java   
private void rollbackTransaction() {
    final Transaction txn = session.getTransaction();
    if (txn != null && txn.getStatus() == TransactionStatus.ACTIVE) {
        txn.rollback();
    }
}
项目:dropwizard-db-sharding-bundle    文件:TransactionHandler.java   
private void commitTransaction() {
    final Transaction txn = session.getTransaction();
    if (txn != null && txn.getStatus() == TransactionStatus.ACTIVE) {
        txn.commit();
    }
}
项目:ignite    文件:CacheHibernateStoreSessionListenerSelfTest.java   
/**
 */
private void checkSession() {
    Session hibSes = ses.attachment();

    assertNotNull(hibSes);

    assertTrue(hibSes.isOpen());

    Transaction tx = hibSes.getTransaction();

    assertNotNull(tx);

    if (ses.isWithinTransaction())
        assertEquals(TransactionStatus.ACTIVE, tx.getStatus());
    else
        assertFalse("Unexpected status: " + tx.getStatus(), tx.getStatus() == TransactionStatus.ACTIVE);

    verifySameInstance(hibSes);
}