HHH-6263 Refactoring HibernateXmlBinder and HibernateMappingBinder. Removing the former and renaming the latter to HbmBinder
This commit is contained in:
parent
86ddbc09d9
commit
bd900d9bb1
|
@ -69,6 +69,7 @@ public class EntityBinding {
|
|||
|
||||
private Map<String, MetaAttribute> metaAttributes;
|
||||
|
||||
private String proxyInterfaceName;
|
||||
private boolean lazy;
|
||||
private boolean mutable;
|
||||
private boolean explicitPolymorphism;
|
||||
|
|
|
@ -60,7 +60,7 @@ import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
|||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
|
||||
/**
|
||||
* Creates the domain and relational metamodel for a configured class and binds them together.
|
||||
* Creates the domain and relational metamodel for a configured class and <i>binds</i> them together.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
|
@ -84,11 +84,9 @@ public class EntityBinder {
|
|||
schemaName = createSchemaName();
|
||||
bindTable( entityBinding );
|
||||
|
||||
entityBinding.setInheritanceType( configuredClass.getInheritanceType() );
|
||||
bindInheritance( entityBinding );
|
||||
|
||||
bindWhereFilter( entityBinding );
|
||||
|
||||
bindJpaCaching( entityBinding );
|
||||
bindHibernateCaching( entityBinding );
|
||||
|
||||
|
@ -96,6 +94,8 @@ public class EntityBinder {
|
|||
if ( configuredClass.isRoot() ) {
|
||||
bindId( entityBinding );
|
||||
}
|
||||
|
||||
// bind all attributes - simple as well as associations
|
||||
bindAttributes( entityBinding );
|
||||
|
||||
// last, but not least we register the new EntityBinding with the metadata
|
||||
|
@ -103,6 +103,7 @@ public class EntityBinder {
|
|||
}
|
||||
|
||||
private void bindInheritance(EntityBinding entityBinding) {
|
||||
entityBinding.setInheritanceType( configuredClass.getInheritanceType() );
|
||||
switch ( configuredClass.getInheritanceType() ) {
|
||||
case SINGLE_TABLE: {
|
||||
bindDiscriminatorColumn( entityBinding );
|
||||
|
|
|
@ -84,10 +84,10 @@ import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
abstract class AbstractEntityBinder {
|
||||
private final HibernateMappingBinder hibernateMappingBinder;
|
||||
private final HbmBinder hibernateMappingBinder;
|
||||
private final Schema.Name schemaName;
|
||||
|
||||
AbstractEntityBinder(HibernateMappingBinder hibernateMappingBinder,
|
||||
AbstractEntityBinder(HbmBinder hibernateMappingBinder,
|
||||
XMLHibernateMapping.XMLClass entityClazz) {
|
||||
this.hibernateMappingBinder = hibernateMappingBinder;
|
||||
this.schemaName = new Schema.Name(
|
||||
|
@ -100,16 +100,12 @@ abstract class AbstractEntityBinder {
|
|||
);
|
||||
}
|
||||
|
||||
protected HibernateMappingBinder getHibernateMappingBinder() {
|
||||
public HbmBinder getHibernateMappingBinder() {
|
||||
return hibernateMappingBinder;
|
||||
}
|
||||
|
||||
protected HibernateXmlBinder getHibernateXmlBinder() {
|
||||
return hibernateMappingBinder.getHibernateXmlBinder();
|
||||
}
|
||||
|
||||
protected MetadataImplementor getMetadata() {
|
||||
return hibernateMappingBinder.getHibernateXmlBinder().getMetadata();
|
||||
return hibernateMappingBinder.getMetadata();
|
||||
}
|
||||
|
||||
protected Schema.Name getSchemaName() {
|
||||
|
@ -244,14 +240,14 @@ abstract class AbstractEntityBinder {
|
|||
String physicalTableName;
|
||||
if ( entityClazz.getTable() == null ) {
|
||||
logicalTableName = StringHelper.unqualify( entityName );
|
||||
physicalTableName = getHibernateXmlBinder().getMetadata()
|
||||
physicalTableName = getMetadata()
|
||||
.getOptions()
|
||||
.getNamingStrategy()
|
||||
.classToTableName( entityName );
|
||||
}
|
||||
else {
|
||||
logicalTableName = entityClazz.getTable();
|
||||
physicalTableName = getHibernateXmlBinder().getMetadata()
|
||||
physicalTableName = getMetadata()
|
||||
.getOptions()
|
||||
.getNamingStrategy()
|
||||
.tableName( logicalTableName );
|
||||
|
@ -295,7 +291,7 @@ abstract class AbstractEntityBinder {
|
|||
if ( XMLBagElement.class.isInstance( attribute ) ) {
|
||||
XMLBagElement collection = XMLBagElement.class.cast( attribute );
|
||||
BagBinding collectionBinding = makeBagAttributeBinding( collection, entityBinding );
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata().addCollection( collectionBinding );
|
||||
hibernateMappingBinder.getMetadata().addCollection( collectionBinding );
|
||||
attributeBinding = collectionBinding;
|
||||
}
|
||||
else if ( XMLIdbagElement.class.isInstance( attribute ) ) {
|
||||
|
@ -447,7 +443,7 @@ PrimitiveArray
|
|||
EntityBinding entityBinding) {
|
||||
SimpleAttributeBindingState bindingState = new HbmSimpleAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getMetaAttributes(),
|
||||
property
|
||||
);
|
||||
|
@ -456,7 +452,7 @@ PrimitiveArray
|
|||
ValueRelationalState relationalState =
|
||||
convertToSimpleValueRelationalStateIfPossible(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
hibernateMappingBinder,
|
||||
true,
|
||||
property
|
||||
)
|
||||
|
@ -534,7 +530,7 @@ PrimitiveArray
|
|||
// boolean (true here) indicates that by default column names should be guessed
|
||||
ManyToOneRelationalState relationalState =
|
||||
new HbmManyToOneRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
hibernateMappingBinder,
|
||||
true,
|
||||
manyToOne
|
||||
);
|
||||
|
|
|
@ -27,7 +27,9 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.dom4j.Attribute;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
@ -47,16 +49,16 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlQueryElement;
|
|||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSubclassElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLUnionSubclassElement;
|
||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Responsible for performing binding of the {@code <hibernate-mapping/>} DOM element
|
||||
* Responsible for performing binding of hbm xml.
|
||||
*/
|
||||
public class HibernateMappingBinder implements MappingDefaults {
|
||||
public class HbmBinder implements MappingDefaults {
|
||||
private static final String DEFAULT_IDENTIFIER_COLUMN_NAME = "id";
|
||||
private static final String DEFAULT_DISCRIMINATOR_COLUMN_NAME = "class";
|
||||
|
||||
private final HibernateXmlBinder hibernateXmlBinder;
|
||||
private final JaxbRoot<XMLHibernateMapping> jaxbRoot;
|
||||
private final XMLHibernateMapping hibernateMapping;
|
||||
|
||||
|
@ -68,14 +70,18 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
private final String packageName;
|
||||
private final boolean autoImport;
|
||||
|
||||
private final MetadataImplementor metadata;
|
||||
private final Map<String, MetaAttribute> globalMetas;
|
||||
|
||||
private Map<String, MetaAttribute> mappingMetas;
|
||||
|
||||
|
||||
HibernateMappingBinder(HibernateXmlBinder hibernateXmlBinder, JaxbRoot<XMLHibernateMapping> jaxbRoot) {
|
||||
this.hibernateXmlBinder = hibernateXmlBinder;
|
||||
public HbmBinder(MetadataImplementor metadata, Map<String, MetaAttribute> globalMetas, JaxbRoot<XMLHibernateMapping> jaxbRoot) {
|
||||
this.jaxbRoot = jaxbRoot;
|
||||
this.hibernateMapping = jaxbRoot.getRoot();
|
||||
|
||||
this.metadata = metadata;
|
||||
this.globalMetas = globalMetas;
|
||||
|
||||
defaultSchemaName = hibernateMapping.getSchema();
|
||||
defaultCatalogName = hibernateMapping.getCatalog();
|
||||
defaultCascade = MappingHelper.getStringValue( hibernateMapping.getDefaultCascade(), "none" );
|
||||
|
@ -84,17 +90,18 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
packageName = hibernateMapping.getPackage();
|
||||
autoImport = hibernateMapping.isAutoImport();
|
||||
|
||||
mappingMetas = HbmHelper.extractMetas( hibernateMapping.getMeta(), true, hibernateXmlBinder.getGlobalMetas() );
|
||||
mappingMetas = HbmHelper.extractMetas( hibernateMapping.getMeta(), true, globalMetas );
|
||||
}
|
||||
|
||||
HibernateXmlBinder getHibernateXmlBinder() {
|
||||
return hibernateXmlBinder;
|
||||
public MetadataImplementor getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
XMLHibernateMapping getHibernateMapping() {
|
||||
return hibernateMapping;
|
||||
}
|
||||
|
||||
|
||||
Origin getOrigin() {
|
||||
return jaxbRoot.getOrigin();
|
||||
}
|
||||
|
@ -109,9 +116,8 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
|
||||
public String getDefaultIdColumnName() {
|
||||
return DEFAULT_IDENTIFIER_COLUMN_NAME;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public String getDefaultDiscriminatorColumnName() {
|
||||
return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
|
||||
}
|
||||
|
@ -130,11 +136,11 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
|
||||
@Override
|
||||
public ServiceRegistry getServiceRegistry() {
|
||||
return hibernateXmlBinder.getMetadata().getServiceRegistry();
|
||||
return metadata.getServiceRegistry();
|
||||
}
|
||||
|
||||
public NamingStrategy getNamingStrategy() {
|
||||
return hibernateXmlBinder.getMetadata().getOptions().getNamingStrategy();
|
||||
return metadata.getOptions().getNamingStrategy();
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
|
@ -149,14 +155,14 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
return mappingMetas;
|
||||
}
|
||||
|
||||
void processHibernateMapping() {
|
||||
public void processHibernateMapping() {
|
||||
if ( hibernateMapping.getFilterDef() != null ) {
|
||||
// parseFilterDefs( hibernateMapping.getFilterDef() );
|
||||
}
|
||||
if ( hibernateMapping.getFetchProfile() != null ) {
|
||||
parseFetchProfiles( hibernateMapping.getFetchProfile(), null );
|
||||
}
|
||||
if ( hibernateMapping.getIdentifierGenerator() != null ) {
|
||||
if ( hibernateMapping.getIdentifierGenerator() != null ) {
|
||||
// parseIdentifierGeneratorRegistrations( hibernateMapping.getIdentifierGenerator() );
|
||||
}
|
||||
if ( hibernateMapping.getTypedef() != null ) {
|
||||
|
@ -182,8 +188,9 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
// handleUnionSubclass( superModel, mappings, element, inheritedMetas );
|
||||
}
|
||||
else {
|
||||
throw new org.hibernate.metamodel.source.MappingException( "unknown type of class or subclass: " +
|
||||
clazzOrSubclass.getClass().getName(), jaxbRoot.getOrigin()
|
||||
throw new org.hibernate.metamodel.source.MappingException(
|
||||
"unknown type of class or subclass: " +
|
||||
clazzOrSubclass.getClass().getName(), jaxbRoot.getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -197,8 +204,9 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
// bindNamedSQLQuery( element, null, mappings );
|
||||
}
|
||||
else {
|
||||
throw new org.hibernate.metamodel.source.MappingException( "unknown type of query: " +
|
||||
queryOrSqlQuery.getClass().getName(), jaxbRoot.getOrigin()
|
||||
throw new org.hibernate.metamodel.source.MappingException(
|
||||
"unknown type of query: " +
|
||||
queryOrSqlQuery.getClass().getName(), jaxbRoot.getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -219,26 +227,28 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
String className = getClassName( importValue.getClazz() );
|
||||
String rename = importValue.getRename();
|
||||
rename = ( rename == null ) ? StringHelper.unqualify( className ) : rename;
|
||||
hibernateXmlBinder.getMetadata().addImport( className, rename );
|
||||
metadata.addImport( className, rename );
|
||||
}
|
||||
}
|
||||
|
||||
protected void parseFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
|
||||
for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) {
|
||||
String profileName = fetchProfile.getName();
|
||||
Set<Fetch> fetches = new HashSet<Fetch>();
|
||||
for ( XMLFetch fetch : fetchProfile.getFetch() ) {
|
||||
Set<Fetch> fetches = new HashSet<Fetch>();
|
||||
for ( XMLFetch fetch : fetchProfile.getFetch() ) {
|
||||
String entityName = fetch.getEntity() == null ? containingEntityName : fetch.getEntity();
|
||||
if ( entityName == null ) {
|
||||
throw new MappingException( "could not determine entity for fetch-profile fetch [" + profileName + "]:[" + fetch.getAssociation() + "]" );
|
||||
throw new MappingException(
|
||||
"could not determine entity for fetch-profile fetch [" + profileName + "]:[" + fetch.getAssociation() + "]"
|
||||
);
|
||||
}
|
||||
fetches.add(new Fetch(entityName, fetch.getAssociation(), fetch.getStyle()));
|
||||
fetches.add( new Fetch( entityName, fetch.getAssociation(), fetch.getStyle() ) );
|
||||
}
|
||||
hibernateXmlBinder.getMetadata().addFetchProfile( new FetchProfile(profileName, fetches));
|
||||
metadata.addFetchProfile( new FetchProfile( profileName, fetches ) );
|
||||
}
|
||||
}
|
||||
|
||||
String extractEntityName( XMLClass entityClazz) {
|
||||
String extractEntityName(XMLClass entityClazz) {
|
||||
return HbmHelper.extractEntityName( entityClazz, packageName );
|
||||
}
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, 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.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.JoinedIterator;
|
||||
import org.hibernate.internal.util.xml.XmlDocument;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Binder for {@code hbm.xml} files
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HibernateXmlBinder {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, HibernateXmlBinder.class.getName() );
|
||||
|
||||
private final MetadataImplementor metadata;
|
||||
private final Map<String, MetaAttribute> globalMetas;
|
||||
|
||||
public HibernateXmlBinder(MetadataImplementor metadata) {
|
||||
this( metadata, Collections.<String, MetaAttribute>emptyMap() );
|
||||
}
|
||||
|
||||
public HibernateXmlBinder(MetadataImplementor metadata, Map<String, MetaAttribute> globalMetas) {
|
||||
this.metadata = metadata;
|
||||
this.globalMetas = globalMetas;
|
||||
}
|
||||
|
||||
public void bindRoot(JaxbRoot<XMLHibernateMapping> jaxbRoot) {
|
||||
if (LOG.isDebugEnabled()) LOG.debugf( jaxbRoot.toString() );
|
||||
bindRoot( jaxbRoot, Collections.<String>emptySet() );
|
||||
}
|
||||
|
||||
public void bindRoot(JaxbRoot<XMLHibernateMapping> jaxbRoot, Set<String> entityNames) {
|
||||
final HibernateMappingBinder mappingBinder = new HibernateMappingBinder( this, jaxbRoot );
|
||||
|
||||
// this is irrelevant due to HHH-6118 and the fact that now all sources should be
|
||||
// List<String> names = locateEntityNamesAwaitingExtends( metadataXml, mappingBinder );
|
||||
// if ( !names.isEmpty() ) {
|
||||
// // classes mentioned in extends not available - so put it in queue
|
||||
// for ( String name : names ) {
|
||||
// metadata.getExtendsQueue()
|
||||
// .add( new ExtendsQueueEntry( name, mappingBinder.getPackageName(), metadataXml, entityNames ) );
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
|
||||
mappingBinder.processHibernateMapping();
|
||||
}
|
||||
|
||||
MetadataImplementor getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
Map<String, MetaAttribute> getGlobalMetas() {
|
||||
return globalMetas;
|
||||
}
|
||||
|
||||
private List<String> locateEntityNamesAwaitingExtends(XmlDocument metadataXml, HibernateMappingBinder mappingBinder) {
|
||||
final String unqualifiedPackageName = mappingBinder.getPackageName();
|
||||
final Element rootElement = metadataXml.getDocumentTree().getRootElement();
|
||||
|
||||
List<String> awaitingExtends = new ArrayList<String>();
|
||||
|
||||
// first, iterate over all elements capable of defining an extends attribute
|
||||
// collecting all found extends references if they cannot be resolved
|
||||
// against the already processed mappings.
|
||||
Iterator[] subclasses = new Iterator[3];
|
||||
subclasses[0] = rootElement.elementIterator( "subclass" );
|
||||
subclasses[1] = rootElement.elementIterator( "joined-subclass" );
|
||||
subclasses[2] = rootElement.elementIterator( "union-subclass" );
|
||||
|
||||
Iterator iterator = new JoinedIterator( subclasses );
|
||||
while ( iterator.hasNext() ) {
|
||||
final Element element = (Element) iterator.next();
|
||||
final String extendsName = element.attributeValue( "extends" );
|
||||
// mappings might contain either the "raw" extends name (in the case of
|
||||
// an entity-name mapping) or a FQN (in the case of a POJO mapping).
|
||||
if ( getMetadata().getEntityBinding( extendsName ) == null
|
||||
&& getMetadata().getEntityBinding(
|
||||
HbmHelper.getClassName(
|
||||
extendsName, unqualifiedPackageName
|
||||
)
|
||||
) == null ) {
|
||||
awaitingExtends.add( extendsName );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !awaitingExtends.isEmpty() ) {
|
||||
// So far, the 'awaitingExtends' list containg all entity names found as extends in this
|
||||
// current document which were not previously processed in earlier documents.
|
||||
//
|
||||
// Now we will go through and remove the ones that are contained in this document
|
||||
final java.util.Set<String> set = new HashSet<String>( awaitingExtends );
|
||||
EntityElementHandler handler = new EntityElementHandler() {
|
||||
public void handleEntity(String entityName, String className) {
|
||||
if ( entityName != null ) {
|
||||
set.remove( entityName );
|
||||
}
|
||||
else {
|
||||
String fqn = HbmHelper.getClassName( className, unqualifiedPackageName );
|
||||
set.remove( fqn );
|
||||
if ( unqualifiedPackageName != null ) {
|
||||
set.remove( StringHelper.unqualify( fqn ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
recognizeEntities( rootElement, handler );
|
||||
awaitingExtends.clear();
|
||||
awaitingExtends.addAll( set );
|
||||
}
|
||||
|
||||
return awaitingExtends;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an entity-containing-element (startNode) recursively locate all
|
||||
* entity names defined within that element.
|
||||
*
|
||||
* @param startNode The containing element
|
||||
* @param handler The thing that knows what to do whenever we recognize an
|
||||
* entity-name
|
||||
*/
|
||||
private static void recognizeEntities(final Element startNode, EntityElementHandler handler) {
|
||||
Iterator[] classes = new Iterator[4];
|
||||
classes[0] = startNode.elementIterator( "class" );
|
||||
classes[1] = startNode.elementIterator( "subclass" );
|
||||
classes[2] = startNode.elementIterator( "joined-subclass" );
|
||||
classes[3] = startNode.elementIterator( "union-subclass" );
|
||||
|
||||
Iterator classIterator = new JoinedIterator( classes );
|
||||
while ( classIterator.hasNext() ) {
|
||||
Element element = (Element) classIterator.next();
|
||||
handler.handleEntity(
|
||||
element.attributeValue( "entity-name" ),
|
||||
element.attributeValue( "name" )
|
||||
);
|
||||
recognizeEntities( element, handler );
|
||||
}
|
||||
}
|
||||
|
||||
private static interface EntityElementHandler {
|
||||
public void handleEntity(String entityName, String className);
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.relational.Identifier;
|
||||
import org.hibernate.metamodel.relational.InLineView;
|
||||
|
@ -41,7 +42,6 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
|||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLCompositeId;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
|
||||
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
|
@ -50,7 +50,7 @@ import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
|||
*/
|
||||
class RootEntityBinder extends AbstractEntityBinder {
|
||||
|
||||
RootEntityBinder(HibernateMappingBinder hibernateMappingBinder, XMLClass xmlClazz) {
|
||||
RootEntityBinder(HbmBinder hibernateMappingBinder, XMLClass xmlClazz) {
|
||||
super( hibernateMappingBinder, xmlClazz );
|
||||
}
|
||||
|
||||
|
@ -86,12 +86,12 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
// called createClassProperties in HBMBinder...
|
||||
buildAttributeBindings( xmlClazz, entityBinding );
|
||||
|
||||
getHibernateXmlBinder().getMetadata().addEntity( entityBinding );
|
||||
getMetadata().addEntity( entityBinding );
|
||||
}
|
||||
|
||||
private void basicTableBinding(XMLClass xmlClazz,
|
||||
EntityBinding entityBinding) {
|
||||
final Schema schema = getHibernateXmlBinder().getMetadata().getDatabase().getSchema( getSchemaName() );
|
||||
final Schema schema = getMetadata().getDatabase().getSchema( getSchemaName() );
|
||||
|
||||
final String subSelect =
|
||||
xmlClazz.getSubselectAttribute() == null ? xmlClazz.getSubselect() : xmlClazz.getSubselectAttribute();
|
||||
|
@ -245,9 +245,9 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
}
|
||||
|
||||
DiscriminatorBindingState bindingState = new HbmDiscriminatorBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
xmlEntityClazz.getDiscriminator()
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
xmlEntityClazz.getDiscriminator()
|
||||
);
|
||||
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
|
@ -283,13 +283,13 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
}
|
||||
|
||||
protected void bindVersion(XMLHibernateMapping.XMLClass.XMLVersion version,
|
||||
EntityBinding entityBinding) {
|
||||
EntityBinding entityBinding) {
|
||||
SimpleAttributeBindingState bindingState =
|
||||
new HbmSimpleAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
version
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
version
|
||||
);
|
||||
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
|
@ -313,10 +313,10 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
|
||||
SimpleAttributeBindingState bindingState =
|
||||
new HbmSimpleAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
timestamp
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
timestamp
|
||||
);
|
||||
|
||||
// relational model has not been bound yet
|
||||
|
@ -332,7 +332,7 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
|
||||
entityBinding.makeVersionBinding( bindingState.getAttributeName() )
|
||||
.initialize( bindingState )
|
||||
.initialize( relationalState );
|
||||
.initialize( relationalState );
|
||||
}
|
||||
|
||||
private void bindCaching(XMLClass xmlClazz,
|
||||
|
|
|
@ -27,12 +27,15 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.jandex.Index;
|
||||
import org.jboss.jandex.Indexer;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.DuplicateMappingException;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
@ -47,11 +50,12 @@ import org.hibernate.metamodel.binding.FetchProfile;
|
|||
import org.hibernate.metamodel.binding.IdGenerator;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.TypeDef;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
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.xml.OrmXmlParser;
|
||||
import org.hibernate.metamodel.source.hbm.HibernateXmlBinder;
|
||||
import org.hibernate.metamodel.source.hbm.HbmBinder;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.BasicServiceRegistry;
|
||||
|
@ -66,13 +70,16 @@ import org.hibernate.type.TypeResolver;
|
|||
*/
|
||||
public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, MetadataImpl.class.getName());
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
MetadataImpl.class.getName()
|
||||
);
|
||||
|
||||
private final BasicServiceRegistry serviceRegistry;
|
||||
private final Options options;
|
||||
|
||||
private final Database database = new Database();
|
||||
private TypeResolver typeResolver = new TypeResolver();
|
||||
private TypeResolver typeResolver = new TypeResolver();
|
||||
|
||||
/**
|
||||
* Maps the fully qualified class name of an entity to its entity binding
|
||||
|
@ -81,11 +88,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
||||
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||
private Map<String, String> imports;
|
||||
private Map<String, TypeDef> typeDefs = new HashMap<String, TypeDef>();
|
||||
private Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
|
||||
private Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
|
||||
private Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>();
|
||||
private Map<String, FilterDefinition> filterDefs = new HashMap<String, FilterDefinition>();
|
||||
private Map<String, TypeDef> typeDefs = new HashMap<String, TypeDef>();
|
||||
private Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
|
||||
private Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
|
||||
private Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>();
|
||||
private Map<String, FilterDefinition> filterDefs = new HashMap<String, FilterDefinition>();
|
||||
|
||||
public MetadataImpl(MetadataSources metadataSources, Options options) {
|
||||
this.serviceRegistry = metadataSources.getServiceRegistry();
|
||||
|
@ -104,44 +111,68 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
new EntityReferenceResolver( this ).resolve();
|
||||
}
|
||||
|
||||
public void addFetchProfile( FetchProfile profile ) {
|
||||
fetchProfiles.put(profile.getName(), profile);
|
||||
}
|
||||
public void addFetchProfile(FetchProfile profile) {
|
||||
fetchProfiles.put( profile.getName(), profile );
|
||||
}
|
||||
|
||||
public void addFilterDef( FilterDefinition def ) {
|
||||
filterDefs.put(def.getFilterName(), def);
|
||||
}
|
||||
public void addFilterDef(FilterDefinition def) {
|
||||
filterDefs.put( def.getFilterName(), def );
|
||||
}
|
||||
|
||||
public Map<String, FilterDefinition> getFilterDefinitions() {
|
||||
return filterDefs;
|
||||
|
||||
}
|
||||
|
||||
public void addIdGenerator( IdGenerator generator ) {
|
||||
idGenerators.put(generator.getName(), generator);
|
||||
}
|
||||
public void addIdGenerator(IdGenerator generator) {
|
||||
idGenerators.put( generator.getName(), generator );
|
||||
}
|
||||
|
||||
public void addNamedNativeQuery( String name,
|
||||
NamedSQLQueryDefinition def ) {
|
||||
namedNativeQueryDefs.put(name, def);
|
||||
}
|
||||
public IdGenerator getIdGenerator(String name) {
|
||||
if ( name == null ) {
|
||||
throw new IllegalArgumentException( "null is not a valid generator name" );
|
||||
}
|
||||
return idGenerators.get( name );
|
||||
}
|
||||
|
||||
public void addNamedQuery( String name,
|
||||
NamedQueryDefinition def ) {
|
||||
namedQueryDefs.put(name, def);
|
||||
}
|
||||
public void addNamedNativeQuery(String name, NamedSQLQueryDefinition def) {
|
||||
namedNativeQueryDefs.put( name, def );
|
||||
}
|
||||
|
||||
public void addTypeDef(String name, TypeDef typeDef) {
|
||||
// TODO - should we check whether the typedef already exists? Log it? Exception? (HF)
|
||||
typeDefs.put( name, typeDef );
|
||||
}
|
||||
public NamedSQLQueryDefinition getNamedNativeQuery(String name) {
|
||||
if ( name == null ) {
|
||||
throw new IllegalArgumentException( "null is not a valid native query name" );
|
||||
}
|
||||
return namedNativeQueryDefs.get( name );
|
||||
}
|
||||
|
||||
public void addNamedQuery(String name, NamedQueryDefinition def) {
|
||||
namedQueryDefs.put( name, def );
|
||||
}
|
||||
|
||||
public NamedQueryDefinition getNamedQuery(String name) {
|
||||
if ( name == null ) {
|
||||
throw new IllegalArgumentException( "null is not a valid query name" );
|
||||
}
|
||||
return namedQueryDefs.get( name );
|
||||
}
|
||||
|
||||
public void addTypeDef(String name, TypeDef typeDef) {
|
||||
// TODO - should we check whether the typedef already exists? Log it? Exception? (HF)
|
||||
typeDefs.put( name, typeDef );
|
||||
}
|
||||
|
||||
public TypeDef getTypeDef(String name) {
|
||||
return typeDefs.get( name );
|
||||
}
|
||||
|
||||
private void applyHibernateMappings(MetadataSources metadataSources, List<String> processedEntityNames) {
|
||||
final HibernateXmlBinder hibernateXmlBinder = new HibernateXmlBinder( this );
|
||||
for ( JaxbRoot jaxbRoot : metadataSources.getJaxbRootList() ) {
|
||||
// filter to just hbm-based roots
|
||||
if ( jaxbRoot.getRoot() instanceof XMLHibernateMapping ) {
|
||||
hibernateXmlBinder.bindRoot( jaxbRoot );
|
||||
final HbmBinder mappingBinder = new HbmBinder(
|
||||
this, Collections.<String, MetaAttribute>emptyMap(), jaxbRoot
|
||||
);
|
||||
mappingBinder.processHibernateMapping();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -260,15 +291,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public TypeDef getTypeDef(String name) {
|
||||
return typeDefs.get( name );
|
||||
public Iterable<FetchProfile> getFetchProfiles() {
|
||||
return fetchProfiles.values();
|
||||
}
|
||||
|
||||
public Iterable<FetchProfile> getFetchProfiles() {
|
||||
return fetchProfiles.values();
|
||||
}
|
||||
|
||||
public TypeResolver getTypeResolver() {
|
||||
return typeResolver;
|
||||
}
|
||||
public TypeResolver getTypeResolver() {
|
||||
return typeResolver;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue