本文整理汇总了Java中javax.transaction.Synchronization.beforeCompletion方法的典型用法代码示例。如果您正苦于以下问题:Java Synchronization.beforeCompletion方法的具体用法?Java Synchronization.beforeCompletion怎么用?Java Synchronization.beforeCompletion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.transaction.Synchronization
的用法示例。
在下文中一共展示了Synchronization.beforeCompletion方法的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");
}
示例2: 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);
}
示例3: 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);
}
示例4: fireBeforeCompletionEvent
import javax.transaction.Synchronization; //导入方法依赖的package包/类
/**
* Run all registered Synchronizations' beforeCompletion() method. Be aware that this method can change the
* transaction status to mark it as rollback only for instance.
* @throws bitronix.tm.internal.BitronixSystemException if status changing due to a synchronization throwing an
* exception fails.
*/
private void fireBeforeCompletionEvent() throws BitronixSystemException {
if (log.isDebugEnabled()) { log.debug("before completion, " + synchronizationScheduler.size() + " synchronization(s) to execute"); }
Iterator<Synchronization> it = synchronizationScheduler.reverseIterator();
while (it.hasNext()) {
Synchronization synchronization = it.next();
try {
if (log.isDebugEnabled()) { log.debug("executing synchronization " + synchronization); }
synchronization.beforeCompletion();
} catch (RuntimeException ex) {
if (log.isDebugEnabled()) { log.debug("Synchronization.beforeCompletion() call failed for " + synchronization + ", marking transaction as rollback only - " + ex); }
setStatus(Status.STATUS_MARKED_ROLLBACK);
throw ex;
}
}
}
示例5: 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);
}
}
示例6: notifySynchronizationsBeforeTransactionCompletion
import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Override
public void notifySynchronizationsBeforeTransactionCompletion() {
if ( synchronizations != null ) {
for ( Synchronization synchronization : synchronizations ) {
try {
synchronization.beforeCompletion();
}
catch ( Throwable t ) {
LOG.synchronizationFailed( synchronization, t );
}
}
}
}
示例7: 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();
}
示例8: 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());
}
示例9: notifyLocalSynchsBeforeTransactionCompletion
import javax.transaction.Synchronization; //导入方法依赖的package包/类
private void notifyLocalSynchsBeforeTransactionCompletion() {
if (synchronizations!=null) {
for ( int i=0; i<synchronizations.size(); i++ ) {
Synchronization sync = (Synchronization) synchronizations.get(i);
try {
sync.beforeCompletion();
}
catch (Throwable t) {
log.error("exception calling user Synchronization", t);
}
}
}
}
示例10: beforeCompletion
import javax.transaction.Synchronization; //导入方法依赖的package包/类
private void beforeCompletion(Synchronization sync) {
try {
sync.beforeCompletion();
} catch (Throwable t) {
logger.debug("Failed to process the before completion: " + sync, t);
status = Status.STATUS_MARKED_ROLLBACK;
endResources(XAResource.TMFAIL);
rollbackResources();
}
}
示例11: beforeCompletion
import javax.transaction.Synchronization; //导入方法依赖的package包/类
private void beforeCompletion() {
if (!synchronizations.isEmpty()) {
for (Synchronization sync : synchronizations) {
sync.beforeCompletion();
}
}
}
示例12: beforeCompletion
import javax.transaction.Synchronization; //导入方法依赖的package包/类
public void beforeCompletion() {
int length = this.synchronizations.size();
for (int i = 0; i < length; i++) {
Synchronization synchronization = this.synchronizations.get(i);
synchronization.beforeCompletion();
} // end-for
}
示例13: beforeCompletion
import javax.transaction.Synchronization; //导入方法依赖的package包/类
private void beforeCompletion() {
if (this.synList == null) {
return;
}
for (Synchronization syn : this.synList) {
syn.beforeCompletion();
}
}
示例14: onFlush
import javax.transaction.Synchronization; //导入方法依赖的package包/类
@Override
public void onFlush(FlushEvent event) throws HibernateException {
Session session = event.getSession();
Synchronization synchronization = flushSynch.get( session );
if ( synchronization != null ) {
//first cleanup
flushSynch.remove( session );
LOGGER.fine( "flush event causing index update out of transaction" );
synchronization.beforeCompletion();
synchronization.afterCompletion( Status.STATUS_COMMITTED );
}
}
示例15: invoke
import javax.transaction.Synchronization; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = null;
String methodName = method.getName();
logger.trace(methodName);
if( "commit".equals(methodName) && args == null) {
BitronixTransaction bt = ((BitronixTransactionManager) ut).getCurrentTransaction();
// Ensure that all actions have occurred so that we get what is _really_ commited to the db
// (This code is straight from bitronix)
Iterator<?> iter = bt.getSynchronizationScheduler().reverseIterator();
while (iter.hasNext()) {
Synchronization synchronization = (Synchronization) iter.next();
try {
synchronization.beforeCompletion();
} catch (RuntimeException ex) {
bt.setStatus(Status.STATUS_MARKED_ROLLBACK);
throw ex;
}
}
String testMethodName = MarshallingTestUtil.getTestMethodName();
if( testMethodName != null ) {
EntityManager em = emf.createEntityManager();
Set<MarshalledData> newMarshalledData = objectSpecificMarshallingActions.updateManagedObjects(testMethodName);
for( MarshalledData marshalledData : newMarshalledData ) {
em.persist(marshalledData);
}
em.close();
}
ut.commit();
return result;
}
else {
result = invoke(method, ut, args);
}
return result;
}