diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/TruthValue.java b/hibernate-core/src/main/java/org/hibernate/boot/model/TruthValue.java index d244d5c0ad..0b54f4ac41 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/TruthValue.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/TruthValue.java @@ -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; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractPluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractPluralAttributeSourceImpl.java index a92a4a9913..86797c5ce9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractPluralAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractPluralAttributeSourceImpl.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java index afadcf9221..44ebac0205 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/EntityHierarchySourceImpl.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java index 204c7d2533..f5ecc25ec5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java @@ -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,32 +74,26 @@ public class Helper { } public static Caching createCaching(JaxbHbmCacheType cacheElement) { - if ( cacheElement == null ) { - return new Caching( TruthValue.UNKNOWN ); - } - else { - return new Caching( - cacheElement.getRegion(), - cacheElement.getUsage(), - cacheElement.getInclude() == null - || !"non-lazy".equals( cacheElement.getInclude().value() ), - TruthValue.TRUE - ); - } + return cacheElement == null + ? new Caching() + : new Caching( + cacheElement.getRegion(), + cacheElement.getUsage(), + cacheElement.getInclude() == null + || !"non-lazy".equals( cacheElement.getInclude().value() ), + true + ); } public static Caching createNaturalIdCaching(JaxbHbmNaturalIdCacheType cacheElement) { - if ( cacheElement == null ) { - return new Caching( TruthValue.UNKNOWN ); - } - else { - return new Caching( - nullIfEmpty( cacheElement.getRegion() ), - null, - false, - TruthValue.TRUE - ); - } + return cacheElement == null + ? new Caching() + : new Caching( + nullIfEmpty( cacheElement.getRegion() ), + null, + false, + true + ); } public static String getPropertyAccessorName(String access, boolean isEmbedded, String defaultAccess) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index c1f92c945d..8132e017cd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -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); }; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/Caching.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/Caching.java similarity index 57% rename from hibernate-core/src/main/java/org/hibernate/boot/model/Caching.java rename to hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/Caching.java index 691b80327e..eef99363a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/Caching.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/Caching.java @@ -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,37 +65,37 @@ 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 ( isEmpty( overrides.getRegion() ) ) { + region = overrides.getRegion(); + } + // ugh, primitive boolean + cacheLazyProperties = overrides.isCacheLazy(); } - - requested = TruthValue.TRUE; - accessType = AccessType.fromExternalName( overrides.getUsage() ); - if ( StringHelper.isEmpty( overrides.getRegion() ) ) { - region = overrides.getRegion(); - } - // ugh, primitive boolean - cacheLazyProperties = overrides.isCacheLazy(); } public void overlay(Caching overrides) { - if ( overrides == null ) { - return; + if ( overrides != null ) { + this.requested = overrides.requested; + this.accessType = overrides.accessType; + this.region = overrides.region; + this.cacheLazyProperties = overrides.cacheLazyProperties; } - - this.requested = overrides.requested; - this.accessType = overrides.accessType; - this.region = overrides.region; - this.cacheLazyProperties = overrides.cacheLazyProperties; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/EntityHierarchySource.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/EntityHierarchySource.java index 2922dcfa8b..172e8be9eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/EntityHierarchySource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/EntityHierarchySource.java @@ -4,7 +4,6 @@ */ package org.hibernate.boot.model.source.spi; -import org.hibernate.boot.model.Caching; import org.hibernate.engine.OptimisticLockStyle; /** diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/PluralAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/PluralAttributeSource.java index 7798a186e3..a0b0a2c843 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/PluralAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/PluralAttributeSource.java @@ -4,7 +4,6 @@ */ package org.hibernate.boot.model.source.spi; -import org.hibernate.boot.model.Caching; import org.hibernate.boot.model.CustomSql; /**