List of usage examples for org.hibernate.boot.registry StandardServiceRegistryBuilder destroy
public static void destroy(ServiceRegistry serviceRegistry)
From source file:org.infinispan.test.hibernate.cache.commons.AbstractGeneralDataRegionTest.java
License:LGPL
protected void withSessionFactoriesAndRegions(int num, SFRConsumer consumer) throws Exception { StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder().applySetting( AvailableSettings.CACHE_REGION_FACTORY, TestRegionFactoryProvider.load().getRegionFactoryClass().getName()); Properties properties = CacheTestUtil.toProperties(ssrb.getSettings()); List<StandardServiceRegistry> registries = new ArrayList<>(); List<SessionFactory> sessionFactories = new ArrayList<>(); List<InfinispanBaseRegion> regions = new ArrayList<>(); for (int i = 0; i < num; ++i) { StandardServiceRegistry registry = ssrb.build(); registries.add(registry);//from ww w .j a v a 2s . com SessionFactory sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); sessionFactories.add(sessionFactory); TestRegionFactory regionFactory = TestRegionFactoryProvider.load() .wrap(registry.getService(RegionFactory.class)); InfinispanBaseRegion region = createRegion(regionFactory, REGION_PREFIX + "/who-cares"); regions.add(region); } waitForClusterToForm(regions); try { consumer.accept(sessionFactories, regions); } finally { for (SessionFactory sessionFactory : sessionFactories) { sessionFactory.close(); } for (StandardServiceRegistry registry : registries) { StandardServiceRegistryBuilder.destroy(registry); } } }
From source file:org.infinispan.test.hibernate.cache.commons.JndiInfinispanRegionFactoryTestCase.java
License:LGPL
@Test public void testConstruction() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting(AvailableSettings.CACHE_REGION_FACTORY, JndiInfinispanRegionFactory.class.getName()) .build();//from w w w. j a v a2 s .c om try { RegionFactory regionFactory = ssr.getService(RegionFactory.class); assertTyping(JndiInfinispanRegionFactory.class, regionFactory); } finally { StandardServiceRegistryBuilder.destroy(ssr); } }
From source file:org.infinispan.test.hibernate.cache.commons.NodeEnvironment.java
License:LGPL
public void release() throws Exception { try {// ww w . j av a2 s . c o m if (entityRegionMap != null) { for (InfinispanBaseRegion region : entityRegionMap.values()) { try { region.getCache().stop(); } catch (Exception e) { // Ignore... } } entityRegionMap.clear(); } if (collectionRegionMap != null) { for (InfinispanBaseRegion reg : collectionRegionMap.values()) { try { reg.getCache().stop(); } catch (Exception e) { // Ignore... } } collectionRegionMap.clear(); } } finally { try { if (regionFactory != null) { // Currently the RegionFactory is shutdown by its registration // with the CacheTestSetup from CacheTestUtil when built regionFactory.stop(); } } finally { if (serviceRegistry != null) { StandardServiceRegistryBuilder.destroy(serviceRegistry); } } } }
From source file:org.infinispan.test.hibernate.cache.commons.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 {//from www . java 2s .c om final Properties properties = CacheTestUtil.toProperties(ssrb.getSettings()); TestRegionFactory regionFactory = CacheTestUtil.startRegionFactory(registry, getCacheTestSupport()); TestRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(registry2, getCacheTestSupport()); InfinispanBaseRegion region = regionFactory.buildTimestampsRegion(REGION_PREFIX + "/timestamps"); InfinispanBaseRegion region2 = regionFactory2.buildTimestampsRegion(REGION_PREFIX + "/timestamps"); 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.NodeEnvironment.java
License:LGPL
public void release() throws Exception { try {/*from w w w .j av a 2 s. c o m*/ if (entityRegionMap != null) { for (EntityRegionImpl region : entityRegionMap.values()) { try { region.getCache().stop(); } catch (Exception e) { // Ignore... } } entityRegionMap.clear(); } if (collectionRegionMap != null) { for (CollectionRegionImpl reg : collectionRegionMap.values()) { try { reg.getCache().stop(); } catch (Exception e) { // Ignore... } } collectionRegionMap.clear(); } } finally { try { if (regionFactory != null) { // Currently the RegionFactory is shutdown by its registration // with the CacheTestSetup from CacheTestUtil when built regionFactory.stop(); } } finally { if (serviceRegistry != null) { StandardServiceRegistryBuilder.destroy(serviceRegistry); } } } }
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 {//from w w w. j a v a 2s .c o m 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.kitodo.data.database.persistence.HibernateUtil.java
License:Open Source License
/** * Destroy session./*from ww w .ja v a 2 s . c o m*/ */ private static void shutdown() { if (Objects.nonNull(registry)) { StandardServiceRegistryBuilder.destroy(registry); } }
From source file:org.osbo.framework.core.persist.Persistence.java
public void shutDown() { try {/* w w w . j a va 2 s .c om*/ sessionFactory.close(); StandardServiceRegistryBuilder.destroy(sessionFactory.getSessionFactoryOptions().getServiceRegistry()); } catch (Throwable t) { System.err.println("Exception while closing session factory: " + t); } }
From source file:poo.cine.controller.Main.java
public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build();//from w ww .j a va2 s . c o m try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } new GestorPelicula(sessionFactory).run(); }
From source file:poo.consultorio.controller.Main.java
/** * @param args the command line arguments *//* w w w.ja va2s .co m*/ public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build(); try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } // creamos los objetos de DAO OdontologosDao odontologosDao = new OdontologosDaoHibernateImpl(sessionFactory); EstadosDao estadosDao = new EstadosDaoHibernateImpl(sessionFactory); // iniciamos el caso de uso new GestorDeAgenda(odontologosDao, estadosDao).run(); }