List of usage examples for org.hibernate.cfg Configuration configure
public Configuration configure() throws HibernateException
From source file:org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImplTest.java
License:Apache License
@Test public void get_configuration() { HibernateConfigurer configurer = new HibernateConfigurer() { @Override/* ww w . j av a 2 s .co m*/ public void configure(Configuration configuration) { configuration.setProperty("foo", "bar"); configuration.configure(); } }; HibernateSessionSource source = new HibernateSessionSourceImpl(log, Arrays.asList(configurer)); Configuration config = source.getConfiguration(); Assert.assertNotNull(config); Assert.assertEquals("bar", config.getProperty("foo")); // Configuration was immutable in 5.1, but Hibernate 3.6.0.Final made that impossible }
From source file:org.bedework.util.hibernate.HibSessionFactory.java
License:Apache License
/** * @param hibProps possibly null list of hibernate properties * @return the SessionFactory/* w w w .j av a2 s.c o m*/ * @throws HibException */ public static SessionFactory getSessionFactory(List<String> hibProps) throws HibException { if (sessionFactory != null) { return sessionFactory; } synchronized (lock) { if (sessionFactory != null) { return sessionFactory; } /** Get a new hibernate session factory. This is configured from an * application resource hibernate.cfg.xml together with some run time values */ try { Configuration conf = new Configuration(); /* if (props != null) { String cachePrefix = props.getProperty("cachePrefix"); if (cachePrefix != null) { conf.setProperty("hibernate.cache.use_second_level_cache", props.getProperty("cachingOn")); conf.setProperty("hibernate.cache.region_prefix", cachePrefix); } } */ if (hibProps != null) { StringBuilder sb = new StringBuilder(); for (String p : hibProps) { sb.append(p); sb.append("\n"); } Properties hprops = new Properties(); hprops.load(new StringReader(sb.toString())); conf.addProperties(hprops); } conf.configure(); sessionFactory = conf.buildSessionFactory(); return sessionFactory; } catch (Throwable t) { throw new HibException(t); } } }
From source file:org.blueoxygen.cimande.persistence.hibernate.DefaultHibernateSessionFactory.java
License:Open Source License
private SessionFactory buildSessionFactory() throws HibernateException { Configuration config = new Configuration(); config.configure(); if (System.getProperty("hibernate.connect.url.override") != null) { config.setProperty("hibernate.connection.url", System.getProperty("hibernate.connect.url.override")); config.setProperty("hibernate.connection.username", "sa"); config.setProperty("hibernate.connection.password", ""); config.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.HSQLDialect"); }//from www. j a va 2 s .co m // update database schema if required try { new SchemaUpdate(config).execute(false, false); } catch (HibernateException e) { log.fatal("Cannot update schema", e); throw new PersistenceException("Cannot update schema", e); } SessionFactory result = config.buildSessionFactory(); return result; }
From source file:org.chenillekit.hibernate.services.impl.PropertiesHibernateConfigurer.java
License:Apache License
/** * Passed the configuration so as to make changes. *///from ww w . ja va 2s . c o m public void configure(Configuration configuration) { Properties properties = new Properties(); try { properties.load(new FileInputStream(propertiesFileName)); configuration.addProperties(properties); configuration.configure(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.dt.bsa.util.HibernateUtil.java
License:Open Source License
public static void init() { try {/*from w w w . ja v a 2 s.c o m*/ Configuration configuration = new Configuration(); configuration.setNamingStrategy(ImprovedNamingStrategy.INSTANCE); configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()) .buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { log.error("HibernateUtil:init error:" + ex.getMessage()); throw new ExceptionInInitializerError(ex); } }
From source file:org.exoplatform.services.organization.idm.DisabledUserMigrationScript.java
License:Open Source License
private void setupHibernate(Properties config) throws Exception { final Configuration conf_ = new Configuration(); conf_.setProperty("hibernate.connection.driver_class", config.getProperty("hibernate.connection.driver_class")); conf_.setProperty("hibernate.connection.url", config.getProperty("hibernate.connection.url")); conf_.setProperty("hibernate.connection.username", config.getProperty("hibernate.connection.username")); conf_.setProperty("hibernate.connection.password", config.getProperty("hibernate.connection.password")); conf_.setProperty("hibernate.dialect", config.getProperty("hibernate.dialect")); String config_path = config.getProperty("hibernate.config_path"); URL url = Thread.currentThread().getContextClassLoader().getResource(config_path); if (url == null) { log.error("hibernate config file not found: {}", config_path); } else {/*ww w .j a v a2 s. c o m*/ log.info("adding hibernate config file {}", config_path); conf_.addURL(url); } sessionFactory_ = SecurityHelper.doPrivilegedAction(new PrivilegedAction<SessionFactory>() { public SessionFactory run() { SessionFactory factory = conf_.configure().buildSessionFactory(); return factory; } }); }
From source file:org.glite.security.voms.admin.integration.orgdb.database.OrgDBSessionFactory.java
License:Apache License
public synchronized static void initialize(Properties orgbHibernateProperties) { if (orgDbSessionFactory != null) throw new OrgDBError("Session factory already initialized!"); try {/*from w ww .ja v a 2 s . c o m*/ Configuration cfg = buildConfiguration(orgbHibernateProperties); orgDbSessionFactory = cfg.configure().buildSessionFactory(); } catch (HibernateException e) { String errorMsg = String.format("Cannot initialize OrgDB database connection: %s", e.getMessage()); log.error(errorMsg, e); throw new OrgDBError(errorMsg, e); } }
From source file:org.glite.security.voms.admin.persistence.deployer.SchemaDeployer.java
License:Apache License
private Configuration loadHibernateConfiguration() { Configuration cfg; if (hibernatePropertiesFile == null) { cfg = DBUtil.loadHibernateConfiguration(getVOConfigurationDir(), vo); } else {/*from w w w .ja v a 2 s.co m*/ cfg = DBUtil.loadHibernateConfiguration(hibernatePropertiesFile); } dialect = Dialect.getDialect(cfg.getProperties()); cfg.configure(); return cfg; }
From source file:org.glite.security.voms.admin.persistence.HibernateFactory.java
License:Apache License
public static synchronized void initialize(Properties databaseProperties) { Validate.notNull(databaseProperties); if (sessionFactory != null) { throw new VOMSDatabaseException("Hibernate session factory already initialized!"); }// w ww. j a va 2s . com try { Configuration hibernateConf = new Configuration(); hibernateConf.addProperties(databaseProperties); sessionFactory = hibernateConf.configure().buildSessionFactory(); } catch (HibernateException e) { log.error("Hibernate session factory creation failed!", e); throw new ExceptionInInitializerError(e); } }
From source file:org.glite.security.voms.admin.persistence.tools.AuditLogCtl.java
License:Apache License
private void initializePersistence(CommandLine line) { loadVomsAdminConfiguration(line);//from ww w .j a v a 2 s. c o m initializeLookupPolicyProvider(); Configuration hibernateConfig = DBUtil.loadHibernateConfiguration("/etc/voms-admin", line.getOptionValue("vo")); hibernateConfig.configure(); HibernateFactory.initialize(hibernateConfig); }