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


Java Synchronization类代码示例

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


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

示例1: getConnection

import javax.transaction.Synchronization; //导入依赖的package包/类
@Override
public Connection getConnection() {
    // If TransactionSynchronizationRegistry exists,
    // register Synchronization to release connection automatically
    // at the first invocation of this method in the current thread.
    // TODO: I wonder if I can register for each thread ...
    if(syncRegistry != null && registered.get() == null){
        syncRegistry.registerInterposedSynchronization(new Synchronization() {
            //@Override
            public void beforeCompletion() {
            }

            //@Override
            public void afterCompletion(int status) {
                releaseConnection();
                registered.remove();
            }
        });
        registered.set(true);
    }

    return super.getConnection();
}
 
开发者ID:mirage-sql,项目名称:mirage-integration,代码行数:24,代码来源:SeasarConnectionProvider.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testRollbackNoExisting

import javax.transaction.Synchronization; //导入依赖的package包/类
@Test public void testRollbackNoExisting() throws Exception {
	setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
	execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
	execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
	execute("update x set e1 = e2 where e2 > 1", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
	
	Mockito.verify(txn).registerSynchronization((Synchronization) Mockito.anyObject());
	synch.afterCompletion(Status.STATUS_ROLLEDBACK);
	
	try {
		execute("select * from x", new List[] {});
		fail();
	} catch (Exception e) {
		
	}
	execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:18,代码来源:TestTempTables.java

示例9: doWithSyncs

import javax.transaction.Synchronization; //导入依赖的package包/类
/**
 * Experience shows that in some cases the synchronization objects are added
 * while we are doing the commits as a result of EntityListeners for
 * example. Therefore prevent concurrent modification exceptions.
 * 
 * @param c The consumer to execute on all synchronization objects
 */
private void doWithSyncs(Consumer<Synchronization> c) {
    if (toSync.size() == 0) return;
    List<Synchronization> toDo = toSync;
    toSync = new ArrayList<>();
    try {
        // Perform the consumer on the existing list.
        toDo.stream().forEach((s) -> c.accept(s));
        // And on the new list recursively.
        doWithSyncs(c);
    } finally {
        // Gather the lot to the new list.
        toDo.addAll(toSync);
        toSync = toDo;
    }
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:23,代码来源:TransactionImpl.java

示例10: invoke

import javax.transaction.Synchronization; //导入依赖的package包/类
@AroundInvoke
public Object invoke(final InvocationContext ctx) throws Exception {
    boolean transactional = false;
    try {
        System.out.println("Intercepting "+ctx.getMethod().toGenericString());
        transactional = txRegistry != null && txRegistry.getTransactionStatus() != Status.STATUS_NO_TRANSACTION;
        if (transactional) {
            txRegistry.registerInterposedSynchronization(new Synchronization() {
                @Override
                public void beforeCompletion() {

                }

                @Override
                public void afterCompletion(int i) {
                    registerInvocation(ctx.getMethod());
                }
            });
        }
        return ctx.proceed();
    } finally {
        if (!transactional) {
            registerInvocation(ctx.getMethod());
        }
    }
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:27,代码来源:ReceptionSynchronizer.java

示例11: registerSynchronization

import javax.transaction.Synchronization; //导入依赖的package包/类
@Override
public void registerSynchronization(Synchronization synchronization)
    throws RollbackException, SystemException {
  if (this.status != Status.STATUS_ACTIVE) {
    throw new IllegalStateException("the transaction is not active");
  }
  if (this.rollbackOnly) {
    throw new RollbackException("the transaction is signed to roll back only");
  }
  TransactionAdapter txAdapt =
      (TransactionAdapter) TransactionManagerImpl.getManager().getTransaction();
  if (txAdapt.getTx() != this) {
    throw new IllegalStateException("the transaction is not held");
  }
  if (this.synList == null) {
    this.synList = new ArrayList<Synchronization>();
  }
  this.synList.add(synchronization);
}
 
开发者ID:xionghuiCoder,项目名称:clearpool,代码行数:20,代码来源:TransactionImpl.java

示例12: testCommit

import javax.transaction.Synchronization; //导入依赖的package包/类
@Test
public void testCommit() {
	Transaction tx = new Transaction();
	boolean[] tmp = new boolean[2];
	tx.registerSynchronization(
			new Synchronization() {
				@Override
				public void beforeCompletion() {
					tmp[0] = true;
				}

				@Override
				public void afterCompletion(int status) {
					if ( status == Status.STATUS_COMMITTED ) {
						tmp[1] = true;
					}
				}
			}
	);
	tx.commit();
	for ( boolean t : tmp ) {
		assertTrue( t );
	}
}
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:25,代码来源:TransactionTest.java

示例13: testRollback

import javax.transaction.Synchronization; //导入依赖的package包/类
@Test
public void testRollback() {
	Transaction tx = new Transaction();
	boolean[] tmp = new boolean[2];
	tx.registerSynchronization(
			new Synchronization() {
				@Override
				public void beforeCompletion() {
					tmp[0] = true;
				}

				@Override
				public void afterCompletion(int status) {
					if ( status == Status.STATUS_ROLLEDBACK ) {
						tmp[1] = true;
					}
				}
			}
	);
	tx.rollback();
	for ( boolean t : tmp ) {
		assertTrue( t );
	}
}
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:25,代码来源:TransactionTest.java

示例14: registerInterposedSynchronization

import javax.transaction.Synchronization; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public void registerInterposedSynchronization(Synchronization sync)
{
   TransactionImpl tx = registry.getTransaction();

   if (tx == null)
      throw new IllegalStateException();

   try
   {
      tx.registerSynchronization(sync);
   }
   catch (Throwable t)
   {
      // Nothing to do
   }
}
 
开发者ID:ironjacamar,项目名称:ironjacamar,代码行数:20,代码来源:TransactionSynchronizationRegistryImpl.java

示例15: 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


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