Java 类org.hibernate.TransactionException 实例源码

项目:lams    文件:AbstractTransactionImpl.java   
@Override
public void begin() throws HibernateException {
    if ( !valid ) {
        throw new TransactionException( "Transaction instance is no longer valid" );
    }
    if ( localStatus == LocalStatus.ACTIVE ) {
        throw new TransactionException( "nested transactions not supported" );
    }
    if ( localStatus != LocalStatus.NOT_ACTIVE ) {
        throw new TransactionException( "reuse of Transaction instances not supported" );
    }

    LOG.debug( "begin" );

    doBegin();

    localStatus = LocalStatus.ACTIVE;

    afterTransactionBegin();
}
项目:lams    文件:AbstractTransactionImpl.java   
@Override
public void commit() throws HibernateException {
    if ( localStatus != LocalStatus.ACTIVE ) {
        throw new TransactionException( "Transaction not successfully started" );
    }

    LOG.debug( "committing" );

    beforeTransactionCommit();

    try {
        doCommit();
        localStatus = LocalStatus.COMMITTED;
        afterTransactionCompletion( Status.STATUS_COMMITTED );
    }
    catch (Exception e) {
        localStatus = LocalStatus.FAILED_COMMIT;
        afterTransactionCompletion( Status.STATUS_UNKNOWN );
        throw new TransactionException( "commit failed", e );
    }
    finally {
        invalidate();
        afterAfterCompletion();
    }
}
项目:lams    文件:JdbcTransaction.java   
@Override
protected void doBegin() {
    try {
        if ( managedConnection != null ) {
            throw new TransactionException( "Already have an associated managed connection" );
        }
        managedConnection = transactionCoordinator().getJdbcCoordinator().getLogicalConnection().getConnection();
        wasInitiallyAutoCommit = managedConnection.getAutoCommit();
        LOG.debugv( "initial autocommit status: {0}", wasInitiallyAutoCommit );
        if ( wasInitiallyAutoCommit ) {
            LOG.debug( "disabling autocommit" );
            managedConnection.setAutoCommit( false );
        }
    }
    catch( SQLException e ) {
        throw new TransactionException( "JDBC begin transaction failed: ", e );
    }

    isDriver = transactionCoordinator().takeOwnership();
}
项目:lams    文件:JtaTransaction.java   
@Override
protected void doBegin() {
    LOG.debug( "begin" );

    userTransaction = locateUserTransaction();

    try {
        if ( userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION ) {
            userTransaction.begin();
            isInitiator = true;
            LOG.debug( "Began a new JTA transaction" );
        }
    }
    catch ( Exception e ) {
        throw new TransactionException( "JTA transaction begin failed", e );
    }
}
项目:lams    文件:JtaTransaction.java   
@Override
protected void afterAfterCompletion() {
    // this method is a noop if there is a Synchronization!
    try {
        if ( isDriver ) {
            if ( !isInitiator ) {
                LOG.setManagerLookupClass();
            }
            try {
                transactionCoordinator().afterTransaction( this, userTransaction.getStatus() );
            }
            catch (SystemException e) {
                throw new TransactionException( "Unable to determine UserTransaction status", e );
            }
        }
    }
    finally {
        isInitiator = false;
    }
}
项目:lams    文件:JtaTransaction.java   
@Override
protected void doRollback() {
    try {
        if ( isInitiator ) {
            // failed commits automatically rollback the transaction per JTA spec
            if ( getLocalStatus() != LocalStatus.FAILED_COMMIT  ) {
                userTransaction.rollback();
                LOG.debug( "Rolled back JTA UserTransaction" );
            }
        }
        else {
            markRollbackOnly();
        }
    }
    catch ( Exception e ) {
        throw new TransactionException( "JTA rollback failed", e );
    }
}
项目:cacheonix-core    文件:CMTTransaction.java   
public void begin() throws HibernateException {
    if (begun) {
        return;
    }

    log.debug("begin");

    boolean synchronization = jdbcContext.registerSynchronizationIfPossible();

    if ( !synchronization ) {
        throw new TransactionException("Could not register synchronization for container transaction");
    }

    begun = true;

    jdbcContext.afterTransactionBegin(this);
}
项目:cacheonix-core    文件:CMTTransaction.java   
public void commit() throws HibernateException {
    if (!begun) {
        throw new TransactionException("Transaction not successfully started");
    }

    log.debug("commit");

    boolean flush = !transactionContext.isFlushModeNever() &&
            !transactionContext.isFlushBeforeCompletionEnabled();

    if (flush) {
        transactionContext.managedFlush(); //if an exception occurs during flush, user must call rollback()
    }

    begun = false;

}
项目:cacheonix-core    文件:CMTTransaction.java   
public void rollback() throws HibernateException {
    if (!begun) {
        throw new TransactionException("Transaction not successfully started");
    }

    log.debug("rollback");

    try {
        getTransaction().setRollbackOnly();
    }
    catch (SystemException se) {
        log.error("Could not set transaction to rollback only", se);
        throw new TransactionException("Could not set transaction to rollback only", se);
    }

    begun = false;

}
项目:cacheonix-core    文件:CMTTransaction.java   
public boolean isActive() throws TransactionException {

        if (!begun) return false;

        final int status;
        try {
            status = getTransaction().getStatus();
        }
        catch (SystemException se) {
            log.error("Could not determine transaction status", se);
            throw new TransactionException("Could not determine transaction status: ", se);
        }
        if (status==Status.STATUS_UNKNOWN) {
            throw new TransactionException("Could not determine transaction status");
        }
        else {
            return status==Status.STATUS_ACTIVE;
        }
    }
项目:cacheonix-core    文件:CMTTransaction.java   
public boolean wasRolledBack() throws TransactionException {

        if (!begun) return false;

        final int status;
        try {
            status = getTransaction().getStatus();
        }
        catch (SystemException se) {
            log.error("Could not determine transaction status", se);
            throw new TransactionException("Could not determine transaction status", se);
        }
        if (status==Status.STATUS_UNKNOWN) {
            throw new TransactionException("Could not determine transaction status");
        }
        else {
            return JTAHelper.isRollback(status);
        }
    }
项目:cacheonix-core    文件:CMTTransaction.java   
public boolean wasCommitted() throws TransactionException {

        if ( !begun ) return false;

        final int status;
        try {
            status = getTransaction().getStatus();
        }
        catch (SystemException se) {
            log.error("Could not determine transaction status", se);
            throw new TransactionException("Could not determine transaction status: ", se);
        }
        if (status==Status.STATUS_UNKNOWN) {
            throw new TransactionException("Could not determine transaction status");
        }
        else {
            return status==Status.STATUS_COMMITTED;
        }
    }
项目:cacheonix-core    文件:JTATransaction.java   
public JTATransaction(
        InitialContext context, 
        String utName, 
        JDBCContext jdbcContext, 
        TransactionFactory.Context transactionContext
) {
    this.jdbcContext = jdbcContext;
    this.transactionContext = transactionContext;

    log.debug("Looking for UserTransaction under: " + utName);

    try {
        ut = (UserTransaction) context.lookup(utName);
    }
    catch (NamingException ne) {
        log.error("Could not find UserTransaction in JNDI", ne);
        throw new TransactionException("Could not find UserTransaction in JNDI: ", ne);
    }
    if (ut==null) {
        throw new AssertionFailure("A naming service lookup returned null");
    }

    log.debug("Obtained UserTransaction");
}
项目:cacheonix-core    文件:JTATransaction.java   
public boolean wasRolledBack() throws TransactionException {

        //if (!begun) return false;
        //if (commitFailed) return true;

        final int status;
        try {
            status = ut.getStatus();
        }
        catch (SystemException se) {
            log.error("Could not determine transaction status", se);
            throw new TransactionException("Could not determine transaction status", se);
        }
        if (status==Status.STATUS_UNKNOWN) {
            throw new TransactionException("Could not determine transaction status");
        }
        else {
            return JTAHelper.isRollback(status);
        }
    }
项目:cacheonix-core    文件:JTATransaction.java   
public boolean wasCommitted() throws TransactionException {

        //if (!begun || commitFailed) return false;

        final int status;
        try {
            status = ut.getStatus();
        }
        catch (SystemException se) {
            log.error("Could not determine transaction status", se);
            throw new TransactionException("Could not determine transaction status: ", se);
        }
        if (status==Status.STATUS_UNKNOWN) {
            throw new TransactionException("Could not determine transaction status");
        }
        else {
            return status==Status.STATUS_COMMITTED;
        }
    }
项目:cacheonix-core    文件:JTATransaction.java   
public boolean isActive() throws TransactionException {

        if (!begun || commitFailed || commitSucceeded) return false;

        final int status;
        try {
            status = ut.getStatus();
        }
        catch (SystemException se) {
            log.error("Could not determine transaction status", se);
            throw new TransactionException("Could not determine transaction status: ", se);
        }
        if (status==Status.STATUS_UNKNOWN) {
            throw new TransactionException("Could not determine transaction status");
        }
        else {
            return status==Status.STATUS_ACTIVE;
        }
    }
项目:spacewalk    文件:TestCaseHelper.java   
/**
 * shared logic for tearing down resources used in our unit tests
 */
public static void tearDownHelper() {
    TransactionException rollbackException = null;
    if (HibernateFactory.inTransaction()) {
        try {
            HibernateFactory.rollbackTransaction();
            //HibernateFactory.commitTransaction();
        }
        catch (TransactionException e) {
            rollbackException = e;
        }
    }
    HibernateFactory.closeSession();
    if (rollbackException != null) {
        throw rollbackException;
    }
    // In case someone disabled it and forgot to
    // renable it.
    RhnBaseTestCase.enableLocalizationServiceLogging();

}
项目:lams    文件:ConfigurableJtaPlatform.java   
public boolean canRegisterSynchronization() {
    try {
        return (this.transactionManager.getStatus() == Status.STATUS_ACTIVE);
    }
    catch (SystemException ex) {
        throw new TransactionException("Could not determine JTA transaction status", ex);
    }
}
项目:lams    文件:ConfigurableJtaPlatform.java   
public void registerSynchronization(Synchronization synchronization) {
    if (this.transactionSynchronizationRegistry != null) {
        this.transactionSynchronizationRegistry.registerInterposedSynchronization(synchronization);
    }
    else {
        try {
            this.transactionManager.getTransaction().registerSynchronization(synchronization);
        }
        catch (Exception ex) {
            throw new TransactionException("Could not access JTA Transaction to register synchronization", ex);
        }
    }
}
项目:lams    文件:AbstractTransactionImpl.java   
@Override
public void rollback() throws HibernateException {
    if ( localStatus != LocalStatus.ACTIVE && localStatus != LocalStatus.FAILED_COMMIT ) {
        throw new TransactionException( "Transaction not successfully started" );
    }

    LOG.debug( "rolling back" );

    beforeTransactionRollBack();

    if ( localStatus != LocalStatus.FAILED_COMMIT || allowFailedCommitToPhysicallyRollback() ) {
        try {
            doRollback();
            localStatus = LocalStatus.ROLLED_BACK;
            afterTransactionCompletion( Status.STATUS_ROLLEDBACK );
        }
        catch (Exception e) {
            afterTransactionCompletion( Status.STATUS_UNKNOWN );
            throw new TransactionException( "rollback failed", e );
        }
        finally {
            invalidate();
            afterAfterCompletion();
        }
    }

}
项目:lams    文件:JdbcTransaction.java   
@Override
protected void doCommit() throws TransactionException {
    try {
        managedConnection.commit();
        LOG.debug( "committed JDBC Connection" );
    }
    catch( SQLException e ) {
        throw new TransactionException( "unable to commit against JDBC connection", e );
    }
    finally {
        releaseManagedConnection();
    }
}
项目:lams    文件:JdbcTransaction.java   
@Override
protected void doRollback() throws TransactionException {
    try {
        managedConnection.rollback();
        LOG.debug( "rolled JDBC Connection" );
    }
    catch( SQLException e ) {
        throw new TransactionException( "unable to rollback against JDBC connection", e );
    }
    finally {
        releaseManagedConnection();
    }
}
项目:lams    文件:CMTTransaction.java   
@Override
protected void afterTransactionBegin() {
    if ( ! transactionCoordinator().isSynchronizationRegistered() ) {
        throw new TransactionException("Could not register synchronization for container transaction");
    }
    transactionCoordinator().sendAfterTransactionBeginNotifications( this );
    transactionCoordinator().getTransactionContext().afterTransactionBegin( this );
}
项目:lams    文件:CMTTransaction.java   
@Override
public void markRollbackOnly() {
    try {
        getTransactionManager().setRollbackOnly();
    }
    catch ( SystemException se ) {
        throw new TransactionException("Could not set transaction to rollback only", se);
    }
}
项目:lams    文件:CMTTransactionFactory.java   
@Override
public boolean isJoinableJtaTransaction(TransactionCoordinator transactionCoordinator, CMTTransaction transaction) {
    try {
        final int status = transactionCoordinator
                .getTransactionContext()
                .getTransactionEnvironment()
                .getJtaPlatform()
                .getCurrentStatus();
        return JtaStatusHelper.isActive( status );
    }
    catch( SystemException se ) {
        throw new TransactionException( "Unable to check transaction status", se );
    }
}
项目:lams    文件:JtaTransaction.java   
private UserTransaction locateUserTransaction() {
    final UserTransaction userTransaction = jtaPlatform().retrieveUserTransaction();
    if ( userTransaction == null ) {
        throw new TransactionException( "Unable to locate JTA UserTransaction" );
    }
    return userTransaction;
}
项目:lams    文件:JtaTransaction.java   
private void applyTimeout() {
    if ( getTimeout() > 0 ) {
        if ( userTransaction != null ) {
            try {
                userTransaction.setTransactionTimeout( getTimeout() );
            }
            catch ( SystemException e ) {
                throw new TransactionException( "Unable to apply requested transaction timeout", e );
            }
        }
        else {
            LOG.debug( "Unable to apply requested transaction timeout; no UserTransaction.  Will try later" );
        }
    }
}
项目:lams    文件:JtaTransaction.java   
@Override
protected void doCommit() {
    try {
        if ( isInitiator ) {
            userTransaction.commit();
            LOG.debug( "Committed JTA UserTransaction" );
        }
    }
    catch ( Exception e ) {
        throw new TransactionException( "JTA commit failed: ", e );
    }
}
项目:lams    文件:JtaTransaction.java   
@Override
public boolean isActive() throws HibernateException {
    if ( getLocalStatus() != LocalStatus.ACTIVE ) {
        return false;
    }

    final int status;
    try {
        status = userTransaction.getStatus();
    }
    catch ( SystemException se ) {
        throw new TransactionException( "Could not determine transaction status: ", se );
    }
    return JtaStatusHelper.isActive( status );
}
项目:lams    文件:JtaStatusHelper.java   
/**
 * Extract the status code from a {@link UserTransaction}
 *
 * @param userTransaction The {@link UserTransaction} from which to extract the status.
 *
 * @return The transaction status
 *
 * @throws TransactionException If the {@link UserTransaction} reports the status as unknown
 */
public static int getStatus(UserTransaction userTransaction) {
    try {
        final int status = userTransaction.getStatus();
        if ( status == Status.STATUS_UNKNOWN ) {
            throw new TransactionException( "UserTransaction reported transaction status as unknown" );
        }
        return status;
    }
    catch ( SystemException se ) {
        throw new TransactionException( "Could not determine transaction status", se );
    }
}
项目:lams    文件:JtaStatusHelper.java   
/**
 * Extract the status code from the current {@link javax.transaction.Transaction} associated with the
 * given {@link TransactionManager}
 *
 * @param transactionManager The {@link TransactionManager} from which to extract the status.
 *
 * @return The transaction status
 *
 * @throws TransactionException If the {@link TransactionManager} reports the status as unknown
 */
public static int getStatus(TransactionManager transactionManager) {
    try {
        final int status = transactionManager.getStatus();
        if ( status == Status.STATUS_UNKNOWN ) {
            throw new TransactionException( "TransactionManager reported transaction status as unknwon" );
        }
        return status;
    }
    catch ( SystemException se ) {
        throw new TransactionException( "Could not determine transaction status", se );
    }
}
项目:lams    文件:JdbcCoordinatorImpl.java   
@Override
public int determineRemainingTransactionTimeOutPeriod() {
    if ( transactionTimeOutInstant < 0 ) {
        return -1;
    }
    final int secondsRemaining = (int) ((transactionTimeOutInstant - System.currentTimeMillis()) / 1000);
    if ( secondsRemaining <= 0 ) {
        throw new TransactionException( "transaction timeout expired" );
    }
    return secondsRemaining;
}
项目:sbc-qsystem    文件:ServerProps.java   
private QProperty persistProp(QProperty prop, boolean save) {
    final Exception res;
    try {
        res = (Exception) Spring.getInstance().getTt().execute((TransactionStatus status) -> {
            try {
                if (save) {
                    Spring.getInstance().getHt().saveOrUpdate(prop);
                } else {
                    Spring.getInstance().getHt().delete(prop);
                }
            } catch (Exception ex) {
                QLog.l().logger().error(
                    "Ошибка при " + (save ? "сохранении" : "удалении") + " \n" + ex.toString()
                        + "\n"
                        + Arrays.toString(ex.getStackTrace()));
                status.setRollbackOnly();
                return ex;
            }
            return null;
        });
    } catch (TransactionException ex) {
        throw new ServerException(
            "Ошибка выполнения операции изменения данных в БД(JDBC). Возможно введенные вами параметры не могут быть сохранены.\n("
                + ex.toString() + ")");
    }
    if (res != null) {
        throw new ServerException(
            "Ошибка выполнения операции изменения данных в БД(JDBC). Возможно введенные вами параметры не могут быть сохранены.\n["
                + res.getLocalizedMessage() + "]\n(" + res.toString() + ")\nSQL: ");
    }
    return prop;
}
项目:sbc-qsystem    文件:ServerProps.java   
public void saveAllProperties() {
    final Collection<QProperty> col = new ArrayList<>();
    properties.values().forEach(sec -> {
        col.addAll(sec.properties.values());
    });
    final Exception res;
    try {
        res = (Exception) Spring.getInstance().getTt().execute((TransactionStatus status) -> {
            try {
                Spring.getInstance().getHt().saveOrUpdateAll(col);
            } catch (Exception ex) {
                QLog.l().logger()
                    .error("Ошибка при сохранении \n" + ex.toString() + "\n" + Arrays
                        .toString(ex.getStackTrace()));
                status.setRollbackOnly();
                return ex;
            }
            return null;
        });
    } catch (TransactionException ex) {
        throw new ServerException(
            "Ошибка выполнения операции изменения данных в БД(JDBC). Возможно введенные вами параметры не могут быть сохранены.\n("
                + ex.toString() + ")");
    }
    if (res != null) {
        throw new ServerException(
            "Ошибка выполнения операции изменения данных в БД(JDBC). Возможно введенные вами параметры не могут быть сохранены.\n["
                + res.getLocalizedMessage() + "]\n(" + res.toString() + ")\nSQL: ");
    }
}
项目:spring4-understanding    文件:ConfigurableJtaPlatform.java   
@Override
public boolean canRegisterSynchronization() {
    try {
        return (this.transactionManager.getStatus() == Status.STATUS_ACTIVE);
    }
    catch (SystemException ex) {
        throw new TransactionException("Could not determine JTA transaction status", ex);
    }
}
项目:spring4-understanding    文件:ConfigurableJtaPlatform.java   
@Override
public void registerSynchronization(Synchronization synchronization) {
    if (this.transactionSynchronizationRegistry != null) {
        this.transactionSynchronizationRegistry.registerInterposedSynchronization(synchronization);
    }
    else {
        try {
            this.transactionManager.getTransaction().registerSynchronization(synchronization);
        }
        catch (Exception ex) {
            throw new TransactionException("Could not access JTA Transaction to register synchronization", ex);
        }
    }
}
项目:spring4-understanding    文件:ConfigurableJtaPlatform.java   
public boolean canRegisterSynchronization() {
    try {
        return (this.transactionManager.getStatus() == Status.STATUS_ACTIVE);
    }
    catch (SystemException ex) {
        throw new TransactionException("Could not determine JTA transaction status", ex);
    }
}
项目:spring4-understanding    文件:ConfigurableJtaPlatform.java   
public void registerSynchronization(Synchronization synchronization) {
    if (this.transactionSynchronizationRegistry != null) {
        this.transactionSynchronizationRegistry.registerInterposedSynchronization(synchronization);
    }
    else {
        try {
            this.transactionManager.getTransaction().registerSynchronization(synchronization);
        }
        catch (Exception ex) {
            throw new TransactionException("Could not access JTA Transaction to register synchronization", ex);
        }
    }
}
项目:hibernate-plus    文件:HibernateConfigurableJtaPlatform.java   
@Override
public boolean canRegisterSynchronization() {
    try {
        return (this.transactionManager.getStatus() == Status.STATUS_ACTIVE);
    } catch (SystemException ex) {
        throw new TransactionException("Could not determine JTA transaction status", ex);
    }
}
项目:hibernate-plus    文件:HibernateConfigurableJtaPlatform.java   
@Override
public void registerSynchronization(Synchronization synchronization) {
    if (this.transactionSynchronizationRegistry != null) {
        this.transactionSynchronizationRegistry.registerInterposedSynchronization(synchronization);
    } else {
        try {
            this.transactionManager.getTransaction().registerSynchronization(synchronization);
        } catch (Exception ex) {
            throw new TransactionException("Could not access JTA Transaction to register synchronization", ex);
        }
    }
}