diff options
author | Henri Herscher <henri@oreka.org> | 2005-12-01 01:46:51 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2005-12-01 01:46:51 +0000 |
commit | 790cbf5035fa88a31f61134df055ee36e0b7788f (patch) | |
tree | b1d298fce3bd7a3e1bc393c431890fa31281ea70 /orkbasej | |
parent | 42cfa120cc99dc20debb290fcc82ee58eaa39322 (diff) |
The HibernateManager is now a regular object instead of a bunch of static methods. Each app will now be creating its own HibernateManager (and therefore separate proxool connection pool)
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@80 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasej')
-rw-r--r-- | orkbasej/java/mysql.hbm.template.xml | 35 | ||||
-rw-r--r-- | orkbasej/java/net/sf/oreka/HibernateManager.java | 27 | ||||
-rw-r--r-- | orkbasej/java/net/sf/oreka/test/FillDatabase.java | 6 |
3 files changed, 31 insertions, 37 deletions
diff --git a/orkbasej/java/mysql.hbm.template.xml b/orkbasej/java/mysql.hbm.template.xml index 99c911e..037e99f 100644 --- a/orkbasej/java/mysql.hbm.template.xml +++ b/orkbasej/java/mysql.hbm.template.xml @@ -7,40 +7,13 @@ <property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property> - <property name="hibernate.connection.password">mypassword</property> - <property name="hibernate.connection.username">root</property> - <property name="hibernate.connection.pool_size">1</property> + <property name="hibernate.connection.password">password</property> + <property name="hibernate.connection.username">root</property> - <property name="hibernate.hbm2ddl.auto">update</property> <!-- update, create, create-drop --> - <property name="hibernate.show_sql">true</property> + <!--<property name="hibernate.hbm2ddl.auto">update</property>--> <!-- update, create, create-drop --> + <property name="hibernate.show_sql">false</property> - <!-- Only use one of the three following connection pools (proxools, c3p0 or dbcp): --> - - <property name="hibernate.proxool.pool_alias">ork-pool</property> - <property name="hibernate.proxool.properties">proxool.properties</property> - - <!--<property name="c3p0.acquire_increment">1</property>--> - <!--<property name="c3p0.idle_test_period">100</property>--> <!-- seconds --> - <!--<property name="c3p0.max_size">100</property>--> - <!--<property name="c3p0.max_statements">0</property>--> - <!--<property name="c3p0.min_size">10</property>--> - <!--<property name="c3p0.timeout">100</property>--> <!-- seconds --> - - <!-- dbcp does not appear to work with Hibernate 3 --> - <!--<property name="hibernate.dbcp.ps.maxActive">100</property>--> - <!--<property name="hibernate.dbcp.maxActive">10</property>--> - <!--<property name="hibernate.dbcp.initialSize">2</property>--> - <!--<property name="hibernate.dbcp.maxWait">3000</property>--> - <!--<property name="hibernate.dbcp.validationQuery">select CURRENT_DATE</property>--> - - <property name="hibernate.jdbc.batch_versioned_data">true</property> - <property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> - <property name="hibernate.cache.region_prefix">hibernate.test</property> - <property name="hibernate.default_batch_fetch_size">8</property> - <property name="hibernate.jdbc.use_streams_for_binary">true</property> <property name="hibernate.max_fetch_depth">1</property> <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property> - <property name="hibernate.use_sql_comments">true</property> - <property name="hibernate.order_updates">true</property> </session-factory> </hibernate-configuration> diff --git a/orkbasej/java/net/sf/oreka/HibernateManager.java b/orkbasej/java/net/sf/oreka/HibernateManager.java index 6379ed4..d5d2f1b 100644 --- a/orkbasej/java/net/sf/oreka/HibernateManager.java +++ b/orkbasej/java/net/sf/oreka/HibernateManager.java @@ -17,6 +17,9 @@ package net.sf.oreka; import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; import net.sf.oreka.persistent.Domain; import net.sf.oreka.persistent.LoginString; @@ -29,27 +32,43 @@ import net.sf.oreka.persistent.RecTape; import net.sf.oreka.persistent.Service; import net.sf.oreka.persistent.User; -import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.AnnotationConfiguration; +import org.logicalcobwebs.proxool.ProxoolFacade; public class HibernateManager { - private static SessionFactory sessionFactory = null; + private SessionFactory sessionFactory = null; static Logger logger = Logger.getLogger(HibernateManager.class); - public static void configure(String filename) throws Exception { + public void configure(String filename) throws Exception { File configFile = new File(filename); AnnotationConfiguration config = new AnnotationConfiguration(); config.configure(configFile); + Class.forName("org.logicalcobwebs.proxool.ProxoolDriver"); + Properties info = new Properties(); + info.setProperty("proxool.maximum-connection-count", "10"); + info.setProperty("proxool.house-keeping-test-sql", "select CURRENT_DATE"); + info.setProperty("user", config.getProperty("hibernate.connection.username")); + info.setProperty("password", config.getProperty("hibernate.connection.password")); + SimpleDateFormat sdf = new SimpleDateFormat("HHmmss"); + String alias = "oreka" + sdf.format(new Date()); + String driverClass = config.getProperty("hibernate.connection.driver_class"); + String driverUrl = config.getProperty("hibernate.connection.url"); + String url = "proxool." + alias + ":" + driverClass + ":" + driverUrl; + ProxoolFacade.registerConnectionPool(url, info); + + config.setProperty("hibernate.proxool.pool_alias", alias); + config.setProperty("hibernate.proxool.existing_pool", "true"); + config.addAnnotatedClass(RecProgram.class); config.addAnnotatedClass(RecSession.class); config.addAnnotatedClass(RecSegment.class); @@ -93,7 +112,7 @@ public class HibernateManager { } } - public static Session getSession() throws Exception { + public Session getSession() throws Exception { if (sessionFactory == null) { throw new OrkException("HibernateManager.getSession: application must configure hibernate before using it."); } diff --git a/orkbasej/java/net/sf/oreka/test/FillDatabase.java b/orkbasej/java/net/sf/oreka/test/FillDatabase.java index 849af3c..1bef840 100644 --- a/orkbasej/java/net/sf/oreka/test/FillDatabase.java +++ b/orkbasej/java/net/sf/oreka/test/FillDatabase.java @@ -29,11 +29,13 @@ import org.hibernate.Transaction; public class FillDatabase { + static HibernateManager hibernateManager = new HibernateManager(); + public static void main(String args[]) throws Exception { - HibernateManager.configure("c:/oreka/test/mysql.hbm.xml"); + hibernateManager.configure("c:/oreka/test/mysql.hbm.xml"); - Session hbnSession = HibernateManager.getSession(); + Session hbnSession = hibernateManager.getSession(); Transaction tx = hbnSession.beginTransaction(); Service service = new Service(); |