/**
*
*/
package com.tnc.lucene.util;
import org.apache.log4j.Logger;
import org.compass.core.Compass;
import org.compass.core.CompassSession;
import org.compass.core.CompassTransaction;
import org.compass.core.CompassTransaction.TransactionIsolation;
import org.compass.core.config.CompassConfiguration;
/**
* @author zhangleming_2007-9-30
*
*/
public class CompassUtils {
final static Logger logger=Logger.getLogger(CompassUtils.class);
private static CompassConfiguration config = null;
private static Compass compass = null;
private static final ThreadLocal<CompassSession> threadSession = new ThreadLocal<CompassSession>();
private static final ThreadLocal<CompassTransaction> threadTransaction = new ThreadLocal<CompassTransaction>();
/**
* zhangleming_2007-9-30
*/
public CompassUtils() {
}
static{
config = new CompassConfiguration()
.configure("/com/tnc/compass/tindex/tnc.cfg.xml");
compass = config.buildCompass();
}
public static Compass getCompass() {
return compass;
}
public static void setCompass(Compass compass) {
CompassUtils.compass = compass;
}
/**
* 重建compass
* @param config
*/
public static void rebuildCompass( CompassConfiguration config){
synchronized(compass){
compass=config.buildCompass();
CompassUtils.config=config;
}
}
/**
* 打开Session
* @return
*/
public static CompassSession openSession(){
CompassSession s=(CompassSession)threadSession.get();
if(s==null){
logger.debug("Open new CompassSession for thread");
s=getCompass().openSession();
threadSession.set(s);
}
return s;
}
/**
* 关闭CompassSesion
*
*/
public static void closeSession(){
CompassSession s=(CompassSession)threadSession.get();
threadSession.set(null);
if(s!=null){
logger.debug("Colse CompassSession of the thread");
s.close();
}
}
/**
* 事务启动
*
*/
public static void beginTransaction(){
CompassTransaction transaction=(CompassTransaction)threadTransaction.get();
if(transaction==null){
logger.debug("Open new CompassTransaction for thread");
transaction=CompassUtils.openSession().beginTransaction();
threadTransaction.set(transaction);
}
}
public static void beginTransaction(TransactionIsolation ti){
CompassTransaction transaction=(CompassTransaction)threadTransaction.get();
if(transaction==null){
logger.debug("Open new CompassTransaction for thread");
transaction=CompassUtils.openSession().beginTransaction(ti);
threadTransaction.set(transaction);
}
}
/**
* 事务提交
*
*/
public static void commitTransaction(){
CompassTransaction transaction=(CompassTransaction)threadTransaction.get();
if(transaction!=null&&!transaction.wasCommitted()&&!transaction.wasRolledBack()){
logger.debug("CompassTransaction is committing in the thread");
transaction.commit();
}
threadTransaction.set(null);
}
/**
* 回滚事务
*
*/
public static void rollbackTransaction(){
CompassTransaction transaction=(CompassTransaction)threadTransaction.get();
if(transaction!=null&&!transaction.wasCommitted()&&!transaction.wasRolledBack()){
logger.debug("try to rollback CompassTransaction in the Thread");
transaction.rollback();
}
threadTransaction.set(null);
}
}
分享到:
相关推荐
hibernate 资料hibernate 资料hibernate 资料hibernate 资料
Hibernate.jar包,Hibernate可以应用在任何使用JDBC的场合,包含 hibernate-commons-annotations-4.0.1.Final.jar hibernate-core-4.1.12.Final.jar hibernate-ehcache-4.1.12.Final.jar hibernate-entitymanager-...
hibernate3hibernate3hibernate3hibernate3hibernate3hibernate3hibernate3hibernate3
hibernate annotation hibernate3
hibernate5 hibernate PDF 讲义 动力 hibernate ssh hibernate5 节点
hibernate 5.2.15 hibernate 5.2.15 hibernate 5.2.15 hibernate 5.2.15 hibernate 5.2.15hibernate 5.2.15
hibernate教程hibernate教程hibernate教程
Hibernate连表查询 Hibernate连表查询
DmDialect-for-hibernate2.0、DmDialect-for-hibernate2.1、DmDialect-for-hibernate3.0、DmDialect-for-hibernate3.1、DmDialect-for-hibernate3.6、DmDialect-for-hibernate4.0、DmDialect-for-hibernate5.0、...
hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,包含4个说明文档,分别详细解说了hibernate...
Hibernate连接SQLite配置步骤: 1、添加SQLite库: 1.1、将两个jar包:com.zy.hibernate.dialect.SQLiteDialect.jar、sqlite-jdbc-3.7.2.jar拷贝到“\WEB-INF\lib”文件夹下; 2、配置hibernate: 2.1、将...
hibernate持久化对象生命周期[参照].pdf
/*************************************** * 达梦8 JDBC驱动版本说明 /*************************************** ...8. DmDialect-for-hibernate5.3.jar 对应 Jdk1.7及以上, hibernate5.3 -- 5.4 环境
包含hibernate所有所需jar包还有一些其他包日志包、jpa支持包等: 列如:hibernate-core-5.1.0.Final.jar hibernate-ehcache-5.1.0.Final.jar hibernate-entitymanager-5.1.0.Final.jar hibernate-envers-5.1.0....
Manning出版 Java Persistence With Hibernate 第二版 清晰pdf Hibernate, an open source project that is almost 15 years old. In a recent poll, Hibernate was among the top five tools used by many Java ...
Hibernate面试题专栏 - 最全的Hibernate面试题, Hibernate笔试题, Hibernate问题 Hibernate教程
hibernate 实战 hibernate 实战 hibernate 实战 hibernate 实战
Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板Hibernate留言板
hibernate 用的较频繁的jar包,或者文档
hibernate实战 英文版 最权威的hibernate著作 快来下载吧