本文整理匯總了Java中org.springframework.transaction.TransactionDefinition.getTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java TransactionDefinition.getTimeout方法的具體用法?Java TransactionDefinition.getTimeout怎麽用?Java TransactionDefinition.getTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.transaction.TransactionDefinition
的用法示例。
在下文中一共展示了TransactionDefinition.getTimeout方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: beginTransaction
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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: beginTransaction
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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());
}
示例3: beginTransaction
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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);
}
示例4: beginTransaction
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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;
}
示例5: beginTransaction
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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;
}
示例6: beginTransaction
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
@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);
}
示例7: determineTimeout
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
* 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;
}
示例8: DefaultTransactionDefinition
import org.springframework.transaction.TransactionDefinition; //導入方法依賴的package包/類
/**
* Copy constructor. Definition can be modified through bean property setters.
* @see #setPropagationBehavior
* @see #setIsolationLevel
* @see #setTimeout
* @see #setReadOnly
* @see #setName
*/
public DefaultTransactionDefinition(TransactionDefinition other) {
this.propagationBehavior = other.getPropagationBehavior();
this.isolationLevel = other.getIsolationLevel();
this.timeout = other.getTimeout();
this.readOnly = other.isReadOnly();
this.name = other.getName();
}