Search in sources :

Example 1 with CacheRegionDefinition

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);
}
Also used : StringTokenizer(java.util.StringTokenizer) CacheRegionDefinition(org.hibernate.boot.CacheRegionDefinition)

Example 2 with CacheRegionDefinition

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);
        }
    }
}
Also used : AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) CacheRegionDefinition(org.hibernate.boot.CacheRegionDefinition) TypeContributorList(org.hibernate.jpa.boot.spi.TypeContributorList) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) TypeContributor(org.hibernate.boot.model.TypeContributor)

Example 3 with CacheRegionDefinition

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());
        }
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) HibernateException(org.hibernate.HibernateException) CacheRegionDefinition(org.hibernate.boot.CacheRegionDefinition) Collection(org.hibernate.mapping.Collection) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

CacheRegionDefinition (org.hibernate.boot.CacheRegionDefinition)3 StringTokenizer (java.util.StringTokenizer)1 HibernateException (org.hibernate.HibernateException)1 StandardScanOptions (org.hibernate.boot.archive.scan.internal.StandardScanOptions)1 TypeContributor (org.hibernate.boot.model.TypeContributor)1 AttributeConverterDefinition (org.hibernate.cfg.AttributeConverterDefinition)1 TypeContributorList (org.hibernate.jpa.boot.spi.TypeContributorList)1 Collection (org.hibernate.mapping.Collection)1 IdentifierCollection (org.hibernate.mapping.IdentifierCollection)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 RootClass (org.hibernate.mapping.RootClass)1