|
From: <one...@us...> - 2003-01-26 01:33:44
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jmx
In directory sc8-pr-cvs1:/tmp/cvs-serv14128/sf/hibernate/jmx
Modified Files:
HibernateService.java HibernateServiceMBean.java
SessionFactoryStub.java
Log Message:
redesigned configuration API
Index: HibernateService.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jmx/HibernateService.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** HibernateService.java 20 Jan 2003 12:48:12 -0000 1.4
--- HibernateService.java 26 Jan 2003 01:33:35 -0000 1.5
***************
*** 2,7 ****
package net.sf.hibernate.jmx;
- import java.util.Properties;
-
import javax.naming.InitialContext;
import javax.naming.NamingException;
--- 2,5 ----
***************
*** 10,17 ****
import org.apache.commons.logging.LogFactory;
- import net.sf.hibernate.Environment;
- import net.sf.hibernate.Hibernate;
import net.sf.hibernate.HibernateException;
! import net.sf.hibernate.cfg.Datastore;
import net.sf.hibernate.util.PropertiesHelper;
import net.sf.hibernate.util.StringHelper;
--- 8,14 ----
import org.apache.commons.logging.LogFactory;
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;
***************
*** 26,34 ****
* @see net.sf.hibernate.SessionFactory
*/
! public class HibernateService implements HibernateServiceMBean {
private static final Log log = LogFactory.getLog(HibernateServiceMBean.class);
- private final Properties props = new Properties();
private String mapResources;
private String boundName;
--- 23,30 ----
* @see net.sf.hibernate.SessionFactory
*/
! public class HibernateService extends Configuration implements HibernateServiceMBean {
private static final Log log = LogFactory.getLog(HibernateServiceMBean.class);
private String mapResources;
private String boundName;
***************
*** 39,43 ****
*/
public String getName() {
! return props.getProperty(Environment.SESSION_FACTORY_NAME);
}
--- 35,39 ----
*/
public String getName() {
! return getProperty(Environment.SESSION_FACTORY_NAME);
}
***************
*** 47,51 ****
public void setMapResources(String mapResources) {
! this.mapResources = mapResources.trim();
}
--- 43,52 ----
public void setMapResources(String mapResources) {
! if (mapResources==null) {
! this.mapResources=null;
! }
! else {
! this.mapResources = mapResources.trim();
! }
}
***************
*** 60,118 ****
public String getDatasource() {
! return props.getProperty(Environment.DATASOURCE);
}
public void setDatasource(String datasource) {
! props.setProperty(Environment.DATASOURCE, datasource);
}
public String getDialect() {
! return props.getProperty(Environment.DIALECT);
}
public void setDialect(String dialect) {
! props.setProperty(Environment.DIALECT, dialect);
}
public String getJndiName() {
! return props.getProperty(Environment.SESSION_FACTORY_NAME);
}
public void setJndiName(String jndiName) {
! props.setProperty(Environment.SESSION_FACTORY_NAME, jndiName);
}
public boolean getUseOuterJoin() {
! String prop = props.getProperty(Environment.OUTER_JOIN);
return Boolean.valueOf(prop).booleanValue();
}
public void setUseOuterJoin(boolean uoj) {
! props.setProperty( Environment.OUTER_JOIN, uoj ? "true" : "false" ); //Boolean.toString() only in JDK1.4
}
public boolean getShowSql() {
! String prop = props.getProperty(Environment.SHOW_SQL);
return Boolean.valueOf(prop).booleanValue();
}
public void setShowSql(boolean showSql) {
! props.setProperty(Environment.SHOW_SQL, showSql ? "true" : "false");
}
public String getUserName() {
! return props.getProperty(Environment.USER);
}
public void setUserName(String userName) {
! props.setProperty(Environment.USER, userName);
}
public String getPassword() {
! return props.getProperty(Environment.PASS);
}
public void setPassword(String password) {
! props.setProperty(Environment.PASS, password);
}
--- 61,119 ----
public String getDatasource() {
! return getProperty(Environment.DATASOURCE);
}
public void setDatasource(String datasource) {
! setProperty(Environment.DATASOURCE, datasource);
}
public String getDialect() {
! return getProperty(Environment.DIALECT);
}
public void setDialect(String dialect) {
! setProperty(Environment.DIALECT, dialect);
}
public String getJndiName() {
! return getProperty(Environment.SESSION_FACTORY_NAME);
}
public void setJndiName(String jndiName) {
! setProperty(Environment.SESSION_FACTORY_NAME, jndiName);
}
public boolean getUseOuterJoin() {
! String prop = getProperty(Environment.OUTER_JOIN);
return Boolean.valueOf(prop).booleanValue();
}
public void setUseOuterJoin(boolean uoj) {
! setProperty( Environment.OUTER_JOIN, uoj ? "true" : "false" ); //Boolean.toString() only in JDK1.4
}
public boolean getShowSql() {
! String prop = getProperty(Environment.SHOW_SQL);
return Boolean.valueOf(prop).booleanValue();
}
public void setShowSql(boolean showSql) {
! setProperty(Environment.SHOW_SQL, showSql ? "true" : "false");
}
public String getUserName() {
! return getProperty(Environment.USER);
}
public void setUserName(String userName) {
! setProperty(Environment.USER, userName);
}
public String getPassword() {
! return getProperty(Environment.PASS);
}
public void setPassword(String password) {
! setProperty(Environment.PASS, password);
}
***************
*** 129,133 ****
log.info("Could not build SessionFactory using the MBean classpath - will try again using client classpath");
String[] mappingFiles = parseResourceList( getMapResources() );
! new SessionFactoryStub(mappingFiles, props);
}
}
--- 130,134 ----
log.info("Could not build SessionFactory using the MBean classpath - will try again using client classpath");
String[] mappingFiles = parseResourceList( getMapResources() );
! new SessionFactoryStub(mappingFiles, this);
}
}
***************
*** 144,187 ****
private void bindSessionFactory() throws HibernateException {
! log.info("starting service at JNDI name: " + boundName);
! log.info("properties: " + props);
! Datastore ds = Hibernate.createDatastore();
String[] mappingFiles = parseResourceList( getMapResources() );
for ( int i=0; i<mappingFiles.length; i++ ) {
log.info( "compiling mapping: " + mappingFiles[i] );
! ds.storeResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() );
}
! ds.buildSessionFactory(props);
}
public String getTransactionStrategy() {
! return props.getProperty(Environment.TRANSACTION_STRATEGY);
}
public String getUserTransactionName() {
! return props.getProperty(Environment.USER_TRANSACTION);
}
public void setTransactionStrategy(String txnStrategy) {
! props.setProperty(Environment.TRANSACTION_STRATEGY, txnStrategy);
}
public void setUserTransactionName(String utName) {
! props.setProperty(Environment.USER_TRANSACTION, utName);
! }
!
! public String getProperties() {
! return props.toString();
! }
!
! public void setProperty(String property, String value) {
! props.setProperty(property, value);
}
public String getTransactionManagerLookupStrategy() {
! return props.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY);
}
public void setTransactionManagerLookupStrategy(String lkpStrategy) {
! props.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, lkpStrategy);
}
--- 145,184 ----
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();
}
public String getTransactionStrategy() {
! return getProperty(Environment.TRANSACTION_STRATEGY);
}
public String getUserTransactionName() {
! return getProperty(Environment.USER_TRANSACTION);
}
public void setTransactionStrategy(String txnStrategy) {
! setProperty(Environment.TRANSACTION_STRATEGY, txnStrategy);
}
public void setUserTransactionName(String utName) {
! setProperty(Environment.USER_TRANSACTION, utName);
}
public String getTransactionManagerLookupStrategy() {
! return getProperty(Environment.TRANSACTION_MANAGER_STRATEGY);
}
public void setTransactionManagerLookupStrategy(String lkpStrategy) {
! setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, lkpStrategy);
! }
!
! public String getPropertyList() {
! return getProperties().toString();
}
Index: HibernateServiceMBean.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jmx/HibernateServiceMBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** HibernateServiceMBean.java 5 Jan 2003 02:11:21 -0000 1.3
--- HibernateServiceMBean.java 26 Jan 2003 01:33:35 -0000 1.4
***************
*** 33,41 ****
*/
public void setProperty(String property, String value);
/**
! * Display all properties to the user
! * @return String
*/
! public String getProperties();
/**
--- 33,49 ----
*/
public void setProperty(String property, String value);
+
/**
! * Get a property
! * @param property the property name
! * @return the property value
*/
! public String getProperty(String property);
!
! /**
! * Display the properties
! * @return a list of property names and values
! */
! public String getPropertyList();
/**
Index: SessionFactoryStub.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jmx/SessionFactoryStub.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SessionFactoryStub.java 14 Jan 2003 13:42:15 -0000 1.4
--- SessionFactoryStub.java 26 Jan 2003 01:33:35 -0000 1.5
***************
*** 6,10 ****
import java.sql.Connection;
import java.util.Map;
- import java.util.Properties;
import javax.naming.NamingException;
--- 6,9 ----
***************
*** 17,22 ****
import net.sf.hibernate.AssertionFailure;
import net.sf.hibernate.Databinder;
- import net.sf.hibernate.Environment;
- import net.sf.hibernate.Hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Interceptor;
--- 16,19 ----
***************
*** 24,28 ****
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
! import net.sf.hibernate.cfg.Datastore;
import net.sf.hibernate.id.IdentifierGenerator;
import net.sf.hibernate.id.UUIDHexGenerator;
--- 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;
***************
*** 45,56 ****
private transient SessionFactory impl;
private transient String[] resources;
! private transient Properties properties;
private String uuid;
private String name;
! SessionFactoryStub(String[] resources, Properties properties) {
this.resources = resources;
! this.properties = properties;
! this.name = properties.getProperty(Environment.SESSION_FACTORY_NAME);
try {
uuid = (String) uuidgen.generate(null, null);
--- 43,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);
***************
*** 60,64 ****
}
! SessionFactoryObjectFactory.addInstance(uuid, name, this, properties);
}
--- 58,62 ----
}
! SessionFactoryObjectFactory.addInstance( uuid, name, this, mapper.getProperties() );
}
***************
*** 76,84 ****
if (impl==null) {
try {
- Datastore ds = Hibernate.createDatastore();
for ( int i=0; i<resources.length; i++ ) {
! ds.storeResource( resources[i], Thread.currentThread().getContextClassLoader() );
}
! impl = ds.buildSessionFactory(properties);
// now impl will be bound to the name this was bound to
}
--- 74,81 ----
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
}
***************
*** 123,133 ****
}
! public ClassMetadata getClassMetadata(Class persistentClass)
! throws HibernateException {
return getImpl().getClassMetadata(persistentClass);
}
! public CollectionMetadata getCollectionMetadata(String roleName)
! throws HibernateException {
return getImpl().getCollectionMetadata(roleName);
}
--- 120,128 ----
}
! public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {
return getImpl().getClassMetadata(persistentClass);
}
! public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {
return getImpl().getCollectionMetadata(roleName);
}
|