Mark field `INSTANCE` as private or deprecated for removal if method `instance()` present

This commit is contained in:
Yanming Zhou 2024-08-20 15:35:07 +08:00 committed by Christian Beikov
parent c181e1913e
commit 464ad489d6
19 changed files with 38 additions and 21 deletions

View File

@ -15,7 +15,9 @@ import java.util.Comparator;
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings("rawtypes")
public class ComparableComparator<T extends Comparable> implements Comparator<T>, Serializable { public class ComparableComparator<T extends Comparable> implements Comparator<T>, Serializable {
public static final Comparator INSTANCE = new ComparableComparator(); public static final Comparator INSTANCE = new ComparableComparator();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -19,13 +19,12 @@ public final class RowVersionComparator implements Comparator<byte[]> {
} }
@Override @Override
@SuppressWarnings("unchecked")
public int compare(byte[] o1, byte[] o2) { public int compare(byte[] o1, byte[] o2) {
final int lengthToCheck = Math.min( o1.length, o2.length ); final int lengthToCheck = Math.min( o1.length, o2.length );
for ( int i = 0 ; i < lengthToCheck ; i++ ) { for ( int i = 0 ; i < lengthToCheck ; i++ ) {
// must do an unsigned int comparison // must do an unsigned int comparison
final int comparison = ComparableComparator.INSTANCE.compare( final int comparison = ComparableComparator.<Integer>instance().compare(
Byte.toUnsignedInt( o1[i] ), Byte.toUnsignedInt( o1[i] ),
Byte.toUnsignedInt( o2[i] ) Byte.toUnsignedInt( o2[i] )
); );

View File

@ -836,7 +836,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
}; };
} }
else { else {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
} }
} }

View File

@ -695,7 +695,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
}; };
} }
else { else {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
} }

View File

@ -176,7 +176,7 @@ public class GeneratedValuesProcessor {
jdbcSelect, jdbcSelect,
jdbcParamBindings, jdbcParamBindings,
new NoCallbackExecutionContext( session ), new NoCallbackExecutionContext( session ),
RowTransformerArrayImpl.INSTANCE, RowTransformerArrayImpl.instance(),
null, null,
FILTER, FILTER,
1 1

View File

@ -438,13 +438,13 @@ public class MappingModelCreationHelper {
}; };
} }
else { else {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static AttributeMetadata getAttributeMetadata(PropertyAccess propertyAccess) { public static AttributeMetadata getAttributeMetadata(PropertyAccess propertyAccess) {
return new SimpleAttributeMetadata( propertyAccess, ImmutableMutabilityPlan.INSTANCE, false, true, false, false, true, null);// todo (6.0) : not sure if CascadeStyle=null is correct return new SimpleAttributeMetadata( propertyAccess, ImmutableMutabilityPlan.instance(), false, true, false, false, true, null);// todo (6.0) : not sure if CascadeStyle=null is correct
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")

View File

@ -85,6 +85,6 @@ public interface SingleAttributeIdentifierMapping extends EntityIdentifierMappin
@Override @Override
default MutabilityPlan getMutabilityPlan() { default MutabilityPlan getMutabilityPlan() {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
} }

View File

@ -316,7 +316,7 @@ public class MatchingIdSelectionHelper {
rowTransformer = RowTransformerSingularReturnImpl.instance(); rowTransformer = RowTransformerSingularReturnImpl.instance();
} }
else { else {
rowTransformer = RowTransformerArrayImpl.INSTANCE; rowTransformer = RowTransformerArrayImpl.instance();
} }
//noinspection unchecked //noinspection unchecked
return jdbcServices.getJdbcSelectExecutor().list( return jdbcServices.getJdbcSelectExecutor().list(

View File

@ -188,7 +188,7 @@ public class OutputsImpl implements Outputs {
//noinspection unchecked //noinspection unchecked
final RowReader<Object> rowReader = (RowReader<Object>) ResultsHelper.createRowReader( final RowReader<Object> rowReader = (RowReader<Object>) ResultsHelper.createRowReader(
getSessionFactory(), getSessionFactory(),
RowTransformerStandardImpl.INSTANCE, RowTransformerStandardImpl.instance(),
null, null,
jdbcValues jdbcValues
); );

View File

@ -17,7 +17,7 @@ public class RowTransformerArrayImpl implements RowTransformer<Object[]> {
/** /**
* Singleton access * Singleton access
*/ */
public static final RowTransformerArrayImpl INSTANCE = new RowTransformerArrayImpl(); private static final RowTransformerArrayImpl INSTANCE = new RowTransformerArrayImpl();
public static RowTransformerArrayImpl instance() { public static RowTransformerArrayImpl instance() {
return INSTANCE; return INSTANCE;

View File

@ -19,9 +19,11 @@ public class RowTransformerListImpl<T> implements RowTransformer<List<Object>> {
/** /**
* Singleton access * Singleton access
*/ */
public static final RowTransformerListImpl INSTANCE = new RowTransformerListImpl(); @SuppressWarnings( "rawtypes" )
private static final RowTransformerListImpl INSTANCE = new RowTransformerListImpl();
public static RowTransformerListImpl instance() { @SuppressWarnings( "unchecked" )
public static <X> RowTransformerListImpl<X> instance() {
return INSTANCE; return INSTANCE;
} }

View File

@ -22,7 +22,7 @@ public class RowTransformerSingularReturnImpl<R> implements RowTransformer<R> {
* Singleton access * Singleton access
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final RowTransformerSingularReturnImpl INSTANCE = new RowTransformerSingularReturnImpl(); private static final RowTransformerSingularReturnImpl INSTANCE = new RowTransformerSingularReturnImpl();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <R> RowTransformer<R> instance() { public static <R> RowTransformer<R> instance() {

View File

@ -22,7 +22,7 @@ public class RowTransformerStandardImpl<T> implements RowTransformer<T> {
* Singleton access * Singleton access
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final RowTransformerStandardImpl INSTANCE = new RowTransformerStandardImpl(); private static final RowTransformerStandardImpl INSTANCE = new RowTransformerStandardImpl();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> RowTransformer<T> instance() { public static <T> RowTransformer<T> instance() {

View File

@ -73,9 +73,9 @@ public class StandardRowReader<T> implements RowReader<T> {
this.sortedForResolveInstance = (Initializer<InitializerData>[]) sortedForResolveInitializers; this.sortedForResolveInstance = (Initializer<InitializerData>[]) sortedForResolveInitializers;
this.sortedForResolveInstanceData = new InitializerData[sortedForResolveInstance.length]; this.sortedForResolveInstanceData = new InitializerData[sortedForResolveInstance.length];
this.hasCollectionInitializers = hasCollectionInitializers; this.hasCollectionInitializers = hasCollectionInitializers;
this.rowTransformer = rowTransformer == RowTransformerArrayImpl.INSTANCE && resultAssemblers.length != 1 this.rowTransformer = rowTransformer == RowTransformerArrayImpl.instance() && resultAssemblers.length != 1
|| rowTransformer == RowTransformerStandardImpl.INSTANCE || rowTransformer == RowTransformerStandardImpl.instance()
|| rowTransformer == RowTransformerSingularReturnImpl.INSTANCE && resultAssemblers.length == 1 || rowTransformer == RowTransformerSingularReturnImpl.instance() && resultAssemblers.length == 1
? null ? null
: rowTransformer; : rowTransformer;
this.domainResultJavaType = domainResultJavaType; this.domainResultJavaType = domainResultJavaType;

View File

@ -26,7 +26,11 @@ import org.hibernate.sql.results.internal.RowProcessingStateStandardImpl;
public class ScrollableResultsConsumer<R> implements ResultsConsumer<ScrollableResultsImplementor<R>, R> { public class ScrollableResultsConsumer<R> implements ResultsConsumer<ScrollableResultsImplementor<R>, R> {
/** /**
* Singleton access to the standard scrollable-results consumer instance * Singleton access to the standard scrollable-results consumer instance
*
* @deprecated in favor of {@link #instance()}
*/ */
@SuppressWarnings( "rawtypes" )
@Deprecated( forRemoval = true )
public static final ScrollableResultsConsumer INSTANCE = new ScrollableResultsConsumer(); public static final ScrollableResultsConsumer INSTANCE = new ScrollableResultsConsumer();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -27,8 +27,8 @@ public class SingleResultConsumer<T> implements ResultsConsumer<T, T> {
private static final SingleResultConsumer<?> INSTANCE = new SingleResultConsumer<>(); private static final SingleResultConsumer<?> INSTANCE = new SingleResultConsumer<>();
@SuppressWarnings( "unchecked" )
public static <T> SingleResultConsumer<T> instance() { public static <T> SingleResultConsumer<T> instance() {
//noinspection unchecked
return (SingleResultConsumer<T>) INSTANCE; return (SingleResultConsumer<T>) INSTANCE;
} }

View File

@ -46,13 +46,12 @@ public abstract class AbstractClassJavaType<T> implements BasicJavaType<T>, Seri
* @param type The Java type. * @param type The Java type.
* @param mutabilityPlan The plan for handling mutability aspects of the java type. * @param mutabilityPlan The plan for handling mutability aspects of the java type.
*/ */
@SuppressWarnings("unchecked")
protected AbstractClassJavaType(Class<? extends T> type, MutabilityPlan<? extends T> mutabilityPlan) { protected AbstractClassJavaType(Class<? extends T> type, MutabilityPlan<? extends T> mutabilityPlan) {
this( this(
type, type,
mutabilityPlan, mutabilityPlan,
Comparable.class.isAssignableFrom( type ) Comparable.class.isAssignableFrom( type )
? (Comparator<T>) ComparableComparator.INSTANCE ? ComparableComparator.instance()
: null : null
); );
} }

View File

@ -22,7 +22,10 @@ import org.hibernate.annotations.Mutability;
public class Immutability implements MutabilityPlan<Object> { public class Immutability implements MutabilityPlan<Object> {
/** /**
* Singleton access * Singleton access
*
* @deprecated in favor of {@link #instance()}
*/ */
@Deprecated( forRemoval = true )
public static final Immutability INSTANCE = new Immutability(); public static final Immutability INSTANCE = new Immutability();
public static <X> MutabilityPlan<X> instance() { public static <X> MutabilityPlan<X> instance() {

View File

@ -21,6 +21,14 @@ import org.hibernate.SharedSessionContract;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class ImmutableMutabilityPlan<T> implements MutabilityPlan<T> { public class ImmutableMutabilityPlan<T> implements MutabilityPlan<T> {
/**
* Singleton access
*
* @deprecated in favor of {@link #instance()}
*/
@SuppressWarnings( "rawtypes" )
@Deprecated( forRemoval = true )
public static final ImmutableMutabilityPlan INSTANCE = new ImmutableMutabilityPlan(); public static final ImmutableMutabilityPlan INSTANCE = new ImmutableMutabilityPlan();
public static <X> ImmutableMutabilityPlan<X> instance() { public static <X> ImmutableMutabilityPlan<X> instance() {