org.hibernate.cache.spi.RegionFactory Java Examples

The following examples show how to use org.hibernate.cache.spi.RegionFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseRegion.java    From redisson with Apache License 2.0 6 votes vote down vote up
public BaseRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
    super();
    this.mapCache = mapCache;
    this.regionFactory = regionFactory;
    this.metadata = metadata;
    this.connectionManager = connectionManager;
    
    String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
    if (maxEntries != null) {
        mapCache.setMaxSize(Integer.valueOf(maxEntries));
    }
    String timeToLive = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.TTL_SUFFIX);
    if (timeToLive != null) {
        ttl = Integer.valueOf(timeToLive);
    }
    String maxIdleTime = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_IDLE_SUFFIX);
    if (maxIdleTime != null) {
        maxIdle = Integer.valueOf(maxIdleTime);
    }

    String fallbackValue = (String) properties.getOrDefault(RedissonRegionFactory.FALLBACK, "false");
    fallback = Boolean.valueOf(fallbackValue);
}
 
Example #2
Source File: AbstractDomainDataRegion.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public AbstractDomainDataRegion(
			DomainDataRegionConfig regionConfig,
			RegionFactory regionFactory,
			CacheKeysFactory defaultKeysFactory,
			DomainDataRegionBuildingContext buildingContext) {
//		super( regionFactory.qualify( regionConfig.getRegionName() ), regionFactory );
		super( regionConfig.getRegionName(), regionFactory );

		this.sessionFactory = buildingContext.getSessionFactory();

		if ( defaultKeysFactory == null ) {
			defaultKeysFactory = DefaultCacheKeysFactory.INSTANCE;
		}
		this.effectiveKeysFactory = buildingContext.getEnforcedCacheKeysFactory() != null
				? buildingContext.getEnforcedCacheKeysFactory()
				: defaultKeysFactory;
	}
 
Example #3
Source File: QuarkusRegionFactoryInitiator.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public RegionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    final Boolean useSecondLevelCache = ConfigurationHelper.getBooleanWrapper(
            AvailableSettings.USE_SECOND_LEVEL_CACHE,
            configurationValues,
            Boolean.TRUE);
    final Boolean useQueryCache = ConfigurationHelper.getBooleanWrapper(
            AvailableSettings.USE_QUERY_CACHE,
            configurationValues,
            Boolean.TRUE);

    // We should immediately return NoCachingRegionFactory if either:
    //		1) both are explicitly FALSE
    //		2) USE_SECOND_LEVEL_CACHE is FALSE and USE_QUERY_CACHE is null
    if (useSecondLevelCache != null && useSecondLevelCache == FALSE) {
        if (useQueryCache == null || useQueryCache == FALSE) {
            return NoCachingRegionFactory.INSTANCE;
        }
    }

    return new QuarkusInfinispanRegionFactory();
}
 
Example #4
Source File: StrategyRegistrationProviderImpl.java    From hibernate-l2-memcached with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>();

    strategyRegistrations.add(
            new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    MemcachedRegionFactory.class,
                    "memcached",
                    MemcachedRegionFactory.class.getName(),
                    MemcachedRegionFactory.class.getSimpleName(),
                    // legacy impl class name
                    "com.mc.hibernate.memcached.MemcachedRegionFactory"
            )
    );

    return strategyRegistrations;
}
 
Example #5
Source File: BaseRegion.java    From redisson with Apache License 2.0 6 votes vote down vote up
public BaseRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
    super();
    this.mapCache = mapCache;
    this.regionFactory = regionFactory;
    this.metadata = metadata;
    this.connectionManager = connectionManager;
    
    String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
    if (maxEntries != null) {
        mapCache.setMaxSize(Integer.valueOf(maxEntries));
    }
    String timeToLive = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.TTL_SUFFIX);
    if (timeToLive != null) {
        ttl = Integer.valueOf(timeToLive);
    }
    String maxIdleTime = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_IDLE_SUFFIX);
    if (maxIdleTime != null) {
        maxIdle = Integer.valueOf(maxIdleTime);
    }

    String fallbackValue = (String) properties.getOrDefault(RedissonRegionFactory.FALLBACK, "false");
    fallback = Boolean.valueOf(fallbackValue);
}
 
Example #6
Source File: BaseRegion.java    From redisson with Apache License 2.0 6 votes vote down vote up
public BaseRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
    super();
    this.mapCache = mapCache;
    this.regionFactory = regionFactory;
    this.metadata = metadata;
    this.connectionManager = connectionManager;
    
    String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
    if (maxEntries != null) {
        mapCache.setMaxSize(Integer.valueOf(maxEntries));
    }
    String timeToLive = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.TTL_SUFFIX);
    if (timeToLive != null) {
        ttl = Integer.valueOf(timeToLive);
    }
    String maxIdleTime = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_IDLE_SUFFIX);
    if (maxIdleTime != null) {
        maxIdle = Integer.valueOf(maxIdleTime);
    }

    String fallbackValue = (String) properties.getOrDefault(RedissonRegionFactory.FALLBACK, "false");
    fallback = Boolean.valueOf(fallbackValue);
}
 
Example #7
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #8
Source File: IgniteEntityDataAccess.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
public IgniteEntityDataAccess(
    HibernateAccessStrategyAdapter stgy,
    AccessType accessType,
    RegionFactory regionFactory,
    DomainDataRegion domainDataRegion,
    Ignite ignite,
    HibernateCacheProxy cache
) {
    super(stgy, regionFactory, domainDataRegion, ignite, cache);

    this.accessType = accessType;
}
 
Example #9
Source File: IgniteNaturalIdDataAccess.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
public IgniteNaturalIdDataAccess(
    HibernateAccessStrategyAdapter stgy,
    AccessType accessType,
    RegionFactory regionFactory,
    DomainDataRegion domainDataRegion,
    Ignite ignite,
    HibernateCacheProxy cache
) {
    super(stgy, regionFactory, domainDataRegion, ignite, cache);

    this.accessType = accessType;
}
 
Example #10
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #11
Source File: IgniteDomainDataRegion.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
public IgniteDomainDataRegion(DomainDataRegionConfig regionCfg,
    RegionFactory regionFactory,
    CacheKeysFactory defKeysFactory,
    DomainDataRegionBuildingContext buildingCtx,
    HibernateAccessStrategyFactory stgyFactory) {
    super(regionCfg, regionFactory, defKeysFactory, buildingCtx);

    this.stgyFactory = stgyFactory;

    cache = stgyFactory.regionCache(getName());

    completeInstantiation(regionCfg, buildingCtx);
}
 
Example #12
Source File: TimestampsCacheEnabledImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void preInvalidate(
		String[] spaces,
		SharedSessionContractImplementor session) {
	final SessionFactoryImplementor factory = session.getFactory();
	final RegionFactory regionFactory = factory.getCache().getRegionFactory();

	final boolean stats = factory.getStatistics().isStatisticsEnabled();

	final Long ts = regionFactory.nextTimestamp() + regionFactory.getTimeout();

	for ( Serializable space : spaces ) {
		if ( DEBUG_ENABLED ) {
			log.debugf( "Pre-invalidating space [%s], timestamp: %s", space, ts );
		}

		try {
			session.getEventListenerManager().cachePutStart();

			//put() has nowait semantics, is this really appropriate?
			//note that it needs to be async replication, never local or sync
			timestampsRegion.putIntoCache( space, ts, session );
		}
		finally {
			session.getEventListenerManager().cachePutEnd();
		}

		if ( stats ) {
			factory.getStatistics().updateTimestampsCachePut();
		}
	}
}
 
Example #13
Source File: EnabledCaching.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public EnabledCaching(SessionFactoryImplementor sessionFactory) {
	this.sessionFactory = sessionFactory;

	this.regionFactory = getSessionFactory().getSessionFactoryOptions().getServiceRegistry().getService( RegionFactory.class );
	this.regionFactory.start( sessionFactory.getSessionFactoryOptions(), sessionFactory.getProperties() );

	if ( getSessionFactory().getSessionFactoryOptions().isQueryCacheEnabled() ) {
		final TimestampsRegion timestampsRegion = regionFactory.buildTimestampsRegion(
				RegionFactory.DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME,
				sessionFactory
		);
		timestampsCache = sessionFactory.getSessionFactoryOptions()
				.getTimestampsCacheFactory()
				.buildTimestampsCache( this, timestampsRegion );
		legacySecondLevelCacheNames.add( timestampsRegion.getName() );

		final QueryResultsRegion queryResultsRegion = regionFactory.buildQueryResultsRegion(
				RegionFactory.DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME,
				sessionFactory
		);
		regionsByName.put( queryResultsRegion.getName(), queryResultsRegion );
		defaultQueryResultsCache = new QueryResultsCacheImpl(
				queryResultsRegion,
				timestampsCache
		);
	}
	else {
		timestampsCache = new TimestampsCacheDisabledImpl();
		defaultQueryResultsCache = null;
	}
}
 
Example #14
Source File: IgniteGeneralDataRegion.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param factory Region factory.
 * @param name Region name.
 * @param ignite Grid.
 * @param cache Region cache.
 */
IgniteGeneralDataRegion(RegionFactory factory, String name,
    Ignite ignite, HibernateCacheProxy cache) {
    super(factory, name, ignite, cache);

    log = ignite.log().getLogger(getClass());
}
 
Example #15
Source File: EnabledCaching.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> cls) {
	if ( org.hibernate.Cache.class.isAssignableFrom( cls ) ) {
		return (T) this;
	}

	if ( RegionFactory.class.isAssignableFrom( cls ) ) {
		return (T) regionFactory;
	}

	throw new PersistenceException( "Hibernate cannot unwrap Cache as " + cls.getName() );
}
 
Example #16
Source File: IgniteCollectionDataAccess.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param stgy Access strategy implementation.
 * @param accessType Strategy access type.
 * @param regionFactory Region factory.
 * @param domainDataRegion Data region.
 * @param ignite Ignite instance.
 * @param cache Cache proxy.
 */
public IgniteCollectionDataAccess(
    HibernateAccessStrategyAdapter stgy,
    AccessType accessType,
    RegionFactory regionFactory,
    DomainDataRegion domainDataRegion,
    Ignite ignite,
    HibernateCacheProxy cache
) {
    super(stgy, regionFactory, domainDataRegion, ignite, cache);

    this.accessType = accessType;
}
 
Example #17
Source File: RegionFactoryInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RegionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final RegionFactory regionFactory = resolveRegionFactory( configurationValues, registry );

	LOG.debugf( "Cache region factory : %s", regionFactory.getClass().getName() );

	return regionFactory;
}
 
Example #18
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #19
Source File: StrategyCreatorRegionFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RegionFactory create(Class<? extends RegionFactory> strategyClass) {
	assert RegionFactory.class.isAssignableFrom( strategyClass );

	// first look for a constructor accepting Properties
	try {
		final Constructor<? extends RegionFactory> ctor = strategyClass.getConstructor( Properties.class );
		return ctor.newInstance( properties );
	}
	catch ( NoSuchMethodException e ) {
		log.debugf( "RegionFactory impl [%s] did not provide constructor accepting Properties", strategyClass.getName() );
	}
	catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
		throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
	}

	// next try Map
	try {
		final Constructor<? extends RegionFactory> ctor = strategyClass.getConstructor( Map.class );
		return ctor.newInstance( properties );
	}
	catch ( NoSuchMethodException e ) {
		log.debugf( "RegionFactory impl [%s] did not provide constructor accepting Properties", strategyClass.getName() );
	}
	catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
		throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
	}

	// finally try no-arg
	try {
		return strategyClass.newInstance();
	}
	catch (IllegalAccessException | InstantiationException e) {
		throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
	}
}
 
Example #20
Source File: DomainDataRegionTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public DomainDataRegionTemplate(
		DomainDataRegionConfig regionConfig,
		RegionFactory regionFactory,
		DomainDataStorageAccess storageAccess,
		CacheKeysFactory defaultKeysFactory,
		DomainDataRegionBuildingContext buildingContext) {
	super( regionConfig, regionFactory, defaultKeysFactory, buildingContext );
	this.storageAccess = storageAccess;

	// now the super-type calls will have access to the `DomainDataStorageAccess` reference
	completeInstantiation( regionConfig, buildingContext );
}
 
Example #21
Source File: IgniteCachedDomainDataAccess.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param stgy Access strategy implementation.
 */
protected IgniteCachedDomainDataAccess(HibernateAccessStrategyAdapter stgy,
    RegionFactory regionFactory,
    DomainDataRegion domainDataRegion,
    Ignite ignite, HibernateCacheProxy cache) {
    super(regionFactory, cache.name(), ignite, cache);

    this.stgy = stgy;
    this.domainDataRegion = domainDataRegion;
}
 
Example #22
Source File: CacheInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CacheImplementor initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	final RegionFactory regionFactory = registry.getService( RegionFactory.class );
	return ( ! NoCachingRegionFactory.class.isInstance( regionFactory ) )
			? new EnabledCaching( sessionFactory )
			: new DisabledCaching( sessionFactory );
}
 
Example #23
Source File: LocalSessionFactoryBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Settings buildSettings(Properties props, ServiceRegistry serviceRegistry) throws HibernateException {
	Settings settings = super.buildSettings(props, serviceRegistry);
	if (this.cacheRegionFactory != null) {
		try {
			Method setRegionFactory = Settings.class.getDeclaredMethod("setRegionFactory", RegionFactory.class);
			setRegionFactory.setAccessible(true);
			setRegionFactory.invoke(settings, this.cacheRegionFactory);
		}
		catch (Exception ex) {
			throw new IllegalStateException("Failed to invoke Hibernate's setRegionFactory method", ex);
		}
	}
	return settings;
}
 
Example #24
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #25
Source File: LocalSessionFactoryBuilder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Settings buildSettings(Properties props, ServiceRegistry serviceRegistry) throws HibernateException {
	Settings settings = super.buildSettings(props, serviceRegistry);
	if (this.cacheRegionFactory != null) {
		try {
			Method setRegionFactory = Settings.class.getDeclaredMethod("setRegionFactory", RegionFactory.class);
			setRegionFactory.setAccessible(true);
			setRegionFactory.invoke(settings, this.cacheRegionFactory);
		}
		catch (Exception ex) {
			throw new IllegalStateException("Failed to invoke Hibernate's setRegionFactory method", ex);
		}
	}
	return settings;
}
 
Example #26
Source File: InfinispanCacheJPAFunctionalityTestEndpoint.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void testQuery(EntityManagerFactory entityManagerFactory) {
    //Load all persons and run some checks on the query results:
    Map<String, Counts> counts = new TreeMap<>();
    counts.put(Person.class.getName(), new Counts(4, 0, 0, 4));
    counts.put(RegionFactory.DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME, new Counts(1, 0, 1, 1));
    verifyListOfExistingPersons(entityManagerFactory, counts);

    //Load all persons with same query and verify query results
    counts = new TreeMap<>();
    counts.put(Person.class.getName(), new Counts(0, 4, 0, 4));
    counts.put(RegionFactory.DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME, new Counts(0, 1, 0, 1));
    verifyListOfExistingPersons(entityManagerFactory, counts);
}
 
Example #27
Source File: HibernateRegion.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
protected HibernateRegion(RegionFactory factory, String name, Ignite ignite, HibernateCacheProxy cache) {
    super(name, factory);

    this.ignite = ignite;
    this.cache = cache;
}
 
Example #28
Source File: RedissonCollectionRegion.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RedissonCollectionRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
                                CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey, CacheKeysFactory cacheKeysFactory) {
    super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
    this.settings = settings;
    this.cacheKeysFactory = cacheKeysFactory;
}
 
Example #29
Source File: RedissonQueryRegion.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
        RegionFactory regionFactory, Properties properties, String defaultKey) {
    super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
}
 
Example #30
Source File: RedissonQueryRegion.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
        RegionFactory regionFactory, Properties properties, String defaultKey) {
    super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
}