ormconfig
sqlscript
useDBForMapping
*/
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)
//.setProperty("hibernate.connection.pool_size", "2")//MUST
// SQL dialect
.setProperty("hibernate.dialect", dialect)
// Enable Hibernate's current session context
.setProperty("hibernate.current_session_context_class", "thread")
// Echo all executed SQL to stdout
.setProperty("hibernate.show_sql", CommonUtil.toString(ormConf.logSQL()))
.setProperty("hibernate.format_sql", CommonUtil.toString(ormConf.logSQL()))
// Specifies whether secondary caching should be enabled
.setProperty("hibernate.cache.use_second_level_cache", CommonUtil.toString(ormConf.secondaryCacheEnabled()))
// Drop and re-create the database schema on startup
.setProperty("hibernate.exposeTransactionAwareSessionFactory", "false")
//.setProperty("hibernate.hbm2ddl.auto", "create")
.setProperty("hibernate.default_entity_mode", "dynamic-map");
if(!Util.isEmpty(ormConf.getCatalog()))
configuration.setProperty("hibernate.default_catalog", ormConf.getCatalog());
if(!Util.isEmpty(ormConf.getSchema()))
configuration.setProperty("hibernate.default_schema",ormConf.getSchema());
if(ormConf.secondaryCacheEnabled()){
if(cacheConfig!=null && cacheConfig.isFile())
configuration.setProperty("hibernate.cache.provider_configuration_file_resource_path",cacheConfig.getAbsolutePath());
if(regionFactory!=null || Reflector.isInstaneOf(cacheProvider, RegionFactory.class))
configuration.setProperty("hibernate.cache.region.factory_class", cacheProvider);
else