*/
ORMConfiguration ormConf = data.getORMConfiguration();
// dialect
DataSource ds = dc.getDatasource();
String dialect=null;
try {
if (Class.forName(ormConf.getDialect()) != null) {
dialect = ormConf.getDialect();
}
}
catch (Exception e) {
// MZ: The dialect value could not be bound to a classname or instantiation causes an exception - ignore and use the default dialect entries
}
if (dialect == null) {
dialect = Dialect.getDialect(ormConf.getDialect());
if(Util.isEmpty(dialect)) dialect=Dialect.getDialect(ds);
}
if(Util.isEmpty(dialect))
throw ExceptionUtil.createException(data,null,"A valid dialect definition inside the "+Constants.APP_CFC+"/"+Constants.CFAPP_NAME+" is missing. The dialect cannot be determinated automatically",null);
// Cache Provider
String cacheProvider = ormConf.getCacheProvider();
Class<? extends RegionFactory> regionFactory=null;
if(Util.isEmpty(cacheProvider) || "EHCache".equalsIgnoreCase(cacheProvider)) {
regionFactory=net.sf.ehcache.hibernate.EhCacheRegionFactory.class;
cacheProvider=regionFactory.getName();//"org.hibernate.cache.EhCacheProvider";
}
else if("JBossCache".equalsIgnoreCase(cacheProvider)) cacheProvider="org.hibernate.cache.TreeCacheProvider";
else if("HashTable".equalsIgnoreCase(cacheProvider)) cacheProvider="org.hibernate.cache.HashtableCacheProvider";
else if("SwarmCache".equalsIgnoreCase(cacheProvider)) cacheProvider="org.hibernate.cache.SwarmCacheProvider";
else if("OSCache".equalsIgnoreCase(cacheProvider)) cacheProvider="org.hibernate.cache.OSCacheProvider";
Resource cacheConfig = ormConf.getCacheConfig();
Configuration configuration = new Configuration();
// ormConfig
Resource conf = ormConf.getOrmConfig();
if(conf!=null){
try {
Document doc = CommonUtil.toDocument(conf);
configuration.configure(doc);
}
catch (Throwable t) {
ORMUtil.printError(t);
}
}
try{
configuration.addXML(mappings);
}
catch(MappingException me){
throw ExceptionUtil.createException(data,null, me);
}
configuration
// Database connection settings
.setProperty("hibernate.connection.driver_class", ds.getClazz().getName())
.setProperty("hibernate.connection.url", ds.getDsnTranslated())
.setProperty("hibernate.connection.username", ds.getUsername())
.setProperty("hibernate.connection.password", ds.getPassword())
//.setProperty("hibernate.connection.release_mode", "after_transaction")
.setProperty("hibernate.transaction.flush_before_completion", "false")
.setProperty("hibernate.transaction.auto_close_session", "false")
// JDBC connection pool (use the built-in)