List of usage examples for org.hibernate.cfg Configuration setProperty
public Configuration setProperty(String propertyName, String value)
From source file:org.jboss.tools.hibernate3_6.ConfigurationFactory.java
License:Open Source License
public Configuration createConfiguration(Configuration localCfg, boolean includeMappings) { Properties properties = prefs.getProperties(); if (properties != null) { // in case the transaction manager is empty then we need to inject a faketm since // hibernate will still try and instantiate it. String str = properties.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY); if (str != null && StringHelper.isEmpty(str)) { properties.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, FAKE_TM_LOOKUP); // properties.setProperty( "hibernate.transaction.factory_class", ""); }//w w w . j a va 2s . co m } if (localCfg == null) { localCfg = buildConfiguration(properties, includeMappings); } else { // Properties origProperties = cfg.getProperties(); // origProperties.putAll(properties); // cfg.setProperties(origProperties); // TODO: this is actually only for jdbc reveng... // localCfg = configureStandardConfiguration( includeMappings, localCfg, properties ); } // here both setProperties and configxml have had their chance to tell which databasedriver // is needed. registerFakeDriver(localCfg.getProperty(Environment.DRIVER)); // autoConfigureDialect(localCfg); Disabled for now since it causes very looong timeouts for // non-running databases + i havent been needed until now... // TODO: jpa configuration ? if (includeMappings) { File[] mappingFiles = prefs.getMappingFiles(); for (int i = 0; i < mappingFiles.length; i++) { File hbm = mappingFiles[i]; localCfg = localCfg.addFile(hbm); } } // TODO: HBX- localCfg.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false"); //$NON-NLS-1$//$NON-NLS-2$ localCfg.setProperty(Environment.HBM2DDL_AUTO, "false"); //$NON-NLS-1$ // to fix: JBIDE-5839 & JBIDE-5997 - setup this property: false is default value // to make hibernate tools diff hibernate versions compatible: // if the property not set get NoSuchMethodError with FullTextIndexEventListener if (localCfg.getProperty("hibernate.search.autoregister_listeners") == null) { //$NON-NLS-1$ localCfg.setProperty("hibernate.search.autoregister_listeners", "false"); //$NON-NLS-1$ //$NON-NLS-2$ } return localCfg; }
From source file:org.jboss.tools.hibernate3_6.ConfigurationFactory.java
License:Open Source License
@SuppressWarnings("unused") private void autoConfigureDialect(Configuration localCfg) { if (localCfg.getProperty(Environment.DIALECT) == null) { String dialect = ConnectionProfileUtil.autoDetectDialect(localCfg.getProperties()); if (dialect != null) { localCfg.setProperty(Environment.DIALECT, dialect); }/* w w w . j av a 2 s. c om*/ } }
From source file:org.jboss.tools.hibernate3_6.ConfigurationFactory.java
License:Open Source License
private Configuration configureStandardConfiguration(final boolean includeMappings, Configuration localCfg, Properties properties) {//from w ww.j a va 2s . c o m if (properties != null) { localCfg = localCfg.setProperties(properties); } EntityResolver entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER; if (StringHelper.isNotEmpty(prefs.getEntityResolverName())) { try { entityResolver = (EntityResolver) ReflectHelper.classForName(prefs.getEntityResolverName()) .newInstance(); } catch (Exception c) { throw new HibernateConsoleRuntimeException( ConsoleMessages.ConsoleConfiguration_could_not_configure_entity_resolver + prefs.getEntityResolverName(), c); } } localCfg.setEntityResolver(entityResolver); if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) { try { NamingStrategy ns = (NamingStrategy) ReflectHelper.classForName(prefs.getNamingStrategy()) .newInstance(); localCfg.setNamingStrategy(ns); } catch (Exception c) { throw new HibernateConsoleRuntimeException( ConsoleMessages.ConsoleConfiguration_could_not_configure_naming_strategy + prefs.getNamingStrategy(), c); } } localCfg = loadConfigurationXML(localCfg, includeMappings, entityResolver); changeDatasourceProperties(localCfg); localCfg = configureConnectionProfile(localCfg); // replace dialect if it is set in preferences if (StringHelper.isNotEmpty(prefs.getDialectName())) { localCfg.setProperty(Environment.DIALECT, prefs.getDialectName()); } if (StringHelper.isEmpty(localCfg.getProperty("javax.persistence.validation.mode"))) {//$NON-NLS-1$ localCfg.setProperty("javax.persistence.validation.mode", "none"); //$NON-NLS-1$//$NON-NLS-2$ } return localCfg; }
From source file:org.jboss.tools.hibernate4_0.ConfigurationFactory.java
License:Open Source License
@SuppressWarnings("unused") private void autoConfigureDialect(Configuration localCfg, ServiceRegistry serviceRegistry) { if (localCfg.getProperty(Environment.DIALECT) == null) { String dialect = ConnectionProfileUtil.autoDetectDialect(localCfg.getProperties()); if (dialect != null) { localCfg.setProperty(Environment.DIALECT, dialect); }/*from www . ja v a 2s.c o m*/ } }
From source file:org.jbpm.persistence.db.PersistenceServiceFactoryDbTest.java
License:Open Source License
private SessionFactory createSimplestSessionFactory() { Configuration configuration = new Configuration(); configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); SessionFactory sessionFactory = configuration.buildSessionFactory(); return sessionFactory; }
From source file:org.kalypso.model.wspm.pdb.internal.connect.HibernateConnection.java
License:Open Source License
private void configureSpatial(final Configuration configuration) { /**/* w w w . j a v a 2 s . c o m*/ * IMPORTANT: statically initialize HBSpatialExtension at this place (with the right context class loader active, so * the pseudo DialectProvider will be found; we will get a NPE else later. */ HBSpatialExtension.getDefaultGeomFactory(); /** * Important: we need to specify the spatial dialect ourself, else hibernatespatial will fall back to a default * spatial dialect. */ final SpatialDialect spatialDialect = createSpatialDialect(); final GeometryUserType2 geometryUserType = new GeometryUserType2(spatialDialect); configuration.registerTypeOverride(geometryUserType, new String[] { geometryUserType.getClass().getName() }); configuration.setProperty(Environment.DIALECT, spatialDialect.getClass().getName()); configuration.setProperty(SPATIAL_DIALECT, spatialDialect.getClass().getName()); }
From source file:org.kalypso.model.wspm.pdb.internal.connect.HibernateConnection.java
License:Open Source License
private void configure(final Configuration configuration) { configuration.setProperty(Environment.ORDER_UPDATES, Boolean.TRUE.toString()); // FIXME: why does this not work??? // configuration.setProperty( "hibernate.hbm2dll.auto", "create" ); // cfg.setProperty( org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create" ); // configuration.setProperty( "org.hibernate.tool.hbm2ddl", "debug" ); configuration.setProperty(Environment.POOL_SIZE, "1"); //$NON-NLS-1$ configuration.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); //$NON-NLS-1$ configuration.setProperty(Environment.CACHE_PROVIDER, "org.hibernate.cache.NoCacheProvider"); //$NON-NLS-1$ if (WspmPdbCoreDebug.SHOW_SQL_STATEMENTS.isEnabled()) { configuration.setProperty(Environment.SHOW_SQL, Boolean.TRUE.toString()); configuration.setProperty(Environment.FORMAT_SQL, Boolean.TRUE.toString()); } else {/*from w w w . j a v a2 s .c o m*/ configuration.setProperty(Environment.SHOW_SQL, Boolean.FALSE.toString()); configuration.setProperty(Environment.FORMAT_SQL, Boolean.FALSE.toString()); } // configuration.setProperty( "hibernate.c3p0.min_size", "5" ); // configuration.setProperty( "hibernate.c3p0.max_size", "20" ); // configuration.setProperty( "hibernate.c3p0.timeout", "1800" ); // configuration.setProperty( "hibernate.c3p0.max_statements", "50" ); }
From source file:org.kalypso.model.wspm.pdb.internal.connect.oracle.OracleConnection.java
License:Open Source License
@Override protected void doConfiguration(final Configuration configuration) { final OracleSettings settings = getSettings(); configuration.setProperty(Environment.DRIVER, oracle.jdbc.OracleDriver.class.getName()); final String connectionUrl = String.format("jdbc:oracle:thin:@%s:%d:%s", settings.getHost(), //$NON-NLS-1$ settings.getPort(), settings.getDbName()); configuration.setProperty(Environment.URL, connectionUrl); configuration.setProperty(Environment.USER, settings.getUsername()); configuration.setProperty(Environment.PASS, settings.getPassword()); configuration.setProperty(Environment.CONNECTION_PREFIX + ".defaultNChar", "true"); //$NON-NLS-1$ //$NON-NLS-2$ configuration.setProperty(Environment.CONNECTION_PREFIX + ".charSet", "utf-8"); //$NON-NLS-1$ //$NON-NLS-2$ configuration.setProperty(Environment.CONNECTION_PREFIX + ".useUnicode", "true"); //$NON-NLS-1$ //$NON-NLS-2$ configuration.setProperty(Environment.CONNECTION_PREFIX + ".characterEncoding", "utf-8"); //$NON-NLS-1$ //$NON-NLS-2$ // final OracleConnectInfo connectInfo = getConnectInfo(); ///*w ww .ja va 2 s . c o m*/ // final org.hibernate.dialect.PostgreSQLDialect dialect = new PostgisDialect(); // // configuration.setProperty( "hibernate.connection.driver_class", org.postgresql.Driver.class.getName() ); // // final String connectionUrl = String.format( "jdbc:postgresql://%s:%d/%s", connectInfo.getHost(), // connectInfo.getPort(), connectInfo.getDbName() ); // // configuration.setProperty( "hibernate.connection.url", connectionUrl ); // configuration.setProperty( "hibernate.connection.username", connectInfo.getUsername() ); // configuration.setProperty( "hibernate.connection.password", connectInfo.getPassword() ); // // configuration.setProperty( "hibernate.dialect", dialect.getClass().getName() ); // configuration.setProperty( "hibernate.spatial.dialect", dialect.getClass().getName() ); }
From source file:org.kalypso.model.wspm.pdb.internal.connect.postgis.PostGisConnection.java
License:Open Source License
@Override protected void doConfiguration(final Configuration configuration) { final PostgisSettings settings = getSettings(); configuration.setProperty(Environment.DRIVER, org.postgresql.Driver.class.getName()); final String connectionUrl = String.format("jdbc:postgresql://%s:%d/%s", settings.getHost(), //$NON-NLS-1$ settings.getPort(), settings.getDbName()); configuration.setProperty(Environment.URL, connectionUrl); configuration.setProperty(Environment.USER, settings.getUsername()); configuration.setProperty(Environment.PASS, settings.getPassword()); // In order to use ssl, we need a way to accept the certificate // configuration.setProperty( Environment.CONNECTION_PREFIX + ".ssl", Boolean.TRUE.toString() ); }
From source file:org.mgenterprises.openbooks.configuration.HibernateConfigurationLoader.java
License:Open Source License
public Configuration getConfiguration() { Configuration configuration = new Configuration(); configuration.configure();//from w ww . j a v a 2s. co m for (Object key : properties.keySet()) { String keyString = (String) key; configuration.setProperty(keyString, properties.getProperty(keyString)); } return configuration; }