HHH-6290 : Add EntityBinding.isRoot()

This commit is contained in:
Gail Badner 2011-06-03 10:49:15 -07:00
parent b84ec25b63
commit 834fa2140f
6 changed files with 18 additions and 3 deletions

View File

@ -56,6 +56,8 @@ import org.hibernate.metamodel.source.hbm.util.MappingHelper;
*/ */
public class EntityBinding { public class EntityBinding {
private final EntityIdentifier entityIdentifier = new EntityIdentifier( this ); private final EntityIdentifier entityIdentifier = new EntityIdentifier( this );
private final boolean isRoot;
private InheritanceType entityInheritanceType; private InheritanceType entityInheritanceType;
private EntityDiscriminator entityDiscriminator; private EntityDiscriminator entityDiscriminator;
private SimpleAttributeBinding versionBinding; private SimpleAttributeBinding versionBinding;
@ -94,6 +96,10 @@ public class EntityBinding {
private List<String> synchronizedTableNames; private List<String> synchronizedTableNames;
public EntityBinding(boolean isRoot) {
this.isRoot = isRoot;
}
// TODO: change to intialize from Doimain // TODO: change to intialize from Doimain
public void fromHbmXml(MappingDefaults defaults, XMLClass entityClazz, Entity entity) { public void fromHbmXml(MappingDefaults defaults, XMLClass entityClazz, Entity entity) {
this.entity = entity; this.entity = entity;
@ -175,6 +181,10 @@ public class EntityBinding {
isAbstract = entityClazz.isAbstract(); isAbstract = entityClazz.isAbstract();
} }
public boolean isRoot() {
return isRoot;
}
public Entity getEntity() { public Entity getEntity() {
return entity; return entity;
} }

View File

@ -85,7 +85,7 @@ public class EntityBinder {
} }
public void bind() { public void bind() {
EntityBinding entityBinding = new EntityBinding(); EntityBinding entityBinding = new EntityBinding( configuredClass.isRoot() );
bindJpaEntityAnnotation( entityBinding ); bindJpaEntityAnnotation( entityBinding );
bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity

View File

@ -60,7 +60,7 @@ class RootEntityBinder extends AbstractEntityBinder {
throw new MappingException( "Unable to determine entity name" ); throw new MappingException( "Unable to determine entity name" );
} }
EntityBinding entityBinding = new EntityBinding(); EntityBinding entityBinding = new EntityBinding( true );
basicEntityBinding( xmlClazz, entityBinding, null ); basicEntityBinding( xmlClazz, entityBinding, null );
basicTableBinding( xmlClazz, entityBinding ); basicTableBinding( xmlClazz, entityBinding );

View File

@ -123,6 +123,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
assertNotNull( entityBinding ); assertNotNull( entityBinding );
assertNotNull( entityBinding.getEntityIdentifier() ); assertNotNull( entityBinding.getEntityIdentifier() );
assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() ); assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() );
assertTrue( entityBinding.isRoot() );
AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" ); AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" );
assertNotNull( idAttributeBinding ); assertNotNull( idAttributeBinding );

View File

@ -52,7 +52,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase {
public void testBasicMiddleOutBuilding() { public void testBasicMiddleOutBuilding() {
Table table = new Table( new Schema( null, null ), "the_table" ); Table table = new Table( new Schema( null, null ), "the_table" );
Entity entity = new Entity( "TheEntity", null ); Entity entity = new Entity( "TheEntity", null );
EntityBinding entityBinding = new EntityBinding(); EntityBinding entityBinding = new EntityBinding( true );
entityBinding.setEntity( entity ); entityBinding.setEntity( entity );
entityBinding.setBaseTable( table ); entityBinding.setBaseTable( table );

View File

@ -32,7 +32,9 @@ import org.junit.Test;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
/** /**
* @author Hardy Ferentschik * @author Hardy Ferentschik
@ -42,6 +44,7 @@ public class InheritanceTypeTest extends BaseAnnotationBindingTestCase {
public void testNoInheritance() { public void testNoInheritance() {
buildMetadataSources( SingleEntity.class ); buildMetadataSources( SingleEntity.class );
EntityBinding entityBinding = getEntityBinding( SingleEntity.class ); EntityBinding entityBinding = getEntityBinding( SingleEntity.class );
assertTrue( entityBinding.isRoot() );
assertNull( entityBinding.getEntityDiscriminator() ); assertNull( entityBinding.getEntityDiscriminator() );
} }
@ -51,6 +54,7 @@ public class InheritanceTypeTest extends BaseAnnotationBindingTestCase {
RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class
); );
EntityBinding entityBinding = getEntityBinding( SubclassOfSingleTableInheritance.class ); EntityBinding entityBinding = getEntityBinding( SubclassOfSingleTableInheritance.class );
assertFalse( entityBinding.isRoot() );
assertEquals( "Wrong discriminator value", "foo", entityBinding.getDiscriminatorValue() ); assertEquals( "Wrong discriminator value", "foo", entityBinding.getDiscriminatorValue() );
} }