Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jul 17, 2024
1 parent efdc714 commit 5daf463
Show file tree
Hide file tree
Showing 22 changed files with 206 additions and 433 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public class ReactiveGeneratedValuesHelper {
*
* @see GeneratedValuesHelper#getGeneratedValuesDelegate(EntityPersister, EventType)
*/
public static GeneratedValuesMutationDelegate getGeneratedValuesDelegate(
EntityPersister persister,
EventType timing) {
public static GeneratedValuesMutationDelegate getGeneratedValuesDelegate(EntityPersister persister, EventType timing) {
final boolean hasGeneratedProperties = !persister.getGeneratedProperties( timing ).isEmpty();
final boolean hasRowId = timing == EventType.INSERT && persister.getRowIdMapping() != null;
final Dialect dialect = persister.getFactory().getJdbcServices().getDialect();

if ( hasRowId && dialect.supportsInsertReturning() && dialect.supportsInsertReturningRowId()
if ( hasRowId
&& dialect.supportsInsertReturning()
&& dialect.supportsInsertReturningRowId()
&& noCustomSql( persister, timing ) ) {
// Special case for RowId on INSERT, since GetGeneratedKeysDelegate doesn't support it
// make InsertReturningDelegate the preferred method if the dialect supports it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public class ReactiveInsertReturningDelegate extends AbstractReturningDelegate i
private final MutatingTableReference tableReference;
private final List<ColumnReference> generatedColumns;

public ReactiveInsertReturningDelegate(EntityPersister persister, EventType timing) {
this( persister, timing, false );
}

public ReactiveInsertReturningDelegate(EntityPersister persister, Dialect dialect) {
// With JDBC it's possible to enabled GetGeneratedKeys for identity generation.
// Vert.x doesn't have this option, so we always use the same strategy for all database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.hibernate.reactive.persister.entity.impl;

import java.lang.invoke.MethodHandles;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -43,7 +42,6 @@
import org.hibernate.reactive.loader.ast.internal.ReactiveSingleIdArrayLoadPlan;
import org.hibernate.reactive.loader.ast.spi.ReactiveSingleIdEntityLoader;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.logging.impl.LoggerFactory;
import org.hibernate.reactive.metamodel.mapping.internal.ReactiveCompoundNaturalIdMapping;
import org.hibernate.reactive.metamodel.mapping.internal.ReactiveSimpleNaturalIdMapping;
import org.hibernate.reactive.pool.ReactiveConnection;
Expand All @@ -58,11 +56,13 @@

import jakarta.persistence.metamodel.Attribute;

import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Collections.emptyMap;
import static org.hibernate.generator.EventType.INSERT;
import static org.hibernate.generator.EventType.UPDATE;
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
import static org.hibernate.pretty.MessageHelper.infoString;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
import static org.hibernate.reactive.util.impl.CompletionStages.failedFuture;
import static org.hibernate.reactive.util.impl.CompletionStages.logSqlException;
Expand Down Expand Up @@ -90,8 +90,6 @@
*/
public interface ReactiveAbstractEntityPersister extends ReactiveEntityPersister {

Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );

default Parameters parameters() {
return Parameters.instance( getFactory().getJdbcServices().getDialect() );
}
Expand Down Expand Up @@ -259,6 +257,7 @@ default Object nextVersionForLock(LockMode lockMode, Object id, Object currentVe
final Object nextVersion = getVersionJavaType()
.next( currentVersion, versionMapping.getLength(), versionMapping.getPrecision(), versionMapping.getScale(), session );

Log LOG = make( Log.class, lookup() );
if ( LOG.isTraceEnabled() ) {
LOG.trace( "Forcing version increment [" + infoString( this, id, getFactory() ) + "; "
+ versionType.toLoggableString( currentVersion, getFactory() ) + " -> "
Expand Down Expand Up @@ -289,6 +288,7 @@ default ReactiveSingleIdEntityLoader<?> getReactiveSingleIdEntityLoader() {
*/
@Override
default CompletionStage<Object> reactiveGetCurrentVersion(Object id, SharedSessionContractImplementor session) {
Log LOG = make( Log.class, lookup() );
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Getting version: {0}", infoString( this, id, getFactory() ) );
}
Expand Down Expand Up @@ -379,7 +379,8 @@ default CompletionStage<Object> reactiveInitializeLazyPropertiesFromDatastore(
throw new AssertionFailure( "Expecting bytecode interceptor to be non-null" );
}

LOG.tracef( "Initializing lazy properties from datastore (triggered for `%s`)", fieldName );
make( Log.class, lookup() )
.tracef( "Initializing lazy properties from datastore (triggered for `%s`)", fieldName );

final String fetchGroup = getEntityPersister().getBytecodeEnhancementMetadata()
.getLazyAttributesMetadata()
Expand Down Expand Up @@ -459,7 +460,7 @@ default CompletionStage<Object> initLazyProperty(
}

return resultStage.thenApply( result -> {
LOG.trace( "Done initializing lazy properties" );
make( Log.class, lookup() ).trace( "Done initializing lazy properties" );
return result;
} );
}
Expand Down Expand Up @@ -539,12 +540,8 @@ private CompletionStage<?> loadFromDatabaseOrCache(

Object initializeLazyProperty(String fieldName, Object entity, SharedSessionContractImplementor session);

String[][] getLazyPropertyColumnAliases();

ReactiveSingleIdArrayLoadPlan reactiveGetSQLLazySelectLoadPlan(String fetchGroup);

boolean isBatchable();

/**
* @see AbstractEntityPersister#generateNaturalIdMapping(MappingModelCreationProcess, PersistentClass)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.reactive.loader.ast.internal.ReactiveSingleIdArrayLoadPlan;
import org.hibernate.reactive.loader.ast.spi.ReactiveSingleUniqueKeyEntityLoader;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.persister.entity.mutation.ReactiveDeleteCoordinator;
import org.hibernate.reactive.persister.entity.mutation.ReactiveInsertCoordinatorStandard;
import org.hibernate.reactive.persister.entity.mutation.ReactiveUpdateCoordinator;
Expand All @@ -54,13 +55,18 @@
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.EntityType;

import static java.lang.invoke.MethodHandles.lookup;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;

/**
* An {@link ReactiveEntityPersister} backed by {@link JoinedSubclassEntityPersister}
* and {@link ReactiveAbstractEntityPersister}.
*/
public class ReactiveJoinedSubclassEntityPersister extends JoinedSubclassEntityPersister
implements ReactiveAbstractEntityPersister {

private static final Log LOG = make( Log.class, lookup() );

private final ReactiveAbstractPersisterDelegate reactiveDelegate;

public ReactiveJoinedSubclassEntityPersister(
Expand Down Expand Up @@ -291,11 +297,6 @@ public boolean initializeLazyProperty(String fieldName, Object entity, EntityEnt
return super.initializeLazyProperty( fieldName, entity, entry, lazyIndex, selectedValue );
}

@Override
public String[][] getLazyPropertyColumnAliases() {
return super.getLazyPropertyColumnAliases();
}

/**
* Process properties generated with an insert
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.hibernate.generator.Generator;
import org.hibernate.generator.values.GeneratedValues;
import org.hibernate.generator.values.GeneratedValuesMutationDelegate;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.jdbc.Expectation;
import org.hibernate.loader.ast.spi.MultiIdEntityLoader;
import org.hibernate.loader.ast.spi.MultiIdLoadOptions;
Expand All @@ -47,9 +46,9 @@
import org.hibernate.persister.entity.mutation.UpdateCoordinator;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.reactive.generator.values.GeneratedValuesMutationDelegateAdaptor;
import org.hibernate.reactive.generator.values.ReactiveInsertGeneratedIdentifierDelegate;
import org.hibernate.reactive.loader.ast.internal.ReactiveSingleIdArrayLoadPlan;
import org.hibernate.reactive.loader.ast.spi.ReactiveSingleUniqueKeyEntityLoader;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.persister.entity.mutation.ReactiveAbstractDeleteCoordinator;
import org.hibernate.reactive.persister.entity.mutation.ReactiveInsertCoordinatorStandard;
import org.hibernate.reactive.persister.entity.mutation.ReactiveUpdateCoordinator;
Expand All @@ -60,13 +59,18 @@
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.EntityType;

import static java.lang.invoke.MethodHandles.lookup;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;


/**
* A {@link ReactiveEntityPersister} backed by {@link SingleTableEntityPersister}
* and {@link ReactiveAbstractEntityPersister}.
*/
public class ReactiveSingleTableEntityPersister extends SingleTableEntityPersister implements ReactiveAbstractEntityPersister {

private static final Log LOG = make( Log.class, lookup() );

private ReactiveAbstractPersisterDelegate reactiveDelegate;

public ReactiveSingleTableEntityPersister(
Expand Down Expand Up @@ -147,15 +151,6 @@ public GeneratedValuesMutationDelegate getUpdateDelegate() {
return new GeneratedValuesMutationDelegateAdaptor( updateDelegate );
}

@Override
public InsertGeneratedIdentifierDelegate getIdentityInsertDelegate() {
final GeneratedValuesMutationDelegate insertDelegate = super.getInsertDelegate();
if ( insertDelegate instanceof InsertGeneratedIdentifierDelegate ) {
return new ReactiveInsertGeneratedIdentifierDelegate( (InsertGeneratedIdentifierDelegate) insertDelegate );
}
return null;
}

@Override
public <T> DomainResult<T> createDomainResult(
NavigablePath navigablePath,
Expand Down Expand Up @@ -232,11 +227,6 @@ public Object initializeLazyPropertiesFromDatastore(final Object entity, final O
return reactiveInitializeLazyPropertiesFromDatastore( entity, id, entry, fieldName, session );
}

@Override
public String[][] getLazyPropertyColumnAliases() {
return super.getLazyPropertyColumnAliases();
}

@Override
public Object insert(Object[] fields, Object object, SharedSessionContractImplementor session) {
throw LOG.nonReactiveMethodCall( "insertReactive" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ public Generator getGenerator() throws HibernateException {
return reactiveDelegate.reactive( super.getGenerator() );
}

@Override
public String[][] getLazyPropertyColumnAliases() {
return super.getLazyPropertyColumnAliases();
}

@Override
public boolean check(int rows, Object id, int tableNumber, Expectation expectation, PreparedStatement statement, String sql) throws HibernateException {
return super.check(rows, id, tableNumber, expectation, statement, sql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ public ReactiveInsertCoordinatorStandard(AbstractEntityPersister entityPersister
batchKey = null;
}
else {
batchKey = new BasicBatchKey(
entityPersister.getEntityName() + "#INSERT",
null
);
batchKey = new BasicBatchKey( entityPersister.getEntityName() + "#INSERT" );
}

if ( entityPersister.getEntityMetamodel().isDynamicInsert() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import org.hibernate.engine.jdbc.batch.spi.BatchKey;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.mutation.EntityTableMapping;
import org.hibernate.sql.model.MutationOperation;
import org.hibernate.sql.model.MutationOperationGroup;
Expand All @@ -20,7 +20,7 @@
*/
public class ReactiveMergeCoordinator extends ReactiveUpdateCoordinatorStandard {
public ReactiveMergeCoordinator(
AbstractEntityPersister entityPersister,
EntityPersister entityPersister,
SessionFactoryImplementor factory,
MutationOperationGroup staticUpdateGroup,
BatchKey batchKey,
Expand Down
Loading

0 comments on commit 5daf463

Please sign in to comment.