/** * Used to inject a datasource object as the connection provider. * If used, be sure to <b>not override</b> the hibernate.connection.provider_class * property */ @SuppressWarnings({ "JavaDoc", "unchecked" }) public void setDataSource(DataSource ds) { if ( ds != null ) { cfg.getProperties().put( Environment.DATASOURCE, ds ); this.setProperty( Environment.CONNECTION_PROVIDER, DatasourceConnectionProviderImpl.class.getName() ); } }
/** * Used to inject a datasource object as the connection provider. * If used, be sure to <b>not override</b> the hibernate.connection.provider_class * property */ public void setDataSource(DataSource ds) { if ( ds != null ) { Map cpInjection = new HashMap(); cpInjection.put( "dataSource", ds ); ( (InjectionSettingsFactory) settingsFactory ).setConnectionProviderInjectionData( cpInjection ); this.setProperty( Environment.CONNECTION_PROVIDER, InjectedDataSourceConnectionProvider.class.getName() ); } }
@BeforeClass public static void beforeAll() throws Exception { // Connect to the database ... Ejb3Configuration configurator = new Ejb3Configuration(); configurator.addAnnotatedClass(StoreOptionEntity.class); configurator.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); configurator.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); configurator.setProperty("hibernate.connection.username", "sa"); configurator.setProperty("hibernate.connection.password", ""); configurator.setProperty("hibernate.connection.url", "jdbc:hsqldb:."); configurator.setProperty("hibernate.show_sql", "false"); configurator.setProperty("hibernate.format_sql", "true"); configurator.setProperty("hibernate.use_sql_comments", "true"); configurator.setProperty("hibernate.hbm2ddl.auto", "create"); factory = configurator.buildEntityManagerFactory(); manager = factory.createEntityManager(); }
private void addSecurity(List<String> keys, Map properties, Map workingVars) { log.debug( "Adding security" ); if ( !properties.containsKey( HibernatePersistence.JACC_CONTEXT_ID ) ) { throw new PersistenceException( getExceptionHeader() + "Entities have been configured for JACC, but " + HibernatePersistence.JACC_CONTEXT_ID + " has not been set" ); } String contextId = (String) properties.get( HibernatePersistence.JACC_CONTEXT_ID ); setProperty( Environment.JACC_CONTEXTID, contextId ); int roleStart = HibernatePersistence.JACC_PREFIX.length() + 1; for ( String key : keys ) { JACCConfiguration jaccCfg = new JACCConfiguration( contextId ); try { String role = key.substring( roleStart, key.indexOf( '.', roleStart ) ); int classStart = roleStart + role.length() + 1; String clazz = key.substring( classStart, key.length() ); String actions = (String) properties.get( key ); jaccCfg.addPermission( role, clazz, actions ); } catch (IndexOutOfBoundsException e) { throw new PersistenceException( getExceptionHeader() + "Illegal usage of " + HibernatePersistence.JACC_PREFIX + ": " + key ); } } }
@Before public void beforeEach() throws Exception { model = new SimpleModel(); // Connect to the database ... Ejb3Configuration configurator = new Ejb3Configuration(); for (Class<?> clazz : model.getEntityClasses()) { configurator.addAnnotatedClass(clazz); } configurator.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); configurator.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); configurator.setProperty("hibernate.connection.username", "sa"); configurator.setProperty("hibernate.connection.password", ""); configurator.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:."); configurator.setProperty("hibernate.show_sql", SHOW_SQL.toString()); configurator.setProperty("hibernate.format_sql", "true"); configurator.setProperty("hibernate.use_sql_comments", "true"); configurator.setProperty("hibernate.hbm2ddl.auto", "create"); if (USE_CACHE) { configurator.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider"); } else { configurator.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false"); } factory = configurator.buildEntityManagerFactory(); manager = factory.createEntityManager(); }
private void addSecurity(List<String> keys, Map properties, Map workingVars) { LOG.debugf("Adding security"); if ( !properties.containsKey( AvailableSettings.JACC_CONTEXT_ID ) ) { throw new PersistenceException( getExceptionHeader() + "Entities have been configured for JACC, but " + AvailableSettings.JACC_CONTEXT_ID + " has not been set" ); } String contextId = (String) properties.get( AvailableSettings.JACC_CONTEXT_ID ); setProperty( Environment.JACC_CONTEXTID, contextId ); int roleStart = AvailableSettings.JACC_PREFIX.length() + 1; for ( String key : keys ) { JACCConfiguration jaccCfg = new JACCConfiguration( contextId ); try { String role = key.substring( roleStart, key.indexOf( '.', roleStart ) ); int classStart = roleStart + role.length() + 1; String clazz = key.substring( classStart, key.length() ); String actions = (String) properties.get( key ); jaccCfg.addPermission( role, clazz, actions ); } catch (IndexOutOfBoundsException e) { throw new PersistenceException( getExceptionHeader() + "Illegal usage of " + AvailableSettings.JACC_PREFIX + ": " + key ); } } }
protected EntityManager startEntityManager() { if (manager == null) { // Set the connection properties using the environment defined in the POM files ... JpaSource source = TestEnvironment.configureJpaSource("Test Repository", this); // Connect to the database ... Ejb3Configuration configurator = new Ejb3Configuration(); for (Class<?> clazz : model.getEntityClasses()) { configurator.addAnnotatedClass(clazz); } configurator.setProperty("hibernate.dialect", source.getDialect()); configurator.setProperty("hibernate.connection.driver_class", source.getDriverClassName()); configurator.setProperty("hibernate.connection.username", source.getUsername()); configurator.setProperty("hibernate.connection.password", source.getPassword()); configurator.setProperty("hibernate.connection.url", source.getUrl()); configurator.setProperty("hibernate.show_sql", "false"); configurator.setProperty("hibernate.format_sql", "true"); configurator.setProperty("hibernate.use_sql_comments", "true"); configurator.setProperty("hibernate.hbm2ddl.auto", "create"); configurator.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false"); factory = configurator.buildEntityManagerFactory(); manager = factory.createEntityManager(); } return manager; }
this.setProperty( Environment.DATASOURCE, metadata.getJtaDatasource() ); this.setProperty( Environment.DATASOURCE, metadata.getNonJtaDatasource() );
this.setProperty( Environment.DATASOURCE, metadata.getJtaDatasource() ); this.setProperty( Environment.DATASOURCE, metadata.getNonJtaDatasource() ); this.setProperty( Environment.DRIVER, driver ); this.setProperty( Environment.URL, url ); this.setProperty( Environment.USER, user ); this.setProperty( Environment.PASS, pass );
isJTA ? info.getJtaDataSource() : info.getNonJtaDataSource() ); this.setProperty( Environment.CONNECTION_PROVIDER, InjectedDataSourceConnectionProvider.class.getName() );
isJTA ? info.getJtaDataSource() : info.getNonJtaDataSource() ); this.setProperty( Environment.CONNECTION_PROVIDER, InjectedDataSourceConnectionProvider.class.getName() );