Skip to content

Commit

Permalink
HHH-17504 - Ongoing JPA 32 work
Browse files Browse the repository at this point in the history
HHH-17350 - Work on hibernate-models, XSD and JAXB
HHH-16114 - Improve boot metamodel binding
HHH-15996 - Develop an abstraction for Annotation in annotation processing
HHH-16012 - Develop an abstraction for domain model Class refs
HHH-15997 - Support for dynamic models in orm.xml
HHH-15698 - Support for entity-name in mapping.xsd
  • Loading branch information
sebersole committed Dec 5, 2023
1 parent 75b8b58 commit bb9b17c
Show file tree
Hide file tree
Showing 30 changed files with 47 additions and 223 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* SPDX-License-Identifier: Apache-2.0
* Copyright: Red Hat Inc. and Hibernate Authors
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.boot.models.bind.internal;
package org.hibernate.boot.internal;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.hibernate.annotations.*;
import org.hibernate.boot.internal.Abstract;
import org.hibernate.boot.internal.AnyKeyType;
import org.hibernate.boot.internal.CollectionClassification;
import org.hibernate.boot.internal.Extends;
import org.hibernate.boot.internal.Target;
Expand Down Expand Up @@ -172,6 +173,7 @@ public interface HibernateAnnotations {
AnnotationDescriptor<WhereJoinTable> WHERE_JOIN_TABLE = createOrmDescriptor( WhereJoinTable.class );

AnnotationDescriptor<Abstract> ABSTRACT = createOrmDescriptor( Abstract.class );
AnnotationDescriptor<AnyKeyType> ANY_KEY_TYPE = createOrmDescriptor( AnyKeyType.class );
AnnotationDescriptor<CollectionClassification> COLLECTION_CLASSIFICATION = createOrmDescriptor( CollectionClassification.class );
AnnotationDescriptor<Extends> EXTENDS = createOrmDescriptor( Extends.class );
AnnotationDescriptor<Target> TARGET = createOrmDescriptor( Target.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.OptimisticLock;
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.models.AnnotationPlacementException;
import org.hibernate.boot.models.bind.spi.BindingContext;
import org.hibernate.boot.models.bind.spi.BindingOptions;
import org.hibernate.boot.models.bind.spi.BindingState;
import org.hibernate.boot.models.bind.spi.TableReference;
import org.hibernate.boot.models.categorize.spi.AttributeMetadata;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Component;
Expand Down Expand Up @@ -233,21 +231,6 @@ public <A extends Annotation> void processColumn(
bindingState,
bindingContext
);
// todo : implicit column
final var columnAnn = member.getAnnotationUsage( annotation );
final var column = ColumnHelper.bindColumn( columnAnn, property::getName );

var tableName = BindingHelper.getValue( columnAnn, "table", "" );
if ( "".equals( tableName ) || tableName == null ) {
basicValue.setTable( primaryTable );
}
else {
final Identifier identifier = Identifier.toIdentifier( tableName );
final TableReference tableByName = bindingState.getTableByName( identifier.getCanonicalName() );
basicValue.setTable( tableByName.table() );
}

basicValue.addColumn( column );
}

private void applyNaturalId(AttributeMetadata attributeMetadata, Property property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.boot.models.bind.spi.BindingContext;
import org.hibernate.boot.models.bind.spi.BindingOptions;
import org.hibernate.boot.models.bind.spi.BindingState;
import org.hibernate.boot.models.bind.spi.TableReference;
import org.hibernate.boot.models.categorize.spi.AttributeMetadata;
import org.hibernate.boot.models.categorize.spi.EntityHierarchy;
import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata;
Expand Down Expand Up @@ -356,21 +357,14 @@ private static Method findCallbackMethod(
}
}

protected void processSecondaryTables() {
final List<SecondaryTable> secondaryTables = TableHelper.bindSecondaryTables(
protected void processSecondaryTables(TableReference primaryTableReference) {
TableHelper.bindSecondaryTables(
this,
primaryTableReference,
bindingOptions,
bindingState,
bindingContext
);

secondaryTables.forEach( (secondaryTable) -> {
final Join join = new Join();
join.setTable( secondaryTable.table() );
join.setPersistentClass( getPersistentClass() );
join.setOptional( secondaryTable.optional() );
join.setInverse( !secondaryTable.owned() );
} );
}

protected void prepareSubclassBindings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public RootEntityBinding(
bindingContext
);

processSecondaryTables();
processSecondaryTables( this.tableReference );

bindingState.registerTypeBinding( typeMetadata, this );

Expand Down Expand Up @@ -111,8 +111,6 @@ public RootEntityBinding(
applyFilters( typeMetadata, rootClass );
applyJpaEventListeners( typeMetadata, rootClass );

// todo : handle any super mapped-superclasses

prepareAttributeBindings( tableReference.table() );

prepareSubclassBindings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ else if ( entityTypeMetadata.getHierarchy().getInheritanceType() == InheritanceT
return tableReference;
}

public static List<SecondaryTable> bindSecondaryTables(
public static void bindSecondaryTables(
EntityBinding entityBinding,
TableReference primaryTableReference,
BindingOptions bindingOptions,
BindingState bindingState,
BindingContext bindingContext) {
final ClassDetails typeClassDetails = entityBinding.getTypeMetadata().getClassDetails();

final List<AnnotationUsage<jakarta.persistence.SecondaryTable>> secondaryTableAnns = typeClassDetails.getRepeatedAnnotationUsages( jakarta.persistence.SecondaryTable.class );
final List<SecondaryTable> result = new ArrayList<>( secondaryTableAnns.size() );

secondaryTableAnns.forEach( (secondaryTableAnn) -> {
final AnnotationUsage<SecondaryRow> secondaryRowAnn = typeClassDetails.getNamedAnnotationUsage(
Expand All @@ -150,20 +149,20 @@ public static List<SecondaryTable> bindSecondaryTables(
);
final SecondaryTable binding = bindSecondaryTable(
entityBinding,
primaryTableReference,
secondaryTableAnn,
secondaryRowAnn,
bindingOptions,
bindingState,
bindingContext
);
result.add( binding );
bindingState.addSecondaryTable( binding );
} );
return result;
}

public static SecondaryTable bindSecondaryTable(
EntityBinding entityBinding,
TableReference primaryTableReference,
AnnotationUsage<jakarta.persistence.SecondaryTable> secondaryTableAnn,
AnnotationUsage<SecondaryRow> secondaryRowAnn,
BindingOptions bindingOptions,
Expand Down Expand Up @@ -197,7 +196,7 @@ public static SecondaryTable bindSecondaryTable(
bindingContext
);

final var binding = bindingState.getMetadataBuildingContext().getMetadataCollector().addTable(
final var secondaryTable = bindingState.getMetadataBuildingContext().getMetadataCollector().addTable(
toCanonicalName( schemaName ),
toCanonicalName( catalogName ),
logicalName.getCanonicalName(),
Expand All @@ -206,15 +205,15 @@ public static SecondaryTable bindSecondaryTable(
bindingState.getMetadataBuildingContext()
);

applyComment( binding, secondaryTableAnn, findCommentAnnotation(
applyComment( secondaryTable, secondaryTableAnn, findCommentAnnotation(
entityBinding.getTypeMetadata(),
logicalName,
false
) );
applyOptions( binding, secondaryTableAnn );
applyOptions( secondaryTable, secondaryTableAnn );

final Join join = new Join();
join.setTable( binding );
join.setTable( secondaryTable );
join.setOptional( BindingHelper.getValue( secondaryRowAnn, "optional", true ) );
join.setInverse( !BindingHelper.getValue( secondaryRowAnn, "owned", true ) );
join.setPersistentClass( entityBinding.getPersistentClass() );
Expand All @@ -231,7 +230,7 @@ public static SecondaryTable bindSecondaryTable(
physicalNamingStrategy.toPhysicalSchemaName( schemaName, jdbcEnvironment ),
BindingHelper.getValue( secondaryRowAnn, "optional", true ),
BindingHelper.getValue( secondaryRowAnn, "owned", true ),
binding
secondaryTable
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingKeyImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl;
import org.hibernate.boot.models.bind.internal.AnyKeyType;
import org.hibernate.boot.internal.AnyKeyType;
import org.hibernate.boot.models.categorize.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.categorize.xml.internal.db.ColumnProcessing;
import org.hibernate.boot.models.categorize.xml.spi.XmlDocumentContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.orm.test.boot.models.process;
package org.hibernate.orm.test.boot.models;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.orm.test.boot.models.process;
package org.hibernate.orm.test.boot.models;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.orm.test.boot.models.process;
package org.hibernate.orm.test.boot.models;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.orm.test.boot.models.process.ManagedResourcesImpl;
import org.hibernate.orm.test.boot.models.ManagedResourcesImpl;

/**
* @author Steve Ebersole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.orm.test.boot.models.resources;
package org.hibernate.orm.test.boot.models.process;

import java.util.Iterator;
import java.util.Set;
Expand Down Expand Up @@ -50,7 +50,7 @@
* set of "managed classes" (JPA's term) which Hibernate will process for annotations -
* {@code @Entity}, {@code @Converter}, ...
* <p/>
* And is the likely place that hibernate-models-source would hook in to. Let's see how that might work...
* Let's see how using that with hibernate-models that might work...
*
* @author Steve Ebersole
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.annotations.JavaTypeRegistration;
import org.hibernate.annotations.ParamDef;
import org.hibernate.id.IncrementGenerator;
import org.hibernate.orm.test.boot.models.MyUuidConverter;
import org.hibernate.type.descriptor.java.StringJavaType;

import jakarta.persistence.Entity;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.model.process.spi.ManagedResources;
import org.hibernate.orm.test.boot.models.BootstrapContextTesting;
import org.hibernate.orm.test.boot.models.ManagedResourcesImpl;
import org.hibernate.orm.test.boot.models.MyStringConverter;
import org.hibernate.orm.test.boot.models.MyUuidConverter;
import org.hibernate.orm.test.boot.models.SourceModelTestHelper;
import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel;
import org.hibernate.boot.models.categorize.spi.EntityHierarchy;
Expand All @@ -37,6 +40,8 @@
import static org.hibernate.models.internal.SimpleClassLoading.SIMPLE_CLASS_LOADING;

/**
* Tests the general process / flow of using hibernate-models
*
* @author Steve Ebersole
*/
public class SimpleProcessorTests {
Expand Down Expand Up @@ -71,12 +76,6 @@ void testSimpleUsage() {
);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Above here is work done before hibernate-models.
// Below here is work done by hibernate-models.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
final MetadataBuilderImpl.MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
final BootstrapContextTesting bootstrapContext = new BootstrapContextTesting( jandexIndex, serviceRegistry, metadataBuildingOptions );
Expand Down

0 comments on commit bb9b17c

Please sign in to comment.