Java Code Examples for org.hibernate.cache.spi.RegionFactory

The following examples show how to use org.hibernate.cache.spi.RegionFactory. These examples are extracted from open source projects. 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 Project: quarkus   Source File: QuarkusRegionFactoryInitiator.java    License: 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 2
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
@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 4
Source Project: redisson   Source File: BaseRegion.java    License: 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 5
Source Project: redisson   Source File: BaseRegion.java    License: 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 Project: redisson   Source File: BaseRegion.java    License: 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
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 8
@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 9
Source Project: lams   Source File: CacheInitiator.java    License: 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 10
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 11
@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 12
Source Project: lams   Source File: EnabledCaching.java    License: 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 13
Source Project: lams   Source File: EnabledCaching.java    License: 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 14
Source Project: lams   Source File: RegionFactoryInitiator.java    License: 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 15
@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 16
@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 17
Source Project: ignite   Source File: HibernateRegion.java    License: 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 18
Source Project: ignite   Source File: IgniteEntityDataAccess.java    License: 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 19
Source Project: ignite   Source File: IgniteCachedDomainDataAccess.java    License: 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 20
Source Project: ignite   Source File: IgniteNaturalIdDataAccess.java    License: 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 21
Source Project: ignite   Source File: IgniteCollectionDataAccess.java    License: 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 22
Source Project: ignite   Source File: IgniteGeneralDataRegion.java    License: 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 23
Source Project: ignite   Source File: IgniteDomainDataRegion.java    License: 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 24
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example 25
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example 26
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example 27
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example 28
Source Project: quarkus   Source File: QuarkusRegionFactoryInitiator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Class<RegionFactory> getServiceInitiated() {
    return RegionFactory.class;
}
 
Example 29
Source Project: lams   Source File: Settings.java    License: GNU General Public License v2.0 4 votes vote down vote up
public RegionFactory getRegionFactory() {
	return sessionFactoryOptions.getServiceRegistry().getService( RegionFactory.class );
}
 
Example 30
Source Project: lams   Source File: AbstractRegion.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public RegionFactory getRegionFactory() {
	return regionFactory;
}