hibernate?à·t???÷??êy?Yí?2?(2)
ê±??:2011-03-07
2.òìμ?êy?Yí?2?꧰üoó?ˉ×÷??TBDao->save() ?3?á×′ì?μ?êy?Y?a
public void save(Object obj,String action) {
Session session = null ;
try {
session = SessionManager.currentSession(null,null);
Transaction tr = session.beginTransaction();
ZJcyyTb zj = new ZJcyyTb();
zj.setAction(action);
zj.setInputdate(new Date());
session.save(zj);
session.flush();
session.refresh(zj,LockMode.UPGRADE);
//oracle Blobêy?Y3??? ??2???-->DòáD?ˉoí·′DòáD?ˉ???óμ? êy?Y?a
???????????? zj.setObject( new ObjectConvert().ObjectToBlob(obj) );
tr.commit();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(session!=null&& session.isOpen() )session.close();
}
}
3,꧰üoóó?3é1|á??óoó £¨??3ìêμ??£? TBDao->action()
public int isSql(){
int is_count = 0 ;
Session session = null ;
try {
//μ?μ?±?μ?Session 2é?′ê?·?óDá??ó꧰üoóDòáD?ˉ×÷±?±£′?
???????????? session = SessionManager.currentSession(null,null);
Transaction tr =??session.beginTransaction();
Connection conn = session.connection();
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select count(*) from z_jcyy_tb");
rs.next();
is_count = rs.getInt(1);
tr.commit();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(session!=null&& session.isOpen() )session.close();
}
return is_count ;
}
public boolean action(){
int isSql = 0 ;
ObjectConvert oc = new ObjectConvert();
Session session = null ;
Session session_b = null ;
try {
//óD꧰üá??ó?ˉ×÷oó3¢ê? ??3ìêy?Y?a??
???????????? if( (isSql=isSql())>0 ){
session = SessionManager.currentSession(null,null);
//??3ìêy?Y?aá??ó
//è?1?3é1|á??ó£oz_jcyy_tb±í?Dêy?Yí?2?μ?????êy?Y?a?D
???????????????? session_b = openSessionb();
if(session_b!=null){
Transaction tr_b = session_b.beginTransaction();
Transaction tr = session.beginTransaction();
Query qu = session.createQuery(" from ZJcyyTb t order by t.inputdate");
for(int i=0;i<=isSql/10;i++){
qu.setFirstResult(i*10);
qu.setMaxResults(10);
List list = qu.list();
for(Iterator it=list.iterator();it.hasNext();){
ZJcyyTb tb = (ZJcyyTb)it.next();
Object obj = null ;
obj = oc.BlobToObject(tb.getObject(),obj);
if(obj!=null){
String action = tb.getAction();
if(action.equals( TBDao.DELETE )){
session_b.delete(obj);
}
if(action.equals( TBDao.INSERT )){
session_b.save(obj);
}
if(action.equals( TBDao.UPDATE )){
session_b.update(obj);
}
}
session.delete(tb);
tr.commit();
}
}
tr_b.commit();
}
}????return true ;
} catch (Exception e) {
System.out.println("--??óDá??óμ?×ü·t??(action)--");
}finally{
if(session_b!=null&&session_b.isOpen())session_b.close();
if(session!=null&& session.isOpen() )session.close();
SessionManager.closeSession();
}
return false ;
}
4.hbn à1???÷ ->Interceptor |