org.hibernate.cache.cfg.spi.DomainDataRegionConfig Java Examples

The following examples show how to use org.hibernate.cache.cfg.spi.DomainDataRegionConfig. 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: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
protected DomainDataStorageAccess createDomainDataStorageAccess(DomainDataRegionConfig regionConfig,
        DomainDataRegionBuildingContext buildingContext) {
    String defaultKey = null;
    if (!regionConfig.getCollectionCaching().isEmpty()) {
        defaultKey = COLLECTION_DEF;
    } else if (!regionConfig.getEntityCaching().isEmpty()) {
        defaultKey = ENTITY_DEF;
    } else if (!regionConfig.getNaturalIdCaching().isEmpty()) {
        defaultKey = NATURAL_ID_DEF;
    } else {
        throw new IllegalArgumentException("Unable to determine entity cache type!");
    }
    
    RMapCache<Object, Object> mapCache = getCache(regionConfig.getRegionName(), buildingContext.getSessionFactory().getProperties(), defaultKey);
    return new RedissonStorage(mapCache, ((Redisson)redisson).getConnectionManager(), buildingContext.getSessionFactory().getProperties(), defaultKey);
}
 
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: AbstractDomainDataRegion.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Map<NavigableRole, EntityDataAccess> generateEntityDataAccessMap(
		DomainDataRegionConfig regionConfig) {
	if ( regionConfig.getEntityCaching().isEmpty() ) {
		return Collections.emptyMap();
	}

	final Map<NavigableRole, EntityDataAccess> accessMap = new ConcurrentHashMap<>();
	for ( EntityDataCachingConfig entityAccessConfig : regionConfig.getEntityCaching() ) {
		accessMap.computeIfAbsent(
				entityAccessConfig.getNavigableRole(),
				hierarchy -> generateEntityAccess( entityAccessConfig )
		);
	}

	return Collections.unmodifiableMap( accessMap );
}
 
Example #4
Source File: AbstractDomainDataRegion.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Map<NavigableRole, CollectionDataAccess> generateCollectionDataAccessMap(
		DomainDataRegionConfig regionConfig) {
	if ( regionConfig.getCollectionCaching().isEmpty() ) {
		return Collections.emptyMap();
	}

	final Map<NavigableRole, CollectionDataAccess> accessMap = new ConcurrentHashMap<>();
	for ( CollectionDataCachingConfig cachingConfig : regionConfig.getCollectionCaching() ) {
		accessMap.computeIfAbsent(
				cachingConfig.getNavigableRole(),
				hierarchy -> generateCollectionAccess( cachingConfig )
		);
	}

	return Collections.unmodifiableMap( accessMap );
}
 
Example #5
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 #6
Source File: AbstractDomainDataRegion.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Should be called at the end of the subtype's constructor, or at least after the
 * `#super(...)` (aka, this type's constructor) call.  It's a timing issue - we need access
 * to the DomainDataStorageAccess in DomainDataRegionTemplate but in methods initiated
 * (atm) from AbstractDomainDataRegion's constructor
 */
protected void completeInstantiation(
		DomainDataRegionConfig regionConfig,
		DomainDataRegionBuildingContext buildingContext) {
	log.tracef( "DomainDataRegion created [%s]; key-factory = %s", regionConfig.getRegionName(), effectiveKeysFactory );

	this.entityDataAccessMap = generateEntityDataAccessMap( regionConfig );
	this.naturalIdDataAccessMap = generateNaturalIdDataAccessMap( regionConfig );
	this.collectionDataAccessMap = generateCollectionDataAccessMap( regionConfig );

}
 
Example #7
Source File: AbstractDomainDataRegion.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Map<NavigableRole, NaturalIdDataAccess> generateNaturalIdDataAccessMap(DomainDataRegionConfig regionConfig) {
	if ( regionConfig.getNaturalIdCaching().isEmpty() ) {
		return Collections.emptyMap();
	}

	final Map<NavigableRole, NaturalIdDataAccess> accessMap = new ConcurrentHashMap<>();
	for ( NaturalIdDataCachingConfig naturalIdAccessConfig : regionConfig.getNaturalIdCaching() ) {
		accessMap.computeIfAbsent(
				naturalIdAccessConfig.getNavigableRole(),
				hierarchy -> generateNaturalIdAccess( naturalIdAccessConfig )
		);
	}

	return Collections.unmodifiableMap( accessMap );
}
 
Example #8
Source File: DomainDataRegionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess")
public DomainDataRegionImpl(
		DomainDataRegionConfig regionConfig,
		RegionFactoryTemplate regionFactory,
		DomainDataStorageAccess domainDataStorageAccess,
		CacheKeysFactory defaultKeysFactory,
		DomainDataRegionBuildingContext buildingContext) {
	super(
			regionConfig,
			regionFactory,
			domainDataStorageAccess,
			defaultKeysFactory,
			buildingContext
	);
}
 
Example #9
Source File: RegionFactoryTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DomainDataRegion buildDomainDataRegion(
		DomainDataRegionConfig regionConfig,
		DomainDataRegionBuildingContext buildingContext) {
	verifyStarted();
	return new DomainDataRegionTemplate(
			regionConfig,
			this,
			createDomainDataStorageAccess( regionConfig, buildingContext ),
			getImplicitCacheKeysFactory(),
			buildingContext
	);
}
 
Example #10
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public DomainDataRegion buildDomainDataRegion(
        DomainDataRegionConfig regionConfig,
        DomainDataRegionBuildingContext buildingContext) {
    verifyStarted();
    return new DomainDataRegionImpl(
            regionConfig,
            this,
            createDomainDataStorageAccess( regionConfig, buildingContext ),
            getImplicitCacheKeysFactory(),
            buildingContext
    );
}
 
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: HibernateRegionFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public DomainDataRegion buildDomainDataRegion(
    DomainDataRegionConfig regionCfg,
    DomainDataRegionBuildingContext buildingCtx) {
    return new IgniteDomainDataRegion(regionCfg, this, null, buildingCtx,
        accessStgyFactory);
}
 
Example #13
Source File: RegionFactoryTemplate.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected DomainDataStorageAccess createDomainDataStorageAccess(
		DomainDataRegionConfig regionConfig,
		DomainDataRegionBuildingContext buildingContext) {
	throw new UnsupportedOperationException( "Not implemented by caching provider" );
}
 
Example #14
Source File: MemcachedRegionFactory.java    From hibernate-l2-memcached with Apache License 2.0 4 votes vote down vote up
@Override
protected DomainDataStorageAccess createDomainDataStorageAccess(DomainDataRegionConfig regionConfig, DomainDataRegionBuildingContext buildingContext) {
    return new StorageAccessImpl(getOrCreateCache(regionConfig.getRegionName(), buildingContext.getSessionFactory()));
}
 
Example #15
Source File: MemcachedRegionFactory.java    From hibernate-l2-memcached with Apache License 2.0 4 votes vote down vote up
@Override
public DomainDataRegion buildDomainDataRegion(DomainDataRegionConfig regionConfig, DomainDataRegionBuildingContext buildingContext) {
    return new DomainDataRegionImpl(regionConfig, this, createDomainDataStorageAccess(regionConfig, buildingContext), cacheKeysFactory, buildingContext);
}
 
Example #16
Source File: NoCachingRegionFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DomainDataRegion buildDomainDataRegion(
		DomainDataRegionConfig regionConfig, DomainDataRegionBuildingContext buildingContext) {
	throw new NoCacheRegionFactoryAvailableException();
}
 
Example #17
Source File: EnabledCaching.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void prime(Set<DomainDataRegionConfig> cacheRegionConfigs) {
	for ( DomainDataRegionConfig regionConfig : cacheRegionConfigs ) {
		final DomainDataRegion region = getRegionFactory().buildDomainDataRegion( regionConfig, this );
		regionsByName.put( region.getName(), region );

		if ( ! Objects.equals( region.getName(), regionConfig.getRegionName() ) ) {
			throw new HibernateException(
					String.format(
							Locale.ROOT,
							"Region [%s] returned from RegionFactory [%s] was named differently than requested name.  Expecting `%s`, but found `%s`",
							region,
							getRegionFactory().getClass().getName(),
							regionConfig.getRegionName(),
							region.getName()
					)
			);
		}

		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Entity caching

		for ( EntityDataCachingConfig entityAccessConfig : regionConfig.getEntityCaching() ) {
			final EntityDataAccess entityDataAccess = entityAccessMap.put(
					entityAccessConfig.getNavigableRole(),
					region.getEntityDataAccess( entityAccessConfig.getNavigableRole() )
			);

			legacySecondLevelCacheNames.add(
					StringHelper.qualifyConditionally(
							getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(),
							region.getName()
					)
			);
		}


		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Natural-id caching

		if ( regionConfig.getNaturalIdCaching().isEmpty() ) {
			legacyNaturalIdAccessesForRegion.put( region.getName(), Collections.emptySet() );
		}
		else {
			final HashSet<NaturalIdDataAccess> accesses = new HashSet<>();

			for ( NaturalIdDataCachingConfig naturalIdAccessConfig : regionConfig.getNaturalIdCaching() ) {
				final NaturalIdDataAccess naturalIdDataAccess = naturalIdAccessMap.put(
						naturalIdAccessConfig.getNavigableRole(),
						region.getNaturalIdDataAccess( naturalIdAccessConfig.getNavigableRole() )
				);
				accesses.add( naturalIdDataAccess );
			}

			legacyNaturalIdAccessesForRegion.put( region.getName(), accesses );
		}


		// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Collection caching

		for ( CollectionDataCachingConfig collectionAccessConfig : regionConfig.getCollectionCaching() ) {
			final CollectionDataAccess collectionDataAccess = collectionAccessMap.put(
					collectionAccessConfig.getNavigableRole(),
					region.getCollectionDataAccess( collectionAccessConfig.getNavigableRole() )
			);

			legacySecondLevelCacheNames.add(
					StringHelper.qualifyConditionally(
							getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(),
							region.getName()
					)
			);
		}
	}

}
 
Example #18
Source File: DisabledCaching.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void prime(Set<DomainDataRegionConfig> cacheRegionConfigs) {
	// nothing to do
}
 
Example #19
Source File: CacheImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * An initialization phase allowing the caching provider to prime itself
 * from the passed configs
 *
 * @since 5.3
 */
void prime(Set<DomainDataRegionConfig> cacheRegionConfigs);
 
Example #20
Source File: CacheImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * An initialization phase allowing the caching provider to prime itself
 * from the passed configs
 *
 * @since 5.3
 */
void prime(Set<DomainDataRegionConfig> cacheRegionConfigs);
 
Example #21
Source File: RegionFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a named Region for holding domain model data
 *
 * @param regionConfig The user requested caching configuration for this Region
 * @param buildingContext Access to delegates useful in building the Region
 */
DomainDataRegion buildDomainDataRegion(
		DomainDataRegionConfig regionConfig,
		DomainDataRegionBuildingContext buildingContext);