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