Hi all,

I'd like to write better my XSP code for persistence access.
Actually i use Hibernate(could be OJB) directly accessing Cocoon database connection pool.
Question1 :
Is the code below a good practice? It is a lot of code repeated for each XSP. I didn't find any way to include this code in my XSP page like i would include text. I suppose i need to create a logicsheet for that? Include is for another purpose... Note : i use XSP instead of flow when i have many collections to manipulate and show, otherwhise i use flow than deals only with PersistenceFactory, and put the session in the DAOs. Session is inside the DAOs, easier
Question2:
I wonder about making my DAO (they only manipulate the beans) as static functions or instantiate them each time.

Regards
Phil
____________________________________________________________________________________________________
PersistenceFactory pf = null;
Sessiion hs = null;
Transaction tx = null;

try {
   pf = (PersistenceFactory)manager.lookup(PersistenceFactory.ROLE);
   hs = pf.createSession();
try {
       tx = hs.beginTransaction();
// HERE I USE MY DAOs and show things to user tx.commit(); } catch (HibernateException he) {
       if (tx!=null) tx.rollback();
       getLogger().error("Hibernate exception");
   } catch (RuntimeException e) {
       if (tx!=null) tx.rollback();
getLogger().error("Runtime exception"); }finally {
       try{
           hs.close().close();
//hs.close(); //This is not closing the seesion and uses all my pools
       } catch (SQLException sqle) { //needs to be handled
           getLogger().error("SQLException",sqle);
       }
   }
} catch (ComponentException cme) {//lookup needs to be handled getLogger().error("Could not look up the PersistenceManager", cme); } finally {
   manager.release((Component)pf);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to