HHH-6264 - Bind typedef information
This commit is contained in:
parent
227141e643
commit
fd25e7704b
|
@ -28,24 +28,30 @@ import java.util.Collections;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Placeholder for typedef information
|
||||
* Represents the metamodel view of a typedef (type definition).
|
||||
*
|
||||
* @author John Verhaeg
|
||||
*/
|
||||
public class TypeDef implements Serializable {
|
||||
|
||||
private final String name;
|
||||
private final String typeClass;
|
||||
private final Map<String, String> parameters;
|
||||
|
||||
public TypeDef( String typeClass,
|
||||
Map<String, String> parameters ) {
|
||||
this.typeClass = typeClass;
|
||||
this.parameters = parameters;
|
||||
public TypeDef(String name, String typeClass, Map<String, String> parameters) {
|
||||
this.name = name;
|
||||
this.typeClass = typeClass;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getTypeClass() {
|
||||
return typeClass;
|
||||
}
|
||||
|
||||
public Map<String, String> getParameters() {
|
||||
return Collections.unmodifiableMap(parameters);
|
||||
}
|
||||
|
||||
public String getTypeClass() {
|
||||
return typeClass;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class TypeDefBinder {
|
|||
Map<String, String> prms,
|
||||
MetadataImpl metadata) {
|
||||
LOG.debugf( "Binding type definition: %s", name );
|
||||
metadata.addTypeDef( name, new TypeDef( typeClass, prms ) );
|
||||
metadata.addTypeDef( new TypeDef( name, typeClass, prms ) );
|
||||
}
|
||||
|
||||
private TypeDefBinder() {
|
||||
|
|
|
@ -133,7 +133,7 @@ abstract class AbstractEntityBinder {
|
|||
final String entityName = entityBinding.getEntity().getName();
|
||||
|
||||
if ( entityClazz.getFetchProfile() != null ) {
|
||||
hibernateMappingBinder.parseFetchProfiles( entityClazz.getFetchProfile(), entityName );
|
||||
hibernateMappingBinder.bindFetchProfiles( entityClazz.getFetchProfile(), entityName );
|
||||
}
|
||||
|
||||
getMetadata().addImport( entityName, entityName );
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.source.hbm;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -33,6 +34,7 @@ import org.hibernate.cfg.NamingStrategy;
|
|||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.binding.FetchProfile;
|
||||
import org.hibernate.metamodel.binding.FetchProfile.Fetch;
|
||||
import org.hibernate.metamodel.binding.TypeDef;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.Origin;
|
||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||
|
@ -42,6 +44,7 @@ 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.XMLImport;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLJoinedSubclassElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLParamElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLQueryElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlQueryElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSubclassElement;
|
||||
|
@ -149,17 +152,20 @@ public class HbmBinder implements MappingDefaults {
|
|||
}
|
||||
|
||||
public void processHibernateMapping() {
|
||||
if ( hibernateMapping.getImport() != null ) {
|
||||
bindImports( hibernateMapping.getImport() );
|
||||
}
|
||||
if ( hibernateMapping.getTypedef() != null ) {
|
||||
bindTypeDef( hibernateMapping.getTypedef() );
|
||||
}
|
||||
if ( hibernateMapping.getFilterDef() != null ) {
|
||||
// parseFilterDefs( hibernateMapping.getFilterDef() );
|
||||
}
|
||||
if ( hibernateMapping.getFetchProfile() != null ) {
|
||||
parseFetchProfiles( hibernateMapping.getFetchProfile(), null );
|
||||
bindFetchProfiles( hibernateMapping.getFetchProfile(), null );
|
||||
}
|
||||
if ( hibernateMapping.getIdentifierGenerator() != null ) {
|
||||
// parseIdentifierGeneratorRegistrations( hibernateMapping.getIdentifierGenerator() );
|
||||
}
|
||||
if ( hibernateMapping.getTypedef() != null ) {
|
||||
// bindTypeDef( hibernateMapping.getTypedefs() );
|
||||
}
|
||||
if ( hibernateMapping.getClazzOrSubclassOrJoinedSubclass() != null ) {
|
||||
for ( Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) {
|
||||
|
@ -207,15 +213,12 @@ public class HbmBinder implements MappingDefaults {
|
|||
if ( hibernateMapping.getResultset() != null ) {
|
||||
// bindResultSetMappingDefinitions( element, null, mappings );
|
||||
}
|
||||
if ( hibernateMapping.getImport() != null ) {
|
||||
processImports( hibernateMapping.getImport() );
|
||||
}
|
||||
if ( hibernateMapping.getDatabaseObject() != null ) {
|
||||
// bindAuxiliaryDatabaseObjects( element, mappings );
|
||||
}
|
||||
}
|
||||
|
||||
private void processImports(List<XMLImport> imports) {
|
||||
private void bindImports(List<XMLImport> imports) {
|
||||
for ( XMLImport importValue : imports ) {
|
||||
String className = getClassName( importValue.getClazz() );
|
||||
String rename = importValue.getRename();
|
||||
|
@ -224,7 +227,17 @@ public class HbmBinder implements MappingDefaults {
|
|||
}
|
||||
}
|
||||
|
||||
protected void parseFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
|
||||
private void bindTypeDef(List<XMLHibernateMapping.XMLTypedef> typedefs) {
|
||||
for ( XMLHibernateMapping.XMLTypedef typedef : typedefs ) {
|
||||
final Map<String, String> parameters = new HashMap<String, String>();
|
||||
for ( XMLParamElement paramElement : typedef.getParam() ) {
|
||||
parameters.put( paramElement.getName(), paramElement.getValue() );
|
||||
}
|
||||
metadata.addTypeDef( new TypeDef( typedef.getName(), typedef.getClazz(), parameters ) );
|
||||
}
|
||||
}
|
||||
|
||||
protected void bindFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
|
||||
for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) {
|
||||
String profileName = fetchProfile.getName();
|
||||
Set<Fetch> fetches = new HashSet<Fetch>();
|
||||
|
|
|
@ -156,9 +156,17 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
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 );
|
||||
@Override
|
||||
public void addTypeDef(TypeDef typeDef) {
|
||||
final TypeDef previous = typeDefs.put( typeDef.getName(), typeDef );
|
||||
if ( previous != null ) {
|
||||
LOG.debugf( "Duplicate typedef name [%s] now -> %s", typeDef.getName(), typeDef.getTypeClass() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<TypeDef> getTypeDefs() {
|
||||
return typeDefs.values();
|
||||
}
|
||||
|
||||
public TypeDef getTypeDef(String name) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.hibernate.metamodel.Metadata;
|
|||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.FetchProfile;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.TypeDef;
|
||||
import org.hibernate.metamodel.relational.Database;
|
||||
import org.hibernate.service.BasicServiceRegistry;
|
||||
import org.hibernate.type.TypeResolver;
|
||||
|
@ -55,4 +56,8 @@ public interface MetadataImplementor extends Metadata {
|
|||
public void addCollection(PluralAttributeBinding collectionBinding);
|
||||
|
||||
public void addFetchProfile( FetchProfile profile );
|
||||
|
||||
public void addTypeDef(TypeDef typeDef);
|
||||
|
||||
public Iterable<TypeDef> getTypeDefs();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue