spring实现jdbctemplate添加事务支持示例
public interface jdbctemplate extends jdbcoperations {
public abstract void begintranstaion();
public abstract void commit();
public abstract void rollback();
}
public class jdbctemplateimpl extends org.springframework.jdbc.core.jdbctemplate implements jdbctemplate {
private platformtransactionmanager platformtransactionmanager;
private defaulttransactiondefinition transactiondefinition;
private threadlocal<transactionstatus> transcationstatus = new threadlocal<transactionstatus>();
public void begintranstaion() {
transactionstatus tmp = platformtransactionmanager.gettransaction(transactiondefinition);
transcationstatus.set(tmp);
}
public void commit() {
transactionstatus tmp = transcationstatus.get();
if (tmp == null) {
throw new rmsruntimeexception("no transcation");
}
platformtransactionmanager.commit(tmp);
transcationstatus.remove();
}
public void rollback() {
transactionstatus tmp = transcationstatus.get();
if (tmp == null) {
throw new rmsruntimeexception("no transcation");
}
platformtransactionmanager.rollback(tmp);
transcationstatus.remove();
}
@override
public void afterpropertiesset() {
super.afterpropertiesset();
transactiondefinition = new defaulttransactiondefinition();
transactiondefinition.setisolationlevel(transactiondefinition.isolation_read_committed);
transactiondefinition.setpropagationbehavior(transactiondefinition.propagation_required);
platformtransactionmanager = new datasourcetransactionmanager(getdatasource());
}
public platformtransactionmanager getplatformtransactionmanager() {
return platformtransactionmanager;
}
public defaulttransactiondefinition gettransactiondefinition() {
return transactiondefinition;
}
public threadlocal<transactionstatus> gettranscationstatus() {
return transcationstatus;
}
}
上一篇: jsp中文显示问号问题解决方法
推荐阅读
-
spring实现jdbctemplate添加事务支持示例
-
Spring实战之使用TransactionProxyFactoryBean实现声明式事务操作示例
-
基于spring JdbcTemplate的扩展,结合velocity模板实现sql语句的可配置可动态添加
-
基于spring JdbcTemplate的扩展,结合velocity模板实现sql语句的可配置可动态添加
-
spring实现jdbctemplate添加事务支持示例
-
Spring事务用法示例与实现原理
-
Spring实战之使用TransactionProxyFactoryBean实现声明式事务操作示例
-
Spring实战之使用注解实现声明式事务操作示例
-
Spring事务用法示例与实现原理