List of usage examples for org.hibernate.cfg Configuration addProperties
public Configuration addProperties(Properties properties)
From source file:org.bedework.calcore.hibernate.SchemaBuilderImpl.java
License:Apache License
private Configuration getConfiguration(final Properties props) throws Throwable { Configuration cfg = new Configuration(); cfg.addProperties(props).configure(); return cfg;/*www . j a v a 2s. c o m*/ }
From source file:org.bedework.carddav.server.dirHandlers.db.DbDirHandler.java
License:Apache License
private SessionFactory getSessionFactory() throws WebdavException { if (sessionFactory != null) { return sessionFactory; }/*from w w w . java 2s .c om*/ synchronized (this) { 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); } } */ StringBuilder sb = new StringBuilder(); List<String> ps = dbConfig.getHibernateProperties(); for (String p : ps) { sb.append(p); sb.append("\n"); } Properties hprops = new Properties(); hprops.load(new StringReader(sb.toString())); conf.addProperties(hprops).configure(); sessionFactory = conf.buildSessionFactory(); return sessionFactory; } catch (Throwable t) { // Always bad. error(t); throw new WebdavException(t); } } }
From source file:org.bedework.util.hibernate.HibSessionFactory.java
License:Apache License
/** * @param hibProps possibly null list of hibernate properties * @return the SessionFactory/*from ww w . j av a2s. co 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.bonitasoft.engine.persistence.AbstractHibernatePersistenceService.java
License:Open Source License
/** * @param name/*from w w w. j av a 2s.co m*/ * @param hbmConfigurationProvider * @param likeEscapeCharacter * @param logger * @param sequenceManager * @param datasource * @param enableWordSearch * @param wordSearchExclusionMappings * @throws SPersistenceException * @throws ClassNotFoundException */ public AbstractHibernatePersistenceService(final String name, final HibernateConfigurationProvider hbmConfigurationProvider, final Properties extraHibernateProperties, final String likeEscapeCharacter, final TechnicalLoggerService logger, final SequenceManager sequenceManager, final DataSource datasource, final boolean enableWordSearch, final Set<String> wordSearchExclusionMappings) throws SPersistenceException, ClassNotFoundException { super(name, likeEscapeCharacter, sequenceManager, datasource, enableWordSearch, wordSearchExclusionMappings, logger); orderByCheckingMode = getOrderByCheckingMode(); Configuration configuration; try { configuration = hbmConfigurationProvider.getConfiguration(); if (extraHibernateProperties != null) { configuration.addProperties(extraHibernateProperties); } } catch (final ConfigurationException e) { throw new SPersistenceException(e); } final String dialect = configuration.getProperty("hibernate.dialect"); if (dialect != null) { if (dialect.contains("PostgreSQL")) { configuration.setInterceptor(new PostgresInterceptor()); } else if (dialect.contains("SQLServer")) { configuration.setInterceptor(new SQLServerInterceptor()); } } final String className = configuration.getProperty("hibernate.interceptor"); if (className != null && !className.isEmpty()) { try { final Interceptor interceptor = (Interceptor) Class.forName(className).newInstance(); configuration.setInterceptor(interceptor); } catch (final ClassNotFoundException cnfe) { throw new SPersistenceException(cnfe); } catch (final InstantiationException e) { throw new SPersistenceException(e); } catch (final IllegalAccessException e) { throw new SPersistenceException(e); } } sessionFactory = configuration.buildSessionFactory(); statistics = sessionFactory.getStatistics(); final Iterator<PersistentClass> classMappingsIterator = configuration.getClassMappings(); classMapping = new ArrayList<Class<? extends PersistentObject>>(); while (classMappingsIterator.hasNext()) { classMapping.add(classMappingsIterator.next().getMappedClass()); } classAliasMappings = hbmConfigurationProvider.getClassAliasMappings(); interfaceToClassMapping = hbmConfigurationProvider.getInterfaceToClassMapping(); mappingExclusions = hbmConfigurationProvider.getMappingExclusions(); cacheQueries = hbmConfigurationProvider.getCacheQueries(); }
From source file:org.bonitasoft.engine.persistence.HibernateConfigurationProviderImpl.java
License:Open Source License
protected Configuration buildConfiguration(final Properties properties, final HibernateResourcesConfigurationProvider hibernateResourcesConfigurationProvider) { final Configuration configuration = new Configuration(); configuration.addProperties(properties); for (final String resource : hibernateResourcesConfigurationProvider.getResources()) { configuration.addResource(resource); }/*from w w w. ja v a 2 s . c o m*/ configuration.buildMappings(); return configuration; }
From source file:org.chenillekit.hibernate.services.impl.PropertiesHibernateConfigurer.java
License:Apache License
/** * Passed the configuration so as to make changes. *///from ww w . j a va 2 s . 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.glite.security.voms.admin.integration.orgdb.database.OrgDBSessionFactory.java
License:Apache License
public static Configuration buildConfiguration(Properties orgDbHibernateProperties) { Configuration cfg = new Configuration().addAnnotatedClass(Country.class).addAnnotatedClass(Experiment.class) .addAnnotatedClass(Institute.class).addAnnotatedClass(InstituteAddress.class) .addAnnotatedClass(Participation.class).addAnnotatedClass(VOMSOrgDBPerson.class) .setProperties(orgDbHibernateProperties); // Hardwired configuration properties Properties p = new Properties(); p.setProperty("hibernate.current_session_context_class", ThreadLocalSessionContext.class.getName()); log.debug("Hardwired configuration properties: {}", p); cfg.addProperties(p); return cfg;//from ww w. j a v a2s . com }
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!"); }/*from www. j a va 2s . c o m*/ 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.inheritsource.taskform.engine.persistence.HibernateUtil.java
License:Open Source License
/** * Override properties in a Hibernate configuration if an environment * variable is set. No exceptions are propagated, this step is just omitted * in such case. SIDE EFFECT: Properties are set in the configuration, * possibly overriding those already set. *//*from w w w. j a v a2 s . c o m*/ public static void overrideProperties(Configuration cfg) { try { Properties props = ConfigUtil.getConfigProperties(); Properties hibernateProps = new Properties(); for (Object key : props.keySet()) { if (key instanceof String && ((String) key).startsWith("dataSource.")) { Object val = props.get(key); String hibernateKey = "hibernate.connection." + ((String) key).substring(11); hibernateProps.put(hibernateKey, val); } } cfg.addProperties(hibernateProps); } catch (Exception exc) { // Warn and ignore log.warn("Db default connect params (got " + exc.getClass().getName() + ")"); } String url = cfg.getProperty("hibernate.connection.url"); log.info("Db connect url: " + ((url != null) ? url : "*NO URL*")); }
From source file:org.jboss.tools.hibernate3_6.ConfigurationFactory.java
License:Open Source License
private Configuration configureConnectionProfile(Configuration localCfg) { String connProfileName = prefs.getConnectionProfileName(); if (connProfileName == null) { return localCfg; }/*www .j av a 2s. co m*/ IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(connProfileName); if (profile != null) { localCfg.addProperties(ConnectionProfileUtil.getHibernateConnectionProperties(profile)); } else { String out = NLS.bind(ConsoleMessages.ConsoleConfiguration_connection_profile_not_found, connProfileName); throw new HibernateConsoleRuntimeException(out); } return localCfg; }