hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <ja...@carmanconsulting.com>
Subject RE: access hibernate session
Date Thu, 14 Oct 2004 01:15:03 GMT
John, there is a WIKI
(http://wiki.apache.org/jakarta-hivemind/HibernateSupport) page set up to
discuss Hibernate support in Hivemind.  I have posted an example application
(http://issues.apache.org/jira/browse/HIVEMIND-54?page=comments#action_53136
) as a comment on the JIRA issue which requests Hibernate support in
Hivemind, which you can download and run.  It might give you some good
ideas.  I'm not saying that my solution is the best solution, but it can get
you started.  I hope the example can help you.  Let me know if you need
anything.  

-----Original Message-----
From: John Coleman [mailto:john.s.coleman@ntlworld.com] 
Sent: Tuesday, October 12, 2004 7:41 PM
To: hivemind-user@jakarta.apache.org
Subject: access hibernate session

I want to access HiveMind services in my Tapestry application.

In my engine I put this:-

 protected Object createGlobal(RequestContext context) {
        Global global = (Global) super.createGlobal(context);
        global.initResitry(context);
        return global;
    }

 public UserService getUserService() {
  if (userService == null) {
   userService = (UserService) ((Global)
getGlobal()).getRegistry().getService(UserService.class);
  }
  return userService;
 }

I use the engine to instantiate the Global object with the registry:-

 // for services
 public void initResitry(RequestContext context) {
  if (registry == null) {
   registry = HiveMindFilter.getRegistry(context.getRequest());
  }
 }

I am interested in comments on this design. How are others dealing with
their HiveMind service references in Tapestry?

My main question is about how services inside HiveMind will share a
"SessionManager" service, and can I make that service private to classes
inside HiveMind.

I have considered a SessionManager interface but at the moment simply have a
implementation like this:-

public class HibernateSessionManager {

    private static final SessionFactory sessionFactory;

 static {
        // Create the SessionFactory
  try {
       sessionFactory = new
Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
         throw new ExceptionInInitializerError(ex);
        }
 }
 // variable to hold a session object for a thread
    public static final ThreadLocal session = new ThreadLocal();

    // obtain the session of the current thread
    public static Session currentSession() throws HibernateException {
     Session s = (Session) session.get();
        // Open a new Session, if this Thread has none yet
        if (s == null) {
            s = sessionFactory.openSession();
            session.set(s);
        }
        return s;
    }

    // close the session on the current thread
    public static void closeSession() throws HibernateException {
        Session s = (Session) session.get();
        session.set(null);
        if (s != null) s.close();
    }

}

I suppose as everything is static I can just use static access, but is that
best practice as that will tie me to an implemenation class! I would rather
create an interface and be get a ref to the implementing class that is
defined in the xml configs.

Is there an example xml to show me this please?

TIA
John


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Mime
View raw message