mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 13:14:50 +00:00
HHH-7049 - Add tests of org.hibernate.metamodel.internal.source stuff
This commit is contained in:
parent
8cad8a487b
commit
26ecd26ac0
@ -92,7 +92,7 @@ public Metadata buildMetadata() {
|
|||||||
return new MetadataImpl( sources, options );
|
return new MetadataImpl( sources, options );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class OptionsImpl implements Metadata.Options {
|
public static class OptionsImpl implements Metadata.Options {
|
||||||
private MetadataSourceProcessingOrder metadataSourceProcessingOrder = MetadataSourceProcessingOrder.HBM_FIRST;
|
private MetadataSourceProcessingOrder metadataSourceProcessingOrder = MetadataSourceProcessingOrder.HBM_FIRST;
|
||||||
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
|
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
|
||||||
// todo : entity-resolver maybe needed for ServiceRegistry building also
|
// todo : entity-resolver maybe needed for ServiceRegistry building also
|
||||||
|
@ -131,14 +131,14 @@ public MetadataImpl(MetadataSources metadataSources, Options options) {
|
|||||||
final MetadataSourceProcessor[] metadataSourceProcessors;
|
final MetadataSourceProcessor[] metadataSourceProcessors;
|
||||||
if ( options.getMetadataSourceProcessingOrder() == MetadataSourceProcessingOrder.HBM_FIRST ) {
|
if ( options.getMetadataSourceProcessingOrder() == MetadataSourceProcessingOrder.HBM_FIRST ) {
|
||||||
metadataSourceProcessors = new MetadataSourceProcessor[] {
|
metadataSourceProcessors = new MetadataSourceProcessor[] {
|
||||||
new HbmMetadataSourceProcessorImpl( this ),
|
new HbmMetadataSourceProcessorImpl( this, metadataSources ),
|
||||||
new AnnotationMetadataSourceProcessorImpl( this )
|
new AnnotationMetadataSourceProcessorImpl( this, metadataSources )
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
metadataSourceProcessors = new MetadataSourceProcessor[] {
|
metadataSourceProcessors = new MetadataSourceProcessor[] {
|
||||||
new AnnotationMetadataSourceProcessorImpl( this ),
|
new AnnotationMetadataSourceProcessorImpl( this, metadataSources ),
|
||||||
new HbmMetadataSourceProcessorImpl( this )
|
new HbmMetadataSourceProcessorImpl( this, metadataSources )
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,16 +159,14 @@ public PersisterClassResolver initialize() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
prepare( metadataSourceProcessors, metadataSources );
|
processTypeDefinitions( metadataSourceProcessors );
|
||||||
|
processFilterDefinitions( metadataSourceProcessors );
|
||||||
|
|
||||||
processTypeDefinitions( metadataSourceProcessors, metadataSources );
|
processIdentifierGenerators( metadataSourceProcessors );
|
||||||
processFilterDefinitions( metadataSourceProcessors, metadataSources );
|
|
||||||
|
|
||||||
processIdentifierGenerators( metadataSourceProcessors, metadataSources );
|
processMappings( metadataSourceProcessors );
|
||||||
|
|
||||||
processMappings( metadataSourceProcessors, metadataSources );
|
bindMappingDependentMetadata( metadataSourceProcessors );
|
||||||
|
|
||||||
bindMappingDependentMetadata( metadataSourceProcessors, metadataSources );
|
|
||||||
|
|
||||||
// todo : remove this by coordinated ordering of entity processing
|
// todo : remove this by coordinated ordering of entity processing
|
||||||
new AssociationResolver( this ).resolve();
|
new AssociationResolver( this ).resolve();
|
||||||
@ -178,22 +176,11 @@ public PersisterClassResolver initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// general preparation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
private void prepare(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) {
|
|
||||||
for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
|
|
||||||
metadataSourceProcessor.prepare( metadataSources );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// type definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// type definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
private void processTypeDefinitions(
|
private void processTypeDefinitions(MetadataSourceProcessor[] metadataSourceProcessors) {
|
||||||
MetadataSourceProcessor[] metadataSourceProcessors,
|
|
||||||
MetadataSources metadataSources) {
|
|
||||||
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
|
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
|
||||||
for ( TypeDescriptorSource typeDescriptorSource : processor.extractTypeDefinitionSources( metadataSources ) ) {
|
for ( TypeDescriptorSource typeDescriptorSource : processor.extractTypeDefinitionSources() ) {
|
||||||
addTypeDefinition(
|
addTypeDefinition(
|
||||||
new TypeDefinition(
|
new TypeDefinition(
|
||||||
typeDescriptorSource.getName(),
|
typeDescriptorSource.getName(),
|
||||||
@ -233,11 +220,9 @@ public TypeDefinition getTypeDefinition(String name) {
|
|||||||
|
|
||||||
// filter definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// filter definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
private void processFilterDefinitions(
|
private void processFilterDefinitions(MetadataSourceProcessor[] metadataSourceProcessors) {
|
||||||
MetadataSourceProcessor[] metadataSourceProcessors,
|
|
||||||
MetadataSources metadataSources) {
|
|
||||||
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
|
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
|
||||||
for ( FilterDefinitionSource filterDefinitionSource : processor.extractFilterDefinitionSources( metadataSources ) ) {
|
for ( FilterDefinitionSource filterDefinitionSource : processor.extractFilterDefinitionSources() ) {
|
||||||
addFilterDefinition(
|
addFilterDefinition(
|
||||||
new FilterDefinition(
|
new FilterDefinition(
|
||||||
filterDefinitionSource.getName(),
|
filterDefinitionSource.getName(),
|
||||||
@ -264,19 +249,15 @@ public Iterable<FilterDefinition> getFilterDefinitions() {
|
|||||||
|
|
||||||
// identifier generators ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// identifier generators ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
private void processIdentifierGenerators(
|
private void processIdentifierGenerators(MetadataSourceProcessor[] metadataSourceProcessors) {
|
||||||
MetadataSourceProcessor[] metadataSourceProcessors,
|
|
||||||
MetadataSources metadataSources) {
|
|
||||||
// HHH-7040
|
// HHH-7040
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMappings(
|
private void processMappings(MetadataSourceProcessor[] metadataSourceProcessors) {
|
||||||
MetadataSourceProcessor[] metadataSourceProcessors,
|
|
||||||
MetadataSources metadataSources) {
|
|
||||||
final ArrayList<String> processedEntityNames = new ArrayList<String>();
|
final ArrayList<String> processedEntityNames = new ArrayList<String>();
|
||||||
final Binder binder = new Binder( this, processedEntityNames );
|
final Binder binder = new Binder( this, processedEntityNames );
|
||||||
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
|
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
|
||||||
for ( EntityHierarchy entityHierarchy : processor.extractEntityHierarchies( metadataSources ) ) {
|
for ( EntityHierarchy entityHierarchy : processor.extractEntityHierarchies() ) {
|
||||||
binder.processEntityHierarchy( entityHierarchy );
|
binder.processEntityHierarchy( entityHierarchy );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,9 +268,9 @@ private void processMappings(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void bindMappingDependentMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) {
|
private void bindMappingDependentMetadata(MetadataSourceProcessor[] metadataSourceProcessors) {
|
||||||
for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
|
for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
|
||||||
metadataSourceProcessor.processMappingDependentMetadata( metadataSources );
|
metadataSourceProcessor.processMappingDependentMetadata();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,30 +63,27 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
|
|||||||
private static final Logger LOG = Logger.getLogger( AnnotationMetadataSourceProcessorImpl.class );
|
private static final Logger LOG = Logger.getLogger( AnnotationMetadataSourceProcessorImpl.class );
|
||||||
|
|
||||||
private final MetadataImplementor metadata;
|
private final MetadataImplementor metadata;
|
||||||
|
|
||||||
private AnnotationBindingContext bindingContext;
|
private AnnotationBindingContext bindingContext;
|
||||||
|
|
||||||
public AnnotationMetadataSourceProcessorImpl(MetadataImpl metadata) {
|
public AnnotationMetadataSourceProcessorImpl(MetadataImpl metadata, MetadataSources metadataSources) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings( { "unchecked" })
|
|
||||||
public void prepare(MetadataSources sources) {
|
|
||||||
// create a jandex index from the annotated classes
|
// create a jandex index from the annotated classes
|
||||||
Indexer indexer = new Indexer();
|
Indexer indexer = new Indexer();
|
||||||
for ( Class<?> clazz : sources.getAnnotatedClasses() ) {
|
for ( Class<?> clazz : metadataSources.getAnnotatedClasses() ) {
|
||||||
indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class" );
|
indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// add package-info from the configured packages
|
// add package-info from the configured packages
|
||||||
for ( String packageName : sources.getAnnotatedPackages() ) {
|
for ( String packageName : metadataSources.getAnnotatedPackages() ) {
|
||||||
indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class" );
|
indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class" );
|
||||||
}
|
}
|
||||||
|
|
||||||
Index index = indexer.complete();
|
Index index = indexer.complete();
|
||||||
|
|
||||||
List<JaxbRoot<JaxbEntityMappings>> mappings = new ArrayList<JaxbRoot<JaxbEntityMappings>>();
|
List<JaxbRoot<JaxbEntityMappings>> mappings = new ArrayList<JaxbRoot<JaxbEntityMappings>>();
|
||||||
for ( JaxbRoot<?> root : sources.getJaxbRootList() ) {
|
for ( JaxbRoot<?> root : metadataSources.getJaxbRootList() ) {
|
||||||
if ( root.getRoot() instanceof JaxbEntityMappings ) {
|
if ( root.getRoot() instanceof JaxbEntityMappings ) {
|
||||||
mappings.add( (JaxbRoot<JaxbEntityMappings>) root );
|
mappings.add( (JaxbRoot<JaxbEntityMappings>) root );
|
||||||
}
|
}
|
||||||
@ -104,7 +101,7 @@ public void prepare(MetadataSources sources) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<TypeDescriptorSource> extractTypeDefinitionSources(MetadataSources sources) {
|
public Iterable<TypeDescriptorSource> extractTypeDefinitionSources() {
|
||||||
assertBindingContextExists();
|
assertBindingContextExists();
|
||||||
|
|
||||||
List<TypeDescriptorSource> typeDescriptorSources = new ArrayList<TypeDescriptorSource>();
|
List<TypeDescriptorSource> typeDescriptorSources = new ArrayList<TypeDescriptorSource>();
|
||||||
@ -134,7 +131,7 @@ private void assertBindingContextExists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<FilterDefinitionSource> extractFilterDefinitionSources(MetadataSources sources) {
|
public Iterable<FilterDefinitionSource> extractFilterDefinitionSources() {
|
||||||
assertBindingContextExists();
|
assertBindingContextExists();
|
||||||
|
|
||||||
List<FilterDefinitionSource> filterDefinitionSources = new ArrayList<FilterDefinitionSource>();
|
List<FilterDefinitionSource> filterDefinitionSources = new ArrayList<FilterDefinitionSource>();
|
||||||
@ -158,14 +155,14 @@ public Iterable<FilterDefinitionSource> extractFilterDefinitionSources(MetadataS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends EntityHierarchy> extractEntityHierarchies(MetadataSources sources) {
|
public Iterable<EntityHierarchy> extractEntityHierarchies() {
|
||||||
assertBindingContextExists();
|
assertBindingContextExists();
|
||||||
// need to order our annotated entities into an order we can process
|
// need to order our annotated entities into an order we can process
|
||||||
return EntityHierarchyBuilder.createEntityHierarchies( bindingContext );
|
return EntityHierarchyBuilder.createEntityHierarchies( bindingContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processMappingDependentMetadata(MetadataSources sources) {
|
public void processMappingDependentMetadata() {
|
||||||
TableProcessor.bind( bindingContext );
|
TableProcessor.bind( bindingContext );
|
||||||
FetchProfileProcessor.bind( bindingContext );
|
FetchProfileProcessor.bind( bindingContext );
|
||||||
QueryProcessor.bind( bindingContext );
|
QueryProcessor.bind( bindingContext );
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
|
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
|
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
|
||||||
|
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||||
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
|
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
|
||||||
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
||||||
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
|
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
|
||||||
@ -45,16 +46,12 @@ public class HbmMetadataSourceProcessorImpl implements MetadataSourceProcessor {
|
|||||||
private List<HibernateMappingProcessor> processors = new ArrayList<HibernateMappingProcessor>();
|
private List<HibernateMappingProcessor> processors = new ArrayList<HibernateMappingProcessor>();
|
||||||
private List<EntityHierarchyImpl> entityHierarchies;
|
private List<EntityHierarchyImpl> entityHierarchies;
|
||||||
|
|
||||||
public HbmMetadataSourceProcessorImpl(MetadataImplementor metadata) {
|
public HbmMetadataSourceProcessorImpl(MetadataImplementor metadata, MetadataSources metadataSources) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
public void prepare(MetadataSources sources) {
|
|
||||||
final HierarchyBuilder hierarchyBuilder = new HierarchyBuilder();
|
final HierarchyBuilder hierarchyBuilder = new HierarchyBuilder();
|
||||||
|
|
||||||
for ( JaxbRoot jaxbRoot : sources.getJaxbRootList() ) {
|
for ( JaxbRoot jaxbRoot : metadataSources.getJaxbRootList() ) {
|
||||||
if ( ! JaxbHibernateMapping.class.isInstance( jaxbRoot.getRoot() ) ) {
|
if ( ! JaxbHibernateMapping.class.isInstance( jaxbRoot.getRoot() ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -71,7 +68,7 @@ public void prepare(MetadataSources sources) {
|
|||||||
// todo : still need to deal with auxiliary database objects
|
// todo : still need to deal with auxiliary database objects
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<TypeDescriptorSource> extractTypeDefinitionSources(MetadataSources sources) {
|
public Iterable<TypeDescriptorSource> extractTypeDefinitionSources() {
|
||||||
final List<TypeDescriptorSource> typeDescriptorSources = new ArrayList<TypeDescriptorSource>();
|
final List<TypeDescriptorSource> typeDescriptorSources = new ArrayList<TypeDescriptorSource>();
|
||||||
for ( HibernateMappingProcessor processor : processors ) {
|
for ( HibernateMappingProcessor processor : processors ) {
|
||||||
processor.collectTypeDescriptorSources( typeDescriptorSources );
|
processor.collectTypeDescriptorSources( typeDescriptorSources );
|
||||||
@ -80,7 +77,7 @@ public Iterable<TypeDescriptorSource> extractTypeDefinitionSources(MetadataSourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<FilterDefinitionSource> extractFilterDefinitionSources(MetadataSources sources) {
|
public Iterable<FilterDefinitionSource> extractFilterDefinitionSources() {
|
||||||
final List<FilterDefinitionSource> filterDefinitionSources = new ArrayList<FilterDefinitionSource>();
|
final List<FilterDefinitionSource> filterDefinitionSources = new ArrayList<FilterDefinitionSource>();
|
||||||
for ( HibernateMappingProcessor processor : processors ) {
|
for ( HibernateMappingProcessor processor : processors ) {
|
||||||
processor.collectFilterDefSources( filterDefinitionSources );
|
processor.collectFilterDefSources( filterDefinitionSources );
|
||||||
@ -89,12 +86,13 @@ public Iterable<FilterDefinitionSource> extractFilterDefinitionSources(MetadataS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<EntityHierarchyImpl> extractEntityHierarchies(MetadataSources sources) {
|
@SuppressWarnings( {"unchecked", "RedundantCast"})
|
||||||
return entityHierarchies;
|
public Iterable<EntityHierarchy> extractEntityHierarchies() {
|
||||||
|
return (Iterable) entityHierarchies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processMappingDependentMetadata(MetadataSources sources) {
|
public void processMappingDependentMetadata() {
|
||||||
for ( HibernateMappingProcessor processor : processors ) {
|
for ( HibernateMappingProcessor processor : processors ) {
|
||||||
processor.processMappingDependentMetadata();
|
processor.processMappingDependentMetadata();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.spi;
|
package org.hibernate.metamodel.spi;
|
||||||
|
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
|
||||||
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||||
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
|
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
|
||||||
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
|
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
|
||||||
@ -34,45 +33,30 @@
|
|||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface MetadataSourceProcessor {
|
public interface MetadataSourceProcessor {
|
||||||
/**
|
|
||||||
* Prepare for processing the given sources.
|
|
||||||
*
|
|
||||||
* @param sources The metadata sources.
|
|
||||||
*/
|
|
||||||
public void prepare(MetadataSources sources);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the sources pertaining to type descriptors.
|
* Retrieve the sources pertaining to type descriptors.
|
||||||
*
|
*
|
||||||
* @param sources The metadata sources.
|
|
||||||
*
|
|
||||||
* @return The type descriptor sources.
|
* @return The type descriptor sources.
|
||||||
*/
|
*/
|
||||||
public Iterable<? extends TypeDescriptorSource> extractTypeDefinitionSources(MetadataSources sources);
|
public Iterable<TypeDescriptorSource> extractTypeDefinitionSources();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the sources pertaining to filter defs.
|
* Retrieve the sources pertaining to filter defs.
|
||||||
*
|
*
|
||||||
* @param sources The metadata sources.
|
|
||||||
*
|
|
||||||
* @return The filter def sources.
|
* @return The filter def sources.
|
||||||
*/
|
*/
|
||||||
public Iterable<? extends FilterDefinitionSource> extractFilterDefinitionSources(MetadataSources sources);
|
public Iterable<FilterDefinitionSource> extractFilterDefinitionSources();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the entity hierarchies.
|
* Retrieve the entity hierarchies.
|
||||||
*
|
*
|
||||||
* @param sources The metadata sources.
|
|
||||||
*
|
|
||||||
* @return The entity hierarchies
|
* @return The entity hierarchies
|
||||||
*/
|
*/
|
||||||
public Iterable<? extends EntityHierarchy> extractEntityHierarchies(MetadataSources sources);
|
public Iterable<EntityHierarchy> extractEntityHierarchies();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the parts of the metadata that depend on mapping (entities, et al) information having been
|
* Process the parts of the metadata that depend on mapping (entities, et al) information having been
|
||||||
* processed and available.
|
* processed and available.
|
||||||
*
|
|
||||||
* @param sources The metadata sources.
|
|
||||||
*/
|
*/
|
||||||
public void processMappingDependentMetadata(MetadataSources sources);
|
public void processMappingDependentMetadata();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.internal.source;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.Metadata;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
|
import org.hibernate.metamodel.internal.MetadataBuilderImpl;
|
||||||
|
import org.hibernate.metamodel.internal.MetadataImpl;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.AnnotationMetadataSourceProcessorImpl;
|
||||||
|
import org.hibernate.metamodel.internal.source.hbm.HbmMetadataSourceProcessorImpl;
|
||||||
|
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
|
||||||
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
|
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||||
|
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
||||||
|
import org.hibernate.metamodel.spi.source.RootEntitySource;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
import org.hibernate.service.ServiceRegistryBuilder;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class AssertSourcesTest extends BaseUnitTestCase {
|
||||||
|
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry() ;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUserEntitySources() {
|
||||||
|
MetadataSources hbm = new MetadataSources( serviceRegistry );
|
||||||
|
hbm.addResource( getClass().getPackage().getName().replace( '.', '/' ) + "/User.hbm.xml" );
|
||||||
|
MetadataSourceProcessor hbmProcessor = new HbmMetadataSourceProcessorImpl( buildMetadata( hbm ), hbm );
|
||||||
|
testUserEntitySources( hbmProcessor );
|
||||||
|
|
||||||
|
// breaking from HHH-7040
|
||||||
|
// MetadataSources ann = new MetadataSources( serviceRegistry );
|
||||||
|
// ann.addAnnotatedClass( User.class );
|
||||||
|
// MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( buildMetadata( ann ), ann );
|
||||||
|
// testUserEntitySources( annProcessor );
|
||||||
|
}
|
||||||
|
|
||||||
|
private MetadataImpl buildMetadata(MetadataSources sources) {
|
||||||
|
return new MetadataImpl( sources, new MetadataBuilderImpl.OptionsImpl( serviceRegistry ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testUserEntitySources(MetadataSourceProcessor processor) {
|
||||||
|
Iterator<EntityHierarchy> hierarchies = processor.extractEntityHierarchies().iterator();
|
||||||
|
assertTrue( hierarchies.hasNext() );
|
||||||
|
EntityHierarchy hierarchy = hierarchies.next();
|
||||||
|
assertFalse( hierarchies.hasNext() );
|
||||||
|
assertTrue( hierarchy.getHierarchyInheritanceType() == InheritanceType.NO_INHERITANCE );
|
||||||
|
RootEntitySource entitySource = hierarchy.getRootEntitySource();
|
||||||
|
assertFalse( entitySource.subclassEntitySources().iterator().hasNext() );
|
||||||
|
|
||||||
|
// finish up with assertions on attributes, etc
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<hibernate-mapping package="org.hibernate.metamodel.internal.source"
|
||||||
|
xmlns="http://www.hibernate.org/xsd/hibernate-mapping">
|
||||||
|
|
||||||
|
<class name="User">
|
||||||
|
<id name="id">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
<property name="userName" column="UNAME"/>
|
||||||
|
<component name="name" class="User$Name">
|
||||||
|
<property name="firstName" column="FNAME"/>
|
||||||
|
<property name="middleName" column="MNAME"/>
|
||||||
|
<property name="lastName" column="LNAME"/>
|
||||||
|
</component>
|
||||||
|
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.internal.source;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Embeddable;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.Version;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
import org.hibernate.annotations.NaturalId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class User {
|
||||||
|
private Long id;
|
||||||
|
private Name name;
|
||||||
|
private String userName;
|
||||||
|
private Date lastLogin;
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue( generator = "increment" )
|
||||||
|
@GenericGenerator( name = "increment", strategy = "increment" )
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(Name name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NaturalId
|
||||||
|
@Column( name = "UNAME" )
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Temporal( TemporalType.TIMESTAMP )
|
||||||
|
public Date getLastLogin() {
|
||||||
|
return lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastLogin(Date lastLogin) {
|
||||||
|
this.lastLogin = lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Version
|
||||||
|
@Column( name = "LAST_UPDATED" )
|
||||||
|
public int getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(int version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Embeddable
|
||||||
|
public static class Name {
|
||||||
|
private String firstName;
|
||||||
|
private String middleName;
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
public Name() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name(String firstName, String middleName, String lastName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.middleName = middleName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column( name = "FNAME" )
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column( name="LNAME" )
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column( name = "MNAME" )
|
||||||
|
public String getMiddleName() {
|
||||||
|
return middleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMiddleName(String middleName) {
|
||||||
|
this.middleName = middleName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user