本文整理匯總了Java中org.springframework.transaction.support.DefaultTransactionDefinition.setTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTransactionDefinition.setTimeout方法的具體用法?Java DefaultTransactionDefinition.setTimeout怎麽用?Java DefaultTransactionDefinition.setTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.transaction.support.DefaultTransactionDefinition
的用法示例。
在下文中一共展示了DefaultTransactionDefinition.setTimeout方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: TransactionImpl
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public TransactionImpl(PlatformTransactionManager transactionManager, PersistenceImpl persistence, boolean join,
@Nullable TransactionParams params, String storeName) {
this.tm = transactionManager;
this.persistence = persistence;
this.storeName = storeName;
td = new DefaultTransactionDefinition();
if (join)
td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
else
td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
if (params != null) {
if (params.getTimeout() != 0)
td.setTimeout(params.getTimeout());
if (params.isReadOnly())
td.setReadOnly(true);
}
ts = tm.getTransaction(td);
persistence.registerSynchronizations(storeName);
}
示例2: execute
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Override
public <T> T execute(final Function<Session, T> callback) {
try {
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setIsolationLevel(getTransactionIsolation().getTransactionIsolation());
int timeout = getTimeout();
if (timeout >= 0) {
definition.setTimeout(timeout);
}
definition.setReadOnly(isReadOnly());
return connectionProvider.connection(false, connection -> {
Session session = newSession(connection);
TransactionTemplate tt = new TransactionTemplate(platformTransactionManager, definition);
return tt.execute(transactionStatus -> callback.apply(session));
});
} catch (final Exception e) {
throw JdbcTemplateExceptionTranslator.doTranslate(e);
}
}
示例3: beginTransaction
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private void beginTransaction(Context ctx)
{
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
if (timeout > 0)
{
def.setTimeout(timeout);
}
TransactionStatus tx = tm.getTransaction(def);
ctx.put(TX, tx);
}
示例4: newTransactionWithCommitAndTimeout
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Test
public void newTransactionWithCommitAndTimeout() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setTimeout(10);
definition.setReadOnly(true);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
return "result";
}
}));
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals(10, manager.getUOWTimeout());
assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
assertFalse(manager.getJoined());
assertFalse(manager.getRollbackOnly());
}
示例5: createTransactionTemplate
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
/**
* Creates the transaction template.
* <p>
* This is Hibernate aware if Hibernate is available.
*
* @param repo the component repository, only used to register secondary items like lifecycle, not null
* @param hibernateSessionFactory the session factory, not null
* @return the template, not null
*/
protected TransactionTemplate createTransactionTemplate(ComponentRepository repo, SessionFactory hibernateSessionFactory) {
DefaultTransactionDefinition transactionDef = new DefaultTransactionDefinition();
transactionDef.setName(getName());
if (getTransactionIsolationLevel() != null) {
transactionDef.setIsolationLevelName(getTransactionIsolationLevel());
}
if (getTransactionPropagationBehavior() != null) {
transactionDef.setPropagationBehaviorName(getTransactionPropagationBehavior());
}
if (getTransactionTimeout() != 0) {
transactionDef.setTimeout(getTransactionTimeout());
}
return new TransactionTemplate(createTransactionManager(repo, hibernateSessionFactory), transactionDef);
}
示例6: createTransactionDefinition
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
/**
* Creates the transaction definition.
*
* @return the transaction definition, not null
*/
protected DefaultTransactionDefinition createTransactionDefinition() {
DefaultTransactionDefinition transDefn = new DefaultTransactionDefinition();
transDefn.setName(getName());
if (getTransactionIsolationLevelName() != null) {
transDefn.setIsolationLevelName(getTransactionIsolationLevelName());
}
if (getTransactionPropagationBehaviorName() != null) {
transDefn.setPropagationBehaviorName(getTransactionPropagationBehaviorName());
}
if (getTransactionTimeout() != 0) {
transDefn.setTimeout(getTransactionTimeout());
}
return transDefn;
}
示例7: start
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public void start() throws Exception {
LOG.info("Starting a transaction from TransactionalLifecycle...");
DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
defaultTransactionDefinition.setTimeout(3600);
TRANSACTION_STATUS = getTransactionManager().getTransaction(defaultTransactionDefinition);
started = true;
}
示例8: testNewTransactionWithCommitAndTimeout
import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public void testNewTransactionWithCommitAndTimeout() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setTimeout(10);
definition.setReadOnly(true);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals("result", ptm.execute(definition, new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
return "result";
}
}));
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals(10, manager.getUOWTimeout());
assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
assertFalse(manager.getJoined());
assertFalse(manager.getRollbackOnly());
}