Skip to content

Commit

Permalink
#80 - Union subclass binding
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Nov 19, 2023
1 parent fb4efc5 commit aa87600
Show file tree
Hide file tree
Showing 35 changed files with 524 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package org.hibernate.boot.models.bind.internal;

import org.hibernate.boot.internal.ClassmateContext;
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.boot.models.bind.spi.BindingContext;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel;
Expand All @@ -24,6 +26,8 @@ public class BindingContextImpl implements BindingContext {
private final AnnotationDescriptorRegistry annotationDescriptorRegistry;
private final GlobalRegistrations globalRegistrations;

private final ImplicitNamingStrategy implicitNamingStrategy;
private final PhysicalNamingStrategy physicalNamingStrategy;
private final SharedCacheMode sharedCacheMode;
private final ClassmateContext classmateContext;
private final BootstrapContext bootstrapContext;
Expand All @@ -33,6 +37,8 @@ public BindingContextImpl(CategorizedDomainModel categorizedDomainModel, Bootstr
categorizedDomainModel.getClassDetailsRegistry(),
categorizedDomainModel.getAnnotationDescriptorRegistry(),
categorizedDomainModel.getGlobalRegistrations(),
bootstrapContext.getMetadataBuildingOptions().getImplicitNamingStrategy(),
bootstrapContext.getMetadataBuildingOptions().getPhysicalNamingStrategy(),
bootstrapContext.getMetadataBuildingOptions().getSharedCacheMode(),
bootstrapContext.getClassmateContext(),
bootstrapContext
Expand All @@ -43,11 +49,15 @@ public BindingContextImpl(
ClassDetailsRegistry classDetailsRegistry,
AnnotationDescriptorRegistry annotationDescriptorRegistry,
GlobalRegistrations globalRegistrations,
ImplicitNamingStrategy implicitNamingStrategy,
PhysicalNamingStrategy physicalNamingStrategy,
SharedCacheMode sharedCacheMode,
ClassmateContext classmateContext,
BootstrapContext bootstrapContext) {
this.classDetailsRegistry = classDetailsRegistry;
this.annotationDescriptorRegistry = annotationDescriptorRegistry;
this.implicitNamingStrategy = implicitNamingStrategy;
this.physicalNamingStrategy = physicalNamingStrategy;
this.bootstrapContext = bootstrapContext;
this.globalRegistrations = globalRegistrations;
this.classmateContext = classmateContext;
Expand Down Expand Up @@ -83,4 +93,14 @@ public ClassmateContext getClassmateContext() {
public SharedCacheMode getSharedCacheMode() {
return sharedCacheMode;
}

@Override
public ImplicitNamingStrategy getImplicitNamingStrategy() {
return implicitNamingStrategy;
}

@Override
public PhysicalNamingStrategy getPhysicalNamingStrategy() {
return physicalNamingStrategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,27 @@
*/
package org.hibernate.boot.models.bind.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.models.bind.spi.BindingState;
import org.hibernate.boot.models.bind.spi.TableReference;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.util.KeyedConsumer;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.models.ModelsException;
import org.hibernate.boot.models.bind.internal.binders.EntityTypeBinder;
import org.hibernate.boot.models.bind.internal.binders.IdentifiableTypeBinder;
import org.hibernate.boot.models.bind.internal.binders.ManagedTypeBinder;
import org.hibernate.boot.models.bind.internal.binders.MappedSuperTypeBinder;
import org.hibernate.boot.models.bind.internal.binders.TableBinder;
import org.hibernate.boot.models.bind.spi.BindingState;
import org.hibernate.boot.models.bind.spi.TableOwner;
import org.hibernate.boot.models.bind.spi.TableReference;
import org.hibernate.boot.models.categorize.spi.FilterDefRegistration;
import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata;
import org.hibernate.boot.models.categorize.spi.ManagedTypeMetadata;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.util.KeyedConsumer;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.type.spi.TypeConfiguration;

Expand All @@ -41,46 +37,15 @@ public class BindingStateImpl implements BindingState {
private final MetadataBuildingContext metadataBuildingContext;

private final Map<String, TableReference> tableMap = new HashMap<>();
private final Map<TableOwner, TableReference> tableByOwnerMap = new HashMap<>();

private final Map<ClassDetails, ManagedTypeBinder> typeBinders = new HashMap<>();
private final Map<ClassDetails, IdentifiableTypeBinder> typeBindersBySuper = new HashMap<>();

private List<TableBinder.TableSecondPass> tableSecondPasses;

public BindingStateImpl(MetadataBuildingContext metadataBuildingContext) {
this.metadataBuildingContext = metadataBuildingContext;
}

public void processSecondPasses() {
processSecondPasses( tableSecondPasses );
}

private void processSecondPasses(List<? extends SecondPass> secondPasses) {
int processedCount = 0;
final Iterator<? extends SecondPass> secondPassItr = secondPasses.iterator();
while ( secondPassItr.hasNext() ) {
final SecondPass secondPass = secondPassItr.next();
try {
final boolean success = secondPass.process();
if ( success ) {
processedCount++;
secondPassItr.remove();
}
}
catch (Exception ignoreForNow) {
}
}

if ( !secondPasses.isEmpty() ) {
if ( processedCount == 0 ) {
// there are second-passes in the queue, but we were not able to
// successfully process any of them. this is a non-changing
// error condition - just throw an exception
throw new ModelsException( "Unable to process second-pass list" );
}
}
}

@Override
public MetadataBuildingContext getMetadataBuildingContext() {
return metadataBuildingContext;
Expand Down Expand Up @@ -143,16 +108,20 @@ public <T extends TableReference> T getTableByName(String name) {
}

@Override
public void addTable(TableReference table) {
tableMap.put( table.getLogicalName().getCanonicalName(), table );
public <T extends TableReference> T getTableByOwner(TableOwner owner) {
//noinspection unchecked
return (T) tableByOwnerMap.get( owner );
}

@Override
public void registerTableSecondPass(TableBinder.TableSecondPass secondPass) {
if ( tableSecondPasses == null ) {
tableSecondPasses = new ArrayList<>();
}
tableSecondPasses.add( secondPass );
public void addTable(TableOwner owner, TableReference table) {
tableMap.put( table.logicalName().getCanonicalName(), table );
tableByOwnerMap.put( owner, table );
}

@Override
public void addSecondaryTable(SecondaryTable table) {
tableMap.put( table.logicalName().getCanonicalName(), table );
}

private String resolveSchemaName(Identifier explicit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public record InLineView(Identifier logicalName, Table binding) implements TableReference {
@Override
public Identifier getLogicalName() {
public Identifier logicalName() {
return logicalName;
}

Expand All @@ -28,12 +28,12 @@ public String getQuery() {
}

@Override
public boolean isExportable() {
public boolean exportable() {
return false;
}

@Override
public Table getBinding() {
public Table binding() {
return binding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public record PhysicalTable(
Table binding) implements PhysicalTableReference {

@Override
public Identifier getLogicalName() {
public Identifier logicalName() {
return logicalName;
}

Expand Down Expand Up @@ -59,12 +59,12 @@ public Identifier getPhysicalCatalogName() {
}

@Override
public boolean isExportable() {
public boolean exportable() {
return !binding.isAbstract() && binding.getExportIdentifier() != null;
}

@Override
public Table getBinding() {
public Table binding() {
return binding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public record PhysicalView(
Identifier physicalSchemaName,
Table binding) implements PersistentTableReference {
@Override
public Identifier getLogicalName() {
public Identifier logicalName() {
return logicalName;
}

Expand All @@ -49,12 +49,12 @@ public Identifier getLogicalCatalogName() {
}

@Override
public boolean isExportable() {
public boolean exportable() {
return true;
}

@Override
public Table getBinding() {
public Table binding() {
return binding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public record SecondaryTable(
boolean owned,
Table binding) implements PhysicalTableReference {
@Override
public Identifier getLogicalName() {
public Identifier logicalName() {
return logicalName;
}

Expand Down Expand Up @@ -56,12 +56,12 @@ public Identifier getPhysicalCatalogName() {
}

@Override
public boolean isExportable() {
public boolean exportable() {
return !binding.isAbstract();
}

@Override
public Table getBinding() {
public Table binding() {
return binding;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* SPDX-License-Identifier: Apache-2.0
* Copyright: Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.models.bind.internal;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.models.bind.spi.TableReference;
import org.hibernate.mapping.DenormalizedTable;

/**
* @author Steve Ebersole
*/
public record UnionTable(
Identifier logicalName,
UnionTable base,
DenormalizedTable binding,
boolean exportable) implements TableReference {
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static void processColumn(
if ( tableName != null ) {
final Identifier identifier = Identifier.toIdentifier( tableName );
tableByName = bindingState.getTableByName( identifier.getCanonicalName() );
basicValue.setTable( tableByName.getBinding() );
basicValue.setTable( tableByName.binding() );
}
}

Expand Down Expand Up @@ -354,7 +354,7 @@ private void processTimeZoneStorage(MemberDetails member, Property property, Bas
if ( tableName != null ) {
final Identifier identifier = Identifier.toIdentifier( tableName );
tableByName = bindingState.getTableByName( identifier.getCanonicalName() );
basicValue.setTable( tableByName.getBinding() );
basicValue.setTable( tableByName.binding() );
}

property.setInsertable( columnAnn.getBoolean( "insertable", true ) );
Expand Down
Loading

0 comments on commit aa87600

Please sign in to comment.