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


Java Synchronization.afterCompletion方法代码示例

本文整理汇总了Java中javax.transaction.Synchronization.afterCompletion方法的典型用法代码示例。如果您正苦于以下问题:Java Synchronization.afterCompletion方法的具体用法?Java Synchronization.afterCompletion怎么用?Java Synchronization.afterCompletion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.transaction.Synchronization的用法示例。


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

示例1: testClobStringTypeWithJtaSynchronization

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testClobStringTypeWithJtaSynchronization() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);

	given(lobHandler.getClobAsString(rs, "column")).willReturn("content");

	ClobStringType type = new ClobStringType(lobHandler, tm);
	assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, "content", 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.beforeCompletion();
	synch.afterCompletion(Status.STATUS_COMMITTED);
	verify(lobCreator).setClobAsString(ps, 1, "content");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:LobTypeTests.java

示例2: testClobStringTypeWithJtaSynchronizationAndRollback

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testClobStringTypeWithJtaSynchronizationAndRollback() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);
	given(lobHandler.getClobAsString(rs, "column")).willReturn("content");

	ClobStringType type = new ClobStringType(lobHandler, tm);
	assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, "content", 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.afterCompletion(Status.STATUS_ROLLEDBACK);

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

示例3: testBlobStringTypeWithJtaSynchronization

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testBlobStringTypeWithJtaSynchronization() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);

	String content = "content";
	byte[] contentBytes = content.getBytes();
	given(lobHandler.getBlobAsBytes(rs, "column")).willReturn(contentBytes);

	BlobStringType type = new BlobStringType(lobHandler, tm);
	assertEquals(content, type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, content, 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.beforeCompletion();
	synch.afterCompletion(Status.STATUS_COMMITTED);

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

示例4: testBlobStringTypeWithJtaSynchronizationAndRollback

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testBlobStringTypeWithJtaSynchronizationAndRollback() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);

	String content = "content";
	byte[] contentBytes = content.getBytes();
	given(lobHandler.getBlobAsBytes(rs, "column")).willReturn(contentBytes);

	BlobStringType type = new BlobStringType(lobHandler, tm);
	assertEquals(content, type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, content, 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.afterCompletion(Status.STATUS_ROLLEDBACK);
	verify(lobCreator).setBlobAsBytes(ps, 1, contentBytes);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:LobTypeTests.java

示例5: testBlobByteArrayTypeWithJtaSynchronization

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testBlobByteArrayTypeWithJtaSynchronization() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);

	byte[] content = "content".getBytes();
	given(lobHandler.getBlobAsBytes(rs, "column")).willReturn(content);

	BlobByteArrayType type = new BlobByteArrayType(lobHandler, tm);
	assertEquals(content, type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, content, 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.beforeCompletion();
	synch.afterCompletion(Status.STATUS_COMMITTED);
	verify(lobCreator).setBlobAsBytes(ps, 1, content);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:LobTypeTests.java

示例6: testBlobByteArrayTypeWithJtaSynchronizationAndRollback

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testBlobByteArrayTypeWithJtaSynchronizationAndRollback() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);

	byte[] content = "content".getBytes();
	given(lobHandler.getBlobAsBytes(rs, "column")).willReturn(content);

	BlobByteArrayType type = new BlobByteArrayType(lobHandler, tm);
	assertEquals(content, type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, content, 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.afterCompletion(Status.STATUS_ROLLEDBACK);
	verify(lobCreator).setBlobAsBytes(ps, 1, content);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:LobTypeTests.java

示例7: doAfterCompletion

import javax.transaction.Synchronization; //导入方法依赖的package包/类
synchronized void doAfterCompletion()
{
    for ( Synchronization s : syncHooks )
    {
        try
        {
            s.afterCompletion( status );
        }
        catch ( Throwable t )
        {
            log.log( Level.WARNING, "Caught exception from tx syncronization[" + s
                + "] afterCompletion()", t );
        }
    }
    syncHooks = null; // help gc
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-mobile-android,代码行数:17,代码来源:TransactionImpl.java

示例8: doAfterCompletion

import javax.transaction.Synchronization; //导入方法依赖的package包/类
synchronized void doAfterCompletion()
{
    for ( Synchronization s : syncHooks )
    {
        try
        {
            s.afterCompletion( status );
        }
        catch ( Throwable t )
        {
            log.warning( "Caught exception from tx syncronization[" + s
                + "] afterCompletion()" );
        }
    }
    syncHooks = null; // help gc
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-mobile-android,代码行数:17,代码来源:ReadOnlyTransactionImpl.java

示例9: fireAfterCompletionEvent

import javax.transaction.Synchronization; //导入方法依赖的package包/类
private void fireAfterCompletionEvent() {
    // this TX is no longer in-flight -> remove this transaction's state from all XAResourceHolders
    getResourceManager().clearXAResourceHolderStates();

    if (log.isDebugEnabled()) { log.debug("after completion, " + synchronizationScheduler.size() + " synchronization(s) to execute"); }
    for (Synchronization synchronization : synchronizationScheduler) {
        try {
            if (log.isDebugEnabled()) { log.debug("executing synchronization " + synchronization + " with status=" + Decoder.decodeStatus(status)); }
            synchronization.afterCompletion(status);
        } catch (Exception ex) {
            log.warn("Synchronization.afterCompletion() call failed for " + synchronization, ex);
        }
    }

    ManagementRegistrar.unregister("bitronix.tm:type=Transaction,Gtrid=" + resourceManager.getGtrid());
}
 
开发者ID:bitronix,项目名称:btm,代码行数:17,代码来源:BitronixTransaction.java

示例10: registerSynchronization

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Override
public void registerSynchronization(final Synchronization synchronization)
		throws RollbackException, IllegalStateException,
		SystemException {

	final InvocationHandler ih = new InvocationHandler() {

		@Override
		public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
			if ( "afterCompletion".equals( method.getName() ) ) {
				int status = args[2].equals(Boolean.TRUE) ?
						Status.STATUS_COMMITTED :
						Status.STATUS_UNKNOWN;
				synchronization.afterCompletion(status);
			}
			else if ( "beforeCompletion".equals( method.getName() ) ) {
				synchronization.beforeCompletion();
			}
			else if ( "toString".equals( method.getName() ) ) {
				return synchronization.toString();
			}
			return null;
		}

	};

	final Object synchronizationCallback = Proxy.newProxyInstance(
			getClass().getClassLoader(),
			new Class[] {synchronizationCallbackClass},
			ih
	);

	try {
		registerSynchronizationMethod.invoke( extendedJTATransaction, synchronizationCallback );
	}
	catch (Exception e) {
		throw new HibernateException(e);
	}

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:WebSphereExtendedJtaPlatform.java

示例11: notifySynchronizationsAfterTransactionCompletion

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Override
public void notifySynchronizationsAfterTransactionCompletion(int status) {
	if ( synchronizations != null ) {
		for ( Synchronization synchronization : synchronizations ) {
			try {
				synchronization.afterCompletion( status );
			}
			catch ( Throwable t ) {
				LOG.synchronizationFailed( synchronization, t );
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:SynchronizationRegistryImpl.java

示例12: testJtaSessionSynchronization

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronization() throws Exception {

	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getTransaction()).willReturn(transaction);
	final SessionFactoryImplementor sf = mock(SessionFactoryImplementor.class);
	final Session session = mock(Session.class);
	given(sf.openSession()).willReturn(session);
	given(sf.getTransactionManager()).willReturn(tm);
	given(session.isOpen()).willReturn(true);
	given(session.getFlushMode()).willReturn(FlushMode.AUTO);

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	HibernateTemplate ht = new HibernateTemplate(sf);
	ht.setExposeNativeSession(true);
	for (int i = 0; i < 5; i++) {
		ht.executeFind(new HibernateCallback() {

			@Override
			public Object doInHibernate(org.hibernate.Session sess) {
				assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
				assertEquals(session, sess);
				return null;
			}
		});
	}

	Synchronization synchronization = transaction.getSynchronization();
	assertTrue("JTA synchronization registered", synchronization != null);
	synchronization.beforeCompletion();
	synchronization.afterCompletion(Status.STATUS_COMMITTED);

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	verify(session).flush();
	verify(session).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:41,代码来源:HibernateJtaTransactionTests.java

示例13: testJtaSessionSynchronizationWithRollback

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithRollback() throws Exception {

	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getTransaction()).willReturn(transaction);
	final SessionFactoryImplementor sf = mock(SessionFactoryImplementor.class);
	final Session session = mock(Session.class);
	given(sf.openSession()).willReturn(session);
	given(sf.getTransactionManager()).willReturn(tm);
	given(session.isOpen()).willReturn(true);

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	HibernateTemplate ht = new HibernateTemplate(sf);
	ht.setExposeNativeSession(true);
	for (int i = 0; i < 5; i++) {
		ht.executeFind(new HibernateCallback() {

			@Override
			public Object doInHibernate(org.hibernate.Session sess) {
				assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
				assertEquals(session, sess);
				return null;
			}
		});
	}

	Synchronization synchronization = transaction.getSynchronization();
	assertTrue("JTA synchronization registered", synchronization != null);
	synchronization.afterCompletion(Status.STATUS_ROLLEDBACK);

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	verify(session).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:HibernateJtaTransactionTests.java

示例14: testBlobSerializableTypeWithJtaSynchronization

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testBlobSerializableTypeWithJtaSynchronization() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(baos);
	oos.writeObject("content");
	oos.close();

	given(lobHandler.getBlobAsBinaryStream(rs, "column")).willReturn(
			new ByteArrayInputStream(baos.toByteArray()));

	BlobSerializableType type = new BlobSerializableType(lobHandler, tm);
	assertEquals(1, type.sqlTypes().length);
	assertEquals(Types.BLOB, type.sqlTypes()[0]);
	assertEquals(Serializable.class, type.returnedClass());
	assertTrue(type.isMutable());

	assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, "content", 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.beforeCompletion();
	synch.afterCompletion(Status.STATUS_COMMITTED);
	verify(lobCreator).setBlobAsBytes(ps, 1, baos.toByteArray());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:LobTypeTests.java

示例15: testBlobSerializableTypeWithJtaSynchronizationAndRollback

import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Test
public void testBlobSerializableTypeWithJtaSynchronizationAndRollback() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	MockJtaTransaction transaction = new MockJtaTransaction();
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.getTransaction()).willReturn(transaction);

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(baos);
	oos.writeObject("content");
	oos.close();

	given(lobHandler.getBlobAsBinaryStream(rs, "column")).willReturn(
			new ByteArrayInputStream(baos.toByteArray()));

	BlobSerializableType type = new BlobSerializableType(lobHandler, tm);
	assertEquals(1, type.sqlTypes().length);
	assertEquals(Types.BLOB, type.sqlTypes()[0]);
	assertEquals(Serializable.class, type.returnedClass());
	assertTrue(type.isMutable());

	assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
	type.nullSafeSet(ps, "content", 1);
	Synchronization synch = transaction.getSynchronization();
	assertNotNull(synch);
	synch.afterCompletion(Status.STATUS_ROLLEDBACK);
	verify(lobCreator).setBlobAsBytes(ps, 1, baos.toByteArray());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:LobTypeTests.java


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