| 1 21 22 package com.rift.coad.daemon.timer.db.util; 23 24 import com.rift.coad.daemon.timer.TimerException; 26 import com.rift.coad.lib.configuration.*; 27 28 import org.hibernate.*; 30 import org.hibernate.cfg.*; 31 32 35 public class HibernateUtil { 36 37 private static SessionFactory sessionFactory; 38 39 43 public static void init() throws TimerException { 44 try { 45 com.rift.coad.lib.configuration.Configuration coadConfig = 47 com.rift.coad.lib.configuration.ConfigurationFactory. 48 getInstance() 49 .getConfig(com.rift.coad.daemon.timer.TimerImpl.class); 50 org.hibernate.cfg.Configuration config = new 51 org.hibernate.cfg.Configuration() 52 .addResource("com/rift/coad/daemon/timer/db/Schedule.hbm.xml") 53 .setProperty("hibernate.dialect",coadConfig.getString("db_dialect")) 54 .setProperty("hibernate.connection.datasource", 55 coadConfig.getString("db_datasource")) 56 .setProperty("hibernate.current_session_context_class","jta") 57 .setProperty("hibernate.transaction.factory_class", 58 "org.hibernate.transaction.JTATransactionFactory") 59 .setProperty("hibernate.transaction.manager_lookup_class", 60 "org.hibernate.transaction.JOTMTransactionManagerLookup") 61 .setProperty("hibernate.cache.provider_class", 62 "org.hibernate.cache.NoCacheProvider") 63 .setProperty("hibernate.show_sql", 64 coadConfig.getString("hibernate_sql","false")) 65 .setProperty("hibernate.hbm2ddl.auto", 66 coadConfig.getString("hibernate_hbm2ddl_auto","update")); 67 sessionFactory = config.buildSessionFactory(); 68 } catch (Throwable ex) { 69 throw new TimerException("Initial SessionFactory creation failed: " 71 + ex); 72 } 73 } 74 75 78 public static SessionFactory getSessionFactory() { 79 return sessionFactory; 80 } 81 82 } | Popular Tags |