HHH-6371 Bringing the annotation side into sync with the new push (setter) approach for the binders

Creating an explicit AnnotationBindingContext (instead of letting AnnotationProcessor implement it) and making use of the context in the global binders

Updating EntityBinder to use the push approach. Still needs major cleanup
This commit is contained in:
Hardy Ferentschik 2011-07-15 18:48:01 +02:00
parent aa28d7016e
commit 3f31aa8f69
27 changed files with 714 additions and 453 deletions

View File

@ -69,6 +69,10 @@ public class EntityDiscriminator {
return discriminatorValue;
}
public void setDiscriminatorValue(String discriminatorValue) {
this.discriminatorValue = discriminatorValue;
}
public boolean isForced() {
return forced;
}

View File

@ -32,7 +32,7 @@ import org.hibernate.internal.util.Value;
*
* @author Steve Ebersole
*/
public class Component extends AbstractAttributeContainer implements Hierarchical {
public class Component extends AbstractAttributeContainer {
public Component(String name, String className, Value<Class<?>> classReference, Hierarchical superType) {
super( name, className, classReference, superType );
}

View File

@ -30,7 +30,7 @@ import org.hibernate.internal.util.Value;
*
* @author Hardy Ferentschik
*/
public class NonEntity extends AbstractAttributeContainer implements Hierarchical {
public class NonEntity extends AbstractAttributeContainer {
/**
* Constructor for the non-entity
*

View File

@ -30,7 +30,7 @@ import org.hibernate.internal.util.Value;
*
* @author Steve Ebersole
*/
public class Superclass extends AbstractAttributeContainer implements Hierarchical {
public class Superclass extends AbstractAttributeContainer {
/**
* Constructor for the entity
*

View File

@ -31,14 +31,19 @@ import org.jboss.jandex.Index;
import org.hibernate.metamodel.source.BindingContext;
/**
* Defines an interface for providing additional annotation related context information.
*
* @author Steve Ebersole
* @author Hardy Ferentschik
*/
public interface AnnotationsBindingContext extends BindingContext {
public Index getIndex();
public ClassInfo getClassInfo(String name);
public interface AnnotationBindingContext extends BindingContext {
Index getIndex();
public void resolveAllTypes(String className);
public ResolvedType getResolvedType(Class<?> clazz);
ClassInfo getClassInfo(String name);
public ResolvedTypeWithMembers resolveMemberTypes(ResolvedType type);
void resolveAllTypes(String className);
ResolvedType getResolvedType(Class<?> clazz);
ResolvedTypeWithMembers resolveMemberTypes(ResolvedType type);
}

View File

@ -0,0 +1,156 @@
/*
* 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.util.HashMap;
import java.util.Map;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
import com.fasterxml.classmate.TypeResolver;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.domain.Type;
import org.hibernate.metamodel.source.MappingDefaults;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.classloading.spi.ClassLoaderService;
/**
* @author Steve Ebersole
*/
public class AnnotationBindingContextImpl implements AnnotationBindingContext {
private final MetadataImplementor metadata;
private final Value<ClassLoaderService> classLoaderService;
private final Index index;
private final TypeResolver typeResolver = new TypeResolver();
private final Map<Class<?>, ResolvedType> resolvedTypeCache = new HashMap<Class<?>, ResolvedType>();
public AnnotationBindingContextImpl(MetadataImplementor metadata, Index index) {
this.metadata = metadata;
this.classLoaderService = new Value<ClassLoaderService>(
new Value.DeferredInitializer<ClassLoaderService>() {
@Override
public ClassLoaderService initialize() {
return AnnotationBindingContextImpl.this.metadata
.getServiceRegistry()
.getService( ClassLoaderService.class );
}
}
);
this.index = index;
}
@Override
public Index getIndex() {
return index;
}
@Override
public ClassInfo getClassInfo(String name) {
DotName dotName = DotName.createSimple( name );
return index.getClassByName( dotName );
}
@Override
public void resolveAllTypes(String className) {
// the resolved type for the top level class in the hierarchy
Class<?> clazz = classLoaderService.getValue().classForName( className );
ResolvedType resolvedType = typeResolver.resolve( clazz );
while ( resolvedType != null ) {
// todo - check whether there is already something in the map
resolvedTypeCache.put( clazz, resolvedType );
resolvedType = resolvedType.getParentClass();
if ( resolvedType != null ) {
clazz = resolvedType.getErasedType();
}
}
}
@Override
public ResolvedType getResolvedType(Class<?> clazz) {
// todo - error handling
return resolvedTypeCache.get( clazz );
}
@Override
public ResolvedTypeWithMembers resolveMemberTypes(ResolvedType type) {
// todo : is there a reason we create this resolver every time?
MemberResolver memberResolver = new MemberResolver( typeResolver );
return memberResolver.resolve( type, null, null );
}
@Override
public ServiceRegistry getServiceRegistry() {
return getMetadataImplementor().getServiceRegistry();
}
@Override
public NamingStrategy getNamingStrategy() {
return metadata.getNamingStrategy();
}
@Override
public MappingDefaults getMappingDefaults() {
return metadata.getMappingDefaults();
}
@Override
public MetadataImplementor getMetadataImplementor() {
return metadata;
}
@Override
public <T> Class<T> locateClassByName(String name) {
return classLoaderService.getValue().classForName( name );
}
private Map<String, Type> nameToJavaTypeMap = new HashMap<String, Type>();
@Override
public Type makeJavaType(String className) {
Type javaType = nameToJavaTypeMap.get( className );
if ( javaType == null ) {
javaType = metadata.makeJavaType( className );
nameToJavaTypeMap.put( className, javaType );
}
return javaType;
}
@Override
public Value<Class<?>> makeClassReference(String className) {
return new Value<Class<?>>( locateClassByName( className ) );
}
@Override
public boolean isGloballyQuotedIdentifiers() {
return metadata.isGloballyQuotedIdentifiers();
}
}

View File

@ -26,31 +26,27 @@ package org.hibernate.metamodel.source.annotations;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
import com.fasterxml.classmate.TypeResolver;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.jandex.Indexer;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.source.MappingDefaults;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.domain.Hierarchical;
import org.hibernate.metamodel.domain.NonEntity;
import org.hibernate.metamodel.domain.Superclass;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.SourceProcessor;
import org.hibernate.metamodel.source.annotation.jaxb.XMLEntityMappings;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassType;
import org.hibernate.metamodel.source.annotations.entity.EntityBinder;
import org.hibernate.metamodel.source.annotations.entity.EntityClass;
import org.hibernate.metamodel.source.annotations.global.FetchProfileBinder;
import org.hibernate.metamodel.source.annotations.global.FilterDefBinder;
import org.hibernate.metamodel.source.annotations.global.IdGeneratorBinder;
@ -61,14 +57,6 @@ import org.hibernate.metamodel.source.annotations.xml.PseudoJpaDotNames;
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.binding.EntityBinding;
import org.hibernate.metamodel.domain.Hierarchical;
import org.hibernate.metamodel.domain.Type;
import org.hibernate.metamodel.domain.NonEntity;
import org.hibernate.metamodel.domain.Superclass;
import org.hibernate.metamodel.source.annotation.jaxb.XMLEntityMappings;
import org.hibernate.metamodel.source.annotations.entity.EntityClass;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.classloading.spi.ClassLoaderService;
/**
@ -79,27 +67,14 @@ import org.hibernate.service.classloading.spi.ClassLoaderService;
* @author Hardy Ferentschik
* @author Steve Ebersole
*/
public class AnnotationsSourceProcessor implements SourceProcessor, AnnotationsBindingContext {
private static final Logger LOG = Logger.getLogger( AnnotationsSourceProcessor.class );
public class AnnotationProcessor implements SourceProcessor {
private static final Logger LOG = Logger.getLogger( AnnotationProcessor.class );
private final MetadataImplementor metadata;
private final Value<ClassLoaderService> classLoaderService;
private AnnotationBindingContext bindingContext;
private Index index;
private final TypeResolver typeResolver = new TypeResolver();
private final Map<Class<?>, ResolvedType> resolvedTypeCache = new HashMap<Class<?>, ResolvedType>();
public AnnotationsSourceProcessor(MetadataImpl metadata) {
public AnnotationProcessor(MetadataImpl metadata) {
this.metadata = metadata;
this.classLoaderService = new Value<ClassLoaderService>(
new Value.DeferredInitializer<ClassLoaderService>() {
@Override
public ClassLoaderService initialize() {
return AnnotationsSourceProcessor.this.metadata.getServiceRegistry().getService( ClassLoaderService.class );
}
}
);
}
@Override
@ -116,7 +91,7 @@ public class AnnotationsSourceProcessor implements SourceProcessor, AnnotationsB
indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class" );
}
index = indexer.complete();
Index index = indexer.complete();
List<JaxbRoot<XMLEntityMappings>> mappings = new ArrayList<JaxbRoot<XMLEntityMappings>>();
for ( JaxbRoot<?> root : sources.getJaxbRootList() ) {
@ -128,11 +103,81 @@ public class AnnotationsSourceProcessor implements SourceProcessor, AnnotationsB
index = parseAndUpdateIndex( mappings, index );
}
if ( index.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ) != null ) {
if ( index.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ) != null ) {
// todo : this needs to move to AnnotationBindingContext
// what happens right now is that specifying this in an orm.xml causes it to effect all orm.xmls
metadata.setGloballyQuotedIdentifiers( true );
}
metadata.setGloballyQuotedIdentifiers( true );
}
bindingContext = new AnnotationBindingContextImpl( metadata, index );
}
@Override
public void processIndependentMetadata(MetadataSources sources) {
assertBindingContextExists();
TypeDefBinder.bind( bindingContext );
}
private void assertBindingContextExists() {
if ( bindingContext == null ) {
throw new AssertionFailure( "The binding context should exist. Has prepare been called!?" );
}
}
@Override
public void processTypeDependentMetadata(MetadataSources sources) {
assertBindingContextExists();
IdGeneratorBinder.bind( bindingContext );
}
@Override
public void processMappingMetadata(MetadataSources sources, List<String> processedEntityNames) {
assertBindingContextExists();
// need to order our annotated entities into an order we can process
Set<ConfiguredClassHierarchy<EntityClass>> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(
bindingContext
);
// now we process each hierarchy one at the time
Hierarchical parent = null;
for ( ConfiguredClassHierarchy<EntityClass> hierarchy : hierarchies ) {
for ( EntityClass entityClass : hierarchy ) {
// for classes annotated w/ @Entity we create a EntityBinding
if ( ConfiguredClassType.ENTITY.equals( entityClass.getConfiguredClassType() ) ) {
LOG.debugf( "Binding entity from annotated class: %s", entityClass.getName() );
EntityBinder entityBinder = new EntityBinder( entityClass, parent, bindingContext );
EntityBinding binding = entityBinder.bind( processedEntityNames );
parent = binding.getEntity();
}
// for classes annotated w/ @MappedSuperclass we just create the domain instance
// the attribute bindings will be part of the first entity subclass
else if ( ConfiguredClassType.MAPPED_SUPERCLASS.equals( entityClass.getConfiguredClassType() ) ) {
parent = new Superclass(
entityClass.getName(),
entityClass.getName(),
bindingContext.makeClassReference( entityClass.getName() ),
parent
);
}
// for classes which are not annotated at all we create the NonEntity domain class
// todo - not sure whether this is needed. It might be that we don't need this information (HF)
else {
parent = new NonEntity(
entityClass.getName(),
entityClass.getName(),
bindingContext.makeClassReference( entityClass.getName() ),
parent
);
}
}
}
}
@Override
public void processMappingDependentMetadata(MetadataSources sources) {
TableBinder.bind( bindingContext );
FetchProfileBinder.bind( bindingContext );
QueryBinder.bind( bindingContext );
FilterDefBinder.bind( bindingContext );
}
private Index parseAndUpdateIndex(List<JaxbRoot<XMLEntityMappings>> mappings, Index annotationIndex) {
@ -144,7 +189,9 @@ public class AnnotationsSourceProcessor implements SourceProcessor, AnnotationsB
}
private void indexClass(Indexer indexer, String className) {
InputStream stream = classLoaderService.getValue().locateResourceStream( className );
InputStream stream = metadata.getServiceRegistry().getService( ClassLoaderService.class ).locateResourceStream(
className
);
try {
indexer.index( stream );
}
@ -152,156 +199,6 @@ public class AnnotationsSourceProcessor implements SourceProcessor, AnnotationsB
throw new HibernateException( "Unable to open input stream for class " + className, e );
}
}
@Override
public void processIndependentMetadata(MetadataSources sources) {
TypeDefBinder.bind( metadata, index );
}
@Override
public void processTypeDependentMetadata(MetadataSources sources) {
IdGeneratorBinder.bind( metadata, index );
}
@Override
public void processMappingMetadata(MetadataSources sources, List<String> processedEntityNames) {
// need to order our annotated entities into an order we can process
Set<ConfiguredClassHierarchy<EntityClass>> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(
this
);
// now we process each hierarchy one at the time
Hierarchical parent = null;
for ( ConfiguredClassHierarchy<EntityClass> hierarchy : hierarchies ) {
for ( EntityClass entityClass : hierarchy ) {
// for classes annotated w/ @Entity we create a EntityBinding
if ( ConfiguredClassType.ENTITY.equals( entityClass.getConfiguredClassType() ) ) {
LOG.debugf( "Binding entity from annotated class: %s", entityClass.getName() );
EntityBinder entityBinder = new EntityBinder( entityClass, parent, this );
EntityBinding binding = entityBinder.bind( processedEntityNames );
parent = binding.getEntity();
}
// for classes annotated w/ @MappedSuperclass we just create the domain instance
// the attribute bindings will be part of the first entity subclass
else if ( ConfiguredClassType.MAPPED_SUPERCLASS.equals( entityClass.getConfiguredClassType() ) ) {
parent = new Superclass(
entityClass.getName(),
entityClass.getName(),
makeClassReference( entityClass.getName() ),
parent
);
}
// for classes which are not annotated at all we create the NonEntity domain class
// todo - not sure whether this is needed. It might be that we don't need this information (HF)
else {
parent = new NonEntity(
entityClass.getName(),
entityClass.getName(),
makeClassReference( entityClass.getName() ),
parent
);
}
}
}
}
private Set<ConfiguredClassHierarchy<EntityClass>> createEntityHierarchies() {
return ConfiguredClassHierarchyBuilder.createEntityHierarchies( this );
}
@Override
public void processMappingDependentMetadata(MetadataSources sources) {
TableBinder.bind( metadata, index );
FetchProfileBinder.bind( metadata, index );
QueryBinder.bind( metadata, index );
FilterDefBinder.bind( metadata, index );
}
@Override
public Index getIndex() {
return index;
}
@Override
public ClassInfo getClassInfo(String name) {
DotName dotName = DotName.createSimple( name );
return index.getClassByName( dotName );
}
@Override
public void resolveAllTypes(String className) {
// the resolved type for the top level class in the hierarchy
Class<?> clazz = classLoaderService.getValue().classForName( className );
ResolvedType resolvedType = typeResolver.resolve( clazz );
while ( resolvedType != null ) {
// todo - check whether there is already something in the map
resolvedTypeCache.put( clazz, resolvedType );
resolvedType = resolvedType.getParentClass();
if ( resolvedType != null ) {
clazz = resolvedType.getErasedType();
}
}
}
@Override
public ResolvedType getResolvedType(Class<?> clazz) {
// todo - error handling
return resolvedTypeCache.get( clazz );
}
@Override
public ResolvedTypeWithMembers resolveMemberTypes(ResolvedType type) {
// todo : is there a reason we create this resolver every time?
MemberResolver memberResolver = new MemberResolver( typeResolver );
return memberResolver.resolve( type, null, null );
}
@Override
public ServiceRegistry getServiceRegistry() {
return getMetadataImplementor().getServiceRegistry();
}
@Override
public NamingStrategy getNamingStrategy() {
return metadata.getNamingStrategy();
}
@Override
public MappingDefaults getMappingDefaults() {
return metadata.getMappingDefaults();
}
@Override
public MetadataImplementor getMetadataImplementor() {
return metadata;
}
@Override
public <T> Class<T> locateClassByName(String name) {
return classLoaderService.getValue().classForName( name );
}
private Map<String,Type> nameToJavaTypeMap = new HashMap<String, Type>();
@Override
public Type makeJavaType(String className) {
Type javaType = nameToJavaTypeMap.get( className );
if ( javaType == null ) {
javaType = metadata.makeJavaType( className );
nameToJavaTypeMap.put( className, javaType );
}
return javaType;
}
@Override
public Value<Class<?>> makeClassReference(String className) {
return new Value<Class<?>>( locateClassByName( className ) );
}
@Override
public boolean isGloballyQuotedIdentifiers() {
return metadata.isGloballyQuotedIdentifiers();
}
}

View File

@ -57,7 +57,7 @@ public class ConfiguredClassHierarchyBuilder {
*
* @return a set of {@code ConfiguredClassHierarchy}s. One for each "leaf" entity.
*/
public static Set<ConfiguredClassHierarchy<EntityClass>> createEntityHierarchies(AnnotationsBindingContext bindingContext) {
public static Set<ConfiguredClassHierarchy<EntityClass>> createEntityHierarchies(AnnotationBindingContext bindingContext) {
Map<ClassInfo, List<ClassInfo>> processedClassInfos = new HashMap<ClassInfo, List<ClassInfo>>();
for ( ClassInfo info : bindingContext.getIndex().getKnownClasses() ) {
@ -115,7 +115,7 @@ public class ConfiguredClassHierarchyBuilder {
*
* @return a set of {@code ConfiguredClassHierarchy}s. One for each "leaf" entity.
*/
public static ConfiguredClassHierarchy<EmbeddableClass> createEmbeddableHierarchy(Class<?> embeddableClass, AccessType accessType, AnnotationsBindingContext context) {
public static ConfiguredClassHierarchy<EmbeddableClass> createEmbeddableHierarchy(Class<?> embeddableClass, AccessType accessType, AnnotationBindingContext context) {
ClassInfo embeddableClassInfo = context.getClassInfo( embeddableClass.getName() );
if ( embeddableClassInfo == null ) {

View File

@ -23,6 +23,8 @@
*/
package org.hibernate.metamodel.source.annotations.attribute;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.persistence.DiscriminatorType;
@ -86,12 +88,21 @@ public class SimpleAttribute extends MappedAttribute {
*/
private ColumnValues columnValues;
private final String customWriteFragment;
private final String customReadFragment;
private final String checkCondition;
public static SimpleAttribute createSimpleAttribute(String name, Class<?> type, Map<DotName, List<AnnotationInstance>> annotations) {
return new SimpleAttribute( name, type, annotations, false );
}
public static SimpleAttribute createSimpleAttribute(SimpleAttribute simpleAttribute, ColumnValues columnValues) {
SimpleAttribute attribute = new SimpleAttribute( simpleAttribute.getName(), simpleAttribute.getJavaType(), simpleAttribute.annotations(), false );
SimpleAttribute attribute = new SimpleAttribute(
simpleAttribute.getName(),
simpleAttribute.getJavaType(),
simpleAttribute.annotations(),
false
);
attribute.columnValues = columnValues;
return attribute;
}
@ -134,10 +145,12 @@ public class SimpleAttribute extends MappedAttribute {
this.isDiscriminator = isDiscriminator;
AnnotationInstance idAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.ID );
AnnotationInstance embeddedIdAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.EMBEDDED_ID );
isId = !(idAnnotation == null && embeddedIdAnnotation == null);
AnnotationInstance embeddedIdAnnotation = JandexHelper.getSingleAnnotation(
annotations,
JPADotNames.EMBEDDED_ID
);
isId = !( idAnnotation == null && embeddedIdAnnotation == null );
AnnotationInstance versionAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.VERSION );
isVersioned = versionAnnotation != null;
@ -160,8 +173,14 @@ public class SimpleAttribute extends MappedAttribute {
checkBasicAnnotation();
checkGeneratedAnnotation();
}
String[] readWrite;
List<AnnotationInstance> columnTransformerAnnotations = getAllColumnTransformerAnnotations();
readWrite = createCustomReadWrite( columnTransformerAnnotations );
this.customReadFragment = readWrite[0];
this.customWriteFragment = readWrite[1];
this.checkCondition = parseCheckAnnotation();
}
public final ColumnValues getColumnValues() {
return columnValues;
@ -203,6 +222,18 @@ public class SimpleAttribute extends MappedAttribute {
return isOptimisticLockable;
}
public String getCustomWriteFragment() {
return customWriteFragment;
}
public String getCustomReadFragment() {
return customReadFragment;
}
public String getCheckCondition() {
return checkCondition;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
@ -263,6 +294,58 @@ public class SimpleAttribute extends MappedAttribute {
}
}
}
private List<AnnotationInstance> getAllColumnTransformerAnnotations() {
List<AnnotationInstance> allColumnTransformerAnnotations = new ArrayList<AnnotationInstance>();
// not quite sure about the usefulness of @ColumnTransformers (HF)
AnnotationInstance columnTransformersAnnotations = getIfExists( HibernateDotNames.COLUMN_TRANSFORMERS );
if ( columnTransformersAnnotations != null ) {
AnnotationInstance[] annotationInstances = allColumnTransformerAnnotations.get( 0 ).value().asNestedArray();
allColumnTransformerAnnotations.addAll( Arrays.asList( annotationInstances ) );
}
AnnotationInstance columnTransformerAnnotation = getIfExists( HibernateDotNames.COLUMN_TRANSFORMER );
if ( columnTransformerAnnotation != null ) {
allColumnTransformerAnnotations.add( columnTransformerAnnotation );
}
return allColumnTransformerAnnotations;
}
private String[] createCustomReadWrite(List<AnnotationInstance> columnTransformerAnnotations) {
String[] readWrite = new String[2];
boolean alreadyProcessedForColumn = false;
for ( AnnotationInstance annotationInstance : columnTransformerAnnotations ) {
String forColumn = annotationInstance.value( "forColumn" ) == null ?
null : annotationInstance.value( "forColumn" ).asString();
if ( forColumn != null && !forColumn.equals( getName() ) ) {
continue;
}
if ( alreadyProcessedForColumn ) {
throw new AnnotationException( "Multiple definition of read/write conditions for column " + getName() );
}
readWrite[0] = annotationInstance.value( "read" ) == null ?
null : annotationInstance.value( "read" ).asString();
readWrite[1] = annotationInstance.value( "write" ) == null ?
null : annotationInstance.value( "write" ).asString();
alreadyProcessedForColumn = true;
}
return readWrite;
}
private String parseCheckAnnotation() {
String checkCondition = null;
AnnotationInstance checkAnnotation = getIfExists( HibernateDotNames.CHECK );
if ( checkAnnotation != null ) {
checkCondition = checkAnnotation.value( "constraints" ).toString();
}
return checkCondition;
}
}

View File

@ -52,7 +52,7 @@ import org.jboss.logging.Logger;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.metamodel.source.annotations.AnnotationsBindingContext;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.ConfiguredClassHierarchyBuilder;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
@ -125,13 +125,13 @@ public class ConfiguredClass {
private final Set<String> transientFieldNames = new HashSet<String>();
private final Set<String> transientMethodNames = new HashSet<String>();
private final AnnotationsBindingContext context;
private final AnnotationBindingContext context;
public ConfiguredClass(
ClassInfo classInfo,
AccessType defaultAccessType,
ConfiguredClass parent,
AnnotationsBindingContext context) {
AnnotationBindingContext context) {
this.parent = parent;
this.context = context;
this.classInfo = classInfo;

View File

@ -23,10 +23,10 @@
*/
package org.hibernate.metamodel.source.annotations.entity;
import javax.persistence.AccessType;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.AccessType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
@ -34,10 +34,10 @@ import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
import org.hibernate.AnnotationException;
import org.hibernate.metamodel.source.annotations.AnnotationsBindingContext;
import org.hibernate.metamodel.binding.InheritanceType;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.binding.InheritanceType;
/**
* Contains information about the access and inheritance type for all classes within a class hierarchy.
@ -49,7 +49,7 @@ public class ConfiguredClassHierarchy<T extends ConfiguredClass> implements Iter
private final InheritanceType inheritanceType;
private final List<T> configuredClasses;
public static ConfiguredClassHierarchy<EntityClass> createEntityClassHierarchy(List<ClassInfo> classInfoList, AnnotationsBindingContext context) {
public static ConfiguredClassHierarchy<EntityClass> createEntityClassHierarchy(List<ClassInfo> classInfoList, AnnotationBindingContext context) {
AccessType defaultAccessType = determineDefaultAccessType( classInfoList );
InheritanceType inheritanceType = determineInheritanceType( classInfoList );
return new ConfiguredClassHierarchy<EntityClass>(
@ -64,7 +64,7 @@ public class ConfiguredClassHierarchy<T extends ConfiguredClass> implements Iter
public static ConfiguredClassHierarchy<EmbeddableClass> createEmbeddableClassHierarchy(
List<ClassInfo> classes,
AccessType accessType,
AnnotationsBindingContext context) {
AnnotationBindingContext context) {
return new ConfiguredClassHierarchy<EmbeddableClass>(
classes,
context,
@ -74,9 +74,10 @@ public class ConfiguredClassHierarchy<T extends ConfiguredClass> implements Iter
);
}
@SuppressWarnings("unchecked")
private ConfiguredClassHierarchy(
List<ClassInfo> classInfoList,
AnnotationsBindingContext context,
AnnotationBindingContext context,
AccessType defaultAccessType,
InheritanceType inheritanceType,
Class<T> configuredClassType) {
@ -152,35 +153,28 @@ public class ConfiguredClassHierarchy<T extends ConfiguredClass> implements Iter
* annotations.
*/
private static AccessType determineDefaultAccessType(List<ClassInfo> classes) {
AccessType accessTypeByEmbeddedIdPlacement = null;
AccessType accessTypeByIdPlacement = null;
AccessType accessTypeByEmbeddedIdPlacement = null;
AccessType accessTypeByIdPlacement = null;
for ( ClassInfo info : classes ) {
List<AnnotationInstance> idAnnotations = info.annotations().get( JPADotNames.ID );
List<AnnotationInstance> embeddedIdAnnotations = info.annotations().get( JPADotNames.EMBEDDED_ID );
List<AnnotationInstance> embeddedIdAnnotations = info.annotations().get( JPADotNames.EMBEDDED_ID );
if ( embeddedIdAnnotations != null && !embeddedIdAnnotations.isEmpty() ) {
accessTypeByEmbeddedIdPlacement = determineAccessTypeByIdPlacement( embeddedIdAnnotations );
}
if ( embeddedIdAnnotations != null && !embeddedIdAnnotations.isEmpty() ) {
accessTypeByEmbeddedIdPlacement = determineAccessTypeByIdPlacement( embeddedIdAnnotations );
}
if ( idAnnotations != null && !idAnnotations.isEmpty() ) {
accessTypeByIdPlacement = determineAccessTypeByIdPlacement( idAnnotations );
}
}
if ( accessTypeByEmbeddedIdPlacement != null ) {
return accessTypeByEmbeddedIdPlacement;
} else if (accessTypeByIdPlacement != null ){
return accessTypeByIdPlacement;
} else {
return throwIdNotFoundAnnotationException( classes );
}
//
//
// if ( accessType == null ) {
// return throwIdNotFoundAnnotationException( classes );
// }
//
// return accessType;
if ( accessTypeByEmbeddedIdPlacement != null ) {
return accessTypeByEmbeddedIdPlacement;
}
else if ( accessTypeByIdPlacement != null ) {
return accessTypeByIdPlacement;
}
else {
return throwIdNotFoundAnnotationException( classes );
}
}
private static AccessType determineAccessTypeByIdPlacement(List<AnnotationInstance> idAnnotations) {

View File

@ -27,7 +27,7 @@ import javax.persistence.AccessType;
import org.jboss.jandex.ClassInfo;
import org.hibernate.metamodel.source.annotations.AnnotationsBindingContext;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
/**
* @author Hardy Ferentschik
@ -38,7 +38,7 @@ public class EmbeddableClass extends ConfiguredClass {
ClassInfo classInfo,
EmbeddableClass parent,
AccessType defaultAccessType,
AnnotationsBindingContext context) {
AnnotationBindingContext context) {
super( classInfo, defaultAccessType, parent, context );
}
}

View File

@ -23,12 +23,12 @@
*/
package org.hibernate.metamodel.source.annotations.entity;
import javax.persistence.GenerationType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.persistence.GenerationType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
@ -47,12 +47,6 @@ import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.source.annotations.AnnotationsBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.annotations.UnknownInheritanceTypeException;
import org.hibernate.metamodel.source.annotations.global.IdGeneratorBinder;
import org.hibernate.metamodel.binding.Caching;
import org.hibernate.metamodel.binding.CustomSQL;
import org.hibernate.metamodel.binding.EntityBinding;
@ -61,29 +55,36 @@ import org.hibernate.metamodel.binding.IdGenerator;
import org.hibernate.metamodel.binding.InheritanceType;
import org.hibernate.metamodel.binding.ManyToOneAttributeBinding;
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState;
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
import org.hibernate.metamodel.domain.Attribute;
import org.hibernate.metamodel.domain.AttributeContainer;
import org.hibernate.metamodel.domain.Component;
import org.hibernate.metamodel.domain.Entity;
import org.hibernate.metamodel.domain.Hierarchical;
import org.hibernate.metamodel.domain.SingularAttribute;
import org.hibernate.metamodel.relational.Column;
import org.hibernate.metamodel.relational.Identifier;
import org.hibernate.metamodel.relational.Schema;
import org.hibernate.metamodel.relational.Size;
import org.hibernate.metamodel.relational.TableSpecification;
import org.hibernate.metamodel.relational.UniqueKey;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.annotations.UnknownInheritanceTypeException;
import org.hibernate.metamodel.source.annotations.attribute.AssociationAttribute;
import org.hibernate.metamodel.source.annotations.attribute.AttributeOverride;
import org.hibernate.metamodel.source.annotations.attribute.ColumnValues;
import org.hibernate.metamodel.source.annotations.attribute.DiscriminatorColumnValues;
import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.source.annotations.attribute.SimpleAttribute;
import org.hibernate.metamodel.source.annotations.attribute.state.binding.AttributeBindingStateImpl;
import org.hibernate.metamodel.source.annotations.attribute.state.binding.DiscriminatorBindingStateImpl;
import org.hibernate.metamodel.source.annotations.attribute.state.binding.ManyToOneBindingStateImpl;
import org.hibernate.metamodel.source.annotations.attribute.state.relational.ColumnRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.attribute.state.relational.ManyToOneRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.attribute.state.relational.TupleRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.global.IdGeneratorBinder;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tuple.entity.EntityTuplizer;
@ -95,17 +96,30 @@ import org.hibernate.tuple.entity.EntityTuplizer;
public class EntityBinder {
private final EntityClass entityClass;
private final Hierarchical superType;
private final AnnotationsBindingContext bindingContext;
private final AnnotationBindingContext bindingContext;
private final Schema.Name schemaName;
public EntityBinder(EntityClass entityClass, Hierarchical superType, AnnotationsBindingContext bindingContext) {
public EntityBinder(EntityClass entityClass, Hierarchical superType, AnnotationBindingContext bindingContext) {
this.entityClass = entityClass;
this.superType = superType;
this.bindingContext = bindingContext;
this.schemaName = determineSchemaName();
}
public EntityBinding bind(List<String> processedEntityNames) {
if ( processedEntityNames.contains( entityClass.getName() ) ) {
return bindingContext.getMetadataImplementor().getEntityBinding( entityClass.getName() );
}
final EntityBinding entityBinding = createEntityBinding();
bindingContext.getMetadataImplementor().addEntity( entityBinding );
processedEntityNames.add( entityBinding.getEntity().getName() );
return entityBinding;
}
private Schema.Name determineSchemaName() {
String schema = bindingContext.getMappingDefaults().getSchemaName();
String catalog = bindingContext.getMappingDefaults().getCatalogName();
@ -132,20 +146,7 @@ public class EntityBinder {
return new Schema.Name( schema, catalog );
}
public EntityBinding bind(List<String> processedEntityNames) {
if ( processedEntityNames.contains( entityClass.getName() ) ) {
return bindingContext.getMetadataImplementor().getEntityBinding( entityClass.getName() );
}
final EntityBinding entityBinding = doEntityBindingCreation();
bindingContext.getMetadataImplementor().addEntity( entityBinding );
processedEntityNames.add( entityBinding.getEntity().getName() );
return entityBinding;
}
private EntityBinding doEntityBindingCreation() {
private EntityBinding createEntityBinding() {
final EntityBinding entityBinding = buildBasicEntityBinding();
// bind all attributes - simple as well as associations
@ -163,7 +164,8 @@ public class EntityBinder {
return doRootEntityBindingCreation();
}
case SINGLE_TABLE: {
return doDiscriminatedSubclassBindingCreation();
return doRootEntityBindingCreation();
//return doDiscriminatedSubclassBindingCreation();
}
case JOINED: {
return doJoinedSubclassBindingCreation();
@ -180,7 +182,7 @@ public class EntityBinder {
private EntityBinding doRootEntityBindingCreation() {
EntityBinding entityBinding = new EntityBinding();
entityBinding.setInheritanceType( InheritanceType.NO_INHERITANCE );
entityBinding.setRoot( true );
entityBinding.setRoot( entityClass.isEntityRoot() );
doBasicEntityBinding( entityBinding );
@ -201,7 +203,10 @@ public class EntityBinder {
// see HHH-6401
OptimisticLockType optimisticLockType = OptimisticLockType.VERSION;
if ( hibernateEntityAnnotation != null && hibernateEntityAnnotation.value( "optimisticLock" ) != null ) {
optimisticLockType = OptimisticLockType.valueOf( hibernateEntityAnnotation.value( "optimisticLock" ).asEnum() );
optimisticLockType = OptimisticLockType.valueOf(
hibernateEntityAnnotation.value( "optimisticLock" )
.asEnum()
);
}
entityBinding.setOptimisticLockStyle( OptimisticLockStyle.valueOf( optimisticLockType.name() ) );
@ -237,7 +242,7 @@ public class EntityBinder {
bindPrimaryTable( entityBinding );
bindId( entityBinding );
if ( entityBinding.getInheritanceType() == InheritanceType.SINGLE_TABLE ) {
if ( entityClass.getInheritanceType() == InheritanceType.SINGLE_TABLE ) {
bindDiscriminatorColumn( entityBinding );
}
@ -246,14 +251,15 @@ public class EntityBinder {
return entityBinding;
}
private Caching interpretCaching(ConfiguredClass configuredClass, AnnotationsBindingContext bindingContext) {
private Caching interpretCaching(ConfiguredClass configuredClass, AnnotationBindingContext bindingContext) {
final AnnotationInstance hibernateCacheAnnotation = JandexHelper.getSingleAnnotation(
configuredClass.getClassInfo(), HibernateDotNames.CACHE
);
if ( hibernateCacheAnnotation != null ) {
final AccessType accessType = hibernateCacheAnnotation.value( "usage" ) == null
? bindingContext.getMappingDefaults().getCacheAccessType()
: CacheConcurrencyStrategy.parse( hibernateCacheAnnotation.value( "usage" ).asEnum() ).toAccessType();
: CacheConcurrencyStrategy.parse( hibernateCacheAnnotation.value( "usage" ).asEnum() )
.toAccessType();
return new Caching(
hibernateCacheAnnotation.value( "region" ) == null
? configuredClass.getName()
@ -294,7 +300,7 @@ public class EntityBinder {
}
}
if ( ! doCaching ) {
if ( !doCaching ) {
return null;
}
@ -416,7 +422,7 @@ public class EntityBinder {
final AnnotationInstance batchSizeAnnotation = JandexHelper.getSingleAnnotation(
entityClass.getClassInfo(), HibernateDotNames.BATCH_SIZE
);
entityBinding.setBatchSize( batchSizeAnnotation == null ? -1 : batchSizeAnnotation.value( "size" ).asInt());
entityBinding.setBatchSize( batchSizeAnnotation == null ? -1 : batchSizeAnnotation.value( "size" ).asInt() );
// Proxy generation
final boolean lazy;
@ -454,7 +460,10 @@ public class EntityBinder {
);
if ( persisterAnnotation == null || persisterAnnotation.value( "impl" ) == null ) {
if ( hibernateEntityAnnotation != null && hibernateEntityAnnotation.value( "persister" ) != null ) {
entityPersisterClass = bindingContext.locateClassByName( hibernateEntityAnnotation.value( "persister" ).asString() );
entityPersisterClass = bindingContext.locateClassByName(
hibernateEntityAnnotation.value( "persister" )
.asString()
);
}
else {
entityPersisterClass = null;
@ -497,8 +506,8 @@ public class EntityBinder {
final ExecuteUpdateResultCheckStyle checkStyle = customSqlAnnotation.value( "check" ) == null
? isCallable
? ExecuteUpdateResultCheckStyle.NONE
: ExecuteUpdateResultCheckStyle.COUNT
? ExecuteUpdateResultCheckStyle.NONE
: ExecuteUpdateResultCheckStyle.COUNT
: ExecuteUpdateResultCheckStyle.valueOf( customSqlAnnotation.value( "check" ).asEnum() );
return new CustomSQL( sql, isCallable, checkStyle );
@ -525,7 +534,7 @@ public class EntityBinder {
tableName = bindingContext.getNamingStrategy().classToTableName( entityClass.getClassNameForTable() );
}
if ( bindingContext.isGloballyQuotedIdentifiers() && ! Identifier.isQuoted( tableName ) ) {
if ( bindingContext.isGloballyQuotedIdentifiers() && !Identifier.isQuoted( tableName ) ) {
tableName = StringHelper.quote( tableName );
}
org.hibernate.metamodel.relational.Table table = schema.locateOrCreateTable( Identifier.toIdentifier( tableName ) );
@ -547,7 +556,12 @@ public class EntityBinder {
return null;
}
for ( AnnotationInstance tuplizerAnnotation : JandexHelper.getValue( tuplizersAnnotation, "value", AnnotationInstance[].class ) ) {
AnnotationInstance[] annotations = JandexHelper.getValue(
tuplizersAnnotation,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance tuplizerAnnotation : annotations ) {
if ( EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() ) == EntityMode.POJO ) {
return tuplizerAnnotation;
}
@ -563,7 +577,7 @@ public class EntityBinder {
SimpleAttribute discriminatorAttribute = SimpleAttribute.createDiscriminatorAttribute( typeAnnotations );
bindSingleMappedAttribute( entityBinding, entityBinding.getEntity(), discriminatorAttribute );
if ( !( discriminatorAttribute.getColumnValues() instanceof DiscriminatorColumnValues) ) {
if ( !( discriminatorAttribute.getColumnValues() instanceof DiscriminatorColumnValues ) ) {
throw new AssertionFailure( "Expected discriminator column values" );
}
}
@ -634,7 +648,12 @@ public class EntityBinder {
SimpleAttributeBinding attributeBinding = entityBinding.makeSimpleIdAttributeBinding( attribute );
attributeBinding.initialize( new AttributeBindingStateImpl( (SimpleAttribute) idAttribute ) );
attributeBinding.initialize( new ColumnRelationalStateImpl( (SimpleAttribute) idAttribute, bindingContext.getMetadataImplementor() ) );
attributeBinding.initialize(
new ColumnRelationalStateImpl(
(SimpleAttribute) idAttribute,
bindingContext.getMetadataImplementor()
)
);
bindSingleIdGeneratedValue( entityBinding, idName );
TupleRelationalStateImpl state = new TupleRelationalStateImpl();
@ -643,9 +662,9 @@ public class EntityBinder {
state.addValueState( new ColumnRelationalStateImpl( attr, bindingContext.getMetadataImplementor() ) );
}
attributeBinding.initialize( state );
Map<String, String> parms = new HashMap<String, String>( 1 );
parms.put( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() );
IdGenerator generator = new IdGenerator( "NAME", "assigned", parms );
Map<String, String> parameterMap = new HashMap<String, String>( 1 );
parameterMap.put( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() );
IdGenerator generator = new IdGenerator( "NAME", "assigned", parameterMap );
entityBinding.getEntityIdentifier().setIdGenerator( generator );
// entityBinding.getEntityIdentifier().createIdentifierGenerator( meta.getIdentifierGeneratorFactory() );
}
@ -681,11 +700,21 @@ public class EntityBinder {
SimpleAttributeBinding attributeBinding = entityBinding.makeSimpleIdAttributeBinding( attribute );
attributeBinding.initialize( new AttributeBindingStateImpl( (SimpleAttribute) idAttribute ) );
attributeBinding.initialize( new ColumnRelationalStateImpl( (SimpleAttribute) idAttribute, bindingContext.getMetadataImplementor() ) );
attributeBinding.initialize(
new ColumnRelationalStateImpl(
(SimpleAttribute) idAttribute,
bindingContext.getMetadataImplementor()
)
);
bindSingleIdGeneratedValue( entityBinding, idAttribute.getName() );
if ( ! attribute.isTypeResolved() ) {
attribute.resolveType( bindingContext.makeJavaType( attributeBinding.getHibernateTypeDescriptor().getJavaTypeName() ) );
if ( !attribute.isTypeResolved() ) {
attribute.resolveType(
bindingContext.makeJavaType(
attributeBinding.getHibernateTypeDescriptor()
.getJavaTypeName()
)
);
}
}
@ -784,10 +813,10 @@ public class EntityBinder {
}
private void bindAttributes(
EntityBinding entityBinding,
AttributeContainer attributeContainer,
ConfiguredClass configuredClass,
Map<String,AttributeOverride> attributeOverrideMap) {
EntityBinding entityBinding,
AttributeContainer attributeContainer,
ConfiguredClass configuredClass,
Map<String, AttributeOverride> attributeOverrideMap) {
for ( SimpleAttribute simpleAttribute : configuredClass.getSimpleAttributes() ) {
String attributeName = simpleAttribute.getName();
@ -827,24 +856,34 @@ public class EntityBinder {
}
private void bindEmbeddedAttributes(
EntityBinding entityBinding,
AttributeContainer attributeContainer,
ConfiguredClass configuredClass) {
EntityBinding entityBinding,
AttributeContainer attributeContainer,
ConfiguredClass configuredClass) {
for ( Map.Entry<String, EmbeddableClass> entry : configuredClass.getEmbeddedClasses().entrySet() ) {
String attributeName = entry.getKey();
EmbeddableClass embeddedClass = entry.getValue();
SingularAttribute component = attributeContainer.locateOrCreateComponentAttribute( attributeName );
SingularAttribute componentAttribute = attributeContainer.locateOrCreateComponentAttribute( attributeName );
// we have to resolve the type, if the attribute was just created
if ( !componentAttribute.isTypeResolved() ) {
Component c = new Component(
attributeName,
embeddedClass.getName(),
new Value<Class<?>>( embeddedClass.getConfiguredClass() ),
null
);
componentAttribute.resolveType( c );
}
for ( SimpleAttribute simpleAttribute : embeddedClass.getSimpleAttributes() ) {
bindSingleMappedAttribute(
entityBinding,
component.getAttributeContainer(),
componentAttribute.getAttributeContainer(),
simpleAttribute
);
}
for ( AssociationAttribute associationAttribute : embeddedClass.getAssociationAttributes() ) {
bindAssociationAttribute(
entityBinding,
component.getAttributeContainer(),
componentAttribute.getAttributeContainer(),
associationAttribute
);
}
@ -852,13 +891,16 @@ public class EntityBinder {
}
private void bindAssociationAttribute(
EntityBinding entityBinding,
AttributeContainer container,
AssociationAttribute associationAttribute) {
EntityBinding entityBinding,
AttributeContainer container,
AssociationAttribute associationAttribute) {
switch ( associationAttribute.getAssociationType() ) {
case MANY_TO_ONE: {
Attribute attribute = entityBinding.getEntity().locateOrCreateSingularAttribute( associationAttribute.getName() );
ManyToOneAttributeBinding manyToOneAttributeBinding = entityBinding.makeManyToOneAttributeBinding( attribute );
Attribute attribute = entityBinding.getEntity()
.locateOrCreateSingularAttribute( associationAttribute.getName() );
ManyToOneAttributeBinding manyToOneAttributeBinding = entityBinding.makeManyToOneAttributeBinding(
attribute
);
ManyToOneAttributeBindingState bindingState = new ManyToOneBindingStateImpl( associationAttribute );
manyToOneAttributeBinding.initialize( bindingState );
@ -880,49 +922,73 @@ public class EntityBinder {
}
private void bindSingleMappedAttribute(
EntityBinding entityBinding,
AttributeContainer container,
SimpleAttribute simpleAttribute) {
EntityBinding entityBinding,
AttributeContainer container,
SimpleAttribute simpleAttribute) {
if ( simpleAttribute.isId() ) {
return;
}
ColumnValues columnValues = simpleAttribute.getColumnValues();
String attributeName = simpleAttribute.getName();
SingularAttribute attribute = container.locateOrCreateSingularAttribute( attributeName );
SimpleAttributeBinding attributeBinding;
if ( simpleAttribute.isDiscriminator() ) {
EntityDiscriminator entityDiscriminator = entityBinding.makeEntityDiscriminator( attribute );
DiscriminatorBindingState bindingState = new DiscriminatorBindingStateImpl( simpleAttribute );
entityDiscriminator.initialize( bindingState );
entityDiscriminator.setDiscriminatorValue( ( (DiscriminatorColumnValues) columnValues ).getDiscriminatorValue() );
attributeBinding = entityDiscriminator.getValueBinding();
}
else if ( simpleAttribute.isVersioned() ) {
attributeBinding = entityBinding.makeVersionBinding( attribute );
SimpleAttributeBindingState bindingState = new AttributeBindingStateImpl( simpleAttribute );
attributeBinding.initialize( bindingState );
}
else {
attributeBinding = entityBinding.makeSimpleAttributeBinding( attribute );
SimpleAttributeBindingState bindingState = new AttributeBindingStateImpl( simpleAttribute );
attributeBinding.initialize( bindingState );
}
if ( entityClass.hasOwnTable() ) {
ColumnRelationalStateImpl columnRelationsState = new ColumnRelationalStateImpl(
simpleAttribute, bindingContext.getMetadataImplementor()
);
// TupleRelationalStateImpl relationalState = new TupleRelationalStateImpl();
// relationalState.addValueState( columnRelationsState );
//
// attributeBinding.initialize( relationalState );
attributeBinding.initialize( columnRelationsState );
}
attributeBinding.setInsertable( simpleAttribute.isInsertable() );
attributeBinding.setUpdatable( simpleAttribute.isUpdatable() );
attributeBinding.setGeneration( simpleAttribute.getPropertyGeneration() );
attributeBinding.setLazy( simpleAttribute.isLazy() );
attributeBinding.setIncludedInOptimisticLocking( simpleAttribute.isOptimisticLockable() );
if ( ! attribute.isTypeResolved() ) {
attribute.resolveType( bindingContext.makeJavaType( attributeBinding.getHibernateTypeDescriptor().getJavaTypeName() ) );
}
// attributeBinding.setPropertyAccessorName(
// Helper.getPropertyAccessorName(
// simpleAttribute.getPropertyAccessorName(),
// false,
// bindingContext.getMappingDefaults().getPropertyAccessorName()
// )
// );
final TableSpecification valueSource = attributeBinding.getEntityBinding().getBaseTable();
String columnName = simpleAttribute.getColumnValues()
.getName()
.isEmpty() ? attribute.getName() : simpleAttribute.getColumnValues().getName();
Column column = valueSource.locateOrCreateColumn( columnName );
column.setNullable( columnValues.isNullable() );
column.setDefaultValue( null ); // todo
column.setSqlType( null ); // todo
Size size = new Size(
columnValues.getPrecision(),
columnValues.getScale(),
columnValues.getLength(),
Size.LobMultiplier.NONE
);
column.setSize( size );
column.setDatatype( null ); // todo : ???
column.setReadFragment( simpleAttribute.getCustomReadFragment() );
column.setWriteFragment( simpleAttribute.getCustomWriteFragment() );
column.setUnique( columnValues.isUnique() );
column.setCheckCondition( simpleAttribute.getCheckCondition() );
column.setComment( null ); // todo
attributeBinding.setValue( column );
// if ( ! attribute.isTypeResolved() ) {
// attribute.resolveType( bindingContext.makeJavaType( attributeBinding.getHibernateTypeDescriptor().getJavaTypeName() ) );
// }
}
}

View File

@ -33,7 +33,7 @@ import org.jboss.jandex.DotName;
import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
import org.hibernate.metamodel.source.annotations.AnnotationsBindingContext;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.binding.InheritanceType;
@ -55,7 +55,7 @@ public class EntityClass extends ConfiguredClass {
EntityClass parent,
AccessType hierarchyAccessType,
InheritanceType inheritanceType,
AnnotationsBindingContext context) {
AnnotationBindingContext context) {
super( classInfo, hierarchyAccessType, parent, context );
this.hierarchyAccessType = hierarchyAccessType;
this.inheritanceType = inheritanceType;

View File

@ -24,19 +24,20 @@
package org.hibernate.metamodel.source.annotations.global;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.Index;
import org.hibernate.MappingException;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.FetchProfiles;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.binding.FetchProfile;
import org.hibernate.metamodel.binding.FetchProfile.Fetch;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
/**
* Binds fetch profiles found in annotations.
@ -45,25 +46,32 @@ import org.hibernate.metamodel.source.annotations.HibernateDotNames;
*/
public class FetchProfileBinder {
private FetchProfileBinder() {
}
/**
* Binds all {@link FetchProfiles} and {@link org.hibernate.annotations.FetchProfile} annotations to the supplied metadata.
*
* @param metadata the global metadata
* @param jandex the jandex index
* @param bindingContext the context for annotation binding
*/
// TODO verify that association exists. See former VerifyFetchProfileReferenceSecondPass
public static void bind(MetadataImplementor metadata, Index jandex) {
for ( AnnotationInstance fetchProfile : jandex.getAnnotations( HibernateDotNames.FETCH_PROFILE ) ) {
bind( metadata, fetchProfile );
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex()
.getAnnotations( HibernateDotNames.FETCH_PROFILE );
for ( AnnotationInstance fetchProfile : annotations ) {
bind( bindingContext.getMetadataImplementor(), fetchProfile );
}
for ( AnnotationInstance fetchProfiles : jandex.getAnnotations( HibernateDotNames.FETCH_PROFILES ) ) {
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FETCH_PROFILES );
for ( AnnotationInstance fetchProfiles : annotations ) {
AnnotationInstance[] fetchProfileAnnotations = JandexHelper.getValue(
fetchProfiles,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance fetchProfile : fetchProfileAnnotations ) {
bind( metadata, fetchProfile );
bind( bindingContext.getMetadataImplementor(), fetchProfile );
}
}
}
@ -87,7 +95,4 @@ public class FetchProfileBinder {
}
metadata.addFetchProfile( new FetchProfile( name, fetches ) );
}
private FetchProfileBinder() {
}
}

View File

@ -24,10 +24,10 @@
package org.hibernate.metamodel.source.annotations.global;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.Index;
import org.jboss.logging.Logger;
import org.hibernate.annotations.FilterDef;
@ -35,10 +35,16 @@ import org.hibernate.annotations.FilterDefs;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.type.Type;
/**
* Binds {@link FilterDefs} and {@link FilterDef} annotations.
*
* @author Hardy Ferentschik
*/
public class FilterDefBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
@ -49,21 +55,23 @@ public class FilterDefBinder {
/**
* Binds all {@link FilterDefs} and {@link FilterDef} annotations to the supplied metadata.
*
* @param metadata the global metadata
* @param jandex the jandex index
* @param bindingContext the context for annotation binding
*/
public static void bind(MetadataImplementor metadata, Index jandex) {
for ( AnnotationInstance filterDef : jandex.getAnnotations( HibernateDotNames.FILTER_DEF ) ) {
bind( metadata, filterDef );
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEF );
for ( AnnotationInstance filterDef : annotations ) {
bind( bindingContext.getMetadataImplementor(), filterDef );
}
for ( AnnotationInstance filterDefs : jandex.getAnnotations( HibernateDotNames.FILTER_DEFS ) ) {
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FILTER_DEFS );
for ( AnnotationInstance filterDefs : annotations ) {
AnnotationInstance[] filterDefAnnotations = JandexHelper.getValue(
filterDefs,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance filterDef : filterDefAnnotations ) {
bind( metadata, filterDef );
bind( bindingContext.getMetadataImplementor(), filterDef );
}
}
}

View File

@ -24,12 +24,12 @@
package org.hibernate.metamodel.source.annotations.global;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.Index;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
@ -44,12 +44,19 @@ import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.enhanced.TableGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.binding.IdGenerator;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.binding.IdGenerator;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
/**
* Binds {@link SequenceGenerator}, {@link javax.persistence.TableGenerator}, {@link GenericGenerator}, and
* {@link GenericGenerators} annotations.
*
* @author Hardy Ferentschik
*/
public class IdGeneratorBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
@ -60,6 +67,41 @@ public class IdGeneratorBinder {
private IdGeneratorBinder() {
}
/**
* Binds all {@link SequenceGenerator}, {@link javax.persistence.TableGenerator}, {@link GenericGenerator}, and
* {@link GenericGenerators} annotations to the supplied metadata.
*
* @param bindingContext the context for annotation binding
*/
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex()
.getAnnotations( JPADotNames.SEQUENCE_GENERATOR );
for ( AnnotationInstance generator : annotations ) {
bindSequenceGenerator( bindingContext.getMetadataImplementor(), generator );
}
annotations = bindingContext.getIndex().getAnnotations( JPADotNames.TABLE_GENERATOR );
for ( AnnotationInstance generator : annotations ) {
bindTableGenerator( bindingContext.getMetadataImplementor(), generator );
}
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.GENERIC_GENERATOR );
for ( AnnotationInstance generator : annotations ) {
bindGenericGenerator( bindingContext.getMetadataImplementor(), generator );
}
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.GENERIC_GENERATORS );
for ( AnnotationInstance generators : annotations ) {
for ( AnnotationInstance generator : JandexHelper.getValue(
generators,
"value",
AnnotationInstance[].class
) ) {
bindGenericGenerator( bindingContext.getMetadataImplementor(), generator );
}
}
}
private static void addStringParameter(AnnotationInstance annotation,
String element,
Map<String, String> parameters,
@ -70,34 +112,6 @@ public class IdGeneratorBinder {
}
}
/**
* Binds all {@link SequenceGenerator}, {@link javax.persistence.TableGenerator}, {@link GenericGenerator}, and {
* {@link GenericGenerators} annotations to the supplied metadata.
*
* @param metadata the global metadata
* @param jandex the jandex index
*/
public static void bind(MetadataImplementor metadata, Index jandex) {
for ( AnnotationInstance generator : jandex.getAnnotations( JPADotNames.SEQUENCE_GENERATOR ) ) {
bindSequenceGenerator( metadata, generator );
}
for ( AnnotationInstance generator : jandex.getAnnotations( JPADotNames.TABLE_GENERATOR ) ) {
bindTableGenerator( metadata, generator );
}
for ( AnnotationInstance generator : jandex.getAnnotations( HibernateDotNames.GENERIC_GENERATOR ) ) {
bindGenericGenerator( metadata, generator );
}
for ( AnnotationInstance generators : jandex.getAnnotations( HibernateDotNames.GENERIC_GENERATORS ) ) {
for ( AnnotationInstance generator : JandexHelper.getValue(
generators,
"value",
AnnotationInstance[].class
) ) {
bindGenericGenerator( metadata, generator );
}
}
}
private static void bindGenericGenerator(MetadataImplementor metadata, AnnotationInstance generator) {
String name = JandexHelper.getValue( generator, "name", String.class );
Map<String, String> parameterMap = new HashMap<String, String>();

View File

@ -24,6 +24,7 @@
package org.hibernate.metamodel.source.annotations.global;
import java.util.HashMap;
import java.util.List;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
@ -31,7 +32,6 @@ import javax.persistence.NamedQuery;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.Index;
import org.jboss.logging.Logger;
import org.hibernate.AnnotationException;
@ -46,10 +46,18 @@ import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
/**
* Binds {@link NamedQuery}, {@link NamedQueries}, {@link NamedNativeQuery}, {@link NamedNativeQueries},
* {@link org.hibernate.annotations.NamedQuery}, {@link org.hibernate.annotations.NamedQueries},
* {@link org.hibernate.annotations.NamedNativeQuery}, and {@link org.hibernate.annotations.NamedNativeQueries}.
*
* @author Hardy Ferentschik
*/
public class QueryBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
@ -66,40 +74,54 @@ public class QueryBinder {
* {@link org.hibernate.annotations.NamedNativeQuery}, and {@link org.hibernate.annotations.NamedNativeQueries}
* annotations to the supplied metadata.
*
* @param metadata the global metadata
* @param jandex the jandex index
* @param bindingContext the context for annotation binding
*/
public static void bind(MetadataImplementor metadata, Index jandex) {
for ( AnnotationInstance query : jandex.getAnnotations( JPADotNames.NAMED_QUERY ) ) {
bindNamedQuery( metadata, query );
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( JPADotNames.NAMED_QUERY );
for ( AnnotationInstance query : annotations ) {
bindNamedQuery( bindingContext.getMetadataImplementor(), query );
}
for ( AnnotationInstance queries : jandex.getAnnotations( JPADotNames.NAMED_QUERIES ) ) {
annotations = bindingContext.getIndex().getAnnotations( JPADotNames.NAMED_QUERIES );
for ( AnnotationInstance queries : annotations ) {
for ( AnnotationInstance query : JandexHelper.getValue( queries, "value", AnnotationInstance[].class ) ) {
bindNamedQuery( metadata, query );
bindNamedQuery( bindingContext.getMetadataImplementor(), query );
}
}
for ( AnnotationInstance query : jandex.getAnnotations( JPADotNames.NAMED_NATIVE_QUERY ) ) {
bindNamedNativeQuery( metadata, query );
annotations = bindingContext.getIndex().getAnnotations( JPADotNames.NAMED_NATIVE_QUERY );
for ( AnnotationInstance query : annotations ) {
bindNamedNativeQuery( bindingContext.getMetadataImplementor(), query );
}
for ( AnnotationInstance queries : jandex.getAnnotations( JPADotNames.NAMED_NATIVE_QUERIES ) ) {
annotations = bindingContext.getIndex().getAnnotations( JPADotNames.NAMED_NATIVE_QUERIES );
for ( AnnotationInstance queries : annotations ) {
for ( AnnotationInstance query : JandexHelper.getValue( queries, "value", AnnotationInstance[].class ) ) {
bindNamedNativeQuery( metadata, query );
bindNamedNativeQuery( bindingContext.getMetadataImplementor(), query );
}
}
for ( AnnotationInstance query : jandex.getAnnotations( HibernateDotNames.NAMED_QUERY ) ) {
bindNamedQuery( metadata, query );
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.NAMED_QUERY );
for ( AnnotationInstance query : annotations ) {
bindNamedQuery( bindingContext.getMetadataImplementor(), query );
}
for ( AnnotationInstance queries : jandex.getAnnotations( HibernateDotNames.NAMED_QUERIES ) ) {
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.NAMED_QUERIES );
for ( AnnotationInstance queries : annotations ) {
for ( AnnotationInstance query : JandexHelper.getValue( queries, "value", AnnotationInstance[].class ) ) {
bindNamedQuery( metadata, query );
bindNamedQuery( bindingContext.getMetadataImplementor(), query );
}
}
for ( AnnotationInstance query : jandex.getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERY ) ) {
bindNamedNativeQuery( metadata, query );
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERY );
for ( AnnotationInstance query : annotations ) {
bindNamedNativeQuery( bindingContext.getMetadataImplementor(), query );
}
for ( AnnotationInstance queries : jandex.getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERIES ) ) {
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.NAMED_NATIVE_QUERIES );
for ( AnnotationInstance queries : annotations ) {
for ( AnnotationInstance query : JandexHelper.getValue( queries, "value", AnnotationInstance[].class ) ) {
bindNamedNativeQuery( metadata, query );
bindNamedNativeQuery( bindingContext.getMetadataImplementor(), query );
}
}
}

View File

@ -23,21 +23,23 @@
*/
package org.hibernate.metamodel.source.annotations.global;
import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.Index;
import org.jboss.logging.Logger;
import org.hibernate.AnnotationException;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.relational.Column;
import org.hibernate.metamodel.relational.ObjectName;
import org.hibernate.metamodel.relational.Schema;
import org.hibernate.metamodel.relational.SimpleValue;
import org.hibernate.metamodel.relational.Table;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
/**
* Binds table related information. This binder is called after the entities are bound.
@ -51,20 +53,25 @@ public class TableBinder {
TableBinder.class.getName()
);
private TableBinder() {
}
/**
* Binds {@link org.hibernate.annotations.Tables} and {@link org.hibernate.annotations.Table} annotations to the supplied
* metadata.
*
* @param metadata the global metadata
* @param jandex the annotation index repository
* @param bindingContext the context for annotation binding
*/
public static void bind(MetadataImplementor metadata, Index jandex) {
for ( AnnotationInstance tableAnnotation : jandex.getAnnotations( HibernateDotNames.TABLE ) ) {
bind( metadata, tableAnnotation );
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TABLE );
for ( AnnotationInstance tableAnnotation : annotations ) {
bind( bindingContext.getMetadataImplementor(), tableAnnotation );
}
for ( AnnotationInstance tables : jandex.getAnnotations( HibernateDotNames.TABLES ) ) {
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TABLES );
for ( AnnotationInstance tables : annotations ) {
for ( AnnotationInstance table : JandexHelper.getValue( tables, "value", AnnotationInstance[].class ) ) {
bind( metadata, table );
bind( bindingContext.getMetadataImplementor(), table );
}
}
}
@ -120,7 +127,4 @@ public class TableBinder {
}
return column;
}
private TableBinder() {
}
}

View File

@ -24,21 +24,27 @@
package org.hibernate.metamodel.source.annotations.global;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.Index;
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.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.binding.TypeDef;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
/**
* Binds {@link org.hibernate.annotations.TypeDef} and {@link TypeDefs}.
*
* @author Hardy Ferentschik
*/
public class TypeDefBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
@ -49,21 +55,23 @@ public class TypeDefBinder {
/**
* Binds all {@link org.hibernate.annotations.TypeDef} and {@link TypeDefs} annotations to the supplied metadata.
*
* @param metadata the global metadata
* @param jandex the jandex jandex
* @param bindingContext the context for annotation binding
*/
public static void bind(MetadataImplementor metadata, Index jandex) {
for ( AnnotationInstance typeDef : jandex.getAnnotations( HibernateDotNames.TYPE_DEF ) ) {
bind( metadata, typeDef );
public static void bind(AnnotationBindingContext bindingContext) {
List<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TYPE_DEF );
for ( AnnotationInstance typeDef : annotations ) {
bind( bindingContext.getMetadataImplementor(), typeDef );
}
for ( AnnotationInstance typeDefs : jandex.getAnnotations( HibernateDotNames.TYPE_DEFS ) ) {
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TYPE_DEFS );
for ( AnnotationInstance typeDefs : annotations ) {
AnnotationInstance[] typeDefAnnotations = JandexHelper.getValue(
typeDefs,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance typeDef : typeDefAnnotations ) {
bind( metadata, typeDef );
bind( bindingContext.getMetadataImplementor(), typeDef );
}
}
}

View File

@ -52,7 +52,7 @@ import org.hibernate.metamodel.source.MappingDefaults;
import org.hibernate.metamodel.source.MetaAttributeContext;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.SourceProcessor;
import org.hibernate.metamodel.source.annotations.AnnotationsSourceProcessor;
import org.hibernate.metamodel.source.annotations.AnnotationProcessor;
import org.hibernate.metamodel.source.hbm.HbmSourceProcessorImpl;
import org.hibernate.metamodel.binding.AttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding;
@ -126,12 +126,12 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
if ( options.getSourceProcessingOrder() == SourceProcessingOrder.HBM_FIRST ) {
sourceProcessors = new SourceProcessor[] {
new HbmSourceProcessorImpl( this ),
new AnnotationsSourceProcessor( this )
new AnnotationProcessor( this )
};
}
else {
sourceProcessors = new SourceProcessor[] {
new AnnotationsSourceProcessor( this ),
new AnnotationProcessor( this ),
new HbmSourceProcessorImpl( this )
};
}

View File

@ -38,16 +38,16 @@ import org.hibernate.cfg.EJB3NamingStrategy;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.domain.Type;
import org.hibernate.metamodel.source.MappingDefaults;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.domain.Type;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.classloading.spi.ClassLoaderService;
/**
* @author Steve Ebersole
*/
public class TestAnnotationsBindingContextImpl implements AnnotationsBindingContext {
public class TestAnnotationsBindingContextImpl implements AnnotationBindingContext {
private Index index;
private ServiceRegistry serviceRegistry;
@ -100,6 +100,7 @@ public class TestAnnotationsBindingContextImpl implements AnnotationsBindingCont
public Value<Class<?>> makeClassReference(String className) {
throw new NotYetImplementedException();
}
@Override
public ClassInfo getClassInfo(String name) {
DotName dotName = DotName.createSimple( name );

View File

@ -31,8 +31,9 @@ import javax.persistence.Id;
import org.junit.Test;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.domain.Attribute;
import org.hibernate.metamodel.domain.Component;
import org.hibernate.metamodel.domain.SingularAttribute;;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
@ -51,10 +52,10 @@ public class EmbeddableBindingTests extends BaseAnnotationBindingTestCase {
assertNotNull( binding.getAttributeBinding( "city" ) );
assertNotNull( binding.getAttributeBinding( "postCode" ) );
Attribute attribute = binding.getEntity().getAttribute( "address" );
SingularAttribute attribute = (SingularAttribute) binding.getEntity().getAttribute( "address" );
assertTrue(
"Wrong container type. Should be a component",
attribute.getAttributeContainer() instanceof Component
attribute.getSingularAttributeType() instanceof Component
);
}

View File

@ -64,12 +64,11 @@ public class InheritanceBindingTest extends BaseAnnotationBindingTestCase {
);
EntityBinding noInheritanceEntityBinding = getEntityBinding( SingleEntity.class );
EntityBinding subclassEntityBinding = getEntityBinding( SubclassOfSingleTableInheritance.class );
EntityBinding rootEntityBinding = getEntityBinding( RootOfSingleTableInheritance.class );
assertTrue( noInheritanceEntityBinding.isRoot() );
assertSame( noInheritanceEntityBinding, getRootEntityBinding( SingleEntity.class ) );
EntityBinding subclassEntityBinding = getEntityBinding( SubclassOfSingleTableInheritance.class );
EntityBinding rootEntityBinding = getEntityBinding( RootOfSingleTableInheritance.class );
assertFalse( subclassEntityBinding.isRoot() );
assertSame( rootEntityBinding, getRootEntityBinding( SubclassOfSingleTableInheritance.class ) );

View File

@ -57,11 +57,8 @@ public class MappedSuperclassTests extends BaseAnnotationBindingTestCase {
AttributeBinding nameBinding = binding.getAttributeBinding( "name" );
assertNotNull( "the name attribute should be bound to MyEntity", nameBinding );
Tuple tuple = (Tuple) nameBinding.getValue();
SimpleValue value = tuple.values().iterator().next();
assertTrue( value instanceof Column );
Column column = (Column) value;
assertEquals( "Wrong column name", "`MY_NAME`", column.getColumnName().toString() );
Column column = (Column) nameBinding.getValue();
assertEquals( "Wrong column name", "MY_NAME", column.getColumnName().toString() );
}
@Test
@ -72,11 +69,8 @@ public class MappedSuperclassTests extends BaseAnnotationBindingTestCase {
AttributeBinding fooBinding = binding.getAttributeBinding( "foo" );
assertNotNull( "the foo attribute should be bound to MyEntity", fooBinding );
Tuple tuple = (Tuple) fooBinding.getValue();
SimpleValue value = tuple.values().iterator().next();
assertTrue( value instanceof Column );
Column column = (Column) value;
assertEquals( "Wrong column name", "`MY_FOO`", column.getColumnName().toString() );
Column column = (Column) fooBinding.getValue();
assertEquals( "Wrong column name", "MY_FOO", column.getColumnName().toString() );
}
@Test

View File

@ -26,22 +26,21 @@ package org.hibernate.metamodel.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;
import org.hibernate.annotations.FetchProfile;
import org.hibernate.annotations.FetchProfiles;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContextImpl;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.fail;
@ -78,7 +77,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
}
Index index = JandexHelper.indexForClass( service, Foo.class );
FetchProfileBinder.bind( meta, index );
FetchProfileBinder.bind( new AnnotationBindingContextImpl( meta, index ) );
Iterator<org.hibernate.metamodel.binding.FetchProfile> mappedFetchProfiles = meta.getFetchProfiles().iterator();
assertTrue( mappedFetchProfiles.hasNext() );
@ -92,7 +91,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
@Test
public void testFetchProfiles() {
Index index = JandexHelper.indexForClass( service, FooBar.class );
FetchProfileBinder.bind( meta, index );
FetchProfileBinder.bind( new AnnotationBindingContextImpl( meta, index ) );
Iterator<org.hibernate.metamodel.binding.FetchProfile> mappedFetchProfiles = meta.getFetchProfiles().iterator();
assertTrue( mappedFetchProfiles.hasNext() );
@ -129,7 +128,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
}
Index index = JandexHelper.indexForClass( service, Foo.class );
FetchProfileBinder.bind( meta, index );
FetchProfileBinder.bind( new AnnotationBindingContextImpl( meta, index ) );
}
@FetchProfiles( {

View File

@ -35,6 +35,7 @@ import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContextImpl;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.service.ServiceRegistryBuilder;
@ -73,7 +74,7 @@ public class QueryBinderTest extends BaseUnitTestCase {
class Foo {
}
Index index = JandexHelper.indexForClass( service, Foo.class );
QueryBinder.bind( meta, index );
QueryBinder.bind( new AnnotationBindingContextImpl( meta, index ) );
}
@Test
@ -82,7 +83,7 @@ public class QueryBinderTest extends BaseUnitTestCase {
class Foo {
}
Index index = JandexHelper.indexForClass( service, Foo.class );
QueryBinder.bind( meta, index );
QueryBinder.bind( new AnnotationBindingContextImpl( meta, index ) );
NamedSQLQueryDefinition namedQuery = meta.getNamedNativeQuery( "fubar" );
assertNotNull( namedQuery );