List of usage examples for org.hibernate.cfg AvailableSettings CACHE_REGION_FACTORY
String CACHE_REGION_FACTORY
To view the source code for org.hibernate.cfg AvailableSettings CACHE_REGION_FACTORY.
Click Source Link
From source file:com.corundumstudio.core.extensions.hibernate.BaseTest.java
License:Apache License
protected static void initHibernate() { Properties props = buildDatabaseConfiguration("db1"); Configuration cfg = new Configuration(); cfg.setProperty(Environment.GENERATE_STATISTICS, "true"); cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "create"); cfg.setProperty(AvailableSettings.CACHE_REGION_FACTORY, InfinispanRegionFactory.class.getName()); cfg.setProperty(InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP, "infinispan.xml"); cfg.setProperty(AvailableSettings.QUERY_CACHE_FACTORY, DynamicQueryCacheFactory.class.getName()); cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true"); cfg.setProperty(Environment.USE_QUERY_CACHE, "true"); cfg.addAnnotatedClass(SimpleEntity.class); cfg.buildMappings();/*from ww w. ja va 2 s .co m*/ ServiceRegistryBuilder sb = new ServiceRegistryBuilder(); ServiceRegistry serviceRegistry = sb.applySettings(props).buildServiceRegistry(); sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry); EventListenerRegistry registry = sessionFactory.getServiceRegistry() .getService(EventListenerRegistry.class); registry.getEventListenerGroup(EventType.POST_UPDATE).appendListener(queryCacheEntityListener); registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(queryCacheEntityListener); registry.getEventListenerGroup(EventType.POST_DELETE).appendListener(queryCacheEntityListener); }
From source file:com.github.javarch.persistence.orm.hibernate.conf.HibernatePropertiesConfig.java
License:Apache License
/** * Retorna um objeto Properties com todas as configuraes de propriedades que devem * ser passadas ao {@link SessionFactory}. As propriedades so definidas no arquivo * hibernate.properties que deve estar presente no raiz do classpath. * //www. j a v a 2s. c om * @return Properties do Hibernate. */ @Bean public Properties hibernateProperties() { Properties props = new Properties(); props.put(AvailableSettings.DIALECT, env.getRequiredProperty(AvailableSettings.DIALECT)); if (env.acceptsProfiles(Profiles.TEST)) { props.put(AvailableSettings.HBM2DDL_AUTO, env.getProperty(AvailableSettings.HBM2DDL_AUTO, "update")); } if (env.acceptsProfiles(Profiles.MULT_TENANT)) { if (log.isDebugEnabled()) { log.debug("Profile Multi Tenancy ativado! Realizando configurao..."); } if (currentIdentifierResolver == null || env.acceptsProfiles(Profiles.PRODUCTION)) { throw new DatabaseConfigurationException( "No foi encontrado nenhum objeto CurrentIdentifierResolver."); } props.put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentIdentifierResolver); props.put(AvailableSettings.DATASOURCE, env.getRequiredProperty(AvailableSettings.DATASOURCE)); props.put(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider); props.put(AvailableSettings.MULTI_TENANT, env.getRequiredProperty(AvailableSettings.MULTI_TENANT)); } else { props.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, true); props.put(AvailableSettings.USE_QUERY_CACHE, true); props.put(AvailableSettings.CACHE_REGION_FACTORY, "org.hibernate.cache.ehcache.EhCacheRegionFactory"); } if (env.acceptsProfiles(Profiles.ENVERS)) { props.put("org.hibernate.envers.versionsTableSuffix", "_audit"); props.put("org.hibernate.envers.revisionFieldName", "revision"); props.put("org.hibernate.envers.default_schema", "audit"); } return props; }
From source file:org.infinispan.test.hibernate.cache.AbstractGeneralDataRegionTest.java
License:LGPL
protected void withSessionFactoriesAndRegions(int num, SFRConsumer consumer) throws Exception { StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder() .applySetting(AvailableSettings.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName()); Properties properties = CacheTestUtil.toProperties(ssrb.getSettings()); List<StandardServiceRegistry> registries = new ArrayList<>(); List<SessionFactory> sessionFactories = new ArrayList<>(); List<GeneralDataRegion> regions = new ArrayList<>(); for (int i = 0; i < num; ++i) { StandardServiceRegistry registry = ssrb.build(); registries.add(registry);//from w w w .j a va2s. c om SessionFactory sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); sessionFactories.add(sessionFactory); InfinispanRegionFactory regionFactory = (InfinispanRegionFactory) registry .getService(RegionFactory.class); GeneralDataRegion region = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), properties, null); 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.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 www. ja va 2 s . c o m 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 ww w .j a va 2 s .c o m try { RegionFactory regionFactory = ssr.getService(RegionFactory.class); assertTyping(JndiInfinispanRegionFactory.class, regionFactory); } finally { StandardServiceRegistryBuilder.destroy(ssr); } }
From source file:org.infinispan.test.hibernate.cache.commons.util.CacheTestUtil.java
License:LGPL
@SuppressWarnings("unchecked") public static Map buildBaselineSettings(String regionPrefix, boolean use2ndLevel, boolean useQueries, Class<? extends JtaPlatform> jtaPlatform) { Map settings = new HashMap(); settings.put(AvailableSettings.GENERATE_STATISTICS, "true"); settings.put(AvailableSettings.USE_STRUCTURED_CACHE, "true"); if (jtaPlatform == null || jtaPlatform == NoJtaPlatform.class) { settings.put(Environment.TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class.getName()); settings.put(AvailableSettings.JTA_PLATFORM, NoJtaPlatform.class); } else {// w w w . j a va 2s .com settings.put(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()); settings.put(AvailableSettings.JTA_PLATFORM, jtaPlatform); } settings.put(AvailableSettings.CACHE_REGION_FACTORY, TestRegionFactoryProvider.load().getRegionFactoryClass()); settings.put(AvailableSettings.CACHE_REGION_PREFIX, regionPrefix); settings.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, String.valueOf(use2ndLevel)); settings.put(AvailableSettings.USE_QUERY_CACHE, String.valueOf(useQueries)); return settings; }
From source file:org.infinispan.test.hibernate.cache.util.CacheTestUtil.java
License:LGPL
@SuppressWarnings("unchecked") public static Map buildBaselineSettings(String regionPrefix, Class regionFactory, boolean use2ndLevel, boolean useQueries, Class<? extends JtaPlatform> jtaPlatform) { Map settings = new HashMap(); settings.put(AvailableSettings.GENERATE_STATISTICS, "true"); settings.put(AvailableSettings.USE_STRUCTURED_CACHE, "true"); if (jtaPlatform == null) { settings.put(Environment.TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class.getName()); } else {/* w w w . j a v a 2 s . co m*/ settings.put(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()); settings.put(AvailableSettings.JTA_PLATFORM, jtaPlatform); } settings.put(AvailableSettings.CACHE_REGION_FACTORY, regionFactory.getName()); settings.put(AvailableSettings.CACHE_REGION_PREFIX, regionPrefix); settings.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, String.valueOf(use2ndLevel)); settings.put(AvailableSettings.USE_QUERY_CACHE, String.valueOf(useQueries)); return settings; }
From source file:org.infinispan.test.hibernate.cache.util.CacheTestUtil.java
License:LGPL
public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry) { try {// ww w. j av a 2 s .c om final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class); final Properties properties = toProperties(cfgService.getSettings()); String factoryType = cfgService.getSetting(AvailableSettings.CACHE_REGION_FACTORY, StandardConverters.STRING); Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryType); InfinispanRegionFactory regionFactory; if (clazz == InfinispanRegionFactory.class) { regionFactory = new TestInfinispanRegionFactory(properties); } else { if (InfinispanRegionFactory.class.isAssignableFrom(clazz)) { regionFactory = createRegionFactory(clazz, properties); } else { throw new IllegalArgumentException(clazz + " is not InfinispanRegionFactory"); } } final SessionFactoryOptionsImpl sessionFactoryOptions = new SessionFactoryOptionsImpl( new SessionFactoryBuilderImpl.SessionFactoryOptionsStateStandardImpl( (StandardServiceRegistry) serviceRegistry)); regionFactory.start(sessionFactoryOptions, properties); return regionFactory; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.jboss.as.jpa.hibernate4.HibernateSecondLevelCache.java
License:Open Source License
public static void addSecondLevelCacheDependencies(Properties mutableProperties, String scopedPersistenceUnitName) { if (mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX) == null) { // cache entries for this PU will be identified by scoped pu name + Entity class name if (scopedPersistenceUnitName != null) { mutableProperties.setProperty(AvailableSettings.CACHE_REGION_PREFIX, scopedPersistenceUnitName); }//from w w w .j a va 2s .co m } String regionFactory = mutableProperties.getProperty(AvailableSettings.CACHE_REGION_FACTORY); if (regionFactory == null) { regionFactory = DEFAULT_REGION_FACTORY; mutableProperties.setProperty(AvailableSettings.CACHE_REGION_FACTORY, regionFactory); } if (regionFactory.equals(DEFAULT_REGION_FACTORY)) { // Set infinispan defaults String container = mutableProperties.getProperty(InfinispanRegionFactory.CACHE_CONTAINER); if (container == null) { container = InfinispanRegionFactory.DEFAULT_CACHE_CONTAINER; mutableProperties.setProperty(InfinispanRegionFactory.CACHE_CONTAINER, container); } /** * AS will need the ServiceBuilder<?> builder that used to be passed to PersistenceProviderAdaptor.addProviderDependencies */ Properties cacheSettings = new Properties(); cacheSettings.put(CONTAINER, container); cacheSettings.put(ENTITY, mutableProperties.getProperty(InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_ENTITY_RESOURCE)); cacheSettings.put(COLLECTION, mutableProperties.getProperty(InfinispanRegionFactory.COLLECTION_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_ENTITY_RESOURCE)); cacheSettings.put(NATURAL_ID, mutableProperties.getProperty(InfinispanRegionFactory.NATURAL_ID_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_ENTITY_RESOURCE)); if (Boolean.parseBoolean(mutableProperties.getProperty(AvailableSettings.USE_QUERY_CACHE))) { cacheSettings.put(QUERY, mutableProperties.getProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_QUERY_RESOURCE)); cacheSettings.put(TIMESTAMPS, mutableProperties.getProperty(InfinispanRegionFactory.TIMESTAMPS_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_QUERY_RESOURCE)); } Notification.addCacheDependencies(Classification.INFINISPAN, cacheSettings); } }
From source file:org.jboss.as.jpa.hibernate5.HibernateSecondLevelCache.java
License:Apache License
public static void addSecondLevelCacheDependencies(Properties mutableProperties, String scopedPersistenceUnitName) { if (mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX) == null) { // cache entries for this PU will be identified by scoped pu name + Entity class name if (scopedPersistenceUnitName != null) { mutableProperties.setProperty(AvailableSettings.CACHE_REGION_PREFIX, scopedPersistenceUnitName); }/*from w w w .j a v a 2 s. c o m*/ } String regionFactory = mutableProperties.getProperty(AvailableSettings.CACHE_REGION_FACTORY); if (regionFactory == null) { regionFactory = DEFAULT_REGION_FACTORY; mutableProperties.setProperty(AvailableSettings.CACHE_REGION_FACTORY, regionFactory); } if (regionFactory.equals(DEFAULT_REGION_FACTORY)) { // Set infinispan defaults String container = mutableProperties.getProperty(InfinispanRegionFactory.CACHE_CONTAINER); if (container == null) { container = InfinispanRegionFactory.DEFAULT_CACHE_CONTAINER; mutableProperties.setProperty(InfinispanRegionFactory.CACHE_CONTAINER, container); } /** * AS will need the ServiceBuilder<?> builder that used to be passed to PersistenceProviderAdaptor.addProviderDependencies */ Properties cacheSettings = new Properties(); cacheSettings.put(CONTAINER, container); cacheSettings.put(ENTITY, mutableProperties.getProperty(InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_ENTITY_RESOURCE)); cacheSettings.put(IMMUTABLE_ENTITY, mutableProperties.getProperty(InfinispanRegionFactory.IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_ENTITY_RESOURCE)); cacheSettings.put(COLLECTION, mutableProperties.getProperty(InfinispanRegionFactory.COLLECTION_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_ENTITY_RESOURCE)); cacheSettings.put(NATURAL_ID, mutableProperties.getProperty(InfinispanRegionFactory.NATURAL_ID_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_ENTITY_RESOURCE)); if (mutableProperties.getProperty(PENDING_PUTS_CACHE_RESOURCE_PROP) != null) { cacheSettings.put(PENDING_PUTS, mutableProperties.getProperty(PENDING_PUTS_CACHE_RESOURCE_PROP)); } if (Boolean.parseBoolean(mutableProperties.getProperty(AvailableSettings.USE_QUERY_CACHE))) { cacheSettings.put(QUERY, mutableProperties.getProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_QUERY_RESOURCE)); cacheSettings.put(TIMESTAMPS, mutableProperties.getProperty(InfinispanRegionFactory.TIMESTAMPS_CACHE_RESOURCE_PROP, InfinispanRegionFactory.DEF_QUERY_RESOURCE)); } Notification.addCacheDependencies(Classification.INFINISPAN, cacheSettings); } }