HHH-12760 Remove no longer needed EqualsHelper and cleanup some equality checks
This commit is contained in:
parent
f54949d280
commit
a67c6b9cd4
|
@ -11,11 +11,9 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.boot.MappingException;
|
||||
import org.hibernate.boot.jaxb.Origin;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.EntityInfo;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmEntityBaseDefinition;
|
||||
|
@ -46,7 +44,6 @@ import org.hibernate.boot.model.source.spi.SubclassEntitySource;
|
|||
import org.hibernate.boot.model.source.spi.ToolingHintContext;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
package org.hibernate.bytecode.enhance.internal.bytebuddy;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.bytecode.enhance.spi.EnhancerConstants;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
|
||||
import net.bytebuddy.ClassFileVersion;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -125,8 +125,8 @@ class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppender {
|
|||
else {
|
||||
methodVisitor.visitMethodInsn(
|
||||
Opcodes.INVOKESTATIC,
|
||||
Type.getInternalName( EqualsHelper.class ),
|
||||
"areEqual",
|
||||
Type.getInternalName( Objects.class ),
|
||||
"deepEquals",
|
||||
Type.getMethodDescriptor( Type.getType( boolean.class ), Type.getType( Object.class ), Type.getType( Object.class ) ),
|
||||
false
|
||||
);
|
||||
|
|
|
@ -15,9 +15,7 @@ import javassist.CtClass;
|
|||
import javassist.CtField;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
|
||||
import org.hibernate.bytecode.enhance.spi.EnhancerConstants;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
|
||||
/**
|
||||
* utility class to generate interceptor methods
|
||||
|
@ -66,8 +64,7 @@ public abstract class AttributeTypeDescriptor {
|
|||
}
|
||||
builder.append(
|
||||
String.format(
|
||||
" if ( !%s.areEqual( %s, $1 ) )",
|
||||
EqualsHelper.class.getName(),
|
||||
" if ( !Objects.deepEquals( %s, $1 ) )",
|
||||
readFragment
|
||||
)
|
||||
);
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.HashSet;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
@ -43,7 +44,6 @@ import org.hibernate.metamodel.model.domain.NavigableRole;
|
|||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -108,7 +108,7 @@ public class EnabledCaching implements CacheImplementor, DomainDataRegionBuildin
|
|||
final DomainDataRegion region = getRegionFactory().buildDomainDataRegion( regionConfig, this );
|
||||
regionsByName.put( region.getName(), region );
|
||||
|
||||
if ( !StringTypeDescriptor.INSTANCE.areEqual( region.getName(), regionConfig.getRegionName() ) ) {
|
||||
if ( ! Objects.equals( region.getName(), regionConfig.getRegionName() ) ) {
|
||||
throw new HibernateException(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.internal.util.compare;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Helper for equality determination
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public final class EqualsHelper {
|
||||
|
||||
/**
|
||||
* Like the legacy {@link #equals} method, but handles array-specific checks
|
||||
*
|
||||
* @param x One value to check
|
||||
* @param y The other value
|
||||
*
|
||||
* @return {@code true} if the 2 values are equal; {@code false} otherwise.
|
||||
*/
|
||||
public static boolean areEqual(final Object x, final Object y) {
|
||||
if ( x == y ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( x == null || y == null ) {
|
||||
// One is null, but the other is not (otherwise the `x == y` check would have passed).
|
||||
// null can never equal a non-null
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( x.equals( y ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for possibility of arrays
|
||||
final Class xClass = x.getClass();
|
||||
final Class yClass = y.getClass();
|
||||
|
||||
if ( xClass.isArray() && yClass.isArray() ) {
|
||||
if ( xClass.equals( yClass ) ) {
|
||||
if ( x instanceof boolean[] ) {
|
||||
return Arrays.equals( (boolean[]) x, (boolean[]) y );
|
||||
}
|
||||
else if ( x instanceof byte[] ) {
|
||||
return Arrays.equals( (byte[]) x, (byte[]) y );
|
||||
}
|
||||
else if ( x instanceof char[] ) {
|
||||
return Arrays.equals( (char[]) x, (char[]) y );
|
||||
}
|
||||
else if ( x instanceof short[] ) {
|
||||
return Arrays.equals( (short[]) x, (short[]) y );
|
||||
}
|
||||
else if ( x instanceof int[] ) {
|
||||
return Arrays.equals( (int[]) x, (int[]) y );
|
||||
}
|
||||
else if ( x instanceof long[] ) {
|
||||
return Arrays.equals( (long[]) x, (long[]) y );
|
||||
}
|
||||
else if ( x instanceof double[] ) {
|
||||
return Arrays.equals( (double[]) x, (double[]) y );
|
||||
}
|
||||
else if ( x instanceof float[] ) {
|
||||
return Arrays.equals( (float[]) x, (float[]) y );
|
||||
}
|
||||
}
|
||||
return Arrays.equals( (Object[]) x, (Object[]) y );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private ctor - disallow instantiation
|
||||
*/
|
||||
private EqualsHelper() {
|
||||
// disallow instantiation
|
||||
}
|
||||
|
||||
}
|
|
@ -8,9 +8,9 @@ package org.hibernate.type.descriptor.java;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.hibernate.internal.util.compare.ComparableComparator;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
|
||||
/**
|
||||
|
@ -75,7 +75,7 @@ public interface JavaTypeDescriptor<T> extends Serializable {
|
|||
* @return True if the two are considered equal; false otherwise.
|
||||
*/
|
||||
default boolean areEqual(T one, T another) {
|
||||
return EqualsHelper.areEqual( one, another );
|
||||
return Objects.deepEquals( one, another );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.io.InputStream;
|
|||
import java.io.Serializable;
|
||||
import java.sql.Blob;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.annotations.Immutable;
|
||||
|
@ -71,7 +72,7 @@ public class SerializableTypeDescriptor<T extends Serializable> extends Abstract
|
|||
return false;
|
||||
}
|
||||
return one.equals( another )
|
||||
|| PrimitiveByteArrayTypeDescriptor.INSTANCE.areEqual( toBytes( one ), toBytes( another ) );
|
||||
|| Arrays.equals( toBytes( one ), toBytes( another ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.hibernate.annotations.NaturalIdCache;
|
|||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.spi.CacheImplementor;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.stat.NaturalIdCacheStatistics;
|
||||
import org.hibernate.stat.SecondLevelCacheStatistics;
|
||||
|
@ -149,7 +148,7 @@ public class RegionNameTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
|
||||
boolean foundRegion = false;
|
||||
for ( String name : cache.getSecondLevelCacheRegionNames() ) {
|
||||
if ( EqualsHelper.areEqual( name, regionName ) ) {
|
||||
if ( regionName.equals( name ) ) {
|
||||
foundRegion = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.security.AccessController;
|
|||
import java.security.PrivilegedAction;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
|
@ -22,7 +23,6 @@ import org.hibernate.envers.internal.entities.PropertyData;
|
|||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.internal.tools.ReflectionTools;
|
||||
import org.hibernate.envers.internal.tools.StringTools;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.property.access.spi.SetterFieldImpl;
|
||||
|
||||
|
@ -171,6 +171,6 @@ public class SinglePropertyMapper extends AbstractPropertyMapper implements Simp
|
|||
}
|
||||
// todo (6.0) - Confirm if this is still necessary as everything should use a JavaTypeDescriptor.
|
||||
// This was maintained for legacy 5.2 behavior only.
|
||||
return EqualsHelper.areEqual( newObj, oldObj );
|
||||
return Objects.deepEquals( newObj, oldObj );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
|
@ -29,7 +30,6 @@ import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeD
|
|||
import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.internal.tools.ReflectionTools;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
|
||||
|
@ -167,7 +167,7 @@ public abstract class AbstractCollectionMapper<T> extends AbstractPropertyMapper
|
|||
if ( propertyData.isUsingModifiedFlag() ) {
|
||||
if ( isNotPersistentCollection( newObj ) || isNotPersistentCollection( oldObj ) ) {
|
||||
// Compare POJOs.
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), !EqualsHelper.areEqual( newObj, oldObj ) );
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), !Objects.deepEquals( newObj, oldObj ) );
|
||||
}
|
||||
else if ( isFromNullToEmptyOrFromEmptyToNull( (PersistentCollection) newObj, (Serializable) oldObj ) ) {
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), true );
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.envers.internal.entities.mapper.relation;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
|
@ -17,7 +18,6 @@ import org.hibernate.envers.internal.entities.mapper.id.IdMapper;
|
|||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.internal.tools.EntityTools;
|
||||
import org.hibernate.envers.internal.tools.query.Parameters;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ public class ToOneIdMapper extends AbstractToOneMapper {
|
|||
resolvedOldObjectId = EntityTools.getIdentifier( session, referencedEntityName, oldObj );
|
||||
}
|
||||
|
||||
return !EqualsHelper.areEqual( resolvedNewObjectId, resolvedOldObjectId );
|
||||
return !Objects.deepEquals( resolvedNewObjectId, resolvedOldObjectId );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.tools;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
|
@ -22,7 +23,7 @@ public abstract class EntityTools {
|
|||
final Object id1 = getIdentifier( session, entityName, obj1 );
|
||||
final Object id2 = getIdentifier( session, entityName, obj2 );
|
||||
|
||||
return EqualsHelper.areEqual( id1, id2 );
|
||||
return Objects.deepEquals( id1, id2 );
|
||||
}
|
||||
|
||||
public static Object getIdentifier(SessionImplementor session, String entityName, Object obj) {
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.hibernate.envers.tools.Pair;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
|
@ -38,16 +37,6 @@ public abstract class Tools {
|
|||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated (since 5.2), use {@link EqualsHelper#areEqual(Object, Object)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean objectsEqual(Object obj1, Object obj2) {
|
||||
// HHH-10734
|
||||
// Delegates to core's EqualsHelper to support array and non-array types
|
||||
return EqualsHelper.areEqual( obj1, obj2 );
|
||||
}
|
||||
|
||||
public static <T> List<T> iteratorToList(Iterator<T> iter) {
|
||||
final List<T> ret = new ArrayList<>();
|
||||
while ( iter.hasNext() ) {
|
||||
|
|
Loading…
Reference in New Issue