当前位置: 首页>>代码示例>>Java>>正文


Java TransactionSynchronization类代码示例

本文整理汇总了Java中org.springframework.transaction.support.TransactionSynchronization的典型用法代码示例。如果您正苦于以下问题:Java TransactionSynchronization类的具体用法?Java TransactionSynchronization怎么用?Java TransactionSynchronization使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TransactionSynchronization类属于org.springframework.transaction.support包,在下文中一共展示了TransactionSynchronization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterCompletion

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
/**
 * JTA {@code afterCompletion} callback: invoked after commit/rollback.
 * <p>Needs to invoke the Spring synchronization's {@code beforeCompletion}
 * at this late stage in case of a rollback, since there is no corresponding
 * callback with JTA.
 * @see org.springframework.transaction.support.TransactionSynchronization#beforeCompletion
 * @see org.springframework.transaction.support.TransactionSynchronization#afterCompletion
 */
@Override
public void afterCompletion(int status) {
	if (!this.beforeCompletionCalled) {
		// beforeCompletion not called before (probably because of JTA rollback).
		// Perform the cleanup here.
		this.springSynchronization.beforeCompletion();
	}
	// Call afterCompletion with the appropriate status indication.
	switch (status) {
		case Status.STATUS_COMMITTED:
			this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
			break;
		case Status.STATUS_ROLLEDBACK:
			this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
			break;
		default:
			this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:SpringJtaSynchronizationAdapter.java

示例2: afterCompletion

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Override
public void afterCompletion(int status) {
	switch (status) {
		case Status.STATUS_COMMITTED:
			try {
				TransactionSynchronizationUtils.invokeAfterCommit(this.synchronizations);
			}
			finally {
				TransactionSynchronizationUtils.invokeAfterCompletion(
						this.synchronizations, TransactionSynchronization.STATUS_COMMITTED);
			}
			break;
		case Status.STATUS_ROLLEDBACK:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
			break;
		default:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:JtaAfterCompletionSynchronization.java

示例3: testClobStringTypeWithFlushOnCommit

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void testClobStringTypeWithFlushOnCommit() throws Exception {
	given(lobHandler.getClobAsString(rs, "column")).willReturn("content");

	ClobStringType type = new ClobStringType(lobHandler, null);
	assertEquals(1, type.sqlTypes().length);
	assertEquals(Types.CLOB, type.sqlTypes()[0]);
	assertEquals(String.class, type.returnedClass());
	assertTrue(type.equals("content", "content"));
	assertEquals("content", type.deepCopy("content"));
	assertFalse(type.isMutable());

	assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
	TransactionSynchronizationManager.initSynchronization();
	try {
		type.nullSafeSet(ps, "content", 1);
		List synchs = TransactionSynchronizationManager.getSynchronizations();
		assertEquals(1, synchs.size());
		((TransactionSynchronization) synchs.get(0)).afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
	}
	finally {
		TransactionSynchronizationManager.clearSynchronization();
	}
	verify(lobCreator).setClobAsString(ps, 1, "content");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:LobTypeTests.java

示例4: testBlobStringTypeWithNull

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void testBlobStringTypeWithNull() throws Exception {
	given(lobHandler.getBlobAsBytes(rs, "column")).willReturn(null);

	BlobStringType type = new BlobStringType(lobHandler, null);
	assertEquals(null, type.nullSafeGet(rs, new String[] {"column"}, null));
	TransactionSynchronizationManager.initSynchronization();
	try {
		type.nullSafeSet(ps, null, 1);
		List synchs = TransactionSynchronizationManager.getSynchronizations();
		assertEquals(1, synchs.size());
		((TransactionSynchronization) synchs.get(0)).beforeCompletion();
	}
	finally {
		TransactionSynchronizationManager.clearSynchronization();
	}

	verify(lobCreator).setBlobAsBytes(ps, 1, null);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:LobTypeTests.java

示例5: testBlobSerializableTypeWithNull

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void testBlobSerializableTypeWithNull() throws Exception {
	given(lobHandler.getBlobAsBinaryStream(rs, "column")).willReturn(null);

	BlobSerializableType type = new BlobSerializableType(lobHandler, null);
	assertEquals(null, type.nullSafeGet(rs, new String[] {"column"}, null));
	TransactionSynchronizationManager.initSynchronization();
	try {
		type.nullSafeSet(ps, null, 1);
		List synchs = TransactionSynchronizationManager.getSynchronizations();
		assertEquals(1, synchs.size());
		((TransactionSynchronization) synchs.get(0)).beforeCompletion();
	}
	finally {
		TransactionSynchronizationManager.clearSynchronization();
	}
	verify(lobCreator).setBlobAsBytes(ps, 1, null);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:LobTypeTests.java

示例6: onApplicationEvent

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		TransactionSynchronization transactionSynchronization = createTransactionSynchronization(event);
		TransactionSynchronizationManager.registerSynchronization(transactionSynchronization);
	}
	else if (this.annotation.fallbackExecution()) {
		if (this.annotation.phase() == TransactionPhase.AFTER_ROLLBACK) {
			logger.warn("Processing '" + event + "' as a fallback execution on AFTER_ROLLBACK phase.");
		}
		processEvent(event);
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("No transaction is running, skipping '" + event + "' for '" + this + "'");
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ApplicationListenerMethodTransactionalAdapter.java

示例7: jtaTransactionManagerWithExistingTransactionAndRollbackOnly

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithExistingTransactionAndRollbackOnly() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);

	final TransactionSynchronization synch = mock(TransactionSynchronization.class);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			TransactionSynchronizationManager.registerSynchronization(synch);
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).setRollbackOnly();
	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:JtaTransactionManagerTests.java

示例8: jtaTransactionManagerWithExistingTransactionAndCommitException

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithExistingTransactionAndCommitException() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);

	final TransactionSynchronization synch = mock(TransactionSynchronization.class);
	willThrow(new OptimisticLockingFailureException("")).given(synch).beforeCommit(false);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	try {
		tt.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
				TransactionSynchronizationManager.registerSynchronization(synch);
			}
		});
		fail("Should have thrown OptimisticLockingFailureException");
	}
	catch (OptimisticLockingFailureException ex) {
		// expected
	}
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).setRollbackOnly();
	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:JtaTransactionManagerTests.java

示例9: jtaTransactionManagerWithExistingTransactionAndRollbackOnlyAndNoGlobalRollback

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithExistingTransactionAndRollbackOnlyAndNoGlobalRollback() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);

	final TransactionSynchronization synch = mock(TransactionSynchronization.class);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	ptm.setGlobalRollbackOnParticipationFailure(false);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			TransactionSynchronizationManager.registerSynchronization(synch);
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).setRollbackOnly();
	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:JtaTransactionManagerTests.java

示例10: jtaTransactionManagerWithExistingTransactionAndSynchronizationOnActual

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithExistingTransactionAndSynchronizationOnActual() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);

	final TransactionSynchronization synch = mock(TransactionSynchronization.class);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	ptm.setTransactionSynchronization(JtaTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			TransactionSynchronizationManager.registerSynchronization(synch);
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).setRollbackOnly();
	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:JtaTransactionManagerTests.java

示例11: jtaTransactionManagerWithExistingAndPropagationSupports

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithExistingAndPropagationSupports() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);

	final TransactionSynchronization synch = mock(TransactionSynchronization.class);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			TransactionSynchronizationManager.registerSynchronization(synch);
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).setRollbackOnly();
	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:JtaTransactionManagerTests.java

示例12: jtaTransactionManagerWithPropagationSupports

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithPropagationSupports() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);

	final TransactionSynchronization synch = mock(TransactionSynchronization.class);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			TransactionSynchronizationManager.registerSynchronization(synch);
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:JtaTransactionManagerTests.java

示例13: handleStatus

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
private void handleStatus(int status, String type, Serializable... ids) {
    Message<?> callmess;

    if (TransactionSynchronization.STATUS_COMMITTED == status) {
        // TODO make CommitSuccess handle type/ids combo
        callmess = MessageBuilder.withPayload(new CommitSuccessEvent(ids))
                                 .setHeader(Operative.DESTINATION_NAME, "server.queue").build();
    } else {
        CompensateEvent compensateEvent = new CompensateEvent(status);

        compensateEvent.setIds(ids);
        compensateEvent.setType(type);
        callmess = MessageBuilder.withPayload(compensateEvent)
                                 .setHeader(Operative.DESTINATION_NAME, "server.queue").build();
        LOG.debug("Compensating for " + type + ":" + Arrays.toString(ids));
    }

    asyncChannel.send(callmess);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:20,代码来源:TransactionHandlerImpl.java

示例14: releaseWithTransaction

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
private void releaseWithTransaction(final LockInstance lockInstance) {
   TransactionLockSynchronization synchronization = null;
   for (TransactionSynchronization transactionSynchronization : TransactionSynchronizationManager
            .getSynchronizations()) {
      if (transactionSynchronization instanceof TransactionLockSynchronization) {
         synchronization = (TransactionLockSynchronization) transactionSynchronization;
      }
   }

   if (null == synchronization) {
      synchronization = new TransactionLockSynchronization(this);
      TransactionSynchronizationManager.registerSynchronization(synchronization);
   }

   synchronization.add(lockInstance);
}
 
开发者ID:My-easy-Solutions,项目名称:spring-lock,代码行数:17,代码来源:SessionTransactedLockSynchronizationManager.java

示例15: afterCompletion

import org.springframework.transaction.support.TransactionSynchronization; //导入依赖的package包/类
@Override
public void afterCompletion(int status) {
    if (sessionActive) {
        boolean success = status == TransactionSynchronization.STATUS_COMMITTED;
        // Commit the locks/discard changes on rollback
        try {
            session.afterCompletion(success);
        } finally {
            session.releaseResources();
            StorageSessionHolder.removeSession();
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Session completed: '{}' in {}",
                sessionName, TimeUnitFormat.getTimeString(System.nanoTime() - startTime));
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:18,代码来源:SessionSynchronization.java


注:本文中的org.springframework.transaction.support.TransactionSynchronization类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。