HHH-7042 - Clean up MetadataSources

This commit is contained in:
Steve Ebersole 2012-02-09 15:32:36 -06:00
parent f475dc096b
commit 94480b6905
22 changed files with 143 additions and 355 deletions

View File

@ -1284,7 +1284,7 @@ public final class AnnotationBinder {
if ( BinderHelper.isEmptyAnnotationValue( defAnn.name() ) && defAnn.defaultForType().equals( void.class ) ) {
throw new AnnotationException(
"Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass " +
"Either name or defaultForType (or both) attribute should be set in TypeDefinition having typeClass " +
defAnn.typeClass().getName()
);
}

View File

@ -40,7 +40,7 @@ import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.binding.FetchProfile;
import org.hibernate.metamodel.spi.binding.IdGenerator;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.TypeDef;
import org.hibernate.metamodel.spi.binding.TypeDefinition;
/**
* @author Steve Ebersole
@ -80,9 +80,9 @@ public interface Metadata {
public Iterable<PluralAttributeBinding> getCollectionBindings();
public TypeDef getTypeDefinition(String name);
public TypeDefinition getTypeDefinition(String name);
public Iterable<TypeDef> getTypeDefinitions();
public Iterable<TypeDefinition> getTypeDefinitions();
public Iterable<FilterDefinition> getFilterDefinitions();

View File

@ -60,12 +60,12 @@ import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.binding.FetchProfile;
import org.hibernate.metamodel.spi.binding.IdGenerator;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.TypeDef;
import org.hibernate.metamodel.spi.binding.TypeDefinition;
import org.hibernate.metamodel.spi.domain.BasicType;
import org.hibernate.metamodel.spi.domain.Type;
import org.hibernate.metamodel.spi.relational.Database;
import org.hibernate.metamodel.spi.source.EntityHierarchy;
import org.hibernate.metamodel.spi.source.FilterDefSource;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.MappingDefaults;
import org.hibernate.metamodel.spi.source.MetaAttributeContext;
import org.hibernate.metamodel.spi.source.MetadataImplementor;
@ -105,20 +105,17 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
private final MappingDefaults mappingDefaults;
/**
* Maps the fully qualified class name of an entity to its entity binding
*/
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
private Map<String, TypeDefinition> typeDefinitionMap = new HashMap<String, TypeDefinition>();
private Map<String, FilterDefinition> filterDefinitionMap = new HashMap<String, FilterDefinition>();
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
private Map<String, String> imports = new HashMap<String, String>();
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, ResultSetMappingDefinition> resultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
private Map<String, FilterDefinition> filterDefs = new HashMap<String, FilterDefinition>();
private boolean globallyQuotedIdentifiers = false;
@ -162,12 +159,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
);
prepare( metadataSourceProcessors, metadataSources );
processTypeDescriptors( metadataSourceProcessors, metadataSources );
processFilterDefs( metadataSourceProcessors, metadataSources );
processTypeDefinitions( metadataSourceProcessors, metadataSources );
processFilterDefinitions( metadataSourceProcessors, metadataSources );
processIdentifierGenerators( metadataSourceProcessors, metadataSources );
processMappings( metadataSourceProcessors, metadataSources );
@ -181,6 +177,9 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
new IdentifierGeneratorResolver( this ).resolve();
}
// general preparation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private void prepare(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) {
for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
metadataSourceProcessor.prepare( metadataSources );
@ -188,35 +187,61 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
// type descriptors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// type definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private void processTypeDescriptors(
private void processTypeDefinitions(
MetadataSourceProcessor[] metadataSourceProcessors,
MetadataSources metadataSources) {
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
for ( TypeDescriptorSource typeDescriptorSource : processor.extractTypeDescriptorSources( metadataSources ) ) {
final TypeDef typeDef = new TypeDef(
typeDescriptorSource.getName(),
typeDescriptorSource.getTypeImplementationClassName(),
typeDescriptorSource.getParameters()
for ( TypeDescriptorSource typeDescriptorSource : processor.extractTypeDefinitionSources( metadataSources ) ) {
addTypeDefinition(
new TypeDefinition(
typeDescriptorSource.getName(),
classLoaderService().classForName( typeDescriptorSource.getTypeImplementationClassName() ),
typeDescriptorSource.getRegistrationKeys(),
typeDescriptorSource.getParameters()
)
);
typeDefs.put( typeDef.getName(), typeDef );
}
}
}
@Override
public void addTypeDefinition(TypeDefinition typeDefinition) {
if ( typeDefinition == null ) {
throw new IllegalArgumentException( "Type definition is null" );
}
else if ( typeDefinition.getName() == null ) {
throw new IllegalArgumentException( "Type definition name is null: " + typeDefinition.getTypeImplementorClass().getName() );
}
final TypeDefinition previous = typeDefinitionMap.put( typeDefinition.getName(), typeDefinition );
if ( previous != null ) {
LOG.debugf( "Duplicate typedef name [%s] now -> %s", typeDefinition.getName(), typeDefinition.getTypeImplementorClass().getName() );
}
}
// filter-defs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public Iterable<TypeDefinition> getTypeDefinitions() {
return typeDefinitionMap.values();
}
private void processFilterDefs(
@Override
public TypeDefinition getTypeDefinition(String name) {
return typeDefinitionMap.get( name );
}
// filter definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private void processFilterDefinitions(
MetadataSourceProcessor[] metadataSourceProcessors,
MetadataSources metadataSources) {
for ( MetadataSourceProcessor processor : metadataSourceProcessors ) {
for ( FilterDefSource filterDefSource : processor.extractFilterDefSources( metadataSources ) ) {
for ( FilterDefinitionSource filterDefinitionSource : processor.extractFilterDefinitionSources( metadataSources ) ) {
addFilterDefinition(
new FilterDefinition(
filterDefSource.getName(),
filterDefSource.getCondition(),
filterDefinitionSource.getName(),
filterDefinitionSource.getCondition(),
null // the params, todo : need to figure out how to handle the type portion
)
);
@ -224,6 +249,18 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
}
@Override
public void addFilterDefinition(FilterDefinition filterDefinition) {
if ( filterDefinition == null || filterDefinition.getFilterName() == null ) {
throw new IllegalArgumentException( "Filter definition object or name is null: " + filterDefinition );
}
filterDefinitionMap.put( filterDefinition.getFilterName(), filterDefinition );
}
public Iterable<FilterDefinition> getFilterDefinitions() {
return filterDefinitionMap.values();
}
// identifier generators ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -264,18 +301,6 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
fetchProfiles.put( profile.getName(), profile );
}
@Override
public void addFilterDefinition(FilterDefinition def) {
if ( def == null || def.getFilterName() == null ) {
throw new IllegalArgumentException( "Filter definition object or name is null: " + def );
}
filterDefs.put( def.getFilterName(), def );
}
public Iterable<FilterDefinition> getFilterDefinitions() {
return filterDefs.values();
}
@Override
public void addIdGenerator(IdGenerator generator) {
if ( generator == null || generator.getName() == null ) {
@ -352,30 +377,6 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
return resultSetMappings.values();
}
@Override
public void addTypeDefinition(TypeDef typeDef) {
if ( typeDef == null ) {
throw new IllegalArgumentException( "Type definition is null" );
}
else if ( typeDef.getName() == null ) {
throw new IllegalArgumentException( "Type definition name is null: " + typeDef.getTypeClass() );
}
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> getTypeDefinitions() {
return typeDefs.values();
}
@Override
public TypeDef getTypeDefinition(String name) {
return typeDefs.get( name );
}
private ClassLoaderService classLoaderService() {
return classLoaderService.getValue();
}

View File

@ -57,7 +57,7 @@ import org.hibernate.metamodel.spi.binding.IdGenerator;
import org.hibernate.metamodel.spi.binding.InheritanceType;
import org.hibernate.metamodel.spi.binding.SimpleValueBinding;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.hibernate.metamodel.spi.binding.TypeDef;
import org.hibernate.metamodel.spi.binding.TypeDefinition;
import org.hibernate.metamodel.spi.domain.Component;
import org.hibernate.metamodel.spi.domain.Entity;
import org.hibernate.metamodel.spi.domain.PluralAttribute;
@ -820,11 +820,11 @@ public class Binder {
final String explicitTypeName = typeSource.getName();
if ( explicitTypeName != null ) {
final TypeDef typeDef = currentBindingContext.getMetadataImplementor()
final TypeDefinition typeDefinition = currentBindingContext.getMetadataImplementor()
.getTypeDefinition( explicitTypeName );
if ( typeDef != null ) {
hibernateTypeDescriptor.setExplicitTypeName( typeDef.getTypeClass() );
hibernateTypeDescriptor.getTypeParameters().putAll( typeDef.getParameters() );
if ( typeDefinition != null ) {
hibernateTypeDescriptor.setExplicitTypeName( typeDefinition.getTypeImplementorClass().getName() );
hibernateTypeDescriptor.getTypeParameters().putAll( typeDefinition.getParameters() );
}
else {
hibernateTypeDescriptor.setExplicitTypeName( explicitTypeName );

View File

@ -40,14 +40,13 @@ import org.hibernate.internal.jaxb.mapping.orm.JaxbEntityMappings;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.internal.source.annotations.global.FetchProfileProcessor;
import org.hibernate.metamodel.internal.source.annotations.global.FilterDefProcessor;
import org.hibernate.metamodel.internal.source.annotations.global.QueryProcessor;
import org.hibernate.metamodel.internal.source.annotations.global.TableProcessor;
import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames;
import org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityMappingsMocker;
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
import org.hibernate.metamodel.spi.source.EntityHierarchy;
import org.hibernate.metamodel.spi.source.FilterDefSource;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.MetadataImplementor;
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
import org.hibernate.service.classloading.spi.ClassLoaderService;
@ -105,7 +104,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
}
@Override
public Iterable<TypeDescriptorSource> extractTypeDescriptorSources(MetadataSources sources) {
public Iterable<TypeDescriptorSource> extractTypeDefinitionSources(MetadataSources sources) {
assertBindingContextExists();
List<TypeDescriptorSource> typeDescriptorSources = new ArrayList<TypeDescriptorSource>();
@ -135,13 +134,13 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
}
@Override
public Iterable<FilterDefSource> extractFilterDefSources(MetadataSources sources) {
public Iterable<FilterDefinitionSource> extractFilterDefinitionSources(MetadataSources sources) {
assertBindingContextExists();
List<FilterDefSource> filterDefSources = new ArrayList<FilterDefSource>();
List<FilterDefinitionSource> filterDefinitionSources = new ArrayList<FilterDefinitionSource>();
List<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEF );
for ( AnnotationInstance filterDef : annotations ) {
filterDefSources.add( new FilterDefSourceImpl( filterDef ) );
filterDefinitionSources.add( new FilterDefinitionSourceImpl( filterDef ) );
}
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEFS );
@ -152,10 +151,10 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
AnnotationInstance[].class
);
for ( AnnotationInstance filterDef : filterDefAnnotations ) {
filterDefSources.add( new FilterDefSourceImpl( filterDef ) );
filterDefinitionSources.add( new FilterDefinitionSourceImpl( filterDef ) );
}
}
return filterDefSources;
return filterDefinitionSources;
}
@Override
@ -170,7 +169,6 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
TableProcessor.bind( bindingContext );
FetchProfileProcessor.bind( bindingContext );
QueryProcessor.bind( bindingContext );
FilterDefProcessor.bind( bindingContext );
}
private Index parseAndUpdateIndex(List<JaxbRoot<JaxbEntityMappings>> mappings, Index annotationIndex) {

View File

@ -28,18 +28,18 @@ import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.metamodel.spi.source.FilterDefSource;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.FilterParameterSource;
/**
* @author Steve Ebersole
*/
public class FilterDefSourceImpl implements FilterDefSource {
public class FilterDefinitionSourceImpl implements FilterDefinitionSource {
private final String name;
private final String condition;
private List<FilterParameterSource> parameterSources;
public FilterDefSourceImpl(AnnotationInstance filterDefAnnotation) {
public FilterDefinitionSourceImpl(AnnotationInstance filterDefAnnotation) {
this.name = JandexHelper.getValue( filterDefAnnotation, "name", String.class );
this.condition = JandexHelper.getValue( filterDefAnnotation, "defaultCondition", String.class );
this.parameterSources = buildParameterSources( filterDefAnnotation );

View File

@ -23,7 +23,6 @@
*/
package org.hibernate.metamodel.internal.source.annotations;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -39,7 +38,7 @@ import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
public class TypeDescriptorSourceImpl implements TypeDescriptorSource {
private final String name;
private final String implementationClassName;
private final String registrationKey;
private final String[] registrationKeys;
private Map<String, String> parameterValueMap;
@ -53,17 +52,18 @@ public class TypeDescriptorSourceImpl implements TypeDescriptorSource {
defaultForType = null;
}
}
registrationKey = defaultForType;
String registrationKey = defaultForType;
if ( StringHelper.isEmpty( name ) && registrationKey == null ) {
throw new AnnotationException(
String.format(
"Either name or defaultForType (or both) must be set on TypeDef [%s]",
"Either name or defaultForType (or both) must be set on TypeDefinition [%s]",
implementationClassName
)
);
}
this.registrationKeys = registrationKey == null ? new String[0] : new String[] { registrationKey };
this.parameterValueMap = extractParameterValues( typeDefAnnotation );
}
@ -94,10 +94,8 @@ public class TypeDescriptorSourceImpl implements TypeDescriptorSource {
}
@Override
public Iterable<String> getRegistrationKeys() {
return registrationKey == null
? Collections.<String>emptyList()
: Collections.singletonList( registrationKey );
public String[] getRegistrationKeys() {
return registrationKeys;
}
@Override

View File

@ -1,100 +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.internal.source.annotations.global;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.logging.Logger;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.FilterDefs;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.metamodel.spi.source.MetadataImplementor;
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.internal.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.JandexHelper;
import org.hibernate.type.Type;
/**
* Binds {@link FilterDefs} and {@link FilterDef} annotations.
*
* @author Hardy Ferentschik
*/
public class FilterDefProcessor {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
FilterDefProcessor.class.getName()
);
/**
* Binds all {@link FilterDefs} and {@link FilterDef} annotations to the supplied metadata.
*
* @param bindingContext the context for annotation binding
*/
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEF );
for ( AnnotationInstance filterDef : annotations ) {
bind( bindingContext.getMetadataImplementor(), filterDef );
}
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEFS );
for ( AnnotationInstance filterDefs : annotations ) {
AnnotationInstance[] filterDefAnnotations = JandexHelper.getValue(
filterDefs,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance filterDef : filterDefAnnotations ) {
bind( bindingContext.getMetadataImplementor(), filterDef );
}
}
}
private static void bind(MetadataImplementor metadata, AnnotationInstance filterDef) {
String name = JandexHelper.getValue( filterDef, "name", String.class );
Map<String, Type> prms = new HashMap<String, Type>();
for ( AnnotationInstance prm : JandexHelper.getValue( filterDef, "parameters", AnnotationInstance[].class ) ) {
prms.put(
JandexHelper.getValue( prm, "name", String.class ),
metadata.getTypeResolver().heuristicType( JandexHelper.getValue( prm, "type", String.class ) )
);
}
metadata.addFilterDefinition(
new FilterDefinition(
name,
JandexHelper.getValue( filterDef, "defaultCondition", String.class ),
prms
)
);
LOG.debugf( "Binding filter definition: %s", name );
}
private FilterDefProcessor() {
}
}

View File

@ -1,126 +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.internal.source.annotations.global;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.logging.Logger;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.spi.binding.TypeDef;
import org.hibernate.metamodel.spi.source.MetadataImplementor;
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.internal.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.JandexHelper;
/**
* Binds {@link org.hibernate.annotations.TypeDef} and {@link TypeDefs}.
*
* @author Hardy Ferentschik
*/
public class TypeDefProcessor {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
TypeDefProcessor.class.getName()
);
/**
* Binds all {@link org.hibernate.annotations.TypeDef} and {@link TypeDefs} annotations to the supplied metadata.
*
* @param bindingContext the context for annotation binding
*/
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TYPE_DEF );
for ( AnnotationInstance typeDef : annotations ) {
bind( bindingContext.getMetadataImplementor(), typeDef );
}
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TYPE_DEFS );
for ( AnnotationInstance typeDefs : annotations ) {
AnnotationInstance[] typeDefAnnotations = JandexHelper.getValue(
typeDefs,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance typeDef : typeDefAnnotations ) {
bind( bindingContext.getMetadataImplementor(), typeDef );
}
}
}
private static void bind(MetadataImplementor metadata, AnnotationInstance typeDefAnnotation) {
String name = JandexHelper.getValue( typeDefAnnotation, "name", String.class );
String defaultForType = JandexHelper.getValue( typeDefAnnotation, "defaultForType", String.class );
String typeClass = JandexHelper.getValue( typeDefAnnotation, "typeClass", String.class );
boolean noName = StringHelper.isEmpty( name );
boolean noDefaultForType = defaultForType == null || defaultForType.equals( void.class.getName() );
if ( noName && noDefaultForType ) {
throw new AnnotationException(
"Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass "
+ typeClass
);
}
Map<String, String> parameterMaps = new HashMap<String, String>();
AnnotationInstance[] parameterAnnotations = JandexHelper.getValue(
typeDefAnnotation,
"parameters",
AnnotationInstance[].class
);
for ( AnnotationInstance parameterAnnotation : parameterAnnotations ) {
parameterMaps.put(
JandexHelper.getValue( parameterAnnotation, "name", String.class ),
JandexHelper.getValue( parameterAnnotation, "value", String.class )
);
}
if ( !noName ) {
bind( name, typeClass, parameterMaps, metadata );
}
if ( !noDefaultForType ) {
bind( defaultForType, typeClass, parameterMaps, metadata );
}
}
private static void bind(
String name,
String typeClass,
Map<String, String> prms,
MetadataImplementor metadata) {
LOG.debugf( "Binding type definition: %s", name );
metadata.addTypeDefinition( new TypeDef( name, typeClass, prms ) );
}
private TypeDefProcessor() {
}
}

View File

@ -27,18 +27,18 @@ import java.util.ArrayList;
import java.util.List;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
import org.hibernate.metamodel.spi.source.FilterDefSource;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.FilterParameterSource;
/**
* @author Steve Ebersole
*/
public class FilterDefSourceImpl implements FilterDefSource {
public class FilterDefinitionSourceImpl implements FilterDefinitionSource {
private final String name;
private final String condition;
private List<FilterParameterSource> parameterSources;
public FilterDefSourceImpl(JaxbHibernateMapping.JaxbFilterDef filterDefElement) {
public FilterDefinitionSourceImpl(JaxbHibernateMapping.JaxbFilterDef filterDefElement) {
this.name = filterDefElement.getName();
String conditionAttribute = filterDefElement.getCondition();

View File

@ -30,7 +30,7 @@ import org.hibernate.internal.jaxb.JaxbRoot;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
import org.hibernate.metamodel.spi.source.FilterDefSource;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.MetadataImplementor;
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
@ -71,7 +71,7 @@ public class HbmMetadataSourceProcessorImpl implements MetadataSourceProcessor {
// todo : still need to deal with auxiliary database objects
@Override
public Iterable<TypeDescriptorSource> extractTypeDescriptorSources(MetadataSources sources) {
public Iterable<TypeDescriptorSource> extractTypeDefinitionSources(MetadataSources sources) {
final List<TypeDescriptorSource> typeDescriptorSources = new ArrayList<TypeDescriptorSource>();
for ( HibernateMappingProcessor processor : processors ) {
processor.collectTypeDescriptorSources( typeDescriptorSources );
@ -80,12 +80,12 @@ public class HbmMetadataSourceProcessorImpl implements MetadataSourceProcessor {
}
@Override
public Iterable<FilterDefSource> extractFilterDefSources(MetadataSources sources) {
final List<FilterDefSource> filterDefSources = new ArrayList<FilterDefSource>();
public Iterable<FilterDefinitionSource> extractFilterDefinitionSources(MetadataSources sources) {
final List<FilterDefinitionSource> filterDefinitionSources = new ArrayList<FilterDefinitionSource>();
for ( HibernateMappingProcessor processor : processors ) {
processor.collectFilterDefSources( filterDefSources );
processor.collectFilterDefSources( filterDefinitionSources );
}
return filterDefSources;
return filterDefinitionSources;
}
@Override

View File

@ -37,7 +37,7 @@ import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.spi.binding.FetchProfile;
import org.hibernate.metamodel.spi.relational.AuxiliaryDatabaseObject;
import org.hibernate.metamodel.spi.relational.BasicAuxiliaryDatabaseObjectImpl;
import org.hibernate.metamodel.spi.source.FilterDefSource;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.metamodel.spi.source.MetadataImplementor;
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
@ -136,13 +136,13 @@ public class HibernateMappingProcessor {
}
}
public void collectFilterDefSources(List<FilterDefSource> filterDefSources) {
public void collectFilterDefSources(List<FilterDefinitionSource> filterDefinitionSources) {
if ( mappingRoot().getFilterDef() == null ) {
return;
}
for ( JaxbHibernateMapping.JaxbFilterDef filterDefElement : mappingRoot().getFilterDef() ) {
filterDefSources.add( new FilterDefSourceImpl( filterDefElement ) );
filterDefinitionSources.add( new FilterDefinitionSourceImpl( filterDefElement ) );
}
}

View File

@ -33,6 +33,8 @@ import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
* @author Steve Ebersole
*/
public class TypeDescriptorSourceImpl implements TypeDescriptorSource {
private static final String[] NO_REGISTRATION_KEYS = new String[0];
private final String name;
private final String implementationClassName;
private final Map<String,String> params;
@ -54,8 +56,8 @@ public class TypeDescriptorSourceImpl implements TypeDescriptorSource {
}
@Override
public Iterable<String> getRegistrationKeys() {
return Collections.emptyList();
public String[] getRegistrationKeys() {
return NO_REGISTRATION_KEYS;
}
@Override

View File

@ -25,7 +25,7 @@ package org.hibernate.metamodel.spi;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.spi.source.EntityHierarchy;
import org.hibernate.metamodel.spi.source.FilterDefSource;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
/**
@ -48,7 +48,7 @@ public interface MetadataSourceProcessor {
*
* @return The type descriptor sources.
*/
public Iterable<? extends TypeDescriptorSource> extractTypeDescriptorSources(MetadataSources sources);
public Iterable<? extends TypeDescriptorSource> extractTypeDefinitionSources(MetadataSources sources);
/**
* Retrieve the sources pertaining to filter defs.
@ -57,7 +57,7 @@ public interface MetadataSourceProcessor {
*
* @return The filter def sources.
*/
public Iterable<? extends FilterDefSource> extractFilterDefSources(MetadataSources sources);
public Iterable<? extends FilterDefinitionSource> extractFilterDefinitionSources(MetadataSources sources);
/**
* Retrieve the entity hierarchies.

View File

@ -28,30 +28,40 @@ import java.util.Collections;
import java.util.Map;
/**
* Represents the metamodel view of a typedef (type definition).
* Describes custom type definitions supplied by the user as part of the metadata.
*
* @author John Verhaeg
*/
public class TypeDef implements Serializable {
public class TypeDefinition implements Serializable {
private final String name;
private final String typeClass;
private final Class typeImplementorClass;
private final String[] registrationKeys;
private final Map<String, String> parameters;
public TypeDef(String name, String typeClass, Map<String, String> parameters) {
public TypeDefinition(
String name,
Class typeImplementorClass,
String[] registrationKeys,
Map<String, String> parameters) {
this.name = name;
this.typeClass = typeClass;
this.parameters = parameters;
this.typeImplementorClass = typeImplementorClass;
this.registrationKeys= registrationKeys;
this.parameters = Collections.unmodifiableMap( parameters );
}
public String getName() {
return name;
}
public String getTypeClass() {
return typeClass;
}
public Class getTypeImplementorClass() {
return typeImplementorClass;
}
public Map<String, String> getParameters() {
return Collections.unmodifiableMap(parameters);
public String[] getRegistrationKeys() {
return registrationKeys;
}
public Map<String, String> getParameters() {
return parameters;
}
}

View File

@ -29,7 +29,7 @@ package org.hibernate.metamodel.spi.source;
*
* @author Steve Ebersole
*/
public interface FilterDefSource {
public interface FilterDefinitionSource {
/**
* Retrieve the name of the filter. Would match the related {@link FilterSource#getName}
*

View File

@ -24,7 +24,7 @@
package org.hibernate.metamodel.spi.source;
/**
* Defines the source of filter information. May have an associated {@link FilterDefSource}.
* Defines the source of filter information. May have an associated {@link FilterDefinitionSource}.
* Relates to both {@code <filter/>} and {@link org.hibernate.annotations.Filter @Filter}
*
* @author Steve Ebersole
@ -43,7 +43,7 @@ public interface FilterSource {
*
* @return The condition defined on the filter.
*
* @see {@link org.hibernate.metamodel.spi.source.FilterDefSource#getCondition()}
* @see {@link FilterDefinitionSource#getCondition()}
*/
public String getCondition();
}

View File

@ -33,7 +33,7 @@ import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.binding.FetchProfile;
import org.hibernate.metamodel.spi.binding.IdGenerator;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.TypeDef;
import org.hibernate.metamodel.spi.binding.TypeDefinition;
import org.hibernate.metamodel.spi.relational.Database;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.TypeResolver;
@ -56,7 +56,7 @@ public interface MetadataImplementor extends Metadata, BindingContext, Mapping {
public void addFetchProfile(FetchProfile profile);
public void addTypeDefinition(TypeDef typeDef);
public void addTypeDefinition(TypeDefinition typeDefinition);
public void addFilterDefinition(FilterDefinition filterDefinition);

View File

@ -27,7 +27,7 @@ import java.util.Map;
/**
* Describes the source of a custom type description. For example, {@code <type-def/>} or
* {@link org.hibernate.annotations.TypeDef @TypeDef}
* {@link org.hibernate.annotations.TypeDef @TypeDefinition}
*
* @author Steve Ebersole
*/
@ -58,7 +58,7 @@ public interface TypeDescriptorSource {
*
* @return The registration keys for the type built from this type def.
*/
public Iterable<String> getRegistrationKeys();
public String[] getRegistrationKeys();
/**
* Types accept configuration. The values here represent the user supplied values that will be given

View File

@ -652,7 +652,7 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
}
catch( AnnotationException ex ) {
assertEquals(
"Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType",
"Either name or defaultForType (or both) attribute should be set in TypeDefinition having typeClass org.hibernate.test.annotations.entity.PhoneNumberType",
ex.getMessage());
}
}

View File

@ -44,6 +44,8 @@ import org.hibernate.metamodel.spi.binding.EntityIdentifier;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.testing.FailureExpected;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
@ -170,6 +172,7 @@ public class IdentifierGeneratorTest extends BaseAnnotationBindingTestCase {
}
@Test
@FailureExpected( jiraKey = "HHH-7040" )
@Resources(annotatedClasses = NamedGeneratorEntity2.class)
public void testNamedGenerator() {
EntityBinding binding = getEntityBinding( NamedGeneratorEntity2.class );

View File

@ -26,9 +26,6 @@ package org.hibernate.metamodel.internal.source.annotations.global;
import java.util.Iterator;
import org.jboss.jandex.Index;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.MappingException;
import org.hibernate.annotations.FetchMode;
@ -41,6 +38,11 @@ import org.hibernate.metamodel.internal.source.annotations.JandexHelper;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.StandardServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.fail;