HHH-6291 - Basic MetadataImpl redesign
This commit is contained in:
parent
252eee4dd2
commit
b8b003efa3
|
@ -22,15 +22,20 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* A meta attribute is a named value or values.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class MetaAttribute implements Serializable {
|
||||
|
||||
// todo : this really belongs in the binding package
|
||||
|
||||
private String name;
|
||||
private java.util.List values = new ArrayList();
|
||||
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.source.annotations;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.jandex.Index;
|
||||
import org.jboss.jandex.Indexer;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings;
|
||||
import org.hibernate.metamodel.source.annotations.xml.OrmXmlParser;
|
||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||
import org.hibernate.metamodel.source.spi.Binder;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JpaBinder implements Binder {
|
||||
private final MetadataImplementor metadata;
|
||||
|
||||
private Index index;
|
||||
private ClassLoaderService classLoaderService;
|
||||
|
||||
public JpaBinder(MetadataImplementor metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void prepare(MetadataSources sources) {
|
||||
// create a jandex index from the annotated classes
|
||||
Indexer indexer = new Indexer();
|
||||
for ( Class<?> clazz : sources.getAnnotatedClasses() ) {
|
||||
indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class" );
|
||||
}
|
||||
|
||||
// add package-info from the configured packages
|
||||
for ( String packageName : sources.getAnnotatedPackages() ) {
|
||||
indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class" );
|
||||
}
|
||||
|
||||
index = indexer.complete();
|
||||
|
||||
List<JaxbRoot<XMLEntityMappings>> mappings = new ArrayList<JaxbRoot<XMLEntityMappings>>();
|
||||
for ( JaxbRoot<?> root : sources.getJaxbRootList() ) {
|
||||
if ( root.getRoot() instanceof XMLEntityMappings ) {
|
||||
mappings.add( (JaxbRoot<XMLEntityMappings>) root );
|
||||
}
|
||||
}
|
||||
if ( !mappings.isEmpty() ) {
|
||||
// process the xml configuration
|
||||
final OrmXmlParser ormParser = new OrmXmlParser( metadata );
|
||||
index = ormParser.parseAndUpdateIndex( mappings, index );
|
||||
}
|
||||
}
|
||||
|
||||
private void indexClass(Indexer indexer, String className) {
|
||||
InputStream stream = classLoaderService().locateResourceStream( className );
|
||||
try {
|
||||
indexer.index( stream );
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
throw new HibernateException( "Unable to open input stream for class " + className, e );
|
||||
}
|
||||
}
|
||||
|
||||
private ClassLoaderService classLoaderService(){
|
||||
if ( classLoaderService == null ) {
|
||||
classLoaderService = metadata.getServiceRegistry().getService( ClassLoaderService.class );
|
||||
}
|
||||
return classLoaderService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindIndependentMetadata(MetadataSources sources) {
|
||||
// todo : implement method body
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTypeDependentMetadata(MetadataSources sources) {
|
||||
// todo : implement method body
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindMappingMetadata(MetadataSources sources, List<String> processedEntityNames) {
|
||||
// todo : implement method body
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindMappingDependentMetadata(MetadataSources sources) {
|
||||
// todo : implement method body
|
||||
}
|
||||
}
|
|
@ -31,15 +31,16 @@ import org.jboss.jandex.Index;
|
|||
import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings;
|
||||
import org.hibernate.metamodel.source.annotations.xml.mocker.EntityMappingsMocker;
|
||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class OrmXmlParser {
|
||||
private final MetadataImpl meta;
|
||||
private final MetadataImplementor metadata;
|
||||
|
||||
public OrmXmlParser(MetadataImpl meta) {
|
||||
this.meta = meta;
|
||||
public OrmXmlParser(MetadataImplementor metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,9 +56,7 @@ public class OrmXmlParser {
|
|||
for ( JaxbRoot<XMLEntityMappings> jaxbRoot : mappings ) {
|
||||
list.add( jaxbRoot.getRoot() );
|
||||
}
|
||||
return new EntityMappingsMocker(
|
||||
list, annotationIndex, meta.getServiceRegistry()
|
||||
).mockNewIndex();
|
||||
return new EntityMappingsMocker( list, annotationIndex, metadata.getServiceRegistry() ).mockNewIndex();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.source.hbm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.spi.Binder;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HibernateMappingBinder implements Binder {
|
||||
private final MetadataImplementor metadata;
|
||||
|
||||
public HibernateMappingBinder(MetadataImplementor metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MetadataSources sources) {
|
||||
// nothing to do here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindIndependentMetadata(MetadataSources sources) {
|
||||
// todo : implement method body
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTypeDependentMetadata(MetadataSources sources) {
|
||||
// todo : implement method body
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindMappingMetadata(MetadataSources sources, List<String> processedEntityNames) {
|
||||
// todo : implement method body
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindMappingDependentMetadata(MetadataSources sources) {
|
||||
// todo : implement method body
|
||||
}
|
||||
}
|
|
@ -57,15 +57,16 @@ import org.hibernate.metamodel.relational.AuxiliaryDatabaseObject;
|
|||
import org.hibernate.metamodel.relational.Database;
|
||||
import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings;
|
||||
import org.hibernate.metamodel.source.annotations.AnnotationBinder;
|
||||
import org.hibernate.metamodel.source.annotations.JpaBinder;
|
||||
import org.hibernate.metamodel.source.annotations.xml.OrmXmlParser;
|
||||
import org.hibernate.metamodel.source.hbm.HbmBinder;
|
||||
import org.hibernate.metamodel.source.hbm.HibernateMappingBinder;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||
import org.hibernate.metamodel.source.spi.Binder;
|
||||
import org.hibernate.metamodel.source.spi.MappingDefaults;
|
||||
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.BasicServiceRegistry;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.type.TypeResolver;
|
||||
|
||||
|
@ -115,7 +116,26 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
|
||||
this.mappingDefaults = new MappingDefaultsImpl();
|
||||
|
||||
applyIndependentMetadata();
|
||||
final Binder[] binders;
|
||||
if ( options.getSourceProcessingOrder() == SourceProcessingOrder.HBM_FIRST ) {
|
||||
binders = new Binder[] {
|
||||
new HibernateMappingBinder( this ),
|
||||
new JpaBinder( this )
|
||||
};
|
||||
}
|
||||
else {
|
||||
binders = new Binder[] {
|
||||
new JpaBinder( this ),
|
||||
new HibernateMappingBinder( this )
|
||||
};
|
||||
}
|
||||
|
||||
prepare( binders, metadataSources );
|
||||
bindIndependentMetadata( binders, metadataSources );
|
||||
bindTypeDependentMetadata( binders, metadataSources );
|
||||
bindMappingMetadata( binders, metadataSources );
|
||||
bindMappingDependentMetadata( binders, metadataSources );
|
||||
|
||||
final ArrayList<String> processedEntityNames = new ArrayList<String>();
|
||||
if ( options.getSourceProcessingOrder() == SourceProcessingOrder.HBM_FIRST ) {
|
||||
applyHibernateMappings( metadataSources, processedEntityNames );
|
||||
|
@ -129,8 +149,50 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
new EntityReferenceResolver( this ).resolve();
|
||||
}
|
||||
|
||||
private void applyIndependentMetadata() {
|
||||
// todo : implement method body
|
||||
private void prepare(Binder[] binders, MetadataSources metadataSources) {
|
||||
for ( Binder binder : binders ) {
|
||||
binder.prepare( metadataSources );
|
||||
}
|
||||
}
|
||||
|
||||
private Index prepareIndex(MetadataSources metadataSources) {
|
||||
// create a jandex index from the annotated classes
|
||||
Indexer indexer = new Indexer();
|
||||
for ( Class<?> clazz : metadataSources.getAnnotatedClasses() ) {
|
||||
indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class" );
|
||||
}
|
||||
|
||||
// add package-info from the configured packages
|
||||
for ( String packageName : metadataSources.getAnnotatedPackages() ) {
|
||||
indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class" );
|
||||
}
|
||||
|
||||
return indexer.complete();
|
||||
}
|
||||
|
||||
private void bindIndependentMetadata(Binder[] binders, MetadataSources metadataSources) {
|
||||
for ( Binder binder : binders ) {
|
||||
binder.bindIndependentMetadata( metadataSources );
|
||||
}
|
||||
}
|
||||
|
||||
private void bindTypeDependentMetadata(Binder[] binders, MetadataSources metadataSources) {
|
||||
for ( Binder binder : binders ) {
|
||||
binder.bindTypeDependentMetadata( metadataSources );
|
||||
}
|
||||
}
|
||||
|
||||
private void bindMappingMetadata(Binder[] binders, MetadataSources metadataSources) {
|
||||
final ArrayList<String> processedEntityNames = new ArrayList<String>();
|
||||
for ( Binder binder : binders ) {
|
||||
binder.bindMappingMetadata( metadataSources, processedEntityNames );
|
||||
}
|
||||
}
|
||||
|
||||
private void bindMappingDependentMetadata(Binder[] binders, MetadataSources metadataSources) {
|
||||
for ( Binder binder : binders ) {
|
||||
binder.bindMappingDependentMetadata( metadataSources );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.source.internal;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.spi.MappingDefaults;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class RootMappingDefaults implements MappingDefaults {
|
||||
private final String packageName;
|
||||
private final String schemaName;
|
||||
private final String catalogName;
|
||||
private final String idColumnName;
|
||||
private final String discriminatorColumnName;
|
||||
private final String cascade;
|
||||
private final String propertyAccess;
|
||||
private final boolean associationLaziness;
|
||||
|
||||
public RootMappingDefaults(
|
||||
String packageName,
|
||||
String schemaName,
|
||||
String catalogName,
|
||||
String idColumnName,
|
||||
String discriminatorColumnName,
|
||||
String cascade,
|
||||
String propertyAccess,
|
||||
boolean associationLaziness) {
|
||||
this.packageName = packageName;
|
||||
this.schemaName = schemaName;
|
||||
this.catalogName = catalogName;
|
||||
this.idColumnName = idColumnName;
|
||||
this.discriminatorColumnName = discriminatorColumnName;
|
||||
this.cascade = cascade;
|
||||
this.propertyAccess = propertyAccess;
|
||||
this.associationLaziness = associationLaziness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultSchemaName() {
|
||||
return schemaName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultCatalogName() {
|
||||
return catalogName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultIdColumnName() {
|
||||
return idColumnName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultDiscriminatorColumnName() {
|
||||
return discriminatorColumnName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultCascade() {
|
||||
return cascade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultAccess() {
|
||||
return propertyAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefaultLazy() {
|
||||
return associationLaziness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, MetaAttribute> getMappingMetas() {
|
||||
return null; // todo : implement method body
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.source.spi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Binder {
|
||||
public void prepare(MetadataSources sources);
|
||||
public void bindIndependentMetadata(MetadataSources sources);
|
||||
public void bindTypeDependentMetadata(MetadataSources sources);
|
||||
public void bindMappingMetadata(MetadataSources sources, List<String> processedEntityNames);
|
||||
public void bindMappingDependentMetadata(MetadataSources sources);
|
||||
}
|
Loading…
Reference in New Issue