List of usage examples for org.hibernate.boot.registry StandardServiceRegistryBuilder build
@SuppressWarnings("unchecked") public StandardServiceRegistry build()
From source file:org.infinispan.test.hibernate.cache.commons.tm.JBossStandaloneJtaExampleTest.java
License:LGPL
private SessionFactory buildSessionFactory() { // Extra options located in src/test/resources/hibernate.properties StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySetting(Environment.DIALECT, "HSQL").applySetting(Environment.HBM2DDL_AUTO, "create-drop") .applySetting(Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName()) .applySetting(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory") .applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()) .applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta") .applySetting(Environment.RELEASE_CONNECTIONS, "auto") .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") .applySetting(Environment.JTA_PLATFORM, new NarayanaStandaloneJtaPlatform()) .applySetting(Environment.CACHE_REGION_FACTORY, TestRegionFactoryProvider.load().getRegionFactoryClass().getName()); StandardServiceRegistry serviceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(serviceRegistry); metadataSources.addResource("org/infinispan/test/hibernate/cache/commons/functional/entities/Item.hbm.xml"); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (entityBinding instanceof RootClass) { RootClass rootClass = (RootClass) entityBinding; rootClass.setCacheConcurrencyStrategy("transactional"); rootClass.setCachingExplicitlyRequested(true); }//w ww . ja v a2 s . com } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy("transactional"); } return metadata.buildSessionFactory(); }
From source file:org.infinispan.test.hibernate.cache.stress.CorrectnessTestCase.java
License:LGPL
@BeforeClassOnce public void beforeClass() { TestResourceTracker.testStarted(getClass().getSimpleName()); Arrays.asList(new File(System.getProperty("java.io.tmpdir")) .listFiles((dir, name) -> name.startsWith("family_") || name.startsWith("invalidations-"))).stream() .forEach(f -> f.delete()); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().enableAutoClose() .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.DRIVER, "org.h2.Driver") .applySetting(Environment.URL, "jdbc:h2:mem:" + getDbName() + ";TRACE_LEVEL_FILE=4") .applySetting(Environment.DIALECT, H2Dialect.class.getName()) .applySetting(Environment.HBM2DDL_AUTO, "create-drop") .applySetting(Environment.CACHE_REGION_FACTORY, FailingInfinispanRegionFactory.class.getName()) .applySetting(TestInfinispanRegionFactory.CACHE_MODE, cacheMode) .applySetting(Environment.USE_MINIMAL_PUTS, "false") .applySetting(Environment.GENERATE_STATISTICS, "false"); applySettings(ssrb);/* www . j a v a2 s . c om*/ sessionFactories = new SessionFactory[NUM_NODES]; for (int i = 0; i < NUM_NODES; ++i) { StandardServiceRegistry registry = ssrb.build(); Metadata metadata = buildMetadata(registry); sessionFactories[i] = metadata.buildSessionFactory(); } }
From source file:org.infinispan.test.hibernate.cache.stress.PutFromLoadStressTestCase.java
License:LGPL
@BeforeClass public static void beforeClass() { // Extra options located in src/test/resources/hibernate.properties StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") // TODO: Tweak to have a fully local region factory (no transport, cache mode = local, no marshalling, ...etc) .applySetting(Environment.CACHE_REGION_FACTORY, "org.infinispan.hibernate.cache.InfinispanRegionFactory") .applySetting(Environment.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform") // Force minimal puts off to simplify stressing putFromLoad logic .applySetting(Environment.USE_MINIMAL_PUTS, "false") .applySetting(Environment.HBM2DDL_AUTO, "create-drop"); StandardServiceRegistry serviceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(serviceRegistry) .addResource("cache/infinispan/functional/Item.hbm.xml") .addResource("cache/infinispan/functional/Customer.hbm.xml") .addResource("cache/infinispan/functional/Contact.hbm.xml").addAnnotatedClass(Age.class); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (entityBinding instanceof RootClass) { ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional"); }//from w w w. j a v a 2 s. c o m } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy("transactional"); } sessionFactory = metadata.buildSessionFactory(); tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); }
From source file:org.infinispan.test.hibernate.cache.stress.SecondLevelCacheStressTestCase.java
License:LGPL
@Before public void beforeClass() { provider = getProvider();/* w ww. j a v a 2s . c o m*/ updatedIds = new ConcurrentHashSet<Integer>(); removeIds = new ConcurrentLinkedQueue<Integer>(); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().enableAutoClose() .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") .applySetting(Environment.DRIVER, "com.mysql.jdbc.Driver") .applySetting(Environment.URL, "jdbc:mysql://localhost:3306/hibernate") .applySetting(Environment.DIALECT, "org.hibernate.dialect.MySQL5InnoDBDialect") .applySetting(Environment.USER, "root").applySetting(Environment.PASS, "password") .applySetting(Environment.HBM2DDL_AUTO, "create-drop"); // Create database schema in each run applyCacheSettings(ssrb); StandardServiceRegistry registry = ssrb.build(); Metadata metadata = buildMetadata(registry); sessionFactory = metadata.buildSessionFactory(); tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); }
From source file:org.infinispan.test.hibernate.cache.timestamp.TimestampsRegionImplTest.java
License:LGPL
@Test public void testClearTimestampsRegionInIsolated() throws Exception { StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder(); final StandardServiceRegistry registry = ssrb.build(); final StandardServiceRegistry registry2 = ssrb.build(); try {/* w w w .j a v a 2 s .c om*/ final Properties properties = CacheTestUtil.toProperties(ssrb.getSettings()); InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(registry, getCacheTestSupport()); InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(registry2, getCacheTestSupport()); TimestampsRegionImpl region = (TimestampsRegionImpl) regionFactory .buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties); TimestampsRegionImpl region2 = (TimestampsRegionImpl) regionFactory2 .buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties); Account acct = new Account(); acct.setAccountHolder(new AccountHolder()); region.getCache().withFlags(Flag.FORCE_SYNCHRONOUS).put(acct, "boo"); } finally { StandardServiceRegistryBuilder.destroy(registry); StandardServiceRegistryBuilder.destroy(registry2); } }
From source file:org.infinispan.test.hibernate.cache.tm.JBossStandaloneJtaExampleTest.java
License:LGPL
private SessionFactory buildSessionFactory() { // Extra options located in src/test/resources/hibernate.properties StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySetting(Environment.DIALECT, "HSQL").applySetting(Environment.HBM2DDL_AUTO, "create-drop") .applySetting(Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName()) .applySetting(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory") .applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()) .applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta") .applySetting(Environment.RELEASE_CONNECTIONS, "auto") .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") .applySetting(Environment.JTA_PLATFORM, new JBossStandAloneJtaPlatform()) .applySetting(Environment.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName()); StandardServiceRegistry serviceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(serviceRegistry); metadataSources.addResource("org/infinispan/test/hibernate/cache/functional/entities/Item.hbm.xml"); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (entityBinding instanceof RootClass) { ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional"); }/*w ww. j a v a 2 s . c o m*/ } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy("transactional"); } return metadata.buildSessionFactory(); }
From source file:org.jboss.as.test.integration.hibernate.SFSBHibernatewithCriteriaSession.java
License:Open Source License
public void setupConfig() { // static {/*from w w w .ja v a 2 s .co m*/ try { // prepare the configuration Configuration configuration = new Configuration() .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class); configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS"); configuration.setProperty("hibernate.listeners.envers.autoRegister", "false"); // fetch the properties Properties properties = new Properties(); configuration = configuration.configure("hibernate.cfg.xml"); properties.putAll(configuration.getProperties()); Environment.verifyProperties(properties); ConfigurationHelper.resolvePlaceHolders(properties); // build the serviceregistry StandardServiceRegistryBuilder registry = new StandardServiceRegistryBuilder() .applySettings(properties); sessionFactory = configuration.buildSessionFactory(registry.build()); // build metamodel SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory; MetamodelImpl.buildMetamodel(configuration.getClassMappings(), sfi); sessionFactory.getStatistics().setStatisticsEnabled(true); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); // ex.printStackTrace(); throw new ExceptionInInitializerError(ex); } }
From source file:org.jboss.as.test.integration.hibernate.SFSBHibernatewithMetaDataSession.java
License:Open Source License
public void setupConfig() { // static {//from ww w . j a va 2 s .c o m try { // prepare the configuration Configuration configuration = new Configuration() .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS"); configuration.setProperty("hibernate.listeners.envers.autoRegister", "false"); // fetch the properties Properties properties = new Properties(); configuration = configuration.configure("hibernate.cfg.xml"); properties.putAll(configuration.getProperties()); Environment.verifyProperties(properties); ConfigurationHelper.resolvePlaceHolders(properties); StandardServiceRegistryBuilder registry = new StandardServiceRegistryBuilder() .applySettings(properties); sessionFactory = configuration.buildSessionFactory(registry.build()); // build metamodel SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory; MetamodelImpl.buildMetamodel(configuration.getClassMappings(), sfi); sessionFactory.getStatistics().setStatisticsEnabled(true); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); // ex.printStackTrace(); throw new ExceptionInInitializerError(ex); } }
From source file:org.lncc.martin.ct.dao.hibernate.HibernateUtil.java
License:Open Source License
public Session getConnection() { try {/*from w w w . j a v a2 s . c om*/ Configuration cfg = new Configuration().configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder(); sb.applySettings(cfg.getProperties()); StandardServiceRegistry standardServiceRegistry = sb.build(); sessionFactory = cfg.buildSessionFactory(standardServiceRegistry); return sessionFactory.openSession(); } catch (Exception e) { System.out.println("Problemas ao criar Session Factory: " + e); return null; } }
From source file:org.semtix.db.hibernate.HibernateUtil.java
License:Open Source License
private static SessionFactory buildSessionFactory() { Configuration configuration;/*w w w . ja v a 2 s .c o m*/ try { String path = SettingsExternal.HIBERNATE_CONF_XML; if (path.trim().length() <= 1) { configuration = new Configuration().configure(); } else { // Create the SessionFactory from hibernate.cfg.xml configuration = new Configuration().configure(new File(path)); } } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed configuration = new Configuration().configure(); } StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); return configuration.buildSessionFactory(builder.build()); }