List of usage examples for org.hibernate.cfg Configuration setProperty
public Configuration setProperty(String propertyName, String value)
From source file:org.geolatte.featureserver.dbase.DbaseFacade.java
License:Open Source License
/** * Private constructor of the database facade. Maps all tables currently present in the database! * * @throws java.sql.SQLException If retrieval of the database classes, or mapping of the tables was unsuccesfull. *///w w w. j a v a 2 s . com private DbaseFacade() throws SQLException { if (FeatureServerConfiguration.getInstance() == null || FeatureServerConfiguration.getInstance().isInvalid()) { throw new SQLException("Invalid FeatureServer configuration"); } String connectionString = FeatureServerConfiguration.getInstance() .getHibernateProperty("hibernate.connection.url"); String user = FeatureServerConfiguration.getInstance() .getHibernateProperty("hibernate.connection.username"); String password = FeatureServerConfiguration.getInstance() .getHibernateProperty("hibernate.connection.password"); Connection dbConnection = DriverManager.getConnection(connectionString, user, password); DatabaseMetaData databaseMetaData = dbConnection.getMetaData(); String schema = FeatureServerConfiguration.getInstance().getDbaseSchema(); ResultSet resultSet = databaseMetaData.getTables(null, schema, null, new String[] { "TABLE", "VIEW" }); ArrayList<String> names = new ArrayList<String>(); while (resultSet.next()) { names.add(resultSet.getString("TABLE_NAME")); } Configuration newConfig = new Configuration(); for (String property : FeatureServerConfiguration.getInstance().getHibernateProperties()) { newConfig.setProperty(property, FeatureServerConfiguration.getInstance().getHibernateProperty(property)); } mappedTables = FeatureServerConfiguration.getInstance().includedTables(names); // We may only invoke this once, since currently the automapper crashes if a table was already mapped in the // past. Since this call is present in the private constructor which is only called in the singleton method // there is no problem. Document tableMapping = AutoMapper.map(dbConnection, null, schema, mappedTables); resultSet.close(); dbConnection.close(); newConfig.addXML(tableMapping.asXML()); HSConfiguration configuration = new HSConfiguration(); this.sessionFactory = newConfig.buildSessionFactory(); LOGGER.info("Sessionfactory created: " + sessionFactory); configuration.configure(newConfig); }
From source file:org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.java
License:Apache License
protected void configureGrailsJdbcTransactionFactory(Configuration config) { String configuredStrategy = config.getProperty(Environment.TRANSACTION_STRATEGY); if (configuredStrategy == null || "jdbc".equals(configuredStrategy)) { config.setProperty(Environment.TRANSACTION_STRATEGY, GrailsJdbcTransactionFactory.class.getName()); }//www . ja va 2 s . c o m }
From source file:org.ikasan.connector.basefiletransfer.DataAccessUtil.java
License:BSD License
/** * static accessor for singleton BaseFileTransferDao * /* w w w. jav a 2 s. c o m*/ * @return singleton instance of BaseFileTransferDao */ public static BaseFileTransferDao getBaseFileTransferDao() { if (baseFileTransferDao == null) { Configuration cfg = generateConfiguration(); cfg.setProperty(Environment.DATASOURCE, "java:/datasource/ikasan/xads"); cfg.addClass(FileFilter.class); // this will expect to find // FileFilter.hbm.xml in the fully // qualified package for FileFilter SessionFactory baseFileTrasferHibernateSessionFactory = cfg.buildSessionFactory(); baseFileTransferDao = new HibernateBaseFileTransferDaoImpl(baseFileTrasferHibernateSessionFactory); } return baseFileTransferDao; }
From source file:org.ikasan.connector.basefiletransfer.DataAccessUtil.java
License:BSD License
/** * static accessor for singleton FileChunkDao * // ww w . j a v a 2 s. c o m * @return singleton instance of FileChunkDao */ public static FileChunkDao getFileChunkDao() { if (fileChunkDao == null) { Configuration cfg = generateConfiguration(); cfg.setProperty(Environment.DATASOURCE, "java:/datasource/ikasan/ds"); cfg.addClass(FileChunk.class); // this will expect to find // FileChunk.hbm.xml in the fully // qualified package for FileFilter cfg.addClass(FileChunkHeader.class); // this will expect to find // FileChunkHeader.hbm.xml // in the fully qualified // package for FileFilter SessionFactory fileChunkSessionFactory = cfg.buildSessionFactory(); fileChunkDao = new HibernateFileChunkDao(fileChunkSessionFactory); } return fileChunkDao; }
From source file:org.ikasan.connector.basefiletransfer.DataAccessUtil.java
License:BSD License
/** * static accessor for singleton TransactionalResourceCommandDAO * //from w w w . j ava 2s. co m * @return singleton instance of TransactionalResourceCommandDAO */ public static TransactionalResourceCommandDAO getTransactionalResourceCommandDAO() { if (transactionalResourceCommandDAO == null) { InputStream transactionalResourceCommandMappings = Thread.currentThread().getContextClassLoader() .getResourceAsStream("TransactionalResourceCommand.hbm.xml"); InputStream xidImplMappings = Thread.currentThread().getContextClassLoader() .getResourceAsStream("XidImpl.hbm.xml"); Configuration cfg = generateConfiguration(); cfg.setProperty(Environment.DATASOURCE, "java:/datasource/ikasan/ds"); cfg.addInputStream(transactionalResourceCommandMappings); cfg.addInputStream(xidImplMappings); transactionalResourceCommandDAO = new HibernateTransactionalResourceCommandDAO( cfg.buildSessionFactory()); } return transactionalResourceCommandDAO; }
From source file:org.infinispan.test.hibernate.cache.CacheKeySerializationTest.java
License:LGPL
private SessionFactoryImplementor getSessionFactory(String cacheKeysFactory) { Configuration configuration = new Configuration().setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true") .setProperty(Environment.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName()) .setProperty(Environment.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "transactional") .setProperty(AvailableSettings.SHARED_CACHE_MODE, "ALL") .setProperty(Environment.HBM2DDL_AUTO, "create-drop"); if (cacheKeysFactory != null) { configuration.setProperty(Environment.CACHE_KEYS_FACTORY, cacheKeysFactory); }/* w w w .j av a 2s . c o m*/ configuration.addAnnotatedClass(WithSimpleId.class); configuration.addAnnotatedClass(WithEmbeddedId.class); return (SessionFactoryImplementor) configuration.buildSessionFactory(); }
From source file:org.infinispan.test.hibernate.cache.commons.CacheKeySerializationTest.java
License:LGPL
private SessionFactoryImplementor getSessionFactory(String cacheKeysFactory) { Configuration configuration = new Configuration().setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true") .setProperty(Environment.CACHE_REGION_FACTORY, TestRegionFactoryProvider.load().getRegionFactoryClass().getName()) .setProperty(Environment.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "transactional") .setProperty("javax.persistence.sharedCache.mode", "ALL") .setProperty(Environment.HBM2DDL_AUTO, "create-drop"); if (cacheKeysFactory != null) { configuration.setProperty(Environment.CACHE_KEYS_FACTORY, cacheKeysFactory); }/*from w w w. j a v a 2 s . c om*/ configuration.addAnnotatedClass(WithSimpleId.class); configuration.addAnnotatedClass(WithEmbeddedId.class); return (SessionFactoryImplementor) configuration.buildSessionFactory(); }
From source file:org.infoglue.calendar.controllers.SchemaExportController.java
License:Open Source License
public void exportTables() throws HibernateException { Configuration cfg = new Configuration().addClass(Calendar.class).addClass(Location.class) .addClass(Category.class).addClass(Participant.class).addClass(Resource.class) .addClass(Event.class); cfg.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.MySQLDialect"); SchemaExport schemaExport = new SchemaExport(cfg); schemaExport.setOutputFile("calendar.sql"); schemaExport.create(true, true);/*from w w w . ja v a2 s . c o m*/ }
From source file:org.informea.odata.config.HibernateConfigurator.java
License:Open Source License
private void configure() { org.informea.odata.config.Configuration cfg = org.informea.odata.config.Configuration.getInstance(); //Preferences.userRoot().getBoolean(USE_PATH_PREFIX, false); Configuration hc = new Configuration(); // Use C3P0 connection pooling instead of Tomcat DBCP - which cannot be configured at runtime dynamically hc.setProperty("connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider"); hc.setProperty("hibernate.c3p0.acquire_increment", "1"); hc.setProperty("hibernate.c3p0.idle_test_period", "100"); hc.setProperty("hibernate.c3p0.max_size", "30"); hc.setProperty("hibernate.c3p0.max_statements", "0"); hc.setProperty("hibernate.c3p0.min_size", "1"); hc.setProperty("hibernate.c3p0.timeout", "100"); hc.setProperty("hibernate.c3p0.testConnectionOnCheckout", "true"); // Very important to validate connections - for ITPGRFA fails if false since it's remote DB. // Database connection configuration DatabaseConfiguration dbCfg = cfg.getDatabaseConfiguration(); hc.setProperty("hibernate.connection.driver_class", dbCfg.getJDBCDriver()); hc.setProperty("hibernate.connection.url", dbCfg.getJDBCUrl()); hc.setProperty("hibernate.connection.username", dbCfg.getUser()); hc.setProperty("hibernate.connection.password", dbCfg.getPassword()); hc.setProperty("hibernate.connection.zeroDateTimeBehavior", "convertToNull"); hc.setProperty("hibernate.dialect", dbCfg.getHibernateDialect()); // Cache configuration - Second level // log.info("Secondary cache is disabled - Dynamic enabling not implemented."); // hc.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider"); /*/* ww w. j a v a 2 s . co m*/ hc.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.SingletonEhCacheProvider"); hc.setProperty("hibernate.cache.use_query_cache", "true"); hc.setProperty("hibernate.cache.use_second_level_cache", "true"); hc.setProperty("hibernate.cache.provider_configuration", "/ehcache.xml"); */ hc.setProperty("hibernate.current_session_context_class", "thread"); hc.setProperty("hibernate.show_sql", "true"); hc.setProperty("zeroDateTimeBehavior", "convertToNull"); if (cfg.isUseContacts()) { hc.addAnnotatedClass(org.informea.odata.data.db.ContactTreaty.class); hc.addAnnotatedClass(org.informea.odata.data.db.Contact.class); } if (cfg.isUseCountryProfiles()) { hc.addAnnotatedClass(org.informea.odata.data.db.CountryProfile.class); } if (cfg.isUseCountryReports()) { hc.addAnnotatedClass(org.informea.odata.data.db.CountryReport.class); hc.addAnnotatedClass(org.informea.odata.data.db.CountryReportTitle.class); } if (cfg.isUseDecisions()) { hc.addAnnotatedClass(org.informea.odata.data.db.DBDecisionDocument.class); hc.addAnnotatedClass(org.informea.odata.data.db.DecisionKeyword.class); hc.addAnnotatedClass(org.informea.odata.data.db.DecisionContent.class); hc.addAnnotatedClass(org.informea.odata.data.db.DecisionSummary.class); hc.addAnnotatedClass(org.informea.odata.data.db.DecisionLongTitle.class); hc.addAnnotatedClass(org.informea.odata.data.db.DecisionTitle.class); hc.addAnnotatedClass(org.informea.odata.data.db.Decision.class); } if (cfg.isUseMeetings()) { hc.addAnnotatedClass(org.informea.odata.data.db.MeetingDescription.class); hc.addAnnotatedClass(org.informea.odata.data.db.MeetingTitle.class); hc.addAnnotatedClass(org.informea.odata.data.db.Meeting.class); } if (cfg.isUseNationalPlans()) { hc.addAnnotatedClass(org.informea.odata.data.db.NationalPlanTitle.class); hc.addAnnotatedClass(org.informea.odata.data.db.NationalPlan.class); } if (cfg.isUseSites()) { hc.addAnnotatedClass(org.informea.odata.data.db.Site.class); hc.addAnnotatedClass(org.informea.odata.data.db.SiteName.class); } sessionFactory = hc.buildSessionFactory(); }
From source file:org.inheritsource.test.taskform.engine.TaskFormDbTestCase.java
License:Open Source License
@Before public void before() { Configuration cfg = new AnnotationConfiguration() .addAnnotatedClass(org.inheritsource.taskform.engine.persistence.entity.StartFormDefinition.class) .addAnnotatedClass(/* ww w . j ava2s. c om*/ org.inheritsource.taskform.engine.persistence.entity.ActivityFormDefinition.class) .addAnnotatedClass( org.inheritsource.taskform.engine.persistence.entity.ProcessActivityFormInstance.class) .addAnnotatedClass(org.inheritsource.taskform.engine.persistence.entity.TagType.class) .addAnnotatedClass(org.inheritsource.taskform.engine.persistence.entity.ProcessActivityTag.class) .addAnnotatedClass(org.inheritsource.taskform.engine.persistence.entity.UserEntity.class); cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); cfg.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); cfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:InheritPlatform"); cfg.setProperty("hibernate.hbm2ddl.auto", "create"); cfg.setProperty("show_sql", "true"); sessionFactory = cfg.buildSessionFactory(); HibernateUtil.setSessionFactory(sessionFactory); Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); TagType diaryTagType = new TagType(); diaryTagType.setTagTypeId(TagType.TAG_TYPE_DIARY_NO); diaryTagType.setName("diary_no"); diaryTagType.setLabel("Diarienr"); TagType applicationByTagType = new TagType(); applicationByTagType.setTagTypeId(TagType.TAG_APPLICATION_BY); applicationByTagType.setName("application_by"); applicationByTagType.setLabel("Anskan av"); TagType otherTagType = new TagType(); otherTagType.setTagTypeId(TagType.TAG_OTHER); otherTagType.setName("other"); otherTagType.setLabel("Annan"); session.save(diaryTagType); session.save(applicationByTagType); session.save(otherTagType); session.getTransaction().commit(); session.close(); ProcessActivityFormInstance pafi1 = new ProcessActivityFormInstance(); pafi1.setFormDocId("testDocId"); pafi1.setFormConnectionKey(formPath); pafi1.setUserId(userId); pafi1.setProcessInstanceUuid(processInstanceUuid1); taskFormDb.save(pafi1); ProcessActivityFormInstance pafi2 = new ProcessActivityFormInstance(); pafi2.setFormDocId("testDocId2"); pafi2.setFormConnectionKey(formPath); pafi2.setUserId(userId); pafi2.setProcessInstanceUuid(processInstanceUuid2); taskFormDb.save(pafi2); processActivityFormInstanceId1 = pafi1.getProcessActivityFormInstanceId(); processActivityFormInstanceId2 = pafi2.getProcessActivityFormInstanceId(); }