HHH-6201 Introducing a Nonentity, refactoring ConfiguredClass to properly support binding of mapped superclasses and non entities
This commit is contained in:
parent
7b121038a1
commit
e5da09cee0
|
@ -23,8 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.binding;
|
package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
import org.hibernate.metamodel.relational.Value;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
*
|
*
|
||||||
|
@ -32,9 +30,14 @@ import org.hibernate.metamodel.relational.Value;
|
||||||
*/
|
*/
|
||||||
public interface EntityReferencingAttributeBinding extends AttributeBinding {
|
public interface EntityReferencingAttributeBinding extends AttributeBinding {
|
||||||
boolean isReferenceResolved();
|
boolean isReferenceResolved();
|
||||||
|
|
||||||
boolean isPropertyReference();
|
boolean isPropertyReference();
|
||||||
|
|
||||||
String getReferencedEntityName();
|
String getReferencedEntityName();
|
||||||
|
|
||||||
String getReferencedAttributeName();
|
String getReferencedAttributeName();
|
||||||
|
|
||||||
EntityBinding getReferencedEntityBinding();
|
EntityBinding getReferencedEntityBinding();
|
||||||
|
|
||||||
void resolveReference(AttributeBinding attributeBinding);
|
void resolveReference(AttributeBinding attributeBinding);
|
||||||
}
|
}
|
|
@ -111,7 +111,7 @@ public abstract class AbstractAttributeContainer implements AttributeContainer,
|
||||||
protected void addAttribute(Attribute attribute) {
|
protected void addAttribute(Attribute attribute) {
|
||||||
// todo : how to best "secure" this?
|
// todo : how to best "secure" this?
|
||||||
if ( attributeMap.put( attribute.getName(), attribute ) != null ) {
|
if ( attributeMap.put( attribute.getName(), attribute ) != null ) {
|
||||||
throw new IllegalArgumentException( "Attrtibute with name [" + attribute.getName() + "] already registered" );
|
throw new IllegalArgumentException( "Attribute with name [" + attribute.getName() + "] already registered" );
|
||||||
}
|
}
|
||||||
attributeSet.add( attribute );
|
attributeSet.add( attribute );
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models the concept class in the hierarchy with no persistent attributes.
|
||||||
|
*
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class NonEntity extends AbstractAttributeContainer implements Hierarchical {
|
||||||
|
public NonEntity(String name, Hierarchical superType) {
|
||||||
|
super( name, superType );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public TypeNature getNature() {
|
||||||
|
return TypeNature.NON_ENTITY;
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,8 @@ public enum TypeNature {
|
||||||
BASIC( "basic" ),
|
BASIC( "basic" ),
|
||||||
COMPONENT( "component" ),
|
COMPONENT( "component" ),
|
||||||
ENTITY( "entity" ),
|
ENTITY( "entity" ),
|
||||||
SUPERCLASS( "superclass" );
|
SUPERCLASS( "superclass" ),
|
||||||
|
NON_ENTITY( "non-entity" );
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|
|
@ -75,11 +75,9 @@ public class AnnotationBinder {
|
||||||
|
|
||||||
// now we process each hierarchy one at the time
|
// now we process each hierarchy one at the time
|
||||||
for ( ConfiguredClassHierarchy hierarchy : hierarchies ) {
|
for ( ConfiguredClassHierarchy hierarchy : hierarchies ) {
|
||||||
Iterator<ConfiguredClass> iter = hierarchy.iterator();
|
for ( ConfiguredClass configuredClass : hierarchy ) {
|
||||||
while ( iter.hasNext() ) {
|
log.info( "Binding entity from annotated class: {}", configuredClass.getName() );
|
||||||
ConfiguredClass entity = iter.next();
|
EntityBinder entityBinder = new EntityBinder( metadata, configuredClass );
|
||||||
log.info( "Binding entity from annotated class: {}", entity.getName() );
|
|
||||||
EntityBinder entityBinder = new EntityBinder( metadata, entity );
|
|
||||||
entityBinder.bind();
|
entityBinder.bind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,8 @@ public class ConfiguredClass {
|
||||||
private final InheritanceType inheritanceType;
|
private final InheritanceType inheritanceType;
|
||||||
private final boolean hasOwnTable;
|
private final boolean hasOwnTable;
|
||||||
private final String primaryTableName;
|
private final String primaryTableName;
|
||||||
//private final AnnotationInstance tableAnnotation;
|
|
||||||
|
|
||||||
private final boolean isMappedSuperClass;
|
private final ConfiguredClassType type;
|
||||||
private final boolean isEmbeddable;
|
|
||||||
|
|
||||||
private final Map<String, MappedAttribute> mappedAttributes;
|
private final Map<String, MappedAttribute> mappedAttributes;
|
||||||
|
|
||||||
|
@ -95,22 +93,11 @@ public class ConfiguredClass {
|
||||||
this.inheritanceType = inheritanceType;
|
this.inheritanceType = inheritanceType;
|
||||||
this.clazz = serviceRegistry.getService( ClassLoaderService.class ).classForName( info.toString() );
|
this.clazz = serviceRegistry.getService( ClassLoaderService.class ).classForName( info.toString() );
|
||||||
|
|
||||||
AnnotationInstance mappedSuperClassAnnotation = JandexHelper.getSingleAnnotation(
|
this.type = determineType();
|
||||||
classInfo, JPADotNames.MAPPED_SUPERCLASS
|
this.classAccessType = determineClassAccessType();
|
||||||
);
|
|
||||||
isMappedSuperClass = mappedSuperClassAnnotation != null;
|
|
||||||
|
|
||||||
AnnotationInstance embeddableAnnotation = JandexHelper.getSingleAnnotation(
|
this.hasOwnTable = definesItsOwnTable();
|
||||||
classInfo, JPADotNames.MAPPED_SUPERCLASS
|
this.primaryTableName = determinePrimaryTableName();
|
||||||
);
|
|
||||||
isEmbeddable = embeddableAnnotation != null;
|
|
||||||
|
|
||||||
// todo think about how exactly to handle embeddables regarding access type etc
|
|
||||||
|
|
||||||
classAccessType = determineClassAccessType();
|
|
||||||
|
|
||||||
hasOwnTable = definesItsOwnTable();
|
|
||||||
primaryTableName = determinePrimaryTableName();
|
|
||||||
|
|
||||||
List<MappedAttribute> properties = collectMappedProperties( resolvedType );
|
List<MappedAttribute> properties = collectMappedProperties( resolvedType );
|
||||||
// make sure the properties are ordered by property name
|
// make sure the properties are ordered by property name
|
||||||
|
@ -119,7 +106,7 @@ public class ConfiguredClass {
|
||||||
for ( MappedAttribute property : properties ) {
|
for ( MappedAttribute property : properties ) {
|
||||||
tmpMap.put( property.getName(), property );
|
tmpMap.put( property.getName(), property );
|
||||||
}
|
}
|
||||||
mappedAttributes = Collections.unmodifiableMap( tmpMap );
|
this.mappedAttributes = Collections.unmodifiableMap( tmpMap );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -138,12 +125,8 @@ public class ConfiguredClass {
|
||||||
return isRoot;
|
return isRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMappedSuperClass() {
|
public ConfiguredClassType getType() {
|
||||||
return isMappedSuperClass;
|
return type;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmbeddable() {
|
|
||||||
return isEmbeddable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InheritanceType getInheritanceType() {
|
public InheritanceType getInheritanceType() {
|
||||||
|
@ -170,8 +153,8 @@ public class ConfiguredClass {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
sb.append( "ConfiguredClass" );
|
sb.append( "ConfiguredClass" );
|
||||||
sb.append( "{clazz=" ).append( clazz );
|
sb.append( "{clazz=" ).append( clazz.getSimpleName() );
|
||||||
sb.append( ", mappedAttributes=" ).append( mappedAttributes );
|
sb.append( ", type=" ).append( type );
|
||||||
sb.append( ", classAccessType=" ).append( classAccessType );
|
sb.append( ", classAccessType=" ).append( classAccessType );
|
||||||
sb.append( ", isRoot=" ).append( isRoot );
|
sb.append( ", isRoot=" ).append( isRoot );
|
||||||
sb.append( ", inheritanceType=" ).append( inheritanceType );
|
sb.append( ", inheritanceType=" ).append( inheritanceType );
|
||||||
|
@ -179,6 +162,30 @@ public class ConfiguredClass {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ConfiguredClassType determineType() {
|
||||||
|
AnnotationInstance entityAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
|
classInfo, JPADotNames.ENTITY
|
||||||
|
);
|
||||||
|
if ( entityAnnotation != null ) {
|
||||||
|
return ConfiguredClassType.ENTITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnnotationInstance mappedSuperClassAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
|
classInfo, JPADotNames.MAPPED_SUPERCLASS
|
||||||
|
);
|
||||||
|
if ( mappedSuperClassAnnotation != null ) {
|
||||||
|
return ConfiguredClassType.MAPPED_SUPERCLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnnotationInstance embeddableAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
|
classInfo, JPADotNames.EMBEDDABLE
|
||||||
|
);
|
||||||
|
if ( embeddableAnnotation != null ) {
|
||||||
|
return ConfiguredClassType.EMBEDDABLE;
|
||||||
|
}
|
||||||
|
return ConfiguredClassType.NON_ENTITY;
|
||||||
|
}
|
||||||
|
|
||||||
private AccessType determineClassAccessType() {
|
private AccessType determineClassAccessType() {
|
||||||
// default to the hierarchy access type to start with
|
// default to the hierarchy access type to start with
|
||||||
AccessType accessType = hierarchyAccessType;
|
AccessType accessType = hierarchyAccessType;
|
||||||
|
@ -398,7 +405,8 @@ public class ConfiguredClass {
|
||||||
|
|
||||||
private boolean definesItsOwnTable() {
|
private boolean definesItsOwnTable() {
|
||||||
// mapped super classes and embeddables don't have their own tables
|
// mapped super classes and embeddables don't have their own tables
|
||||||
if ( isMappedSuperClass() || isEmbeddable() ) {
|
if ( ConfiguredClassType.MAPPED_SUPERCLASS.equals( getType() ) || ConfiguredClassType.EMBEDDABLE
|
||||||
|
.equals( getType() ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +436,9 @@ public class ConfiguredClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( parent != null && !parent.isMappedSuperClass && !parent.isEmbeddable ) {
|
else if ( parent != null
|
||||||
|
&& !parent.getType().equals( ConfiguredClassType.MAPPED_SUPERCLASS )
|
||||||
|
&& !parent.getType().equals( ConfiguredClassType.EMBEDDABLE ) ) {
|
||||||
tableName = parent.getPrimaryTableName();
|
tableName = parent.getPrimaryTableName();
|
||||||
}
|
}
|
||||||
return tableName;
|
return tableName;
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public enum ConfiguredClassType {
|
||||||
|
ENTITY,
|
||||||
|
MAPPED_SUPERCLASS,
|
||||||
|
EMBEDDABLE,
|
||||||
|
NON_ENTITY
|
||||||
|
}
|
|
@ -188,8 +188,6 @@ public interface HibernateDotNames {
|
||||||
public static final DotName TYPE_DEFS = DotName.createSimple( TypeDefs.class.getName() );
|
public static final DotName TYPE_DEFS = DotName.createSimple( TypeDefs.class.getName() );
|
||||||
public static final DotName WHERE = DotName.createSimple( Where.class.getName() );
|
public static final DotName WHERE = DotName.createSimple( Where.class.getName() );
|
||||||
public static final DotName WHERE_JOIN_TABLE = DotName.createSimple( WhereJoinTable.class.getName() );
|
public static final DotName WHERE_JOIN_TABLE = DotName.createSimple( WhereJoinTable.class.getName() );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue