From: <one...@us...> - 2003-02-22 06:42:14
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jmx In directory sc8-pr-cvs1:/tmp/cvs-serv17247/sf/hibernate/jmx Modified Files: HibernateService.java SessionFactoryStub.java Log Message: fixed a problem with HibernateService added convenience createBlob() improved some logging added SessionFactory.close() Index: HibernateService.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jmx/HibernateService.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HibernateService.java 26 Jan 2003 01:33:35 -0000 1.5 --- HibernateService.java 22 Feb 2003 06:42:08 -0000 1.6 *************** *** 2,7 **** package net.sf.hibernate.jmx; import javax.naming.InitialContext; - import javax.naming.NamingException; import org.apache.commons.logging.Log; --- 2,8 ---- package net.sf.hibernate.jmx; + import java.util.Properties; + import javax.naming.InitialContext; import org.apache.commons.logging.Log; *************** *** 9,16 **** import net.sf.hibernate.HibernateException; import net.sf.hibernate.cfg.Configuration; import net.sf.hibernate.cfg.Environment; import net.sf.hibernate.util.PropertiesHelper; - import net.sf.hibernate.util.StringHelper; --- 10,18 ---- import net.sf.hibernate.HibernateException; + import net.sf.hibernate.SessionFactory; import net.sf.hibernate.cfg.Configuration; import net.sf.hibernate.cfg.Environment; + import net.sf.hibernate.util.NamingHelper; import net.sf.hibernate.util.PropertiesHelper; *************** *** 23,27 **** * @see net.sf.hibernate.SessionFactory */ ! public class HibernateService extends Configuration implements HibernateServiceMBean { private static final Log log = LogFactory.getLog(HibernateServiceMBean.class); --- 25,29 ---- * @see net.sf.hibernate.SessionFactory */ ! public class HibernateService implements HibernateServiceMBean { private static final Log log = LogFactory.getLog(HibernateServiceMBean.class); *************** *** 29,32 **** --- 31,35 ---- private String mapResources; private String boundName; + private Properties properties = new Properties(); /** *************** *** 119,123 **** private String[] parseResourceList(String resourceList) { ! return PropertiesHelper.toStringArray(resourceList, StringHelper.COMMA_SPACE); } --- 122,126 ---- private String[] parseResourceList(String resourceList) { ! return PropertiesHelper.toStringArray(resourceList, " ,\n\t\r\f"); } *************** *** 125,134 **** boundName = getJndiName(); try { ! bindSessionFactory(); } catch (HibernateException he) { ! log.info("Could not build SessionFactory using the MBean classpath - will try again using client classpath"); ! String[] mappingFiles = parseResourceList( getMapResources() ); ! new SessionFactoryStub(mappingFiles, this); } } --- 128,137 ---- boundName = getJndiName(); try { ! buildSessionFactory(); } catch (HibernateException he) { ! log.info( "Could not build SessionFactory using the MBean classpath - will try again using client classpath: " + he.getMessage() ); ! log.debug("Error was", he); ! new SessionFactoryStub(this); } } *************** *** 137,157 **** log.info("stopping service"); try { ! new InitialContext().unbind(boundName); } ! catch (NamingException e) { ! log.warn("exception while unbinding factory from JNDI", e); } } ! private void bindSessionFactory() throws HibernateException { log.info( "starting service at JNDI name: " + boundName ); ! log.info( "properties: " + getProperties() ); String[] mappingFiles = parseResourceList( getMapResources() ); for ( int i=0; i<mappingFiles.length; i++ ) { ! log.info( "compiling mapping: " + mappingFiles[i] ); ! addResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() ); } ! buildSessionFactory(); } --- 140,163 ---- log.info("stopping service"); try { ! InitialContext context = NamingHelper.getInitialContext( getProperties() ); ! ( (SessionFactory) context.lookup(boundName) ).close(); ! context.unbind(boundName); } ! catch (Exception e) { ! log.warn("exception while stopping service", e); } } ! SessionFactory buildSessionFactory() throws HibernateException { log.info( "starting service at JNDI name: " + boundName ); ! log.info( "service properties: " + properties ); ! ! Configuration cfg = new Configuration().addProperties( getProperties() ); String[] mappingFiles = parseResourceList( getMapResources() ); for ( int i=0; i<mappingFiles.length; i++ ) { ! cfg.addResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() ); } ! return cfg.buildSessionFactory(); } *************** *** 183,186 **** --- 189,204 ---- } + public String getProperty(String property) { + return properties.getProperty(property); + } + + public void setProperty(String property, String value) { + properties.setProperty(property, value); + } + + protected Properties getProperties() { + return properties; + } + } Index: SessionFactoryStub.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jmx/SessionFactoryStub.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SessionFactoryStub.java 9 Feb 2003 06:28:15 -0000 1.6 --- SessionFactoryStub.java 22 Feb 2003 06:42:08 -0000 1.7 *************** *** 21,26 **** import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; - import net.sf.hibernate.cfg.Configuration; - import net.sf.hibernate.cfg.Environment; import net.sf.hibernate.id.IdentifierGenerator; import net.sf.hibernate.id.UUIDHexGenerator; --- 21,24 ---- *************** *** 42,54 **** private transient SessionFactory impl; ! private transient String[] resources; ! private transient Configuration mapper; private String uuid; private String name; ! SessionFactoryStub(String[] resources, Configuration mapper) { ! this.resources = resources; ! this.mapper = mapper; ! this.name = mapper.getProperty(Environment.SESSION_FACTORY_NAME); try { uuid = (String) uuidgen.generate(null, null); --- 40,50 ---- private transient SessionFactory impl; ! private transient HibernateService service; private String uuid; private String name; ! SessionFactoryStub(HibernateService service) { ! this.service = service; ! this.name = service.getJndiName(); try { uuid = (String) uuidgen.generate(null, null); *************** *** 58,62 **** } ! SessionFactoryObjectFactory.addInstance( uuid, name, this, mapper.getProperties() ); } --- 54,58 ---- } ! SessionFactoryObjectFactory.addInstance( uuid, name, this, service.getProperties() ); } *************** *** 74,82 **** if (impl==null) { try { ! for ( int i=0; i<resources.length; i++ ) { ! mapper.addResource( resources[i], Thread.currentThread().getContextClassLoader() ); ! } ! impl = mapper.buildSessionFactory(); ! // now impl will be bound to the name this was bound to } catch (Exception e) { --- 70,74 ---- if (impl==null) { try { ! impl = service.buildSessionFactory(); } catch (Exception e) { *************** *** 145,148 **** --- 137,143 ---- } + public void close() throws HibernateException { + } + } |