當前位置: 首頁>>代碼示例>>Java>>正文


Java TransactionDefinition.TIMEOUT_DEFAULT屬性代碼示例

本文整理匯總了Java中org.springframework.transaction.TransactionDefinition.TIMEOUT_DEFAULT屬性的典型用法代碼示例。如果您正苦於以下問題:Java TransactionDefinition.TIMEOUT_DEFAULT屬性的具體用法?Java TransactionDefinition.TIMEOUT_DEFAULT怎麽用?Java TransactionDefinition.TIMEOUT_DEFAULT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.springframework.transaction.TransactionDefinition的用法示例。


在下文中一共展示了TransactionDefinition.TIMEOUT_DEFAULT屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: beginTransaction

@Override
public Object beginTransaction(final EntityManager entityManager, final TransactionDefinition definition)
        throws SQLException {

    final boolean readOnly = definition.isReadOnly();
    final Connection connection = this.getJdbcConnection(entityManager, readOnly).getConnection();
    final Deque<ConnectionContext> deque = curContext.get();
    final ConnectionContext context = new ConnectionContext(connection, definition);
    deque.addLast(context);

    if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
        getSession(entityManager).getTransaction().setTimeout(definition.getTimeout());
    }

    entityManager.getTransaction().begin();

    return prepareTransaction(entityManager, readOnly, definition.getName());
}
 
開發者ID:subes,項目名稱:invesdwin-context-persistence,代碼行數:18,代碼來源:HibernateExtendedJpaDialect.java

示例2: getTxn

private UserTransaction getTxn()
{
    return new SpringAwareUserTransaction(
            transactionManager,
            false,
            TransactionDefinition.ISOLATION_DEFAULT,
            TransactionDefinition.PROPAGATION_REQUIRED,
            TransactionDefinition.TIMEOUT_DEFAULT);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:9,代碼來源:SpringAwareUserTransactionTest.java

示例3: getFailingTxn

private UserTransaction getFailingTxn()
{
    return new SpringAwareUserTransaction(
            failingTransactionManager,
            false,
            TransactionDefinition.ISOLATION_DEFAULT,
            TransactionDefinition.PROPAGATION_REQUIRED,
            TransactionDefinition.TIMEOUT_DEFAULT);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:9,代碼來源:SpringAwareUserTransactionTest.java

示例4: beginTransaction

@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		getSession(entityManager).getTransaction().setTimeout(definition.getTimeout());
	}
	super.beginTransaction(entityManager, definition);
	return prepareTransaction(entityManager, definition.isReadOnly(), definition.getName());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:HibernateJpaDialect.java

示例5: beginTransaction

@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	Session session = getSession(entityManager);

	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		session.getTransaction().setTimeout(definition.getTimeout());
	}

	boolean isolationLevelNeeded = (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT);
	Integer previousIsolationLevel = null;
	Connection preparedCon = null;

	if (isolationLevelNeeded || definition.isReadOnly()) {
		if (this.prepareConnection) {
			preparedCon = HibernateConnectionHandle.doGetConnection(session);
			previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(preparedCon, definition);
		}
		else if (isolationLevelNeeded) {
			throw new InvalidIsolationLevelException(getClass().getSimpleName() +
					" does not support custom isolation levels since the 'prepareConnection' flag is off. " +
					"This is the case on Hibernate 3.6 by default; either switch that flag at your own risk " +
					"or upgrade to Hibernate 4.x, with 4.2+ recommended.");
		}
	}

	// Standard JPA transaction begin call for full JPA context setup...
	entityManager.getTransaction().begin();

	// Adapt flush mode and store previous isolation level, if any.
	FlushMode previousFlushMode = prepareFlushMode(session, definition.isReadOnly());
	return new SessionTransactionData(session, previousFlushMode, preparedCon, previousIsolationLevel);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:HibernateJpaDialect.java

示例6: beginTransaction

@Override
public Object beginTransaction(final EntityManager entityManager,
		final TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	Session session = (Session) entityManager.getDelegate();
	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		getSession(entityManager).getTransaction().setTimeout(
				definition.getTimeout());
	}

	final TransactionData data = new TransactionData();

	session.doWork(new Work() {
		@Override
		public void execute(Connection connection) throws SQLException {
			Integer previousIsolationLevel = DataSourceUtils
					.prepareConnectionForTransaction(connection, definition);
			data.setPreviousIsolationLevel(previousIsolationLevel);
			data.setConnection(connection);
		}
	});

	entityManager.getTransaction().begin();

	Object springTransactionData = prepareTransaction(entityManager,
			definition.isReadOnly(), definition.getName());

	data.setSpringTransactionData(springTransactionData);

	return data;
}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:32,代碼來源:CustomHibernateJpaDialect.java

示例7: beginTransaction

@Override
public Object beginTransaction(final EntityManager entityManager,
        final TransactionDefinition definition)
        throws PersistenceException, SQLException, TransactionException {

    Session session = (Session) entityManager.getDelegate();
    if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
        getSession(entityManager).getTransaction().setTimeout(
                definition.getTimeout());
    }

    final TransactionData data = new TransactionData();

    session.doWork(new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            Integer previousIsolationLevel = DataSourceUtils
                    .prepareConnectionForTransaction(connection, definition);
            data.setPreviousIsolationLevel(previousIsolationLevel);
            data.setConnection(connection);
        }
    });

    entityManager.getTransaction().begin();

    Object springTransactionData = prepareTransaction(entityManager,
            definition.isReadOnly(), definition.getName());

    data.setSpringTransactionData(springTransactionData);

    return data;
}
 
開發者ID:przodownikR1,項目名稱:springJpaKata,代碼行數:32,代碼來源:CustomHibernateJpaDialect.java

示例8: doBegin

/**
 * This implementation sets the isolation level but ignores the timeout.
 */
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) transaction;
	Connection con = null;

	try {
		if (txObject.getConnectionHolder() == null ||
				txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
			Connection newCon = this.dataSource.getConnection();
			if (logger.isDebugEnabled()) {
				logger.debug("Acquired Connection [" + newCon + "] for JDBC transaction");
			}
			txObject.setConnectionHolder(new ConnectionHolder(newCon), true);
		}

		txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
		con = txObject.getConnectionHolder().getConnection();

		Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
		txObject.setPreviousIsolationLevel(previousIsolationLevel);

		// Switch to manual commit if necessary. This is very expensive in some JDBC drivers,
		// so we don't want to do it unnecessarily (for example if we've explicitly
		// configured the connection pool to set it already).
		if (con.getAutoCommit()) {
			txObject.setMustRestoreAutoCommit(true);
			if (logger.isDebugEnabled()) {
				logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
			}
			con.setAutoCommit(false);
		}
		txObject.getConnectionHolder().setTransactionActive(true);

		int timeout = determineTimeout(definition);
		if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
			txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
		}

		// Bind the session holder to the thread.
		if (txObject.isNewConnectionHolder()) {
			TransactionSynchronizationManager.bindResource(getDataSource(), txObject.getConnectionHolder());
		}
	}

	catch (Throwable ex) {
		DataSourceUtils.releaseConnection(con, this.dataSource);
		throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:52,代碼來源:DataSourceTransactionManager.java

示例9: doBegin

/**
 * This implementation sets the isolation level but ignores the timeout.
 */
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) transaction;
	Connection con = null;

	try {
		if (txObject.getConnectionHolder() == null ||
				txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
			Connection newCon = this.dataSource.getConnection();
			if (logger.isDebugEnabled()) {
				logger.debug("Acquired Connection [" + newCon + "] for JDBC transaction");
			}
			txObject.setConnectionHolder(new ConnectionHolder(newCon), true);
		}

		txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
		con = txObject.getConnectionHolder().getConnection();

		Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
		txObject.setPreviousIsolationLevel(previousIsolationLevel);

		// Switch to manual commit if necessary. This is very expensive in some JDBC drivers,
		// so we don't want to do it unnecessarily (for example if we've explicitly
		// configured the connection pool to set it already).
		if (con.getAutoCommit()) {
			txObject.setMustRestoreAutoCommit(true);
			if (logger.isDebugEnabled()) {
				logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
			}
			con.setAutoCommit(false);
		}
		txObject.getConnectionHolder().setTransactionActive(true);

		int timeout = determineTimeout(definition);
		if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
			txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
		}

		// Bind the session holder to the thread.
		if (txObject.isNewConnectionHolder()) {
			TransactionSynchronizationManager.bindResource(getDataSource(), txObject.getConnectionHolder());
		}
	}

	catch (Throwable ex) {
		if (txObject.isNewConnectionHolder()) {
			DataSourceUtils.releaseConnection(con, this.dataSource);
			txObject.setConnectionHolder(null, false);
		}
		throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:55,代碼來源:DataSourceTransactionManager.java

示例10: beginTransaction

@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException {
    Object result = super.beginTransaction(entityManager, definition);
    Preconditions.checkState(result == null, "Transactional data should be null for EclipseLink dialect");

    // Read default timeout every time - may be somebody wants to change it on the fly
    int defaultTimeout = 0;
    String defaultTimeoutProp = AppContext.getProperty("cuba.defaultQueryTimeoutSec");
    if (!"0".equals(defaultTimeoutProp) && !StringUtils.isBlank(defaultTimeoutProp)) {
        try {
            defaultTimeout = Integer.parseInt(defaultTimeoutProp);
        } catch (NumberFormatException e) {
            log.error("Invalid cuba.defaultQueryTimeoutSec value", e);
        }
    }

    int timeoutSec = 0;
    if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT)
        timeoutSec = definition.getTimeout();
    else if (defaultTimeout != 0)
        timeoutSec = defaultTimeout;

    if (timeoutSec != 0) {
        log.trace("Applying query timeout " + timeoutSec + "sec");
        if (entityManager instanceof JpaEntityManager) {
            UnitOfWork unitOfWork = ((JpaEntityManager) entityManager).getUnitOfWork();
            if (unitOfWork != null) {
                //setup delay in seconds on unit of work
                unitOfWork.setQueryTimeoutDefault(timeoutSec);
            }
        }

        String s = DbmsSpecificFactory.getDbmsFeatures().getTransactionTimeoutStatement();
        if (s != null) {
            Connection connection = entityManager.unwrap(Connection.class);
            try (Statement statement = connection.createStatement()) {
                statement.execute(String.format(s, timeoutSec * 1000));
            }
        }
    }

    return new CubaEclipseLinkTransactionData(entityManager);
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:43,代碼來源:CubaEclipseLinkJpaDialect.java

示例11: setDefaultTimeout

/**
 * Specify the default timeout that this transaction manager should apply
 * if there is no timeout specified at the transaction level, in seconds.
 * <p>Default is the underlying transaction infrastructure's default timeout,
 * e.g. typically 30 seconds in case of a JTA provider, indicated by the
 * {@code TransactionDefinition.TIMEOUT_DEFAULT} value.
 * @see org.springframework.transaction.TransactionDefinition#TIMEOUT_DEFAULT
 */
public final void setDefaultTimeout(int defaultTimeout) {
	if (defaultTimeout < TransactionDefinition.TIMEOUT_DEFAULT) {
		throw new InvalidTimeoutException("Invalid default timeout", defaultTimeout);
	}
	this.defaultTimeout = defaultTimeout;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:AbstractPlatformTransactionManager.java

示例12: determineTimeout

/**
 * Determine the actual timeout to use for the given definition.
 * Will fall back to this manager's default timeout if the
 * transaction definition doesn't specify a non-default value.
 * @param definition the transaction definition
 * @return the actual timeout to use
 * @see org.springframework.transaction.TransactionDefinition#getTimeout()
 * @see #setDefaultTimeout
 */
protected int determineTimeout(TransactionDefinition definition) {
	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		return definition.getTimeout();
	}
	return this.defaultTimeout;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:AbstractPlatformTransactionManager.java

示例13: applyTimeout

/**
 * Apply the given transaction timeout. The default implementation will call
 * {@code UserTransaction.setTransactionTimeout} for a non-default timeout value.
 * @param txObject the JtaTransactionObject containing the UserTransaction
 * @param timeout timeout value taken from transaction definition
 * @throws SystemException if thrown by the JTA implementation
 * @see #doJtaBegin
 * @see JtaTransactionObject#getUserTransaction()
 * @see javax.transaction.UserTransaction#setTransactionTimeout(int)
 */
protected void applyTimeout(JtaTransactionObject txObject, int timeout) throws SystemException {
	if (timeout > TransactionDefinition.TIMEOUT_DEFAULT) {
		txObject.getUserTransaction().setTransactionTimeout(timeout);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:JtaTransactionManager.java


注:本文中的org.springframework.transaction.TransactionDefinition.TIMEOUT_DEFAULT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。