Search in sources :

Example 1 with ENTITY_CACHE_RESOURCE_PROP

use of org.hibernate.cache.infinispan.InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP 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);
    }
}
Also used : NATURAL_ID_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.NATURAL_ID_CACHE_RESOURCE_PROP) COLLECTION_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.COLLECTION_CACHE_RESOURCE_PROP) DEF_QUERY_RESOURCE(org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_QUERY_RESOURCE) INFINISPAN_CONFIG_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP) Properties(java.util.Properties) Notification(org.jipijapa.event.impl.internal.Notification) DEFAULT_CACHE_CONTAINER(org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory.DEFAULT_CACHE_CONTAINER) DEF_ENTITY_RESOURCE(org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_ENTITY_RESOURCE) AvailableSettings(org.hibernate.cfg.AvailableSettings) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SharedInfinispanRegionFactory(org.jboss.as.jpa.hibernate5.infinispan.SharedInfinispanRegionFactory) PENDING_PUTS_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.PENDING_PUTS_CACHE_RESOURCE_PROP) CACHE_CONTAINER(org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory.CACHE_CONTAINER) IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP) Stream(java.util.stream.Stream) QUERY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP) TIMESTAMPS_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.TIMESTAMPS_CACHE_RESOURCE_PROP) ENTITY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP) Classification(org.jipijapa.cache.spi.Classification) Properties(java.util.Properties)

Example 2 with ENTITY_CACHE_RESOURCE_PROP

use of org.hibernate.cache.infinispan.InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP 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);
    }
}
Also used : NATURAL_ID_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.NATURAL_ID_CACHE_RESOURCE_PROP) COLLECTION_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.COLLECTION_CACHE_RESOURCE_PROP) DEF_QUERY_RESOURCE(org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_QUERY_RESOURCE) INFINISPAN_CONFIG_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP) Properties(java.util.Properties) Notification(org.jipijapa.event.impl.internal.Notification) DEF_ENTITY_RESOURCE(org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_ENTITY_RESOURCE) AvailableSettings(org.hibernate.cfg.AvailableSettings) Set(java.util.Set) DEFAULT_CACHE_CONTAINER(org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory.DEFAULT_CACHE_CONTAINER) CACHE_CONTAINER(org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory.CACHE_CONTAINER) Collectors(java.util.stream.Collectors) SharedInfinispanRegionFactory(org.jboss.as.jpa.hibernate4.infinispan.SharedInfinispanRegionFactory) Objects(java.util.Objects) Stream(java.util.stream.Stream) QUERY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP) TIMESTAMPS_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.TIMESTAMPS_CACHE_RESOURCE_PROP) ENTITY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP) Classification(org.jipijapa.cache.spi.Classification) Properties(java.util.Properties)

Aggregations

Objects (java.util.Objects)2 Properties (java.util.Properties)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 COLLECTION_CACHE_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.COLLECTION_CACHE_RESOURCE_PROP)2 DEF_ENTITY_RESOURCE (org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_ENTITY_RESOURCE)2 DEF_QUERY_RESOURCE (org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_QUERY_RESOURCE)2 ENTITY_CACHE_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP)2 INFINISPAN_CONFIG_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP)2 NATURAL_ID_CACHE_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.NATURAL_ID_CACHE_RESOURCE_PROP)2 QUERY_CACHE_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP)2 TIMESTAMPS_CACHE_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.TIMESTAMPS_CACHE_RESOURCE_PROP)2 AvailableSettings (org.hibernate.cfg.AvailableSettings)2 Classification (org.jipijapa.cache.spi.Classification)2 Notification (org.jipijapa.event.impl.internal.Notification)2 IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP)1 PENDING_PUTS_CACHE_RESOURCE_PROP (org.hibernate.cache.infinispan.InfinispanRegionFactory.PENDING_PUTS_CACHE_RESOURCE_PROP)1 CACHE_CONTAINER (org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory.CACHE_CONTAINER)1 DEFAULT_CACHE_CONTAINER (org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory.DEFAULT_CACHE_CONTAINER)1