use of org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_ENTITY_RESOURCE in project wildfly by wildfly.
the class HibernateSecondLevelCache method addSecondLevelCacheDependencies.
public static void addSecondLevelCacheDependencies(Properties mutableProperties, String scopedPersistenceUnitName) {
if (mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX) == null) {
if (scopedPersistenceUnitName != null) {
mutableProperties.setProperty(AvailableSettings.CACHE_REGION_PREFIX, scopedPersistenceUnitName);
}
}
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(CACHE_CONTAINER);
if (container == null) {
container = DEFAULT_CACHE_CONTAINER;
mutableProperties.setProperty(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(ENTITY_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
cacheSettings.put(IMMUTABLE_ENTITY, mutableProperties.getProperty(IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
cacheSettings.put(COLLECTION, mutableProperties.getProperty(COLLECTION_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
cacheSettings.put(NATURAL_ID, mutableProperties.getProperty(NATURAL_ID_CACHE_RESOURCE_PROP, 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(QUERY_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
cacheSettings.put(TIMESTAMPS, mutableProperties.getProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
}
// Collect distinct cache configurations for standard regions
Set<String> standardRegionConfigs = Stream.of(ENTITY, IMMUTABLE_ENTITY, COLLECTION, NATURAL_ID, PENDING_PUTS, QUERY, TIMESTAMPS).map(region -> cacheSettings.getProperty(region)).filter(Objects::nonNull).collect(Collectors.toSet());
int length = INFINISPAN_CONFIG_RESOURCE_PROP.length();
String customRegionPrefix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(0, length - 3) + mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX, "");
String customRegionSuffix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(length - 4, length);
// Collect distinct cache configurations for custom regions
Set<String> customRegionConfigs = mutableProperties.stringPropertyNames().stream().filter(name -> name.startsWith(customRegionPrefix) && name.endsWith(customRegionSuffix)).map(name -> mutableProperties.getProperty(name)).filter(config -> !standardRegionConfigs.contains(config)).collect(Collectors.toSet());
if (!customRegionConfigs.isEmpty()) {
cacheSettings.setProperty(CUSTOM, String.join(" ", customRegionConfigs));
}
Notification.addCacheDependencies(Classification.INFINISPAN, cacheSettings);
}
}
use of org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_ENTITY_RESOURCE in project wildfly by wildfly.
the class HibernateSecondLevelCache method addSecondLevelCacheDependencies.
public static void addSecondLevelCacheDependencies(Properties mutableProperties, String scopedPersistenceUnitName) {
if (mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX) == null) {
if (scopedPersistenceUnitName != null) {
mutableProperties.setProperty(AvailableSettings.CACHE_REGION_PREFIX, scopedPersistenceUnitName);
}
}
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(CACHE_CONTAINER);
if (container == null) {
container = DEFAULT_CACHE_CONTAINER;
mutableProperties.setProperty(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(ENTITY_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
cacheSettings.put(COLLECTION, mutableProperties.getProperty(COLLECTION_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
cacheSettings.put(NATURAL_ID, mutableProperties.getProperty(NATURAL_ID_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
if (Boolean.parseBoolean(mutableProperties.getProperty(AvailableSettings.USE_QUERY_CACHE))) {
cacheSettings.put(QUERY, mutableProperties.getProperty(QUERY_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
cacheSettings.put(TIMESTAMPS, mutableProperties.getProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
}
// Collect distinct cache configurations for standard regions
Set<String> standardRegionConfigs = Stream.of(ENTITY, COLLECTION, NATURAL_ID, QUERY, TIMESTAMPS).map(region -> cacheSettings.getProperty(region)).filter(Objects::nonNull).collect(Collectors.toSet());
int length = INFINISPAN_CONFIG_RESOURCE_PROP.length();
String customRegionPrefix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(0, length - 3) + mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX, "");
String customRegionSuffix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(length - 4, length);
// Collect distinct cache configurations for custom regions
Set<String> customRegionConfigs = mutableProperties.stringPropertyNames().stream().filter(name -> name.startsWith(customRegionPrefix) && name.endsWith(customRegionSuffix)).map(name -> mutableProperties.getProperty(name)).filter(config -> !standardRegionConfigs.contains(config)).collect(Collectors.toSet());
if (!customRegionConfigs.isEmpty()) {
cacheSettings.setProperty(CUSTOM, String.join(" ", customRegionConfigs));
}
Notification.addCacheDependencies(Classification.INFINISPAN, cacheSettings);
}
}
Aggregations