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 Steve Ebersole
*/
@SuppressWarnings("rawtypes")
public class ComparableComparator<T extends Comparable> implements Comparator<T>, Serializable {
public static final Comparator INSTANCE = new ComparableComparator();
@SuppressWarnings("unchecked")

View File

@ -19,13 +19,12 @@ public final class RowVersionComparator implements Comparator<byte[]> {
}
@Override
@SuppressWarnings("unchecked")
public int compare(byte[] o1, byte[] o2) {
final int lengthToCheck = Math.min( o1.length, o2.length );
for ( int i = 0 ; i < lengthToCheck ; i++ ) {
// 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( o2[i] )
);

View File

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

View File

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

View File

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

View File

@ -438,13 +438,13 @@ public class MappingModelCreationHelper {
};
}
else {
return ImmutableMutabilityPlan.INSTANCE;
return ImmutableMutabilityPlan.instance();
}
}
@SuppressWarnings("rawtypes")
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")

View File

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

View File

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

View File

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

View File

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

View File

@ -19,9 +19,11 @@ public class RowTransformerListImpl<T> implements RowTransformer<List<Object>> {
/**
* 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;
}

View File

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

View File

@ -22,7 +22,7 @@ public class RowTransformerStandardImpl<T> implements RowTransformer<T> {
* Singleton access
*/
@SuppressWarnings("rawtypes")
public static final RowTransformerStandardImpl INSTANCE = new RowTransformerStandardImpl();
private static final RowTransformerStandardImpl INSTANCE = new RowTransformerStandardImpl();
@SuppressWarnings("unchecked")
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.sortedForResolveInstanceData = new InitializerData[sortedForResolveInstance.length];
this.hasCollectionInitializers = hasCollectionInitializers;
this.rowTransformer = rowTransformer == RowTransformerArrayImpl.INSTANCE && resultAssemblers.length != 1
|| rowTransformer == RowTransformerStandardImpl.INSTANCE
|| rowTransformer == RowTransformerSingularReturnImpl.INSTANCE && resultAssemblers.length == 1
this.rowTransformer = rowTransformer == RowTransformerArrayImpl.instance() && resultAssemblers.length != 1
|| rowTransformer == RowTransformerStandardImpl.instance()
|| rowTransformer == RowTransformerSingularReturnImpl.instance() && resultAssemblers.length == 1
? null
: rowTransformer;
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> {
/**
* 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();
@SuppressWarnings("unchecked")

View File

@ -27,8 +27,8 @@ public class SingleResultConsumer<T> implements ResultsConsumer<T, T> {
private static final SingleResultConsumer<?> INSTANCE = new SingleResultConsumer<>();
@SuppressWarnings( "unchecked" )
public static <T> SingleResultConsumer<T> instance() {
//noinspection unchecked
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 mutabilityPlan The plan for handling mutability aspects of the java type.
*/
@SuppressWarnings("unchecked")
protected AbstractClassJavaType(Class<? extends T> type, MutabilityPlan<? extends T> mutabilityPlan) {
this(
type,
mutabilityPlan,
Comparable.class.isAssignableFrom( type )
? (Comparator<T>) ComparableComparator.INSTANCE
? ComparableComparator.instance()
: null
);
}

View File

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

View File

@ -21,6 +21,14 @@ import org.hibernate.SharedSessionContract;
* @author Steve Ebersole
*/
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 <X> ImmutableMutabilityPlan<X> instance() {