Java 类org.springframework.transaction.support.SimpleTransactionStatus 实例源码

项目:spring4-understanding    文件:TransactionalTestExecutionListenerTests.java   
private void assertAfterTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
    BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
    Invocable instance = clazz.newInstance();
    given(testContext.getTestInstance()).willReturn(instance);
    given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));

    given(tm.getTransaction(BDDMockito.any(TransactionDefinition.class))).willReturn(new SimpleTransactionStatus());

    assertFalse(instance.invoked);
    TransactionContextHolder.removeCurrentTransactionContext();
    listener.beforeTestMethod(testContext);
    listener.afterTestMethod(testContext);
    assertTrue(instance.invoked);
}
项目:owsi-core-parent    文件:SimpleHibernateBatchExecutor.java   
@Override
public TransactionOperations getExecuteTransactionOperations() {
    return new TransactionOperations() {
        @Override
        public <T2> T2 execute(TransactionCallback<T2> action) throws TransactionException {
            return action.doInTransaction(new SimpleTransactionStatus());
        }
    };
}
项目:owsi-core-parent    文件:OpenEntityManagerWithNoTransactionTransactionTemplate.java   
@Override
public <T> T execute(TransactionCallback<T> action) throws TransactionException {
    try {
        entityManagerUtils.openEntityManager();
        // We do not  call super() here, no transaction will be opened.
        // Note : it doesn't exist any transaction manager which doesn't open transaction while
        // keeping entity manager open.
        return action.doInTransaction(new SimpleTransactionStatus());
    } finally {
        entityManagerUtils.closeEntityManager();
    }
}
项目:opennmszh    文件:CollectdTest.java   
private void setupTransactionManager() {
    m_transactionManager = m_easyMockUtils.createMock(PlatformTransactionManager.class);
    TransactionTemplate transactionTemplate = new TransactionTemplate(m_transactionManager);
    m_collectd.setTransactionTemplate(transactionTemplate);

    expect(m_transactionManager.getTransaction(isA(TransactionDefinition.class))).andReturn(new SimpleTransactionStatus()).anyTimes();
    m_transactionManager.rollback(isA(TransactionStatus.class));
    expectLastCall().anyTimes();
    m_transactionManager.commit(isA(TransactionStatus.class)); //anyTimes();
    expectLastCall().anyTimes();
}
项目:gocd    文件:PipelineStateDaoTest.java   
@Test
public void shouldNotCorruptCacheIfSaveFailsWhileLocking() {
    String pipelineName = UUID.randomUUID().toString();
    Pipeline pipeline = PipelineMother.pipeline(pipelineName, new Stage());
    PipelineState pipelineState = new PipelineState(pipelineName);
    goCache.put(pipelineStateDao.pipelineLockStateCacheKey(pipelineName), pipelineState);

    when(transactionTemplate.execute(any(org.springframework.transaction.support.TransactionCallbackWithoutResult.class))).thenAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            org.springframework.transaction.support.TransactionCallbackWithoutResult callback = (org.springframework.transaction.support.TransactionCallbackWithoutResult) invocation.getArguments()[0];
            callback.doInTransaction(new SimpleTransactionStatus());
            return null;
        }
    });
    doThrow(new RuntimeException("could not save!")).when(session).saveOrUpdate(any(PipelineState.class));

    try {
        pipelineStateDao.lockPipeline(pipeline);
        fail("save should have thrown an exception!");
    } catch (Exception e) {
        PipelineState stateFromCache = (PipelineState) goCache.get(pipelineStateDao.pipelineLockStateCacheKey(pipelineName));
        assertThat(stateFromCache.isLocked(), is(false));
        assertThat(stateFromCache.getLockedByPipelineId(), is(0L));
        assertThat(stateFromCache.getLockedBy(), is(nullValue()));
    }
}
项目:gocd    文件:PipelineStateDaoTest.java   
@Test
public void shouldNotCorruptCacheIfSaveFailsWhileUnLocking() {
    String pipelineName = UUID.randomUUID().toString();
    PipelineState pipelineState = new PipelineState(pipelineName);
    long lockedByPipelineId = 1;
    pipelineState.lock(lockedByPipelineId);
    goCache.put(pipelineStateDao.pipelineLockStateCacheKey(pipelineName), pipelineState);

    when(transactionTemplate.execute(any(org.springframework.transaction.support.TransactionCallbackWithoutResult.class))).thenAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            org.springframework.transaction.support.TransactionCallbackWithoutResult callback = (org.springframework.transaction.support.TransactionCallbackWithoutResult) invocation.getArguments()[0];
            callback.doInTransaction(new SimpleTransactionStatus());
            return null;
        }
    });
    doThrow(new RuntimeException("could not save!")).when(session).saveOrUpdate(any(PipelineState.class));

    try {
        pipelineStateDao.unlockPipeline(pipelineName);
        fail("save should have thrown an exception!");
    } catch (Exception e) {
        PipelineState stateFromCache = (PipelineState) goCache.get(pipelineStateDao.pipelineLockStateCacheKey(pipelineName));
        assertThat(stateFromCache.isLocked(), is(true));
        assertThat(stateFromCache.getLockedByPipelineId(), is(lockedByPipelineId));
    }
}
项目:OpenNMS    文件:CollectdTest.java   
private void setupTransactionManager() {
    m_transactionManager = m_easyMockUtils.createMock(PlatformTransactionManager.class);
    TransactionTemplate transactionTemplate = new TransactionTemplate(m_transactionManager);
    m_collectd.setTransactionTemplate(transactionTemplate);

    expect(m_transactionManager.getTransaction(isA(TransactionDefinition.class))).andReturn(new SimpleTransactionStatus()).anyTimes();
    m_transactionManager.rollback(isA(TransactionStatus.class));
    expectLastCall().anyTimes();
    m_transactionManager.commit(isA(TransactionStatus.class)); //anyTimes();
    expectLastCall().anyTimes();
}
项目:Spring-5.0-Cookbook    文件:TransactionManager.java   
@Override
public TransactionStatus getTransaction(TransactionDefinition definition)
                    throws TransactionException {
      return new SimpleTransactionStatus();
}
项目:db-queue    文件:FakeTransactionTemplate.java   
@Override
public <T> T execute(TransactionCallback<T> action) throws TransactionException {
    return action.doInTransaction(new SimpleTransactionStatus());
}
项目:spring4-understanding    文件:MockCallbackPreferringTransactionManager.java   
@Override
public <T> T execute(TransactionDefinition definition, TransactionCallback<T> callback) throws TransactionException {
    this.definition = definition;
    this.status = new SimpleTransactionStatus();
    return callback.doInTransaction(this.status);
}
项目:class-guard    文件:MockCallbackPreferringTransactionManager.java   
@Override
public Object execute(TransactionDefinition definition, TransactionCallback callback) throws TransactionException {
    this.definition = definition;
    this.status = new SimpleTransactionStatus();
    return callback.doInTransaction(this.status);
}
项目:javaconfig-ftw    文件:StupidPlatformTransactionManager.java   
public TransactionStatus getTransaction(TransactionDefinition definition)
        throws TransactionException {
    return new SimpleTransactionStatus();
}
项目:bandwidth-on-demand    文件:FakeTransactionOperations.java   
@Override
public <T> T execute(TransactionCallback<T> action) throws TransactionException {
  return action.doInTransaction(new SimpleTransactionStatus(true));
}
项目:health-and-care-developer-network    文件:DummyTransactionManager.java   
public TransactionStatus getTransaction(TransactionDefinition transactionDefinition) throws TransactionException {
    committed = false;
    return new SimpleTransactionStatus(true);
}