parent
9303f1a29f
commit
424460af3f
|
@ -18,17 +18,22 @@ public enum TruthValue {
|
|||
FALSE,
|
||||
UNKNOWN;
|
||||
|
||||
public boolean toBoolean(boolean defaultValue) {
|
||||
switch (this) {
|
||||
case TRUE:
|
||||
return true;
|
||||
case FALSE:
|
||||
return false;
|
||||
default:
|
||||
return defaultValue;
|
||||
}
|
||||
public static TruthValue of(boolean bool) {
|
||||
return bool ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
public boolean toBoolean(boolean defaultValue) {
|
||||
return switch ( this ) {
|
||||
case TRUE -> true;
|
||||
case FALSE -> false;
|
||||
default -> defaultValue;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated No longer used
|
||||
*/
|
||||
@Deprecated(since = "7", forRemoval = true)
|
||||
public static boolean toBoolean(TruthValue value, boolean defaultValue) {
|
||||
return value != null ? value.toBoolean( defaultValue ) : defaultValue;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmManyToOneType;
|
|||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.PluralAttributeInfo;
|
||||
import org.hibernate.boot.model.Caching;
|
||||
import org.hibernate.boot.model.source.spi.Caching;
|
||||
import org.hibernate.boot.model.CustomSql;
|
||||
import org.hibernate.boot.model.source.spi.AttributePath;
|
||||
import org.hibernate.boot.model.source.spi.AttributeRole;
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmMultiTenancyType;
|
|||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmPolymorphismEnum;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSimpleIdType;
|
||||
import org.hibernate.boot.model.Caching;
|
||||
import org.hibernate.boot.model.source.spi.Caching;
|
||||
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
|
||||
import org.hibernate.boot.model.naming.EntityNaming;
|
||||
import org.hibernate.boot.model.source.spi.DiscriminatorSource;
|
||||
|
|
|
@ -20,9 +20,8 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmToolingHintType;
|
|||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmUnionSubclassEntityType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.TableInformationContainer;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.ToolingHintContainer;
|
||||
import org.hibernate.boot.model.Caching;
|
||||
import org.hibernate.boot.model.source.spi.Caching;
|
||||
import org.hibernate.boot.model.CustomSql;
|
||||
import org.hibernate.boot.model.TruthValue;
|
||||
import org.hibernate.boot.model.source.spi.InheritanceType;
|
||||
import org.hibernate.boot.model.source.spi.SizeSource;
|
||||
import org.hibernate.boot.model.source.spi.TableSpecificationSource;
|
||||
|
@ -75,33 +74,27 @@ public class Helper {
|
|||
}
|
||||
|
||||
public static Caching createCaching(JaxbHbmCacheType cacheElement) {
|
||||
if ( cacheElement == null ) {
|
||||
return new Caching( TruthValue.UNKNOWN );
|
||||
}
|
||||
else {
|
||||
return new Caching(
|
||||
return cacheElement == null
|
||||
? new Caching()
|
||||
: new Caching(
|
||||
cacheElement.getRegion(),
|
||||
cacheElement.getUsage(),
|
||||
cacheElement.getInclude() == null
|
||||
|| !"non-lazy".equals( cacheElement.getInclude().value() ),
|
||||
TruthValue.TRUE
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static Caching createNaturalIdCaching(JaxbHbmNaturalIdCacheType cacheElement) {
|
||||
if ( cacheElement == null ) {
|
||||
return new Caching( TruthValue.UNKNOWN );
|
||||
}
|
||||
else {
|
||||
return new Caching(
|
||||
return cacheElement == null
|
||||
? new Caching()
|
||||
: new Caching(
|
||||
nullIfEmpty( cacheElement.getRegion() ),
|
||||
null,
|
||||
false,
|
||||
TruthValue.TRUE
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPropertyAccessorName(String access, boolean isEmbedded, String defaultAccess) {
|
||||
return getValue( access, isEmbedded ? "embedded" : defaultAccess );
|
||||
|
|
|
@ -22,9 +22,8 @@ import org.hibernate.boot.MappingException;
|
|||
import org.hibernate.boot.jaxb.Origin;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedQueryType;
|
||||
import org.hibernate.boot.model.Caching;
|
||||
import org.hibernate.boot.model.source.spi.Caching;
|
||||
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
|
||||
import org.hibernate.boot.model.TruthValue;
|
||||
import org.hibernate.boot.model.TypeDefinition;
|
||||
import org.hibernate.boot.model.internal.FkSecondPass;
|
||||
import org.hibernate.boot.model.internal.SimpleToOneFkSecondPass;
|
||||
|
@ -278,7 +277,7 @@ public class ModelBinder {
|
|||
);
|
||||
|
||||
if ( hierarchySource.getNaturalIdCaching() != null ) {
|
||||
if ( hierarchySource.getNaturalIdCaching().getRequested() == TruthValue.TRUE ) {
|
||||
if ( hierarchySource.getNaturalIdCaching().isRequested() ) {
|
||||
rootEntityDescriptor.setNaturalIdCacheRegionName( hierarchySource.getNaturalIdCaching().getRegion() );
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +302,7 @@ public class ModelBinder {
|
|||
return switch ( mappingDocument.getBuildingOptions().getSharedCacheMode() ) {
|
||||
case UNSPECIFIED, ENABLE_SELECTIVE ->
|
||||
// this is default behavior for hbm.xml
|
||||
caching != null && caching.getRequested().toBoolean(false);
|
||||
caching != null && caching.isRequested(false);
|
||||
case NONE ->
|
||||
// this option is actually really useful
|
||||
false;
|
||||
|
@ -314,7 +313,7 @@ public class ModelBinder {
|
|||
case DISABLE_SELECTIVE ->
|
||||
// makes no sense for hbm.xml, and also goes against our
|
||||
// ideology, and so it hurts me to support it here
|
||||
caching == null || caching.getRequested().toBoolean(true);
|
||||
caching == null || caching.isRequested(true);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -2,21 +2,20 @@
|
|||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
* Copyright Red Hat Inc. and Hibernate Authors
|
||||
*/
|
||||
package org.hibernate.boot.model;
|
||||
package org.hibernate.boot.model.source.spi;
|
||||
|
||||
import org.hibernate.boot.CacheRegionDefinition;
|
||||
import org.hibernate.boot.model.TruthValue;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
import static org.hibernate.internal.util.StringHelper.isEmpty;
|
||||
|
||||
/**
|
||||
* Models the caching options for an entity, natural id, or collection.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
*
|
||||
* @deprecated will move to {@link org.hibernate.boot.model.source.spi}, where its only uses are
|
||||
*/
|
||||
@Deprecated(since = "6") // because it is moving packages
|
||||
public class Caching {
|
||||
// NOTE : TruthValue for now because I need to look at how JPA's SharedCacheMode concept is handled
|
||||
private TruthValue requested;
|
||||
|
@ -24,16 +23,19 @@ public class Caching {
|
|||
private AccessType accessType;
|
||||
private boolean cacheLazyProperties;
|
||||
|
||||
public Caching(TruthValue requested) {
|
||||
this.requested = requested;
|
||||
public Caching() {
|
||||
this.requested = TruthValue.UNKNOWN;
|
||||
}
|
||||
|
||||
public Caching(String region, AccessType accessType, boolean cacheLazyProperties) {
|
||||
this( region, accessType, cacheLazyProperties, TruthValue.UNKNOWN );
|
||||
this.requested = TruthValue.UNKNOWN;
|
||||
this.region = region;
|
||||
this.accessType = accessType;
|
||||
this.cacheLazyProperties = cacheLazyProperties;
|
||||
}
|
||||
|
||||
public Caching(String region, AccessType accessType, boolean cacheLazyProperties, TruthValue requested) {
|
||||
this.requested = requested;
|
||||
public Caching(String region, AccessType accessType, boolean cacheLazyProperties, boolean requested) {
|
||||
this.requested = TruthValue.of( requested );
|
||||
this.region = region;
|
||||
this.accessType = accessType;
|
||||
this.cacheLazyProperties = cacheLazyProperties;
|
||||
|
@ -63,38 +65,38 @@ public class Caching {
|
|||
this.cacheLazyProperties = cacheLazyProperties;
|
||||
}
|
||||
|
||||
public TruthValue getRequested() {
|
||||
return requested;
|
||||
public boolean isRequested() {
|
||||
return requested == TruthValue.TRUE;
|
||||
}
|
||||
|
||||
public void setRequested(TruthValue requested) {
|
||||
this.requested = requested;
|
||||
public boolean isRequested(boolean defaultValue) {
|
||||
return requested == TruthValue.UNKNOWN ? defaultValue : isRequested();
|
||||
}
|
||||
|
||||
public void setRequested(boolean requested) {
|
||||
this.requested = TruthValue.of(requested);
|
||||
}
|
||||
|
||||
public void overlay(CacheRegionDefinition overrides) {
|
||||
if ( overrides == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( overrides != null ) {
|
||||
requested = TruthValue.TRUE;
|
||||
accessType = AccessType.fromExternalName( overrides.getUsage() );
|
||||
if ( StringHelper.isEmpty( overrides.getRegion() ) ) {
|
||||
if ( isEmpty( overrides.getRegion() ) ) {
|
||||
region = overrides.getRegion();
|
||||
}
|
||||
// ugh, primitive boolean
|
||||
cacheLazyProperties = overrides.isCacheLazy();
|
||||
}
|
||||
|
||||
public void overlay(Caching overrides) {
|
||||
if ( overrides == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void overlay(Caching overrides) {
|
||||
if ( overrides != null ) {
|
||||
this.requested = overrides.requested;
|
||||
this.accessType = overrides.accessType;
|
||||
this.region = overrides.region;
|
||||
this.cacheLazyProperties = overrides.cacheLazyProperties;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
package org.hibernate.boot.model.source.spi;
|
||||
|
||||
import org.hibernate.boot.model.Caching;
|
||||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
package org.hibernate.boot.model.source.spi;
|
||||
|
||||
import org.hibernate.boot.model.Caching;
|
||||
import org.hibernate.boot.model.CustomSql;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue