use of org.hibernate.cfg.Configuration in project ignite by apache.
the class CacheHibernateBlobStore method init.
/**
* Initializes store.
*
* @throws IgniteException If failed to initialize.
*/
private void init() throws IgniteException {
if (initGuard.compareAndSet(false, true)) {
if (log.isDebugEnabled())
log.debug("Initializing cache store.");
try {
if (sesFactory != null)
// Session factory has been provided - nothing to do.
return;
if (!F.isEmpty(hibernateCfgPath)) {
try {
URL url = new URL(hibernateCfgPath);
sesFactory = new Configuration().configure(url).buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using URL: " + url);
// Session factory has been successfully initialized.
return;
} catch (MalformedURLException e) {
if (log.isDebugEnabled())
log.debug("Caught malformed URL exception: " + e.getMessage());
}
// Provided path is not a valid URL. File?
File cfgFile = new File(hibernateCfgPath);
if (cfgFile.exists()) {
sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using file: " + hibernateCfgPath);
// Session factory has been successfully initialized.
return;
}
// Provided path is not a file. Classpath resource?
sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
} else {
if (hibernateProps == null) {
U.warn(log, "No Hibernate configuration has been provided for store (will use default).");
hibernateProps = new Properties();
hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
}
Configuration cfg = new Configuration();
cfg.setProperties(hibernateProps);
assert resourceAvailable(MAPPING_RESOURCE) : MAPPING_RESOURCE;
cfg.addResource(MAPPING_RESOURCE);
sesFactory = cfg.buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using properties: " + hibernateProps);
}
} catch (HibernateException e) {
throw new IgniteException("Failed to initialize store.", e);
} finally {
initLatch.countDown();
}
} else if (initLatch.getCount() > 0) {
try {
U.await(initLatch);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
if (sesFactory == null)
throw new IgniteException("Cache store was not properly initialized.");
}
use of org.hibernate.cfg.Configuration in project ignite by apache.
the class CacheHibernateStoreSessionListener method start.
/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@Override
public void start() throws IgniteException {
if (sesFactory == null && F.isEmpty(hibernateCfgPath))
throw new IgniteException("Either session factory or Hibernate configuration file is required by " + getClass().getSimpleName() + '.');
if (!F.isEmpty(hibernateCfgPath)) {
if (sesFactory == null) {
try {
URL url = new URL(hibernateCfgPath);
sesFactory = new Configuration().configure(url).buildSessionFactory();
} catch (MalformedURLException ignored) {
// No-op.
}
if (sesFactory == null) {
File cfgFile = new File(hibernateCfgPath);
if (cfgFile.exists())
sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
}
if (sesFactory == null)
sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
if (sesFactory == null)
throw new IgniteException("Failed to resolve Hibernate configuration file: " + hibernateCfgPath);
closeSesOnStop = true;
} else
U.warn(log, "Hibernate configuration file configured in " + getClass().getSimpleName() + " will be ignored (session factory is already set).");
}
}
use of org.hibernate.cfg.Configuration in project ignite by apache.
the class HibernateL2CacheConfigurationSelfTest method hibernateConfiguration.
/**
* @param igniteInstanceName Ignite instance name.
* @return Hibernate configuration.
*/
protected Configuration hibernateConfiguration(String igniteInstanceName) {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Entity1.class);
cfg.addAnnotatedClass(Entity2.class);
cfg.addAnnotatedClass(Entity3.class);
cfg.addAnnotatedClass(Entity4.class);
cfg.setProperty(HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY, AccessType.NONSTRICT_READ_WRITE.name());
cfg.setProperty(HBM2DDL_AUTO, "create");
cfg.setProperty(GENERATE_STATISTICS, "true");
cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");
cfg.setProperty(USE_QUERY_CACHE, "true");
cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
cfg.setProperty(RELEASE_CONNECTIONS, "on_close");
cfg.setProperty(HibernateAccessStrategyFactory.IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
cfg.setProperty(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
cfg.setProperty(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);
if (dfltCache)
cfg.setProperty(DFLT_CACHE_NAME_PROPERTY, "cache3");
return cfg;
}
use of org.hibernate.cfg.Configuration in project ignite by apache.
the class HibernateL2CacheConfigurationSelfTest method startHibernate.
/**
* @param igniteInstanceName Name of the grid providing caches.
* @return Session factory.
*/
private SessionFactory startHibernate(String igniteInstanceName) {
Configuration cfg = hibernateConfiguration(igniteInstanceName);
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
builder.applySetting("hibernate.show_sql", false);
builder.applySettings(cfg.getProperties());
return cfg.buildSessionFactory(builder.build());
}
use of org.hibernate.cfg.Configuration in project scheduling by ow2-proactive.
the class RMDBManager method createInMemoryRMDBManager.
public static RMDBManager createInMemoryRMDBManager() {
Configuration config = new Configuration();
config.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbc.JDBCDriver");
config.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:" + System.currentTimeMillis() + ";hsqldb.tx=mvcc");
config.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
return new RMDBManager(config, true, true);
}
Aggregations