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


Java TransactionCallback类代码示例

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


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

示例1: updateBook

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Override
public boolean updateBook(long ISBN, int price) {
	// TODO Auto-generated method stub
	if (searchBook(ISBN).getISBN() == ISBN) {
		transactionTemplate.setReadOnly(false);
	return transactionTemplate.execute(new TransactionCallback<Boolean>() {

		@Override
		public Boolean doInTransaction(TransactionStatus status) {
			// TODO Auto-generated method stub
			try {
		
					int rows = bookDAO.updateBook(ISBN, price);
					if (rows > 0)
						return true;

			} catch (Exception exception) {
				status.setRollbackOnly();
			}
			return false;

		}
	});
	}
	return false;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:27,代码来源:BookServiceImpl.java

示例2: invoke

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Override
public EasyTransResult invoke(EasyTransFilterChain filterChain, Map<String, Object> header,
		EasyTransRequest<?, ?> request) {

	Integer pTrxStatus = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.PARENT_TRANSACTION_STATUS);
	if(!pTrxStatus.equals(com.yiqiniu.easytrans.datasource.TransStatusLogger.TransactionStatus.UNKNOWN)){
		// start transaction to update 
		PlatformTransactionManager transactionManager = getTransactionManager(filterChain, request);
		TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager,
				new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
		TransactionId pTrxId = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.PARENT_TRX_ID_KEY);
		transactionTemplate.execute(new TransactionCallback<Object>() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				TransactionId trxId = pTrxId;
				transStatusLogger.updateExecuteFlagForSlaveTrx(trxId, request, pTrxStatus);
				return null;
			}
		});
		boolean commited = pTrxStatus.equals(com.yiqiniu.easytrans.datasource.TransStatusLogger.TransactionStatus.COMMITTED);
		//may be concurrent,but it's ok
		easyTransSynchronizer.cascadeExecuteCachedTransaction(pTrxId, commited);
	}
	
	return filterChain.invokeFilterChain(header, request);
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:27,代码来源:ParentTrxStatusUpdateFilter.java

示例3: getTicketInTransaction

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
Ticket getTicketInTransaction(final String ticketId) {
    return new TransactionTemplate(txManager).execute(new TransactionCallback<Ticket>() {
        @Override
        public Ticket doInTransaction(final TransactionStatus status) {
            return jpaTicketRegistry.getTicket(ticketId);
        }
    });
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:9,代码来源:JpaTicketRegistryTests.java

示例4: invoke

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    return new TransactionTemplate(txManager).execute(new TransactionCallback<Object>() {
        @Override
        public Object doInTransaction(final TransactionStatus status) {
            try {
                final Object result = method.invoke(jpaLock, args);
                jpaLock.entityManager.flush();
                logger.debug("Performed {} on {}", method.getName(), jpaLock);
                return result;
                // Force result of transaction to database
            } catch (final Exception e) {
                throw new RuntimeException("Transactional method invocation failed.", e);
            }
        }
    });
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:JpaLockingStrategyTests.java

示例5: invoke

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
   @Override
   public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
       return new TransactionTemplate(txManager).execute(new TransactionCallback<Object>() {
           public Object doInTransaction(final TransactionStatus status) {
               try {
                   final Object result = method.invoke(jpaLock, args);
                   jpaLock.entityManager.flush();
                   logger.debug("Performed {} on {}", method.getName(), jpaLock);
                   return result;
                   // Force result of transaction to database
               } catch (final Exception e) {
                   throw new RuntimeException("Transactional method invocation failed.", e);
               }
           }
       });
   }
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:20,代码来源:JpaLockingStrategyTests.java

示例6: invoke

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    return new TransactionTemplate(txManager).execute(new TransactionCallback<Object>() {
        public Object doInTransaction(final TransactionStatus status) {
            try {
                final Object result = method.invoke(jpaLock, args);
                jpaLock.entityManager.flush();
                logger.debug("Performed {} on {}", method.getName(), jpaLock);
                return result;
                // Force result of transaction to database
            } catch (final Exception e) {
                throw new RuntimeException("Transactional method invocation failed.", e);
            }
        }
    });
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:18,代码来源:JpaLockingStrategyTests.java

示例7: testRwRouteWithTransaction2

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Test
public void testRwRouteWithTransaction2() {

    mapper.findByStatus((short) 1);

    transactionTemplate.execute(new TransactionCallback<Void>() {
        @Override
        public Void doInTransaction(TransactionStatus status) {

            mapper.findByStatus((short) 2);

            UserEntity entity = new UserEntity();
            entity.setCreatedAt(new Date());
            entity.setEmail(RandomStringUtils.random(6, true, true) + "@163.com");
            entity.setMobile("13800" + RandomUtils.nextLong(100000, 999999));
            entity.setType((short) 1);
            entity.setStatus((short) 1);
            mapper.insert(entity);

            mapper.findByStatus((short) 2);

            return null;
        }
    });
    System.out.println();
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:27,代码来源:MybatisTest.java

示例8: run

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
public synchronized void run(boolean useIndex) {
    if (useIndex) {
        jdbcTemplate.query(sql, setter, rowHandler);
    } else {

        long latest = latestFetcher.retrieveLatestSer();

        transactionTemplate.execute(new TransactionCallback<Object>() {
            @Override
            public Object doInTransaction(TransactionStatus status) {

                jdbcTemplate.execute("SET LOCAL enable_bitmapscan=0;");
                jdbcTemplate.query(sql, setter, rowHandler);
                return null;
            }
        });

        // shift to max(retrievedLatestSer, and ser as updated in
        // rowHandler)
        serialToContinueFrom.set(Math.max(serialToContinueFrom.get(), latest));
    }
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:23,代码来源:PGSynchronizedQuery.java

示例9: searchBook

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Override
	public Book searchBook(long ISBN) {
		// TODO Auto-generated method stub
		 transactionTemplate.setReadOnly(true);
		return transactionTemplate.execute(new TransactionCallback<Book>() {

			@Override
			public Book doInTransaction(TransactionStatus status) {
				// TODO Auto-generated method stub
//				Book book = bookDAO.serachBook(ISBN);
				Book book=new Book();
				book.setISBN(ISBN);
				bookDAO.addBook(book);
				return book;
			}

		});

	}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:20,代码来源:BookServiceImpl.java

示例10: deleteBook

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Override
public boolean deleteBook(long ISBN) {
	// TODO Auto-generated method stub
	if (searchBook(ISBN).getISBN() == ISBN) {
	transactionTemplate.setReadOnly(false);	
			return transactionTemplate.execute(new TransactionCallback<Boolean>() {

		@Override
		public Boolean doInTransaction(TransactionStatus status) {
			// TODO Auto-generated method stub
			try {
					boolean result = bookDAO.deleteBook(ISBN);
					return result;

			} catch (Exception exception) {
				status.setRollbackOnly();
			}
			return false;

		}
	});
	}
	return false;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:25,代码来源:BookServiceImpl.java

示例11: updateSql

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
/**
 * 批处理更新操作
 * 
 * @param dbInfoId
 * @param sqls
 * @return 返回更新的列的数量
 * @throws Exception
 */
public int[] updateSql(String dbInfoId, String[] sqls) throws Exception {
	final String[] fsqls = this.getFormatArrays(sqls);
	if (log.isDebugEnabled()) {
		for (String s : fsqls) {
			log.debug(s);
		}
	}
	DataSource ds = getDataSourceByDbInfoId(dbInfoId);
	final TransactionTemplate transactionTemplate = SpringJdbcUtils.getTransactionTemplate(ds);
	return transactionTemplate.execute(new TransactionCallback<int[]>() {
		public int[] doInTransaction(TransactionStatus status) {
			JdbcTemplate jdbcTemplate = SpringJdbcUtils.getJdbcTemplate(transactionTemplate);
			int[] i = jdbcTemplate.batchUpdate(fsqls);
			return i;
		}
	});
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:26,代码来源:DbService.java

示例12: writeIntoFile

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
public boolean writeIntoFile(final File file) {
    return transactionHelper.runInCurrentThread(new TransactionCallback<Boolean>() {

        @Override
        public Boolean doInTransaction(final TransactionStatus status) {
            status.setRollbackOnly();
            try {
                final Image image = imageService.load(id);
                final InputStream in = new ByteArrayInputStream(isThumbnail ? image.getThumbnail() : image.getImage());
                file.getParentFile().mkdirs();
                IOUtils.copy(in, new FileOutputStream(file));
                file.setLastModified(image.getLastModified().getTimeInMillis());
                return true;
            } catch (final Exception e) {
                // Ignore
            }
            return false;
        }
    });
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:21,代码来源:ImageByIdServlet.java

示例13: testTransactionCommitWithSharedEntityManager

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Test
public void testTransactionCommitWithSharedEntityManager() {
	given(manager.getTransaction()).willReturn(tx);

	tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			bean.sharedEntityManager.flush();
			return null;
		}
	});

	verify(tx).commit();
	verify(manager).flush();
	verify(manager).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:PersistenceContextTransactionTests.java

示例14: testTransactionCommitWithSharedEntityManagerAndPropagationSupports

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Test
public void testTransactionCommitWithSharedEntityManagerAndPropagationSupports() {
	given(manager.isOpen()).willReturn(true);

	tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);

	tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			bean.sharedEntityManager.clear();
			return null;
		}
	});

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

示例15: testTransactionCommitWithExtendedEntityManager

import org.springframework.transaction.support.TransactionCallback; //导入依赖的package包/类
@Test
public void testTransactionCommitWithExtendedEntityManager() {
	given(manager.getTransaction()).willReturn(tx);

	tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			bean.extendedEntityManager.flush();
			return null;
		}
	});

	verify(tx, times(2)).commit();
	verify(manager).flush();
	verify(manager).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:PersistenceContextTransactionTests.java


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