HHH-7118 : Extract code to create Caching holder into org.hibernate.metamodel.internal.source.hbm.Helper.createCachingHolder()
This commit is contained in:
parent
5ca5b2287f
commit
d9d8ab67ff
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
|
@ -27,13 +27,12 @@ import java.util.Collections;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.engine.FetchStyle;
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbCacheElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.PluralAttributeElement;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.Value;
|
||||
import org.hibernate.metamodel.spi.binding.Caching;
|
||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
||||
|
@ -58,6 +57,7 @@ public abstract class AbstractPluralAttributeSourceImpl
|
|||
|
||||
private final PluralAttributeKeySource keySource;
|
||||
private final PluralAttributeElementSource elementSource;
|
||||
private final Value<Caching> cachingHolder;
|
||||
|
||||
protected AbstractPluralAttributeSourceImpl(
|
||||
MappingDocument sourceMappingDocument,
|
||||
|
@ -74,6 +74,8 @@ public abstract class AbstractPluralAttributeSourceImpl
|
|||
);
|
||||
this.elementSource = interpretElementType();
|
||||
|
||||
this.cachingHolder = Helper.createCachingHolder( pluralAttributeElement.getCache(), StringHelper.qualify( container().getPath(), getName() ) );
|
||||
|
||||
this.typeInformation = new ExplicitHibernateTypeSource() {
|
||||
@Override
|
||||
public String getName() {
|
||||
|
@ -181,16 +183,7 @@ public abstract class AbstractPluralAttributeSourceImpl
|
|||
|
||||
@Override
|
||||
public Caching getCaching() {
|
||||
final JaxbCacheElement cache = pluralAttributeElement.getCache();
|
||||
if ( cache == null ) {
|
||||
return null;
|
||||
}
|
||||
final String region = cache.getRegion() != null
|
||||
? cache.getRegion()
|
||||
: StringHelper.qualify( container().getPath(), getName() );
|
||||
final AccessType accessType = Enum.valueOf( AccessType.class, cache.getUsage() );
|
||||
final boolean cacheLazyProps = !"non-lazy".equals( cache.getInclude() );
|
||||
return new Caching( region, accessType, cacheLazyProps );
|
||||
return cachingHolder.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,10 +31,12 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.CustomSqlElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.EntityElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbCacheElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbColumnElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbJoinedSubclassElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbMetaElement;
|
||||
|
@ -43,6 +45,8 @@ import org.hibernate.internal.jaxb.mapping.hbm.JaxbSubclassElement;
|
|||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbUnionSubclassElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.TableInformationSource;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.Value;
|
||||
import org.hibernate.metamodel.spi.binding.Caching;
|
||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||
import org.hibernate.metamodel.spi.binding.MetaAttribute;
|
||||
|
@ -122,6 +126,23 @@ public class Helper {
|
|||
: qualifyIfNeeded( entityElement.getName(), unqualifiedClassPackage );
|
||||
}
|
||||
|
||||
public static Value<Caching> createCachingHolder(final JaxbCacheElement cacheElement, final String defaultRegionName) {
|
||||
return new Value<Caching>(
|
||||
new Value.DeferredInitializer<Caching>() {
|
||||
@Override
|
||||
public Caching initialize() {
|
||||
if ( cacheElement == null ) {
|
||||
return null;
|
||||
}
|
||||
final String region = cacheElement.getRegion() != null ? cacheElement.getRegion() : defaultRegionName;
|
||||
final AccessType accessType = Enum.valueOf( AccessType.class, cacheElement.getUsage() );
|
||||
final boolean cacheLazyProps = !"non-lazy".equals( cacheElement.getInclude() );
|
||||
return new Caching( region, accessType, cacheLazyProps );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Qualify a (supposed class) name with the unqualified-class package name if it is not already qualified
|
||||
*
|
||||
|
|
|
@ -27,9 +27,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbCacheElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.Value;
|
||||
|
@ -51,13 +49,14 @@ import org.hibernate.metamodel.spi.source.VersionAttributeSource;
|
|||
*/
|
||||
public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements RootEntitySource {
|
||||
private final TableSpecificationSource primaryTable;
|
||||
private final Value<Caching> cachingHolder;
|
||||
|
||||
protected RootEntitySourceImpl(
|
||||
MappingDocument sourceMappingDocument,
|
||||
JaxbHibernateMapping.JaxbClass entityElement) {
|
||||
super( sourceMappingDocument, entityElement );
|
||||
this.primaryTable = Helper.createTableSource( sourceMappingDocument(), entityElement, this );
|
||||
|
||||
this.cachingHolder = Helper.createCachingHolder( entityElement().getCache(), getEntityName() );
|
||||
afterInstantiation();
|
||||
}
|
||||
|
||||
|
@ -178,22 +177,6 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
|
|||
}
|
||||
}
|
||||
|
||||
private Value<Caching> cachingHolder = new Value<Caching>(
|
||||
new Value.DeferredInitializer<Caching>() {
|
||||
@Override
|
||||
public Caching initialize() {
|
||||
final JaxbCacheElement cache = entityElement().getCache();
|
||||
if ( cache == null ) {
|
||||
return null;
|
||||
}
|
||||
final String region = cache.getRegion() != null ? cache.getRegion() : getEntityName();
|
||||
final AccessType accessType = Enum.valueOf( AccessType.class, cache.getUsage() );
|
||||
final boolean cacheLazyProps = !"non-lazy".equals( cache.getInclude() );
|
||||
return new Caching( region, accessType, cacheLazyProps );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@Override
|
||||
public Caching getCaching() {
|
||||
return cachingHolder.getValue();
|
||||
|
|
Loading…
Reference in New Issue