use of org.hibernate.boot.CacheRegionDefinition in project hibernate-orm by hibernate.
the class EntityManagerFactoryBuilderImpl method parseCacheRegionDefinitionEntry.
private CacheRegionDefinition parseCacheRegionDefinitionEntry(String role, String value, CacheRegionDefinition.CacheRegionType cacheType) {
final StringTokenizer params = new StringTokenizer(value, ";, ");
if (!params.hasMoreTokens()) {
StringBuilder error = new StringBuilder("Illegal usage of ");
if (cacheType == CacheRegionDefinition.CacheRegionType.ENTITY) {
error.append(CLASS_CACHE_PREFIX).append(": ").append(CLASS_CACHE_PREFIX);
} else {
error.append(COLLECTION_CACHE_PREFIX).append(": ").append(COLLECTION_CACHE_PREFIX);
}
error.append('.').append(role).append(' ').append(value).append(". Was expecting configuration (usage[,region[,lazy]]), but found none");
throw persistenceException(error.toString());
}
String usage = params.nextToken();
String region = null;
if (params.hasMoreTokens()) {
region = params.nextToken();
}
boolean lazyProperty = true;
if (cacheType == CacheRegionDefinition.CacheRegionType.ENTITY) {
if (params.hasMoreTokens()) {
lazyProperty = "all".equalsIgnoreCase(params.nextToken());
}
} else {
lazyProperty = false;
}
return new CacheRegionDefinition(cacheType, role, usage, region, lazyProperty);
}
use of org.hibernate.boot.CacheRegionDefinition in project hibernate-orm by hibernate.
the class EntityManagerFactoryBuilderImpl method populate.
protected void populate(MetadataBuilder metamodelBuilder, MergedSettings mergedSettings, StandardServiceRegistry ssr, List<AttributeConverterDefinition> attributeConverterDefinitions) {
if (persistenceUnit.getTempClassLoader() != null) {
metamodelBuilder.applyTempClassLoader(persistenceUnit.getTempClassLoader());
}
metamodelBuilder.applyScanEnvironment(new StandardJpaScanEnvironmentImpl(persistenceUnit));
metamodelBuilder.applyScanOptions(new StandardScanOptions((String) configurationValues.get(org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY), persistenceUnit.isExcludeUnlistedClasses()));
if (mergedSettings.cacheRegionDefinitions != null) {
for (CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions) {
metamodelBuilder.applyCacheRegionDefinition(localCacheRegionDefinition);
}
}
final TypeContributorList typeContributorList = (TypeContributorList) configurationValues.remove(TYPE_CONTRIBUTORS);
if (typeContributorList != null) {
for (TypeContributor typeContributor : typeContributorList.getTypeContributors()) {
metamodelBuilder.applyTypes(typeContributor);
}
}
if (attributeConverterDefinitions != null) {
for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitions) {
metamodelBuilder.applyAttributeConverter(attributeConverterDefinition);
}
}
}
use of org.hibernate.boot.CacheRegionDefinition in project hibernate-orm by hibernate.
the class InFlightMetadataCollectorImpl method processCachingOverrides.
private void processCachingOverrides() {
if (options.getCacheRegionDefinitions() == null) {
return;
}
for (CacheRegionDefinition cacheRegionDefinition : options.getCacheRegionDefinitions()) {
if (cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.ENTITY) {
final PersistentClass entityBinding = getEntityBinding(cacheRegionDefinition.getRole());
if (entityBinding == null) {
throw new HibernateException("Cache override referenced an unknown entity : " + cacheRegionDefinition.getRole());
}
if (!RootClass.class.isInstance(entityBinding)) {
throw new HibernateException("Cache override referenced a non-root entity : " + cacheRegionDefinition.getRole());
}
((RootClass) entityBinding).setCacheRegionName(cacheRegionDefinition.getRegion());
((RootClass) entityBinding).setCacheConcurrencyStrategy(cacheRegionDefinition.getUsage());
((RootClass) entityBinding).setLazyPropertiesCacheable(cacheRegionDefinition.isCacheLazy());
} else if (cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION) {
final Collection collectionBinding = getCollectionBinding(cacheRegionDefinition.getRole());
if (collectionBinding == null) {
throw new HibernateException("Cache override referenced an unknown collection role : " + cacheRegionDefinition.getRole());
}
collectionBinding.setCacheRegionName(cacheRegionDefinition.getRegion());
collectionBinding.setCacheConcurrencyStrategy(cacheRegionDefinition.getUsage());
}
}
}
Aggregations