Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Hibernate ORM to 6.2.8.Final #1745

Merged
merged 6 commits into from
Sep 1, 2023
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Hibernate Reactive has been tested with:
- CockroachDB 22.1
- MS SQL Server 2019
- Oracle 21.3
- [Hibernate ORM][] 6.2.7.Final
- [Hibernate ORM][] 6.2.8.Final
- [Vert.x Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg-client/java/) 4.4.5
- [Vert.x Reactive MySQL Client](https://vertx.io/docs/vertx-mysql-client/java/) 4.4.5
- [Vert.x Reactive Db2 Client](https://vertx.io/docs/vertx-db2-client/java/) 4.4.5
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ version = projectVersion
// ./gradlew clean build -PhibernateOrmVersion=5.6.15-SNAPSHOT
ext {
if ( !project.hasProperty('hibernateOrmVersion') ) {
hibernateOrmVersion = '6.2.7.Final'
hibernateOrmVersion = '6.2.8.Final'
}
if ( !project.hasProperty( 'hibernateOrmGradlePluginVersion' ) ) {
// Same as ORM as default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public ParameterMetaData getParameterMetaData() {

@Override
public void setRowId(int parameterIndex, RowId x) {
throw new UnsupportedOperationException();
put( parameterIndex, Buffer.buffer( x.getBytes() ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Calendar;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Function;

import org.hibernate.engine.jdbc.BlobProxy;
Expand Down Expand Up @@ -847,12 +848,31 @@ public SQLXML getSQLXML(String columnLabel) {

@Override
public RowId getRowId(int columnIndex) {
throw new UnsupportedOperationException();
Buffer buffer = row.getBuffer( columnIndex - 1 );
wasNull = buffer == null;
return wasNull ? null : new RowIdAdaptor( buffer );
}

@Override
public RowId getRowId(String columnLabel) {
throw new UnsupportedOperationException();
Buffer buffer = row.getBuffer( columnLabel );
wasNull = buffer == null;
return wasNull ? null : new RowIdAdaptor( buffer );
}

private static class RowIdAdaptor implements RowId {

private final Buffer buffer;

private RowIdAdaptor(Buffer buffer) {
Objects.requireNonNull( buffer );
this.buffer = buffer;
}

@Override
public byte[] getBytes() {
return buffer.getBytes();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
import org.hibernate.HibernateException;
import org.hibernate.action.internal.AbstractEntityInsertAction;
import org.hibernate.action.internal.EntityInsertAction;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.entry.CacheEntry;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister;
import org.hibernate.stat.internal.StatsHelper;
import org.hibernate.stat.spi.StatisticsImplementor;

import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
Expand Down Expand Up @@ -104,28 +100,6 @@ public CompletionStage<Void> reactiveExecute() throws HibernateException {
}
}

//TODO: copy/paste from superclass (make it protected)
private void putCacheIfNecessary() {
final EntityPersister persister = getPersister();
final SharedSessionContractImplementor session = getSession();
if ( isCachePutEnabled( persister, session ) ) {
final SessionFactoryImplementor factory = session.getFactory();
final CacheEntry ce = persister.buildCacheEntry( getInstance(), getState(), getVersion(), session );
setCacheEntry( persister.getCacheEntryStructure().structure( ce ) );
final EntityDataAccess cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey( getId(), persister, factory, session.getTenantIdentifier() );
final boolean put = cacheInsert( persister, ck );

final StatisticsImplementor statistics = factory.getStatistics();
if ( put && statistics.isStatisticsEnabled() ) {
statistics.entityCachePut(
StatsHelper.INSTANCE.getRootEntityRole( persister ),
cache.getRegion().getName()
);
}
}
}

private CompletionStage<Void> processInsertGeneratedProperties(
ReactiveEntityPersister persister,
SharedSessionContractImplementor session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@
import java.util.concurrent.CompletionStage;

import org.hibernate.AssertionFailure;
import org.hibernate.CacheMode;
import org.hibernate.HibernateException;
import org.hibernate.action.internal.EntityUpdateAction;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.entry.CacheEntry;
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
import org.hibernate.metamodel.mapping.NaturalIdMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.reactive.engine.ReactiveExecutable;
import org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister;
import org.hibernate.stat.internal.StatsHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.type.TypeHelper;
Expand Down Expand Up @@ -156,82 +150,13 @@ private void handleDeleted(EntityEntry entry, EntityPersister persister, Object
}
}

// TODO: copy/paste from superclass (make it protected)
private void handleNaturalIdResolutions(EntityPersister persister, SharedSessionContractImplementor session, Object id) {
NaturalIdMapping naturalIdMapping = getNaturalIdMapping();
if ( naturalIdMapping != null ) {
session.getPersistenceContextInternal().getNaturalIdResolutions().manageSharedResolution(
id,
naturalIdMapping.extractNaturalIdFromEntityState( getState() ),
getPreviousNaturalIdValues(),
persister,
CachedNaturalIdValueSource.UPDATE
);
}
}

// TODO: copy/paste from superclass (make it protected)
private void updateCacheItem(Object previousVersion, Object ck, EntityEntry entry) {
final EntityPersister persister = getPersister();
if ( persister.canWriteToCache() ) {
final SharedSessionContractImplementor session = getSession();
if ( isCacheInvalidationRequired( persister, session ) || entry.getStatus() != Status.MANAGED ) {
persister.getCacheAccessStrategy().remove( session, ck );
}
else if ( session.getCacheMode().isPutEnabled() ) {
//TODO: inefficient if that cache is just going to ignore the updated state!
final CacheEntry ce = persister.buildCacheEntry( getInstance(), getState(), getNextVersion(), getSession() );
setCacheEntry( persister.getCacheEntryStructure().structure( ce ) );
final boolean put = updateCache( persister, previousVersion, ck );

final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( put && statistics.isStatisticsEnabled() ) {
statistics.entityCachePut(
StatsHelper.INSTANCE.getRootEntityRole(persister),
getPersister().getCacheAccessStrategy().getRegion().getName()
);
}
}
}
}

private static boolean isCacheInvalidationRequired(
EntityPersister persister,
SharedSessionContractImplementor session) {
// the cache has to be invalidated when CacheMode is equal to GET or IGNORE
return persister.isCacheInvalidationRequired()
|| session.getCacheMode() == CacheMode.GET
|| session.getCacheMode() == CacheMode.IGNORE;
}

// TODO: copy/paste from superclass (make it protected)
private Object lockCacheItem(Object previousVersion) {
final EntityPersister persister = getPersister();
if ( persister.canWriteToCache() ) {
final SharedSessionContractImplementor session = getSession();
final EntityDataAccess cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(
getId(),
persister,
session.getFactory(),
session.getTenantIdentifier()
);
setLock( cache.lockItem( session, ck, previousVersion ) );
return ck;
}
else {
return null;
}
}

private CompletionStage<Void> processGeneratedProperties(
Object id,
ReactiveEntityPersister persister,
SharedSessionContractImplementor session,
Object instance) {
if ( persister.hasUpdateGeneratedProperties() ) {
// this entity defines property generation, so process those generated
// values...
// this entity defines property generation, so process those generated values...
if ( persister.isVersionPropertyGenerated() ) {
throw new UnsupportedOperationException( "generated version attribute not supported in Hibernate Reactive" );
// setNextVersion( Versioning.getVersion( getState(), persister ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static org.hibernate.reactive.engine.jdbc.ResultsCheckerUtil.checkResults;
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER_TRACE_ENABLED;

/**
* @see org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor
Expand Down Expand Up @@ -95,7 +94,7 @@ default CompletionStage<Void> performReactiveNonBatchedMutation(

final TableMapping tableDetails = statementDetails.getMutatingTableDetails();
if ( inclusionChecker != null && !inclusionChecker.include( tableDetails ) ) {
if ( MODEL_MUTATION_LOGGER_TRACE_ENABLED ) {
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
MODEL_MUTATION_LOGGER.tracef( "Skipping execution of secondary insert : %s", tableDetails.getTableName() );
}
return voidFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
*/
package org.hibernate.reactive.engine.jdbc.mutation.internal;

import static org.hibernate.reactive.engine.jdbc.ResultsCheckerUtil.checkResults;
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER_TRACE_ENABLED;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicReference;

import org.hibernate.engine.jdbc.mutation.OperationResultChecker;
import org.hibernate.engine.jdbc.mutation.ParameterUsage;
import org.hibernate.engine.jdbc.mutation.TableInclusionChecker;
Expand All @@ -27,6 +24,10 @@
import org.hibernate.sql.model.MutationOperationGroup;
import org.hibernate.sql.model.ValuesAnalysis;

import static org.hibernate.reactive.engine.jdbc.ResultsCheckerUtil.checkResults;
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;

public class ReactiveMutationExecutorPostInsert extends MutationExecutorPostInsert implements ReactiveMutationExecutor {

public ReactiveMutationExecutorPostInsert(
Expand All @@ -53,17 +54,22 @@ public CompletionStage<Object> executeReactive(Object modelReference, ValuesAnal
return completedFuture(id);
}
AtomicReference<CompletionStage<Object>> res = new AtomicReference<>(completedFuture(id));
secondaryTablesStatementGroup.forEachStatement((tableName, statementDetails) -> {
res.set(res.get().thenCompose(i -> reactiveExecuteWithId(i, tableName, statementDetails, inclusionChecker, resultChecker, session)));
});
secondaryTablesStatementGroup
.forEachStatement( (tableName, statementDetails) -> res
.set( res.get().thenCompose( i -> reactiveExecuteWithId( i, tableName, statementDetails, inclusionChecker, resultChecker, session ) ) )
);
return res.get();
});
}

private Object logId(Object identifier) {
if ( MODEL_MUTATION_LOGGER_TRACE_ENABLED ) {
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
MODEL_MUTATION_LOGGER
.tracef( "Post-insert generated value : `%s` (%s)", identifier, mutationTarget.getNavigableRole().getFullPath() );
.tracef(
"Post-insert generated value : `%s` (%s)",
identifier,
mutationTarget.getNavigableRole().getFullPath()
);
}
return identifier;
}
Expand All @@ -77,33 +83,30 @@ private CompletionStage<Object> reactiveExecuteWithId(
SharedSessionContractImplementor session) {

if ( statementDetails == null ) {
return completedFuture(id);
return completedFuture( id );
}

final EntityTableMapping tableDetails = (EntityTableMapping) statementDetails.getMutatingTableDetails();
assert !tableDetails.isIdentifierTable();

if ( inclusionChecker != null && !inclusionChecker.include( tableDetails ) ) {
if ( MODEL_MUTATION_LOGGER_TRACE_ENABLED ) {
MODEL_MUTATION_LOGGER.tracef(
"Skipping execution of secondary insert : %s",
tableDetails.getTableName()
);
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
MODEL_MUTATION_LOGGER
.tracef( "Skipping execution of secondary insert : %s", tableDetails.getTableName() );
}
return completedFuture(id);
return completedFuture( id );
}


tableDetails.getKeyMapping().breakDownKeyJdbcValues(
id,
(jdbcValue, columnMapping) -> {
valueBindings.bindValue(
jdbcValue,
tableName,
columnMapping.getColumnName(),
ParameterUsage.SET
);
},
(jdbcValue, columnMapping) -> valueBindings
.bindValue(
jdbcValue,
tableName,
columnMapping.getColumnName(),
ParameterUsage.SET
),
session
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@
*/
package org.hibernate.reactive.engine.jdbc.mutation.internal;

import java.util.List;
import java.util.concurrent.CompletionStage;

import org.hibernate.engine.jdbc.mutation.OperationResultChecker;
import org.hibernate.engine.jdbc.mutation.TableInclusionChecker;
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
import org.hibernate.engine.jdbc.mutation.internal.MutationExecutorPostInsertSingleTable;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.jdbc.Expectation;
import org.hibernate.persister.entity.mutation.EntityMutationTarget;
import org.hibernate.reactive.engine.jdbc.env.internal.ReactiveMutationExecutor;
import org.hibernate.reactive.id.insert.ReactiveInsertGeneratedIdentifierDelegate;
import org.hibernate.sql.exec.spi.JdbcParameterBinder;
import org.hibernate.sql.model.MutationOperationGroup;
import org.hibernate.sql.model.MutationTarget;
import org.hibernate.sql.model.PreparableMutationOperation;
import org.hibernate.sql.model.TableMapping;
import org.hibernate.sql.model.ValuesAnalysis;
import org.hibernate.sql.model.jdbc.JdbcInsertMutation;

import static org.hibernate.engine.jdbc.mutation.internal.ModelMutationHelper.identityPreparation;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER_TRACE_ENABLED;


public class ReactiveMutationExecutorPostInsertSingleTable extends MutationExecutorPostInsertSingleTable
implements ReactiveMutationExecutor {
Expand All @@ -43,19 +35,6 @@ public ReactiveMutationExecutorPostInsertSingleTable(MutationOperationGroup muta
this.identityInsertStatementDetails = identityPreparation( operation, session );
}

private static class ReactiveIdentityInsertMutation extends JdbcInsertMutation {

public ReactiveIdentityInsertMutation(
TableMapping tableDetails,
MutationTarget<?> mutationTarget,
String sql,
boolean callable,
Expectation expectation,
List<? extends JdbcParameterBinder> parameterBinders) {
super( tableDetails, mutationTarget, sql, callable, expectation, parameterBinders );
}
}

@Override
public CompletionStage<Object> executeReactive(
Object modelReference,
Expand All @@ -74,7 +53,7 @@ public CompletionStage<Object> executeReactive(
}

private Object logId(Object identifier) {
if ( MODEL_MUTATION_LOGGER_TRACE_ENABLED ) {
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
MODEL_MUTATION_LOGGER
.tracef( "Post-insert generated value : `%s` (%s)", identifier, mutationTarget.getNavigableRole().getFullPath() );
}
Expand Down
Loading
Loading