Created
June 24, 2011 08:10
-
-
Save stliu/1044422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentBinding.java | |
index 66c3cb9..185223c 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentBinding.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentBinding.java | |
@@ -1,7 +1,13 @@ | |
package org.hibernate.metamodel.binding; | |
+import org.hibernate.metamodel.domain.Component; | |
+ | |
/** | |
* @author Strong Liu | |
*/ | |
public class ComponentBinding { | |
+ private Component component; | |
+ /** | |
+ * 1. annotation | |
+ */ | |
} | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java | |
index 89fc350..57a1bf7 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java | |
@@ -32,6 +32,7 @@ import org.hibernate.AssertionFailure; | |
import org.hibernate.EntityMode; | |
import org.hibernate.MappingException; | |
import org.hibernate.metamodel.binding.state.EntityBindingState; | |
+import org.hibernate.metamodel.domain.Component; | |
import org.hibernate.metamodel.domain.Entity; | |
import org.hibernate.metamodel.domain.JavaType; | |
import org.hibernate.metamodel.relational.Column; | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/AbstractAttributeContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/AbstractAttributeContainer.java | |
index f7d6f1a..e638fbb 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/AbstractAttributeContainer.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/AbstractAttributeContainer.java | |
@@ -40,10 +40,11 @@ public abstract class AbstractAttributeContainer implements AttributeContainer, | |
private final Hierarchical superType; | |
private LinkedHashSet<Attribute> attributeSet = new LinkedHashSet<Attribute>(); | |
private HashMap<String, Attribute> attributeMap = new HashMap<String, Attribute>(); | |
- | |
- public AbstractAttributeContainer(String name, Hierarchical superType) { | |
+ private final JavaType javaType; | |
+ public AbstractAttributeContainer(String name, Hierarchical superType, JavaType javaType) { | |
this.name = name; | |
this.superType = superType; | |
+ this.javaType = javaType; | |
} | |
@Override | |
@@ -51,6 +52,9 @@ public abstract class AbstractAttributeContainer implements AttributeContainer, | |
return name; | |
} | |
+ public JavaType getJavaType() { | |
+ return javaType; | |
+ } | |
@Override | |
public Hierarchical getSuperType() { | |
return superType; | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java | |
index 48c75d4..966dee6 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java | |
@@ -30,7 +30,7 @@ package org.hibernate.metamodel.domain; | |
* @author Hardy Ferentschik | |
*/ | |
public class Entity extends AbstractAttributeContainer { | |
- final JavaType javaType; | |
+ | |
/** | |
* Constructor for the entity | |
@@ -40,8 +40,7 @@ public class Entity extends AbstractAttributeContainer { | |
* @param javaType the java type of the entity | |
*/ | |
public Entity(String name, Hierarchical superType, JavaType javaType) { | |
- super( name, superType ); | |
- this.javaType = javaType; | |
+ super( name, superType, javaType ); | |
} | |
@Override | |
@@ -49,8 +48,6 @@ public class Entity extends AbstractAttributeContainer { | |
return TypeNature.ENTITY; | |
} | |
- public JavaType getJavaType() { | |
- return javaType; | |
- } | |
+ | |
} | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java b/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java | |
index 5960917..af50cd4 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/relational/Schema.java | |
@@ -33,11 +33,14 @@ import java.util.Map; | |
*/ | |
public class Schema { | |
private final Name name; | |
+ private final String desc; | |
private Map<String, InLineView> inLineViews = new HashMap<String, InLineView>(); | |
private Map<Identifier, Table> tables = new HashMap<Identifier, Table>(); | |
public Schema(Name name) { | |
this.name = name; | |
+ final StringBuilder sb = new StringBuilder().append( "Schema" ).append( "{name=" ).append( name ).append( '}' ); | |
+ this.desc = sb.toString(); | |
} | |
public Schema(Identifier schema, Identifier catalog) { | |
@@ -70,11 +73,7 @@ public class Schema { | |
@Override | |
public String toString() { | |
- final StringBuilder sb = new StringBuilder(); | |
- sb.append( "Schema" ); | |
- sb.append( "{name=" ).append( name ); | |
- sb.append( '}' ); | |
- return sb.toString(); | |
+ return desc; | |
} | |
@Override | |
@@ -103,10 +102,24 @@ public class Schema { | |
public static class Name { | |
private final Identifier schema; | |
private final Identifier catalog; | |
+ private final int hashcode; | |
+ private final String desc; | |
public Name(Identifier schema, Identifier catalog) { | |
this.schema = schema; | |
this.catalog = catalog; | |
+ | |
+ int result = schema != null ? schema.hashCode() : 0; | |
+ result = 31 * result + ( catalog != null ? catalog.hashCode() : 0 ); | |
+ this.hashcode = result; | |
+ | |
+ final StringBuilder sb = new StringBuilder().append( "Name" ) | |
+ .append( "{schema=" ) | |
+ .append( schema ) | |
+ .append( ", catalog=" ) | |
+ .append( catalog ) | |
+ .append( '}' ); | |
+ this.desc = sb.toString(); | |
} | |
public Name(String schema, String catalog) { | |
@@ -123,12 +136,7 @@ public class Schema { | |
@Override | |
public String toString() { | |
- final StringBuilder sb = new StringBuilder(); | |
- sb.append( "Name" ); | |
- sb.append( "{schema=" ).append( schema ); | |
- sb.append( ", catalog=" ).append( catalog ); | |
- sb.append( '}' ); | |
- return sb.toString(); | |
+ return desc; | |
} | |
@Override | |
@@ -154,9 +162,7 @@ public class Schema { | |
@Override | |
public int hashCode() { | |
- int result = schema != null ? schema.hashCode() : 0; | |
- result = 31 * result + ( catalog != null ? catalog.hashCode() : 0 ); | |
- return result; | |
+ return hashcode; | |
} | |
} | |
} | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/AnnotationBinder.java | |
index a2b67be..ffbc644 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/AnnotationBinder.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/AnnotationBinder.java | |
@@ -34,10 +34,13 @@ import org.hibernate.internal.CoreMessageLogger; | |
import org.jboss.jandex.Index; | |
import org.hibernate.metamodel.MetadataSources; | |
+import org.hibernate.metamodel.ValidationException; | |
import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings; | |
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass; | |
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy; | |
+import org.hibernate.metamodel.source.annotations.entity.EmbeddableBinder; | |
import org.hibernate.metamodel.source.annotations.entity.EntityBinder; | |
+import org.hibernate.metamodel.source.annotations.entity.MappedSuperClassBinder; | |
import org.hibernate.metamodel.source.annotations.global.FilterDefBinder; | |
import org.hibernate.metamodel.source.annotations.global.IdGeneratorBinder; | |
import org.hibernate.metamodel.source.annotations.global.QueryBinder; | |
@@ -140,9 +143,28 @@ public class AnnotationBinder implements Binder { | |
// now we process each hierarchy one at the time | |
for ( ConfiguredClassHierarchy hierarchy : hierarchies ) { | |
for ( ConfiguredClass configuredClass : hierarchy ) { | |
- LOG.bindingEntityFromAnnotatedClass( configuredClass.getName() ); | |
- EntityBinder entityBinder = new EntityBinder( metadata, configuredClass ); | |
- entityBinder.bind(); | |
+ switch ( configuredClass.getConfiguredClassType() ) { | |
+ case ENTITY: | |
+ LOG.bindingEntityFromAnnotatedClass( configuredClass.getName() ); | |
+ EntityBinder entityBinder = new EntityBinder( metadata, configuredClass ); | |
+ entityBinder.bind(); | |
+ break; | |
+ case EMBEDDABLE: | |
+ //todo log | |
+ EmbeddableBinder embeddableBinder = new EmbeddableBinder( metadata, configuredClass ); | |
+ embeddableBinder.bind(); | |
+ break; | |
+ case MAPPED_SUPERCLASS: | |
+ MappedSuperClassBinder mappedSuperClassBinder = new MappedSuperClassBinder( metadata, configuredClass ); | |
+ mappedSuperClassBinder.bind(); | |
+ break; | |
+ case NON_ENTITY: | |
+ //todo | |
+ break; | |
+ default: | |
+ throw new ValidationException( "not a valid configured class type" ); | |
+ } | |
+ | |
} | |
} | |
} | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AbstractBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AbstractBinder.java | |
index f3e0815..4ff9889 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AbstractBinder.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AbstractBinder.java | |
@@ -1,7 +1,36 @@ | |
package org.hibernate.metamodel.source.annotations.entity; | |
+import org.hibernate.AssertionFailure; | |
+import org.hibernate.metamodel.binding.EntityBinding; | |
+import org.hibernate.metamodel.domain.Hierarchical; | |
+import org.hibernate.metamodel.source.spi.MetadataImplementor; | |
+ | |
/** | |
* @author Strong Liu | |
*/ | |
-public class AbstractBinder { | |
+public abstract class AbstractBinder { | |
+ protected final ConfiguredClass configuredClass; | |
+ protected final MetadataImplementor meta; | |
+ | |
+ protected AbstractBinder(MetadataImplementor meta, ConfiguredClass configuredClass) { | |
+ this.configuredClass = configuredClass; | |
+ this.meta = meta; | |
+ } | |
+ | |
+ abstract public void bind(); | |
+ protected Hierarchical getSuperType() { | |
+ ConfiguredClass parent = configuredClass.getParent(); | |
+ if ( parent == null ) { | |
+ return null; | |
+ } | |
+ | |
+ EntityBinding parentBinding = meta.getEntityBinding( parent.getName() ); | |
+ if ( parentBinding == null ) { | |
+ throw new AssertionFailure( | |
+ "Parent entity " + parent.getName() + " of entity " + configuredClass.getName() + " not yet created!" | |
+ ); | |
+ } | |
+ | |
+ return parentBinding.getEntity(); | |
+ } | |
} | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AttributeType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AttributeType.java | |
index 4e6eb44..cb97150 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AttributeType.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/AttributeType.java | |
@@ -38,7 +38,8 @@ public enum AttributeType { | |
ONE_TO_MANY( JPADotNames.ONE_TO_MANY ), | |
MANY_TO_ONE( JPADotNames.MANY_TO_ONE ), | |
MANY_TO_MANY( JPADotNames.MANY_TO_MANY ), | |
- EMBEDDED( JPADotNames.EMBEDDED ); | |
+ EMBEDDED( JPADotNames.EMBEDDED ), | |
+ ELEMENT_COLLECTION( JPADotNames.ELEMENT_COLLECTION ); | |
private final DotName annotationDotName; | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java | |
index 9087d91..0dfa577 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java | |
@@ -172,42 +172,37 @@ public class ConfiguredClass { | |
public MappedAttribute getMappedProperty(String propertyName) { | |
return mappedAttributes.get( propertyName ); | |
} | |
+ private String desc; | |
@Override | |
public String toString() { | |
- final StringBuilder sb = new StringBuilder(); | |
- sb.append( "ConfiguredClass" ); | |
- sb.append( "{clazz=" ).append( clazz.getSimpleName() ); | |
- sb.append( ", type=" ).append( configuredClassType ); | |
- sb.append( ", classAccessType=" ).append( classAccessType ); | |
- sb.append( ", isRoot=" ).append( isRoot ); | |
- sb.append( ", inheritanceType=" ).append( inheritanceType ); | |
- sb.append( '}' ); | |
- return sb.toString(); | |
+ if ( desc == null ) { | |
+ final StringBuilder sb = new StringBuilder(); | |
+ sb.append( "ConfiguredClass" ); | |
+ sb.append( "{clazz=" ).append( clazz.getSimpleName() ); | |
+ sb.append( ", type=" ).append( configuredClassType ); | |
+ sb.append( ", classAccessType=" ).append( classAccessType ); | |
+ sb.append( ", isRoot=" ).append( isRoot ); | |
+ sb.append( ", inheritanceType=" ).append( inheritanceType ); | |
+ sb.append( '}' ); | |
+ desc = sb.toString(); | |
+ } | |
+ return desc; | |
} | |
private ConfiguredClassType determineType() { | |
- AnnotationInstance entityAnnotation = JandexHelper.getSingleAnnotation( | |
- classInfo, JPADotNames.ENTITY | |
- ); | |
- if ( entityAnnotation != null ) { | |
+ if ( classInfo.annotations().containsKey( JPADotNames.ENTITY ) ) { | |
return ConfiguredClassType.ENTITY; | |
} | |
- | |
- AnnotationInstance mappedSuperClassAnnotation = JandexHelper.getSingleAnnotation( | |
- classInfo, JPADotNames.MAPPED_SUPERCLASS | |
- ); | |
- if ( mappedSuperClassAnnotation != null ) { | |
+ else if ( classInfo.annotations().containsKey( JPADotNames.MAPPED_SUPERCLASS ) ) { | |
return ConfiguredClassType.MAPPED_SUPERCLASS; | |
} | |
- | |
- AnnotationInstance embeddableAnnotation = JandexHelper.getSingleAnnotation( | |
- classInfo, JPADotNames.EMBEDDABLE | |
- ); | |
- if ( embeddableAnnotation != null ) { | |
+ else if ( classInfo.annotations().containsKey( JPADotNames.EMBEDDABLE ) ) { | |
return ConfiguredClassType.EMBEDDABLE; | |
} | |
- return ConfiguredClassType.NON_ENTITY; | |
+ else { | |
+ return ConfiguredClassType.NON_ENTITY; | |
+ } | |
} | |
private AccessType determineClassAccessType() { | |
@@ -219,6 +214,10 @@ public class ConfiguredClass { | |
accessType = JandexHelper.getValueAsEnum( accessAnnotation, "value", AccessType.class ); | |
} | |
+ if(accessType == null){ | |
+ accessType = AccessType.PROPERTY; | |
+ } | |
+ | |
return accessType; | |
} | |
@@ -400,6 +399,9 @@ public class ConfiguredClass { | |
case EMBEDDED: { | |
throw new HibernateException( "foo" ); | |
} | |
+ case ELEMENT_COLLECTION: { | |
+ //todo | |
+ } | |
// TODO handle the different association types | |
default: { | |
attribute = AssociationAttribute.createAssociationAttribute( | |
@@ -447,6 +449,11 @@ public class ConfiguredClass { | |
discoveredAttributeTypes.put( AttributeType.EMBEDDED, embedded ); | |
} | |
+ AnnotationInstance elementCollection = JandexHelper.getSingleAnnotation( annotations, JPADotNames.ELEMENT_COLLECTION ); | |
+ if ( elementCollection != null ) { | |
+ discoveredAttributeTypes.put( AttributeType.ELEMENT_COLLECTION, elementCollection ); | |
+ } | |
+ | |
if ( discoveredAttributeTypes.size() == 0 ) { | |
return AttributeType.BASIC; | |
} | |
@@ -516,6 +523,7 @@ public class ConfiguredClass { | |
} | |
} | |
} | |
+ //todo shouldn't this keep checking parent's parent until find the root? --stliu | |
else if ( parent != null | |
&& !parent.getConfiguredClassType().equals( ConfiguredClassType.MAPPED_SUPERCLASS ) | |
&& !parent.getConfiguredClassType().equals( ConfiguredClassType.EMBEDDABLE ) ) { | |
@@ -525,7 +533,7 @@ public class ConfiguredClass { | |
} | |
private IdType determineIdType() { | |
- List<AnnotationInstance> idAnnotations = getClassInfo().annotations().get( JPADotNames.ENTITY ); | |
+ List<AnnotationInstance> idAnnotations = getClassInfo().annotations().get( JPADotNames.ID ); | |
List<AnnotationInstance> embeddedIdAnnotations = getClassInfo() | |
.annotations() | |
.get( JPADotNames.EMBEDDED_ID ); | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClassHierarchy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClassHierarchy.java | |
index b90cac4..7baf316 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClassHierarchy.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClassHierarchy.java | |
@@ -107,20 +107,38 @@ public class ConfiguredClassHierarchy implements Iterable<ConfiguredClass> { | |
* annotations. | |
*/ | |
private AccessType determineDefaultAccessType(List<ClassInfo> classes) { | |
- AccessType accessType = null; | |
+ AccessType entityAccessType = null; | |
+ AccessType accessTypeFromIdPlacement = null; | |
for ( ClassInfo info : classes ) { | |
+ List<AnnotationInstance> accessTypeAnnotations = info.annotations().get( JPADotNames.ACCESS ); | |
+ if ( accessTypeAnnotations != null && !accessTypeAnnotations.isEmpty() ) { | |
+ entityAccessType = determinAccessTypeByAccessOnEntity( accessTypeAnnotations ); | |
+ } | |
List<AnnotationInstance> idAnnotations = info.annotations().get( JPADotNames.ID ); | |
- if ( idAnnotations == null || idAnnotations.size() == 0 ) { | |
- continue; | |
+ if ( idAnnotations != null && !idAnnotations.isEmpty() ) { | |
+ accessTypeFromIdPlacement = determineAccessTypeByIdPlacement( idAnnotations ); | |
} | |
- accessType = determineAccessTypeByIdPlacement( idAnnotations ); | |
} | |
- if ( accessType == null ) { | |
- return throwIdNotFoundAnnotationException( classes ); | |
+ if ( entityAccessType != null ) { | |
+ return entityAccessType; | |
+ } | |
+ else if ( accessTypeFromIdPlacement != null ) { | |
+ return accessTypeFromIdPlacement; | |
+ } | |
+ else { | |
+// return throwIdNotFoundAnnotationException( classes ); | |
+ return null; | |
} | |
- return accessType; | |
+ } | |
+ private AccessType determinAccessTypeByAccessOnEntity(List<AnnotationInstance> annotationInstances){ | |
+ for ( AnnotationInstance annotation : annotationInstances ) { | |
+ if ( annotation.target() instanceof ClassInfo ) { | |
+ return JandexHelper.getValueAsEnum( annotation, "value", AccessType.class ); | |
+ } | |
+ } | |
+ return null; | |
} | |
private AccessType determineAccessTypeByIdPlacement(List<AnnotationInstance> idAnnotations) { | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddableBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddableBinder.java | |
index 416df36..9014278 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddableBinder.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddableBinder.java | |
@@ -1,7 +1,52 @@ | |
package org.hibernate.metamodel.source.annotations.entity; | |
+import org.hibernate.metamodel.binding.EntityBinding; | |
+import org.hibernate.metamodel.source.annotations.entity.state.binding.EntityBindingStateImpl; | |
+import org.hibernate.metamodel.source.spi.MetadataImplementor; | |
+ | |
/** | |
* @author Strong Liu | |
*/ | |
-public class EmbeddableBinder { | |
+public class EmbeddableBinder extends AbstractBinder { | |
+ public EmbeddableBinder(MetadataImplementor meta, ConfiguredClass configuredClass) { | |
+ super( meta, configuredClass ); | |
+ } | |
+ | |
+ @Override | |
+ public void bind() { | |
+ EntityBinding entityBinding = new EntityBinding(); | |
+ EntityBindingStateImpl entityBindingState = new EntityBindingStateImpl( getSuperType(), configuredClass ); | |
+ | |
+// bindJpaEntityAnnotation( entityBindingState ); | |
+// bindHibernateEntityAnnotation( entityBindingState ); // optional hibernate specific @org.hibernate.annotations.Entity | |
+// | |
+// schemaName = createSchemaName(); | |
+// bindTable( entityBinding ); | |
+// | |
+// // bind entity level annotations | |
+// bindWhereFilter( entityBindingState ); | |
+// bindJpaCaching( entityBindingState ); | |
+// bindHibernateCaching( entityBindingState ); | |
+// bindProxy( entityBindingState ); | |
+// bindSynchronize( entityBindingState ); | |
+// bindCustomSQL( entityBindingState ); | |
+// bindRowId( entityBindingState ); | |
+// bindBatchSize( entityBindingState ); | |
+// | |
+// entityBinding.initialize( meta, entityBindingState ); | |
+// | |
+// bindInheritance( entityBinding ); | |
+// | |
+// // take care of the id, attributes and relations | |
+// if ( configuredClass.isRoot() ) { | |
+// bindId( entityBinding ); | |
+// } | |
+// | |
+// // bind all attributes - simple as well as associations | |
+// bindAttributes( entityBinding ); | |
+// bindTableUniqueConstraints( entityBinding ); | |
+ | |
+ // last, but not least we initialize and register the new EntityBinding | |
+ meta.addEntity( entityBinding ); | |
+ } | |
} | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java | |
index 0f6ed61..c61ce71 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java | |
@@ -77,17 +77,17 @@ import org.hibernate.persister.entity.EntityPersister; | |
* | |
* @author Hardy Ferentschik | |
*/ | |
-public class EntityBinder { | |
- private final ConfiguredClass configuredClass; | |
- private final MetadataImplementor meta; | |
+public class EntityBinder extends AbstractBinder{ | |
+ | |
private Schema.Name schemaName; | |
+ | |
+ | |
public EntityBinder(MetadataImplementor metadata, ConfiguredClass configuredClass) { | |
- this.configuredClass = configuredClass; | |
- this.meta = metadata; | |
+ super(metadata, configuredClass); | |
} | |
- | |
+ @Override | |
public void bind() { | |
EntityBinding entityBinding = new EntityBinding(); | |
EntityBindingStateImpl entityBindingState = new EntityBindingStateImpl( getSuperType(), configuredClass ); | |
@@ -442,7 +442,7 @@ public class EntityBinder { | |
break; | |
} | |
case EMBEDDED: { | |
- // todo | |
+ bindEmbeddedIdAnnotation( entityBinding ); | |
break; | |
} | |
default: { | |
@@ -465,6 +465,25 @@ public class EntityBinder { | |
entityBindingState.setJpaEntityName( name ); | |
} | |
+ private void bindEmbeddedIdAnnotation(EntityBinding entityBinding){ | |
+ AnnotationInstance idAnnotation = JandexHelper.getSingleAnnotation( | |
+ configuredClass.getClassInfo(), JPADotNames.EMBEDDED_ID | |
+ ); | |
+ | |
+ String idName = JandexHelper.getPropertyName( idAnnotation.target() ); | |
+// MappedAttribute idAttribute = configuredClass.getMappedProperty( idName ); | |
+// if ( !( idAttribute instanceof SimpleAttribute ) ) { | |
+// throw new AssertionFailure( "Unexpected attribute type for id attribute" ); | |
+// } | |
+// | |
+// entityBinding.getEntity().getOrCreateSingularAttribute( idName ); | |
+// | |
+// SimpleAttributeBinding attributeBinding = entityBinding.makeSimpleIdAttributeBinding( idName ); | |
+// attributeBinding.initialize( new AttributeBindingStateImpl( (SimpleAttribute) idAttribute ) ); | |
+// attributeBinding.initialize( new ColumnRelationalStateImpl( (SimpleAttribute) idAttribute, meta ) ); | |
+// bindSingleIdGeneratedValue( entityBinding, idName ); | |
+ } | |
+ | |
private void bindSingleIdAnnotation(EntityBinding entityBinding) { | |
AnnotationInstance idAnnotation = JandexHelper.getSingleAnnotation( | |
configuredClass.getClassInfo(), JPADotNames.ID | |
@@ -681,21 +700,5 @@ public class EntityBinder { | |
entityBindingState.setExplicitPolymorphism( PolymorphismType.EXPLICIT.equals( polymorphism ) ); | |
entityBindingState.setOptimisticLock( optimisticLock ); | |
} | |
- | |
- private Hierarchical getSuperType() { | |
- ConfiguredClass parent = configuredClass.getParent(); | |
- if ( parent == null ) { | |
- return null; | |
- } | |
- | |
- EntityBinding parentBinding = meta.getEntityBinding( parent.getName() ); | |
- if ( parentBinding == null ) { | |
- throw new AssertionFailure( | |
- "Parent entity " + parent.getName() + " of entity " + configuredClass.getName() + " not yet created!" | |
- ); | |
- } | |
- | |
- return parentBinding.getEntity(); | |
- } | |
} | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/IdType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/IdType.java | |
index 164e756..9ddd901 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/IdType.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/IdType.java | |
@@ -24,7 +24,7 @@ | |
package org.hibernate.metamodel.source.annotations.entity; | |
/** | |
- * An emum for the type of id configuration for an entity. | |
+ * An enum for the type of id configuration for an entity. | |
* | |
* @author Hardy Ferentschik | |
*/ | |
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/MappedSuperClassBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/MappedSuperClassBinder.java | |
index 692bc78..56af74f 100644 | |
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/MappedSuperClassBinder.java | |
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/MappedSuperClassBinder.java | |
@@ -1,7 +1,16 @@ | |
package org.hibernate.metamodel.source.annotations.entity; | |
+import org.hibernate.metamodel.source.spi.MetadataImplementor; | |
+ | |
/** | |
* @author Strong Liu | |
*/ | |
-public class MappedSuperClassBinder { | |
+public class MappedSuperClassBinder extends AbstractBinder { | |
+ public MappedSuperClassBinder(MetadataImplementor meta, ConfiguredClass configuredClass) { | |
+ super( meta, configuredClass ); | |
+ } | |
+ | |
+ @Override | |
+ public void bind() { | |
+ } | |
} | |
diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddIdBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddIdBindingTests.java | |
index 56389ed..11dbc21 100644 | |
--- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddIdBindingTests.java | |
+++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddIdBindingTests.java | |
@@ -1,7 +1,49 @@ | |
package org.hibernate.metamodel.source.annotations.entity; | |
+import javax.persistence.Access; | |
+import javax.persistence.AccessType; | |
+import javax.persistence.Embeddable; | |
+import javax.persistence.Embedded; | |
+import javax.persistence.EmbeddedId; | |
+import javax.persistence.Entity; | |
+import javax.persistence.Id; | |
+ | |
+import org.junit.Test; | |
+ | |
+import org.hibernate.metamodel.binding.EntityBinding; | |
+import org.hibernate.metamodel.binding.EntityIdentifier; | |
+import org.hibernate.testing.FailureExpected; | |
+ | |
+import static junit.framework.Assert.assertNotNull; | |
+ | |
/** | |
* @author Strong Liu | |
*/ | |
-public class EmbeddIdBindingTests { | |
+public class EmbeddIdBindingTests extends BaseAnnotationBindingTestCase { | |
+ @Test | |
+ //@FailureExpected(jiraKey = "HHH6109", message = "Under construction") | |
+ public void testEmbeddable() { | |
+ buildMetadataSources( User.class ); | |
+ EntityBinding binding = getEntityBinding( User.class ); | |
+ EntityIdentifier identifier = binding.getEntityIdentifier(); | |
+ assertNotNull( identifier ); | |
+ | |
+ } | |
+ | |
+ @Entity | |
+ @Access( AccessType.FIELD ) | |
+ class User { | |
+ @EmbeddedId | |
+ private int id; | |
+ } | |
+ | |
+ @Embeddable | |
+ class Address { | |
+ String street; | |
+ String city; | |
+ String postCode; | |
+ } | |
} | |
+ | |
+ | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment