-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: why not rollback on exception?
PostPosted: Tue Apr 05, 2005 11:52 pm 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
why not rollback on exception?


Code:
   public String execute() throws Exception {

      for (int i = 0; i < model.getWspzxh().length; i++) {
         Session session = null;
         Session xfileSession = null;
         try {

            session = sourceSessionFactory.openSession();
            xfileSession = xfileSessionFactory.openSession();

            Query query = session.createQuery("from KydaWsDjxxTmp wsDjxx where (wsDjxx.nsrsbh=:nsrsbh) and (wsDjxx.wspzxh=:wspzxh)");
            query.setString("nsrsbh", model.getNsrsbh()[i]);
            query.setString("wspzxh", model.getWspzxh()[i]);
            Iterator it = query.iterate();

            if (it.hasNext()) {
               KydaWsDjxxTmp wsDjxx = (KydaWsDjxxTmp)it.next();

               StringBuffer uri = new StringBuffer();
               uri.append("model.wspzxh=");
               uri.append(wsDjxx.getWspzxh());
               uri.append("&");
               uri.append("model.nsrsbh=");
               uri.append(wsDjxx.getNsrsbh());
               uri.append("&");
               uri.append("model.wszldm=");
               uri.append(wsDjxx.getWszlDm());

               Xtype xtype = new Xtype();
               xtype.setSymbol("WS" + wsDjxx.getWszlDm());
               Xource xource = new Xource();
               xource.setXtype(xtype);
               xource.setUri(uri.toString());
               xource.setTitle(wsDjxx.getWszlDm());
               xource.setCreateTime(wsDjxx.getSlxhrq());
               xource.setXourceOwner(wsDjxx.getNsrsbh());
               xource.setXourceGroup(wsDjxx.getSwjgDm());
               xource.setCollectTime(new Date());
               xfileSession.save(xource);

               KydaWsDjxxGd wsDjxx2 = new KydaWsDjxxGd();
               BeanUtils.copyProperties(wsDjxx2, wsDjxx);
               session.save(wsDjxx2);
//               session.delete(wsDjxx);

               StringBuffer hql = new StringBuffer();
               hql.append(" from KydaFszl fszl where (fszl.wspzxh=:wspzxh) and (fszl.nsrsbh=:nsrsbh) ");
               hql.append(" order by fszl.qcfwDmWsfxzl.wsfszlDm, fszl.pageNo ");
               Query fszlQuery = session.createQuery(hql.toString());
               fszlQuery.setString("nsrsbh", model.getNsrsbh()[i]);
               fszlQuery.setString("wspzxh", model.getWspzxh()[i]);
               it = fszlQuery.iterate();
               while (it.hasNext()) {
                  KydaFszl row = (KydaFszl)it.next();

                  Xtype imageXtype = new Xtype();
                  imageXtype.setSymbol("IMAGE");
                  Xource image = new Xource();
                  image.setXtype(imageXtype);
                  uri = new StringBuffer();
                  uri.append("fileName=");
                  uri.append(row.getFileName());
                  image.setUri(uri.toString());
                  image.setCreateTime(row.getUploadtime());
                  image.setTitle(row.getQcfwDmWsfxzl().getWsfszlMc() + row.getPageNo());
                  image.setNote(row.getQcfwDmWsfxzl().getWsfszlMc());
                  image.setXourceOwner(row.getNsrsbh());
                  image.setCollectTime(new Date());
                  image.setXourceGroup(xource.getXourceGroup());
                  [color=red]xfileSession.save(image);[/color]

                    XourceRelation relation = new XourceRelation();
                  XourceRelationId id = new XourceRelationId();
                  id.setXourceMain(xource);
                  id.setXourceFriend(image);
                  relation.setId(id);
                  relation.setTitle(image.getTitle());
                  xfileSession.save(relation);
[color=red]throw new Exception("xxxxxxxx");[/color]
               }
//               xfileSession.update(xource);
               session.flush();
               xfileSession.flush();
            }



         } catch (Exception e) {
            e.printStackTrace();
            addActionError(e.getLocalizedMessage());
//            throw SessionFactoryUtils.convertHibernateAccessException(he);
//            System.out.println(e.getLocalizedMessage());
         } finally {
            SessionFactoryUtils.closeSessionIfNecessary(session, sourceSessionFactory);
            SessionFactoryUtils.closeSessionIfNecessary(xfileSession, xfileSessionFactory);
         }
      }
      return SUCCESS;
   }

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 11:55 pm 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
public String execute() throws Exception {

for (int i = 0; i < model.getWspzxh().length; i++) {
Session session = null;
Session xfileSession = null;
try {

session = sourceSessionFactory.openSession();
xfileSession = xfileSessionFactory.openSession();

Query query = session.createQuery("from KydaWsDjxxTmp wsDjxx where (wsDjxx.nsrsbh=:nsrsbh) and (wsDjxx.wspzxh=:wspzxh)");
query.setString("nsrsbh", model.getNsrsbh()[i]);
query.setString("wspzxh", model.getWspzxh()[i]);
Iterator it = query.iterate();

if (it.hasNext()) {
KydaWsDjxxTmp wsDjxx = (KydaWsDjxxTmp)it.next();

StringBuffer uri = new StringBuffer();
uri.append("model.wspzxh=");
uri.append(wsDjxx.getWspzxh());
uri.append("&");
uri.append("model.nsrsbh=");
uri.append(wsDjxx.getNsrsbh());
uri.append("&");
uri.append("model.wszldm=");
uri.append(wsDjxx.getWszlDm());

Xtype xtype = new Xtype();
xtype.setSymbol("WS" + wsDjxx.getWszlDm());
Xource xource = new Xource();
xource.setXtype(xtype);
xource.setUri(uri.toString());
xource.setTitle(wsDjxx.getWszlDm());
xource.setCreateTime(wsDjxx.getSlxhrq());
xource.setXourceOwner(wsDjxx.getNsrsbh());
xource.setXourceGroup(wsDjxx.getSwjgDm());
xource.setCollectTime(new Date());
xfileSession.save(xource);
KydaWsDjxxGd wsDjxx2 = new KydaWsDjxxGd();
BeanUtils.copyProperties(wsDjxx2, wsDjxx);
session.save(wsDjxx2);
// session.delete(wsDjxx);

StringBuffer hql = new StringBuffer();
hql.append(" from KydaFszl fszl where (fszl.wspzxh=:wspzxh) and (fszl.nsrsbh=:nsrsbh) ");
hql.append(" order by fszl.qcfwDmWsfxzl.wsfszlDm, fszl.pageNo ");
Query fszlQuery = session.createQuery(hql.toString());
fszlQuery.setString("nsrsbh", model.getNsrsbh()[i]);
fszlQuery.setString("wspzxh", model.getWspzxh()[i]);
it = fszlQuery.iterate();
while (it.hasNext()) {
KydaFszl row = (KydaFszl)it.next();

Xtype imageXtype = new Xtype();
imageXtype.setSymbol("IMAGE");
Xource image = new Xource();
image.setXtype(imageXtype);
uri = new StringBuffer();
uri.append("fileName=");
uri.append(row.getFileName());
image.setUri(uri.toString());
image.setCreateTime(row.getUploadtime());
image.setTitle(row.getQcfwDmWsfxzl().getWsfszlMc() + row.getPageNo());
image.setNote(row.getQcfwDmWsfxzl().getWsfszlMc());
image.setXourceOwner(row.getNsrsbh());
image.setCollectTime(new Date());
image.setXourceGroup(xource.getXourceGroup());
xfileSession.save(image);
XourceRelation relation = new XourceRelation();
XourceRelationId id = new XourceRelationId();
id.setXourceMain(xource);
id.setXourceFriend(image);
relation.setId(id);
relation.setTitle(image.getTitle());
xfileSession.save(relation);
throw new Exception("xxxxxxxx");
}
// xfileSession.update(xource);
session.flush();
xfileSession.flush();
}



} catch (Exception e) {
e.printStackTrace();
addActionError(e.getLocalizedMessage());
// throw SessionFactoryUtils.convertHibernateAccessException(he);
// System.out.println(e.getLocalizedMessage());
} finally {
SessionFactoryUtils.closeSessionIfNecessary(session, sourceSessionFactory);
SessionFactoryUtils.closeSessionIfNecessary(xfileSession, xfileSessionFactory);
}
}
return SUCCESS;
}

_________________
I am the creatxr of world.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.