[jboss-svn-commits] JBL Code SVN: r12420 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jun 8 12:37:21 EDT 2007


Author: tcunning
Date: 2007-06-08 12:37:21 -0400 (Fri, 08 Jun 2007)
New Revision: 12420

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java
Log:
bug:JBESB-434
Support multiple hibernate listeners.


Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java	2007-06-08 16:36:46 UTC (rev 12419)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java	2007-06-08 16:37:21 UTC (rev 12420)
@@ -42,35 +42,47 @@
 public class HibernateSessionFactory {
 	public static final String HIBERNATE_JNDI = "java:comp/env/hibernate/SessionFactory";
 	
-	private static SessionFactory sf = null;
 	private static final Logger m_Logger = Logger.getLogger(HibernateSessionFactory.class);	
 	
 	private HibernateSessionFactory() {
 	}
-		
-	public static SessionFactory getInstance() {
-		if (sf != null) {
-			return sf;
-		} else { 
-			return null;
-		}
+				
+	public static SessionFactory getInstance(Configuration f_cfg) throws ConfigurationException {
+		return init(f_cfg);		
 	}
 		
-	public static SessionFactory getInstance(Configuration f_cfg) throws ConfigurationException {
-		if (sf == null) {
-			init(f_cfg);		
+	/**
+	 * Checks whether the SessionFactory exists within JNDI and whether it is closed.
+	 * @param f_cfg Hibernate Configuration - needed for SESSION_FACTORY_NAME
+	 * @return whether the Hibernate SessionFactory is in JNDI and is alive
+	 */
+	public static boolean isAlive(Configuration f_cfg) {
+		boolean result = false; 
+		SessionFactory sf = null;
+		String cfgName = f_cfg.getProperty(Environment.SESSION_FACTORY_NAME);
+
+		Context ic = null;
+		// Look up SessionFactory in JNDI
+		if (cfgName != null) {
+			try {
+				ic = new InitialContext();
+				sf = (SessionFactory) ic.lookup(cfgName);
+				result = ! sf.isClosed();
+				m_Logger.debug("Connection isAlive is " + result + ".");
+			} catch (NamingException ne) {
+			}
 		}
-		return sf;	
+		return result;
 	}
-		
+	
 	/**
 	 * Grab InitialContext out of JNDI.
 	 * @param f_cfg hibernate configuration
 	 * @throws ConfigurationException
 	 */
-	private static synchronized void init(Configuration f_cfg) throws ConfigurationException {
+	private static SessionFactory init(Configuration f_cfg) throws ConfigurationException {
 		String cfgName = f_cfg.getProperty(Environment.SESSION_FACTORY_NAME);
-
+		SessionFactory sf = null;
 		Context ic = null;
 		// Look up SessionFactory in JNDI
 		if (cfgName != null) {
@@ -95,9 +107,28 @@
 	        	throw new ConfigurationException("Hibernate Configuration is null");
 	        }
 		}
+		return sf;
 	}
 
-	public static void close() {
+	/**
+	 * Close the SessionFactory stored in JNDI at SESSION_FACTORY_NAME.
+	 * @param f_cfg hibernate configuration
+	 */
+	public static void close(Configuration f_cfg) {
+		SessionFactory sf = null;
+		
+		String cfgName = f_cfg.getProperty(Environment.SESSION_FACTORY_NAME);
+
+		Context ic = null;
+		// Look up SessionFactory in JNDI
+		if (cfgName != null) {
+			try {
+				ic = new InitialContext();
+				sf = (SessionFactory) ic.lookup(cfgName);
+			} catch (Exception e) {
+			}
+		}
+		
 		if (sf != null) {
 			sf.close();	
 		}




More information about the jboss-svn-commits mailing list