Skip to content

Some clean up #1771

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

Merged
merged 4 commits into from
Oct 2, 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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
# We want to enable preview features when testing newer builds of OpenJDK:
# even if we don't use these features, just enabling them can cause side effects
# and it's useful to test that.
- { name: "20", java_version_numeric: 20, from: 'jdk.java.net', jvm_args: '--enable-preview' }
- { name: "20", java_version_numeric: 20, jvm_args: '--enable-preview' }
- { name: "21-ea", java_version_numeric: 21, from: 'jdk.java.net', jvm_args: '--enable-preview' }
- { name: "22-ea", java_version_numeric: 22, from: 'jdk.java.net', jvm_args: '--enable-preview' }
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
*/
package org.hibernate.reactive.common;

import org.hibernate.Incubating;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.collections.ArrayHelper;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.hibernate.Incubating;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.collections.ArrayHelper;

import static java.util.Collections.addAll;

/**
* A description of the entities and tables affected by a native query.
* <p>
Expand All @@ -25,7 +27,6 @@
*/
@Incubating
public class AffectedEntities {
private static final Class<?>[] NO_ENTITIES = new Class[0];
private static final String[] NO_TABLES = new String[0];

private final String[] queryTables;
Expand All @@ -36,11 +37,6 @@ public AffectedEntities(Class<?>... queryEntities) {
this.queryEntities = queryEntities;
}

public AffectedEntities(String... queryTables) {
this.queryTables = queryTables;
this.queryEntities = NO_ENTITIES;
}

public String[] getAffectedTables() {
return queryTables;
}
Expand All @@ -51,11 +47,11 @@ public Class<?>[] getAffectedEntities() {

public String[] getAffectedSpaces(SessionFactoryImplementor factory) {
List<String> spaces = new ArrayList<>();
for ( String table : getAffectedTables() ) {
spaces.add( table );
}
addAll( spaces, getAffectedTables() );
for ( Class<?> entity : getAffectedEntities() ) {
Serializable[] querySpaces = factory.getMetamodel().entityPersister( entity ).getQuerySpaces();
Serializable[] querySpaces = factory.getMappingMetamodel()
.getEntityDescriptor( entity.getName() )
.getQuerySpaces();
spaces.addAll( Arrays.asList( (String[]) querySpaces ) );
}
return spaces.toArray( ArrayHelper.EMPTY_STRING_ARRAY );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,8 @@ public void sort(List<ReactiveEntityInsertActionHolder> insertions) {
actionDelegate.getEntityName(),
actionDelegate.getSession()
.getFactory()
.getMetamodel()
.entityPersister( actionDelegate.getEntityName() )
.getMappingMetamodel()
.getEntityDescriptor( actionDelegate.getEntityName() )
.getRootEntityName()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.DeleteContext;
import org.hibernate.event.spi.EventSource;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
Expand Down Expand Up @@ -314,7 +315,7 @@ private void cascadeLogicalOneToOneOrphanRemoval(
// Since the loadedState in the EntityEntry is a flat domain type array
// We first have to extract the component object and then ask the component type
// recursively to give us the value of the sub-property of that object
final Type propertyType = entry.getPersister().getPropertyType( componentPath.get(0) );
final AttributeMapping propertyType = entry.getPersister().findAttributeMapping( componentPath.get( 0) );
if ( propertyType instanceof ComponentType) {
loadedValue = entry.getLoadedValue( componentPath.get( 0 ) );
ComponentType componentType = (ComponentType) propertyType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
Expand Down Expand Up @@ -394,8 +395,8 @@ else if ( isPersistentAttributeInterceptable( value ) ) {
// We now have the value of the property-ref we reference. However,
// we need to dig a little deeper, as that property might also be
// an entity type, in which case we need to resolve its identifier
final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) {
final AttributeMapping type = entityPersister.findAttributeMapping( uniqueKeyPropertyName );
if ( type.isEntityIdentifierMapping() ) {
propertyValue = getIdentifier( (EntityType) type, propertyValue, session );
}
return completedFuture( propertyValue );
Expand All @@ -421,8 +422,8 @@ private static CompletionStage<Object> getIdentifierFromHibernateProxy(
// We now have the value of the property-ref we reference. However,
// we need to dig a little deeper, as that property might also be
// an entity type, in which case we need to resolve its identifier
final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) {
final AttributeMapping type = entityPersister.findAttributeMapping( uniqueKeyPropertyName );
if ( type.isEntityIdentifierMapping() ) {
propertyValue = getIdentifier( (EntityType) type, propertyValue, (SessionImplementor) session );
}
return completedFuture( propertyValue );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void onFlushEntity(FlushEntityEvent event) throws HibernateException {
// now update the object
// has to be outside the main if block above (because of collections)
if ( substitute ) {
persister.setPropertyValues( entity, values );
persister.setValues( entity, values );
}

// Search for collections by reachability, updating their role.
Expand Down Expand Up @@ -266,7 +266,7 @@ private boolean scheduleUpdate(final FlushEntityEvent event) {
dirtyProperties,
event.hasDirtyCollection(),
status == Status.DELETED && !entry.isModifiableEntity()
? persister.getPropertyValues( entity )
? persister.getValues( entity )
: entry.getLoadedState(),
entry.getVersion(),
nextVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.hibernate.reactive.event.impl;

import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.Map;
import java.util.concurrent.CompletionStage;
Expand Down Expand Up @@ -126,7 +125,7 @@ public CompletionStage<Void> reactiveOnMerge(MergeEvent event, MergeContext copi
if ( lazyInitializer != null ) {
if ( lazyInitializer.isUninitialized() ) {
LOG.trace( "Ignoring uninitialized proxy" );
event.setResult( source.load( lazyInitializer.getEntityName(), lazyInitializer.getInternalIdentifier() ) );
event.setResult( source.getReference( lazyInitializer.getEntityName(), lazyInitializer.getInternalIdentifier() ) );
return voidFuture();
}
else {
Expand All @@ -140,7 +139,7 @@ else if ( isPersistentAttributeInterceptable( original ) ) {
final EnhancementAsProxyLazinessInterceptor proxyInterceptor = (EnhancementAsProxyLazinessInterceptor) interceptor;
LOG.trace( "Ignoring uninitialized enhanced-proxy" );
//no need to go async, AFAICT ?
event.setResult( source.load( proxyInterceptor.getEntityName(), (Serializable) proxyInterceptor.getIdentifier() ) );
event.setResult( source.getReference( proxyInterceptor.getEntityName(), proxyInterceptor.getIdentifier() ) );
//EARLY EXIT!
return voidFuture();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DatabaseSnapshotExecutor {
LockOptions.NONE,
DatabaseSnapshotExecutor::visitEmptyFetchList,
true,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
sessionFactory
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public CompletionStage<Object> reactiveSelectByNaturalId(
lockOptions,
fetchProcessor,
true,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
sessionFactory
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.hibernate.loader.ast.internal.SingleIdLoadPlan;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.query.internal.SimpleQueryOptions;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
Expand All @@ -36,13 +35,13 @@
public class ReactiveSingleIdLoadPlan<T> extends SingleIdLoadPlan<CompletionStage<T>> {

public ReactiveSingleIdLoadPlan(
EntityMappingType persister,
EntityMappingType entityMappingType,
ModelPart restrictivePart,
SelectStatement sqlAst,
JdbcParametersList jdbcParameters,
LockOptions lockOptions,
SessionFactoryImplementor sessionFactory) {
super( persister, restrictivePart, sqlAst, jdbcParameters, lockOptions, sessionFactory );
super( entityMappingType, restrictivePart, sqlAst, jdbcParameters, lockOptions, sessionFactory );
}

@Override
Expand Down Expand Up @@ -77,7 +76,7 @@ public CompletionStage<T> load(Object restrictedValue, Object entityInstance, Bo

private <T> void invokeAfterLoadActions(Callback callback, SharedSessionContractImplementor session, T entity) {
if ( entity != null && getLoadable() != null) {
callback.invokeAfterLoadActions( session, entity, (Loadable) getLoadable() );
callback.invokeAfterLoadActions( entity, (EntityMappingType) getLoadable(), session );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public CompletionStage<T> load(Object ukValue, LockOptions lockOptions, Boolean
Collections.emptyList(),
uniqueKeyAttribute,
null,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
LockOptions.NONE,
jdbcParametersListBuilder::add,
sessionFactory
Expand Down Expand Up @@ -131,7 +131,7 @@ public Object resolveId(Object ukValue, SharedSessionContractImplementor session
Collections.singletonList( entityDescriptor.getIdentifierMapping() ),
uniqueKeyAttribute,
null,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
LockOptions.NONE,
jdbcParametersListBuilder::add,
sessionFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.hibernate.metamodel.mapping.*;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.reactive.adaptor.impl.PreparedStatementAdaptor;
import org.hibernate.reactive.loader.ast.internal.ReactiveSingleIdArrayLoadPlan;
import org.hibernate.reactive.loader.ast.spi.ReactiveSingleIdEntityLoader;
Expand Down Expand Up @@ -85,7 +83,7 @@
* @see ReactiveUnionSubclassEntityPersister
* @see ReactiveSingleTableEntityPersister
*/
public interface ReactiveAbstractEntityPersister extends ReactiveEntityPersister, OuterJoinLoadable, Lockable {
public interface ReactiveAbstractEntityPersister extends ReactiveEntityPersister {

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

Expand Down Expand Up @@ -117,11 +115,11 @@ default String generateSelectLockString(LockOptions lockOptions) {
final SessionFactoryImplementor factory = getFactory();
final SimpleSelect select = new SimpleSelect( factory )
.setLockOptions( lockOptions )
.setTableName( getRootTableName() )
.addColumn( getRootTableIdentifierColumnNames()[0] )
.addRestriction( getRootTableIdentifierColumnNames() );
.setTableName( getEntityMappingType().getMappedTableDetails().getTableName() )
.addColumn( getIdentifierPropertyName() )
.addRestriction( getIdentifierPropertyName() );
if ( isVersioned() ) {
select.addRestriction( getVersionColumnName() );
select.addRestriction( getVersionMapping().getVersionAttribute().getAttributeName() );
}
if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) {
select.setComment( lockOptions.getLockMode() + " lock " + getEntityName() );
Expand All @@ -132,10 +130,10 @@ default String generateSelectLockString(LockOptions lockOptions) {
default String generateUpdateLockString(LockOptions lockOptions) {
final SessionFactoryImplementor factory = getFactory();
final Update update = new Update( factory );
update.setTableName( getRootTableName() );
update.addAssignment( getVersionColumnName() );
update.addRestriction( getRootTableIdentifierColumnNames() );
update.addRestriction( getVersionColumnName() );
update.setTableName( getEntityMappingType().getMappedTableDetails().getTableName() );
update.addAssignment( getVersionMapping().getVersionAttribute().getAttributeName() );
update.addRestriction( getIdentifierPropertyName() );
update.addRestriction( getVersionMapping().getVersionAttribute().getAttributeName() );
if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) {
update.setComment( lockOptions.getLockMode() + " lock " + getEntityName() );
}
Expand Down Expand Up @@ -261,8 +259,7 @@ default Object nextVersionForLock(LockMode lockMode, Object id, Object currentVe

@Override
default CompletionStage<Object[]> reactiveGetDatabaseSnapshot(Object id, SharedSessionContractImplementor session) {
ReactiveSingleIdEntityLoader<?> reactiveSingleIdEntityLoader = getReactiveSingleIdEntityLoader();
return reactiveSingleIdEntityLoader.reactiveLoadDatabaseSnapshot( id, session );
return getReactiveSingleIdEntityLoader().reactiveLoadDatabaseSnapshot( id, session );
}

default ReactiveSingleIdEntityLoader<?> getReactiveSingleIdEntityLoader() {
Expand Down Expand Up @@ -327,7 +324,7 @@ else if ( result instanceof PersistentCollection ) {
final String[] propertyNames = getPropertyNames();
for ( int index=0; index<propertyNames.length; index++ ) {
if ( propertyNames[index].equals( field ) ) {
setPropertyValue( entity, index, result );
setValue( entity, index, result );
break;
}
}
Expand Down Expand Up @@ -367,10 +364,10 @@ default CompletionStage<Object> reactiveInitializeLazyPropertiesFromDatastore(

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

final String fetchGroup = getEntityMetamodel().getBytecodeEnhancementMetadata()
final String fetchGroup = getEntityPersister().getBytecodeEnhancementMetadata()
.getLazyAttributesMetadata()
.getFetchGroupName( fieldName );
final List<LazyAttributeDescriptor> fetchGroupAttributeDescriptors = getEntityMetamodel().getBytecodeEnhancementMetadata()
final List<LazyAttributeDescriptor> fetchGroupAttributeDescriptors = getEntityPersister().getBytecodeEnhancementMetadata()
.getLazyAttributesMetadata()
.getFetchGroupAttributeDescriptors( fetchGroup );

Expand Down Expand Up @@ -455,7 +452,7 @@ default CompletionStage<Object> reactiveInitializeEnhancedEntityUsedAsProxy(
String nameOfAttributeBeingAccessed,
SharedSessionContractImplementor session) {

final BytecodeEnhancementMetadata enhancementMetadata = getEntityMetamodel().getBytecodeEnhancementMetadata();
final BytecodeEnhancementMetadata enhancementMetadata = getEntityPersister().getBytecodeEnhancementMetadata();
final BytecodeLazyAttributeInterceptor currentInterceptor = enhancementMetadata.extractLazyInterceptor( entity );
if ( currentInterceptor instanceof EnhancementAsProxyLazinessInterceptor) {
final EnhancementAsProxyLazinessInterceptor proxyInterceptor =
Expand Down Expand Up @@ -540,11 +537,11 @@ default NaturalIdMapping generateNaturalIdMapping(
//noinspection AssertWithSideEffects
assert bootEntityDescriptor.hasNaturalId();

final int[] naturalIdAttributeIndexes = getEntityMetamodel().getNaturalIdentifierProperties();
final int[] naturalIdAttributeIndexes = getEntityPersister().getNaturalIdentifierProperties();
assert naturalIdAttributeIndexes.length > 0;

if ( naturalIdAttributeIndexes.length == 1 ) {
final String propertyName = getEntityMetamodel().getPropertyNames()[naturalIdAttributeIndexes[0]];
final String propertyName = getEntityPersister().getAttributeMappings().get(naturalIdAttributeIndexes[0]).getAttributeName();
final AttributeMapping attributeMapping = findAttributeMapping( propertyName );
final SingularAttributeMapping singularAttributeMapping = (SingularAttributeMapping) attributeMapping;
return new ReactiveSimpleNaturalIdMapping( singularAttributeMapping, this, creationProcess );
Expand Down Expand Up @@ -584,7 +581,7 @@ default NaturalIdLoader<?> getNaturalIdLoader() {
* @see AbstractEntityPersister#getLazyLoadPlanByFetchGroup()
*/
default Map<String, ReactiveSingleIdArrayLoadPlan> getLazyLoadPlanByFetchGroup(String[] subclassPropertyNameClosure ) {
final BytecodeEnhancementMetadata metadata = delegate().getEntityMetamodel().getBytecodeEnhancementMetadata();
final BytecodeEnhancementMetadata metadata = delegate().getEntityPersister().getBytecodeEnhancementMetadata();
return metadata.isEnhancedForLazyLoading() && metadata.getLazyAttributesMetadata().hasLazyAttributes()
? createLazyLoadPlanByFetchGroup( metadata, subclassPropertyNameClosure )
: emptyMap();
Expand Down Expand Up @@ -626,7 +623,7 @@ default ReactiveSingleIdArrayLoadPlan createLazyLoadPlan(List<LazyAttributeDescr
getIdentifierMapping(),
null,
1,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( factory ),
LockOptions.NONE,
jdbcParametersListBuilder::add,
factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private CompletionStage<Void> reactivePreInsertInMemoryValueGeneration(Object[]
stage = stage.thenCompose( v -> generateValue( session, entity, currentValue, beforeGenerator, INSERT )
.thenAccept( generatedValue -> {
currentValues[index] = generatedValue;
entityPersister().setPropertyValue( entity, index, generatedValue );
entityPersister().setValue( entity, index, generatedValue );
} ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private CompletionStage<int[]> reactivePreUpdateInMemoryValueGeneration(
result = result.thenCompose( v -> generateValue( session, entity, currentValue, beforeGenerator, INSERT )
.thenAccept( generatedValue -> {
currentValues[index] = generatedValue;
entityPersister().setPropertyValue( entity, index, generatedValue );
entityPersister().setValue( entity, index, generatedValue );
fieldsPreUpdateNeeded[count.getAndIncrement()] = index;
} ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public EntityManagerFactory build() {
int batchSize = ConfigurationHelper.getInt( Settings.STATEMENT_BATCH_SIZE, getConfigurationValues(), 0 );
optionsBuilder.applyJdbcBatchSize(batchSize);

final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl( metadata, optionsBuilder );
final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl(
metadata,
optionsBuilder,
metadata.getTypeConfiguration()
.getMetadataBuildingContext()
Comment on lines +61 to +62

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [TypeConfiguration.getMetadataBuildingContext](1) should be avoided because it has been deprecated.
.getBootstrapContext()
);
final SessionFactoryBuilderImplementor reactiveSessionFactoryBuilder = new ReactiveSessionFactoryBuilder( metadata, defaultBuilder );
populateSfBuilder( reactiveSessionFactoryBuilder, getStandardServiceRegistry() );

Expand Down
Loading