本文整理匯總了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());
}
示例2: getTxn
private UserTransaction getTxn()
{
return new SpringAwareUserTransaction(
transactionManager,
false,
TransactionDefinition.ISOLATION_DEFAULT,
TransactionDefinition.PROPAGATION_REQUIRED,
TransactionDefinition.TIMEOUT_DEFAULT);
}
示例3: getFailingTxn
private UserTransaction getFailingTxn()
{
return new SpringAwareUserTransaction(
failingTransactionManager,
false,
TransactionDefinition.ISOLATION_DEFAULT,
TransactionDefinition.PROPAGATION_REQUIRED,
TransactionDefinition.TIMEOUT_DEFAULT);
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}