Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package org.hibernate.boot.internal;

import java.util.Map;
import java.util.function.Supplier;

import org.hibernate.CustomEntityDirtinessStrategy;
Expand Down Expand Up @@ -59,7 +58,7 @@ public SessionFactoryBuilderImpl(MetadataImplementor metadata, SessionFactoryOpt
this.bootstrapContext = context;

if ( metadata.getSqlFunctionMap() != null ) {
for ( Map.Entry<String, SqmFunctionDescriptor> sqlFunctionEntry : metadata.getSqlFunctionMap().entrySet() ) {
for ( var sqlFunctionEntry : metadata.getSqlFunctionMap().entrySet() ) {
applySqlFunction( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public ColumnsBuilder extractMetadata() {
columns = buildColumnFromAnnotation(
columnAnn,
property.getDirectAnnotationUsage( FractionalSeconds.class ),
// comment,
nullability,
propertyHolder,
inferredData,
Expand Down Expand Up @@ -149,7 +148,6 @@ else if ( joinColumns == null
//useful for collection of embedded elements
columns = buildColumnFromNoAnnotation(
property.getDirectAnnotationUsage( FractionalSeconds.class ),
// comment,
nullability,
propertyHolder,
inferredData,
Expand Down Expand Up @@ -196,7 +194,7 @@ private AnnotatedJoinColumns buildDefaultJoinColumnsForToOne(

private AnnotatedJoinColumns buildExplicitJoinColumns(MemberDetails property, PropertyData inferredData) {
// process @JoinColumns before @Columns to handle collection of entities properly
final JoinColumn[] joinColumnAnnotations = getJoinColumnAnnotations( property, inferredData );
final JoinColumn[] joinColumnAnnotations = getJoinColumnAnnotations( property );
if ( joinColumnAnnotations != null ) {
return AnnotatedJoinColumns.buildJoinColumns(
joinColumnAnnotations,
Expand All @@ -208,7 +206,7 @@ private AnnotatedJoinColumns buildExplicitJoinColumns(MemberDetails property, Pr
);
}

final JoinColumnOrFormula[] joinColumnOrFormulaAnnotations = joinColumnOrFormulaAnnotations( property, inferredData );
final JoinColumnOrFormula[] joinColumnOrFormulaAnnotations = joinColumnOrFormulaAnnotations( property );
if ( joinColumnOrFormulaAnnotations != null ) {
return AnnotatedJoinColumns.buildJoinColumnsOrFormulas(
joinColumnOrFormulaAnnotations,
Expand All @@ -234,20 +232,16 @@ private AnnotatedJoinColumns buildExplicitJoinColumns(MemberDetails property, Pr
return null;
}

private JoinColumnOrFormula[] joinColumnOrFormulaAnnotations(MemberDetails property, PropertyData inferredData) {
private JoinColumnOrFormula[] joinColumnOrFormulaAnnotations(MemberDetails property) {
final ModelsContext modelsContext = buildingContext.getBootstrapContext().getModelsContext();
final JoinColumnOrFormula[] annotations = property.getRepeatedAnnotationUsages(
HibernateAnnotations.JOIN_COLUMN_OR_FORMULA,
modelsContext
);
if ( isNotEmpty( annotations ) ) {
return annotations;
}

return null;
return isNotEmpty( annotations ) ? annotations : null;
}

private JoinColumn[] getJoinColumnAnnotations(MemberDetails property, PropertyData inferredData) {
private JoinColumn[] getJoinColumnAnnotations(MemberDetails property) {
final ModelsContext modelsContext = buildingContext.getBootstrapContext().getModelsContext();

final JoinColumn[] joinColumns = property.getRepeatedAnnotationUsages(
Expand All @@ -257,8 +251,7 @@ private JoinColumn[] getJoinColumnAnnotations(MemberDetails property, PropertyDa
if ( isNotEmpty( joinColumns ) ) {
return joinColumns;
}

if ( property.hasDirectAnnotationUsage( MapsId.class ) ) {
else if ( property.hasDirectAnnotationUsage( MapsId.class ) ) {
// inelegant solution to HHH-16463, let the PrimaryKeyJoinColumn
// masquerade as a regular JoinColumn (when a @OneToOne maps to
// the primary key of the child table, it's more elegant and more
Expand All @@ -275,19 +268,24 @@ private JoinColumn[] getJoinColumnAnnotations(MemberDetails property, PropertyDa
}
return adapters;
}
else {
return null;
}
}
else {
return null;
}

return null;
}

/**
* Useful to override a column either by {@code @MapsId} or by {@code @IdClass}
*/
AnnotatedColumns overrideColumnFromMapperOrMapsIdProperty(PropertyData override) {
if ( override != null ) {
final AnnotatedJoinColumns joinColumns = buildExplicitJoinColumns( override.getAttributeMember(), override );
final MemberDetails attributeMember = override.getAttributeMember();
final AnnotatedJoinColumns joinColumns = buildExplicitJoinColumns( attributeMember, override );
return joinColumns == null
? buildDefaultJoinColumnsForToOne( override.getAttributeMember(), override )
? buildDefaultJoinColumnsForToOne( attributeMember, override )
: joinColumns;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -477,7 +476,7 @@ protected void closeConnection(Connection conn, Throwable t) {

public void close() throws SQLException {
try {
int allocationCount = allConnections.size() - availableConnections.size();
final int allocationCount = allConnections.size() - availableConnections.size();
if (allocationCount > 0) {
ConnectionInfoLogger.INSTANCE.error( "Connection leak detected: there are " + allocationCount + " unclosed connections upon shutting down pool " + getUrl());
}
Expand Down Expand Up @@ -653,8 +652,7 @@ private void validateConnections(ConnectionValidator validator) {
statelock.writeLock().lock();
try {
RuntimeException ex = null;
for ( Iterator<Connection> iterator = pool.allConnections.iterator(); iterator.hasNext(); ) {
final Connection connection = iterator.next();
for ( Connection connection : pool.allConnections ) {
SQLException e = null;
boolean isValid = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,27 @@ public void nullSafeSet(
}

@Override
public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
public String toLoggableString(Object value, SessionFactoryImplementor factory) {
return value == null ? "[null]" : value.toString();
}

@Override
public Object deepCopy(Object value, SessionFactoryImplementor factory)
throws HibernateException {
public Object deepCopy(Object value, SessionFactoryImplementor factory) {
return value;
}

@Override
public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map<Object, Object> copyCache)
throws HibernateException {
public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map<Object, Object> copyCache) {
return original;
}

@Override
public boolean[] toColumnNullness(Object value, MappingContext mapping) {
return value == null
? ArrayHelper.FALSE
: ArrayHelper.TRUE;
return value == null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
}

@Override
public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session)
throws HibernateException {
public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) {
return Objects.equals( old, current );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.hibernate.engine.jdbc.mutation.ParameterUsage;
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.AttributeMapping;
Expand Down Expand Up @@ -74,12 +73,11 @@ public void delete(
SharedSessionContractImplementor session) {
boolean isImpliedOptimisticLocking = entityPersister().optimisticLockStyle().isAllOrDirty();

final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.getEntry( entity );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( entity );
final Object[] loadedState = entry != null && isImpliedOptimisticLocking ? entry.getLoadedState() : null;
final Object rowId = entry != null ? entry.getRowId() : null;

if ( ( isImpliedOptimisticLocking && loadedState != null ) || ( rowId == null && entityPersister().hasRowId() ) ) {
if ( isImpliedOptimisticLocking && loadedState != null || rowId == null && entityPersister().hasRowId() ) {
doDynamicDelete( entity, id, rowId, loadedState, session );
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,10 @@ public final void beforeAssemble(Serializable cached, SharedSessionContractImple
@Override
@SuppressWarnings("unchecked")
public final Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map<Object, Object> copyCache) {
if ( original == null && target == null ) {
return null;
}
return original == null && target == null
? null
: javaType.getReplacement( (T) original, (T) target, session );

return javaType.getReplacement( (T) original, (T) target, session );
}

@Override
Expand Down
124 changes: 62 additions & 62 deletions hibernate-core/src/main/java/org/hibernate/type/ComponentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,7 @@ public boolean isModified(
@Override
public void nullSafeSet(PreparedStatement st, Object value, int begin, SharedSessionContractImplementor session)
throws HibernateException, SQLException {

Object[] subvalues = nullSafeGetValues( value );

final Object[] subvalues = nullSafeGetValues( value );
for ( int i = 0; i < propertySpan; i++ ) {
propertyTypes[i].nullSafeSet( st, subvalues[i], begin, session );
begin += propertyTypes[i].getColumnSpan( session.getFactory().getRuntimeMetamodels() );
Expand All @@ -372,7 +370,6 @@ public void nullSafeSet(
boolean[] settable,
SharedSessionContractImplementor session)
throws HibernateException, SQLException {

final Object[] subvalues = nullSafeGetValues( value );
int loc = 0;
for ( int i = 0; i < propertySpan; i++ ) {
Expand Down Expand Up @@ -481,18 +478,19 @@ public String toLoggableString(Object value, SessionFactoryImplementor factory)
if ( value == null ) {
return "null";
}

final Map<String, String> result = new HashMap<>();
final Object[] values = getPropertyValues( value );
for ( int i = 0; i < propertyTypes.length; i++ ) {
if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
result.put( propertyNames[i], "<uninitialized>" );
}
else {
result.put( propertyNames[i], propertyTypes[i].toLoggableString( values[i], factory ) );
else {
final Map<String, String> result = new HashMap<>();
final Object[] values = getPropertyValues( value );
for ( int i = 0; i < propertyTypes.length; i++ ) {
if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
result.put( propertyNames[i], "<uninitialized>" );
}
else {
result.put( propertyNames[i], propertyTypes[i].toLoggableString( values[i], factory ) );
}
}
return unqualify( getName() ) + result;
}
return unqualify( getName() ) + result;
}

@Override
Expand All @@ -505,22 +503,23 @@ public Object deepCopy(Object component, SessionFactoryImplementor factory) {
if ( component == null ) {
return null;
}
else {
final Object[] values = getPropertyValues( component );
for ( int i = 0; i < propertySpan; i++ ) {
values[i] = propertyTypes[i].deepCopy( values[i], factory );
}

final Object[] values = getPropertyValues( component );
for ( int i = 0; i < propertySpan; i++ ) {
values[i] = propertyTypes[i].deepCopy( values[i], factory );
}
final Object result = instantiator( component ).instantiate( () -> values );

final Object result = instantiator( component ).instantiate( () -> values );
//not absolutely necessary, but helps for some
//equals()/hashCode() implementations
final PropertyAccess parentAccess = mappingModelPart().getParentInjectionAttributePropertyAccess();
if ( parentAccess != null ) {
parentAccess.getSetter().set( result, parentAccess.getGetter().get( component ) );
}

//not absolutely necessary, but helps for some
//equals()/hashCode() implementations
final PropertyAccess parentAccess = mappingModelPart().getParentInjectionAttributePropertyAccess();
if ( parentAccess != null ) {
parentAccess.getSetter().set( result, parentAccess.getGetter().get( component ) );
return result;
}

return result;
}

@Override
Expand All @@ -530,28 +529,28 @@ public Object replace(
SharedSessionContractImplementor session,
Object owner,
Map<Object, Object> copyCache) {

if ( original == null ) {
return null;
}

final Object[] originalValues = getPropertyValues( original );
final Object[] resultValues = getPropertyValues( target );
final Object[] replacedValues = TypeHelper.replace(
originalValues,
resultValues,
propertyTypes,
session,
owner,
copyCache
);

if ( target == null || !isMutable() ) {
return instantiator( original ).instantiate( () -> replacedValues );
}
else {
setPropertyValues( target, replacedValues );
return target;
final Object[] originalValues = getPropertyValues( original );
final Object[] resultValues = getPropertyValues( target );
final Object[] replacedValues = TypeHelper.replace(
originalValues,
resultValues,
propertyTypes,
session,
owner,
copyCache
);

if ( target == null || !isMutable() ) {
return instantiator( original ).instantiate( () -> replacedValues );
}
else {
setPropertyValues( target, replacedValues );
return target;
}
}
}

Expand All @@ -563,28 +562,29 @@ public Object replace(
Object owner,
Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection) {

if ( original == null ) {
return null;
}
final Object[] originalValues = getPropertyValues( original );
final Object[] resultValues = getPropertyValues( target );
final Object[] replacedValues = TypeHelper.replace(
originalValues,
resultValues,
propertyTypes,
session,
owner,
copyCache,
foreignKeyDirection
);

if ( target == null || !isMutable() ) {
return instantiator( original ).instantiate( () -> replacedValues );
}
else {
setPropertyValues( target, replacedValues );
return target;
final Object[] originalValues = getPropertyValues( original );
final Object[] resultValues = getPropertyValues( target );
final Object[] replacedValues = TypeHelper.replace(
originalValues,
resultValues,
propertyTypes,
session,
owner,
copyCache,
foreignKeyDirection
);

if ( target == null || !isMutable() ) {
return instantiator( original ).instantiate( () -> replacedValues );
}
else {
setPropertyValues( target, replacedValues );
return target;
}
}
}

Expand Down
Loading