HHH-6172 Cleaning up AbstractBasicBindingTests
This commit is contained in:
parent
14efea6e21
commit
49cf328bb8
|
@ -172,11 +172,6 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
: Collections.singletonList( (SimpleValue) value );
|
: Collections.singletonList( (SimpleValue) value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableSpecification getTable() {
|
|
||||||
return getValue().getTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPropertyAccessorName() {
|
public String getPropertyAccessorName() {
|
||||||
return propertyAccessorName;
|
return propertyAccessorName;
|
||||||
|
|
|
@ -74,27 +74,14 @@ public interface AttributeBinding {
|
||||||
public Map<String, MetaAttribute> getMetaAttributes();
|
public Map<String, MetaAttribute> getMetaAttributes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In the case that {@link #getValue()} represents a {@link org.hibernate.metamodel.relational.Tuple} this method
|
* @return In the case that {@link #getValue()} represents a {@link org.hibernate.metamodel.relational.Tuple} this method
|
||||||
* gives access to its compound values. In the case of {@link org.hibernate.metamodel.relational.SimpleValue},
|
* gives access to its compound values. In the case of {@link org.hibernate.metamodel.relational.SimpleValue},
|
||||||
* we return an Iterable over that single simple value.
|
* we return an Iterable over that single simple value.
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Iterable<SimpleValue> getValues();
|
public Iterable<SimpleValue> getValues();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link #getValue()}.{@link Value#getTable() getTable()} instead; to be removed on completion of new metamodel code
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public TableSpecification getTable();
|
|
||||||
|
|
||||||
public String getPropertyAccessorName();
|
public String getPropertyAccessorName();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean hasFormula();
|
public boolean hasFormula();
|
||||||
|
|
||||||
public boolean isAlternateUniqueKey();
|
public boolean isAlternateUniqueKey();
|
||||||
|
|
|
@ -26,11 +26,10 @@ package org.hibernate.metamodel.binding;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState;
|
||||||
|
import org.hibernate.metamodel.relational.Column;
|
||||||
import org.hibernate.metamodel.relational.ForeignKey;
|
import org.hibernate.metamodel.relational.ForeignKey;
|
||||||
import org.hibernate.metamodel.relational.SimpleValue;
|
import org.hibernate.metamodel.relational.SimpleValue;
|
||||||
import org.hibernate.metamodel.relational.Column;
|
|
||||||
import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState;
|
|
||||||
import org.hibernate.metamodel.relational.state.ManyToOneRelationalState;
|
import org.hibernate.metamodel.relational.state.ManyToOneRelationalState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,13 +55,6 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements
|
||||||
isPropertyReference = state.getReferencedAttributeName() != null;
|
isPropertyReference = state.getReferencedAttributeName() != null;
|
||||||
referencedAttributeName = state.getReferencedAttributeName();
|
referencedAttributeName = state.getReferencedAttributeName();
|
||||||
referencedEntityName = state.getReferencedEntityName();
|
referencedEntityName = state.getReferencedEntityName();
|
||||||
if ( referencedEntityName == null ) {
|
|
||||||
referencedEntityName =
|
|
||||||
ReflectHelper.reflectedPropertyClass(
|
|
||||||
getEntityBinding().getEntity().getName(),
|
|
||||||
state.getAttributeName()
|
|
||||||
).getName();
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +76,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements
|
||||||
public final String getReferencedAttributeName() {
|
public final String getReferencedAttributeName() {
|
||||||
if ( referencedAttributeName == null ) {
|
if ( referencedAttributeName == null ) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Referenced attribute name is not available."
|
"Referenced attribute name is not available."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return referencedAttributeName;
|
return referencedAttributeName;
|
||||||
|
@ -95,7 +87,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public final EntityBinding getReferencedEntityBinding() {
|
public final EntityBinding getReferencedEntityBinding() {
|
||||||
if ( ! isReferenceResolved() ) {
|
if ( !isReferenceResolved() ) {
|
||||||
throw new IllegalStateException( "EntityBinding reference has not be referenced." );
|
throw new IllegalStateException( "EntityBinding reference has not be referenced." );
|
||||||
}
|
}
|
||||||
// TODO: throw exception if referencedEntityBinding is null?
|
// TODO: throw exception if referencedEntityBinding is null?
|
||||||
|
@ -103,7 +95,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void resolveReference(AttributeBinding referencedAttributeBinding) {
|
public final void resolveReference(AttributeBinding referencedAttributeBinding) {
|
||||||
if ( ! referencedEntityName.equals( referencedAttributeBinding.getEntityBinding().getEntity().getName() ) ) {
|
if ( !referencedEntityName.equals( referencedAttributeBinding.getEntityBinding().getEntity().getName() ) ) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"attempt to set EntityBinding with name: [" +
|
"attempt to set EntityBinding with name: [" +
|
||||||
referencedAttributeBinding.getEntityBinding().getEntity().getName() +
|
referencedAttributeBinding.getEntityBinding().getEntity().getName() +
|
||||||
|
@ -113,10 +105,10 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements
|
||||||
if ( referencedAttributeName == null ) {
|
if ( referencedAttributeName == null ) {
|
||||||
referencedAttributeName = referencedAttributeBinding.getAttribute().getName();
|
referencedAttributeName = referencedAttributeBinding.getAttribute().getName();
|
||||||
}
|
}
|
||||||
else if ( ! referencedAttributeName.equals( referencedAttributeBinding.getAttribute().getName() ) ) {
|
else if ( !referencedAttributeName.equals( referencedAttributeBinding.getAttribute().getName() ) ) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Inconsistent attribute name; expected: " + referencedAttributeName +
|
"Inconsistent attribute name; expected: " + referencedAttributeName +
|
||||||
"actual: " + referencedAttributeBinding.getAttribute().getName()
|
"actual: " + referencedAttributeBinding.getAttribute().getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.referencedAttributeBinding = referencedAttributeBinding;
|
this.referencedAttributeBinding = referencedAttributeBinding;
|
||||||
|
@ -125,18 +117,21 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements
|
||||||
|
|
||||||
private void buildForeignKey() {
|
private void buildForeignKey() {
|
||||||
// TODO: move this stuff to relational model
|
// TODO: move this stuff to relational model
|
||||||
ForeignKey foreignKey = getTable().createForeignKey( referencedAttributeBinding.getTable(), foreignKeyName );
|
ForeignKey foreignKey = getValue().getTable()
|
||||||
|
.createForeignKey( referencedAttributeBinding.getValue().getTable(), foreignKeyName );
|
||||||
Iterator<SimpleValue> referencingValueIterator = getValues().iterator();
|
Iterator<SimpleValue> referencingValueIterator = getValues().iterator();
|
||||||
Iterator<SimpleValue> targetValueIterator = referencedAttributeBinding.getValues().iterator();
|
Iterator<SimpleValue> targetValueIterator = referencedAttributeBinding.getValues().iterator();
|
||||||
while ( referencingValueIterator.hasNext() ) {
|
while ( referencingValueIterator.hasNext() ) {
|
||||||
if ( ! targetValueIterator.hasNext() ) {
|
if ( !targetValueIterator.hasNext() ) {
|
||||||
// TODO: improve this message
|
// TODO: improve this message
|
||||||
throw new MappingException( "number of values in many-to-one reference is greater than number of values in target" );
|
throw new MappingException(
|
||||||
|
"number of values in many-to-one reference is greater than number of values in target"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
SimpleValue referencingValue = referencingValueIterator.next();
|
SimpleValue referencingValue = referencingValueIterator.next();
|
||||||
SimpleValue targetValue = targetValueIterator.next();
|
SimpleValue targetValue = targetValueIterator.next();
|
||||||
if ( Column.class.isInstance( referencingValue ) ) {
|
if ( Column.class.isInstance( referencingValue ) ) {
|
||||||
if ( ! Column.class.isInstance( targetValue ) ) {
|
if ( !Column.class.isInstance( targetValue ) ) {
|
||||||
// TODO improve this message
|
// TODO improve this message
|
||||||
throw new MappingException( "referencing value is a column, but target is not a column" );
|
throw new MappingException( "referencing value is a column, but target is not a column" );
|
||||||
}
|
}
|
||||||
|
@ -159,7 +154,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements
|
||||||
public void validate() {
|
public void validate() {
|
||||||
// can't check this until both the domain and relational states are initialized...
|
// can't check this until both the domain and relational states are initialized...
|
||||||
if ( getCascade() != null && getCascade().indexOf( "delete-orphan" ) >= 0 ) {
|
if ( getCascade() != null && getCascade().indexOf( "delete-orphan" ) >= 0 ) {
|
||||||
if ( ! isLogicalOneToOne ) {
|
if ( !isLogicalOneToOne ) {
|
||||||
throw new MappingException(
|
throw new MappingException(
|
||||||
"many-to-one attribute [" + getAttribute().getName() + "] does not support orphan delete as it is not unique"
|
"many-to-one attribute [" + getAttribute().getName() + "] does not support orphan delete as it is not unique"
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.hibernate.annotations.OptimisticLockType;
|
||||||
import org.hibernate.annotations.PolymorphismType;
|
import org.hibernate.annotations.PolymorphismType;
|
||||||
import org.hibernate.cache.spi.RegionFactory;
|
import org.hibernate.cache.spi.RegionFactory;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.metamodel.binding.Caching;
|
import org.hibernate.metamodel.binding.Caching;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
||||||
|
@ -291,7 +290,7 @@ public class EntityBinder {
|
||||||
);
|
);
|
||||||
String name;
|
String name;
|
||||||
if ( jpaEntityAnnotation.value( "name" ) == null ) {
|
if ( jpaEntityAnnotation.value( "name" ) == null ) {
|
||||||
name = StringHelper.unqualify( configuredClass.getName() );
|
name = configuredClass.getName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
name = jpaEntityAnnotation.value( "name" ).asString();
|
name = jpaEntityAnnotation.value( "name" ).asString();
|
||||||
|
@ -428,7 +427,7 @@ public class EntityBinder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityBinding parentBinding = meta.getEntityBinding( parent.getSimpleName() );
|
EntityBinding parentBinding = meta.getEntityBinding( parent.getName() );
|
||||||
if ( parentBinding == null ) {
|
if ( parentBinding == null ) {
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
"Parent entity " + parent.getName() + " of entity " + configuredClass.getName() + " not yet created!"
|
"Parent entity " + parent.getName() + " of entity " + configuredClass.getName() + " not yet created!"
|
||||||
|
|
|
@ -74,6 +74,9 @@ public class MetadataImpl implements Metadata, MetadataImplementor, Serializable
|
||||||
private final SharedCacheMode sharedCacheMode;
|
private final SharedCacheMode sharedCacheMode;
|
||||||
private final Database database = new Database();
|
private final Database database = new Database();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the fully qualified class name of an entity to its entity binding
|
||||||
|
*/
|
||||||
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
|
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
|
||||||
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
||||||
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||||
|
|
|
@ -29,8 +29,9 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.relational.Column;
|
import org.hibernate.metamodel.relational.Column;
|
||||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
import org.hibernate.service.BasicServiceRegistry;
|
import org.hibernate.service.BasicServiceRegistry;
|
||||||
import org.hibernate.service.ServiceRegistryBuilder;
|
import org.hibernate.service.ServiceRegistryBuilder;
|
||||||
import org.hibernate.service.internal.BasicServiceRegistryImpl;
|
import org.hibernate.service.internal.BasicServiceRegistryImpl;
|
||||||
|
@ -50,10 +51,12 @@ import static org.junit.Assert.assertTrue;
|
||||||
public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
private BasicServiceRegistryImpl serviceRegistry;
|
private BasicServiceRegistryImpl serviceRegistry;
|
||||||
|
private MetadataSources sources;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
|
||||||
|
sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -67,56 +70,31 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleEntityMapping() {
|
public void testSimpleEntityMapping() {
|
||||||
checkSimpleEntityMapping( buildSimpleEntityBinding() );
|
MetadataImpl metadata = addSourcesForSimpleEntityBinding( sources );
|
||||||
}
|
EntityBinding entityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
|
||||||
|
assertIdAndSimpleProperty( entityBinding );
|
||||||
|
|
||||||
protected void checkSimpleEntityMapping(EntityBinding entityBinding) {
|
|
||||||
assertNotNull( entityBinding );
|
|
||||||
assertNotNull( entityBinding.getEntityIdentifier() );
|
|
||||||
assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() );
|
|
||||||
assertNull( entityBinding.getVersioningValueBinding() );
|
assertNull( entityBinding.getVersioningValueBinding() );
|
||||||
|
|
||||||
AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" );
|
|
||||||
assertNotNull( idAttributeBinding );
|
|
||||||
assertSame( idAttributeBinding, entityBinding.getEntityIdentifier().getValueBinding() );
|
|
||||||
assertNotNull( idAttributeBinding.getAttribute() );
|
|
||||||
assertNotNull( idAttributeBinding.getValue() );
|
|
||||||
assertTrue( idAttributeBinding.getValue() instanceof Column );
|
|
||||||
|
|
||||||
AttributeBinding nameBinding = entityBinding.getAttributeBinding( "name" );
|
|
||||||
assertNotNull( nameBinding );
|
|
||||||
assertNotNull( nameBinding.getAttribute() );
|
|
||||||
assertNotNull( nameBinding.getValue() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleVersionedEntityMapping() {
|
public void testSimpleVersionedEntityMapping() {
|
||||||
EntityBinding entityBinding = buildSimpleVersionedEntityBinding();
|
MetadataImpl metadata = addSourcesForSimpleVersionedEntityBinding( sources );
|
||||||
assertNotNull( entityBinding );
|
EntityBinding entityBinding = metadata.getEntityBinding( SimpleVersionedEntity.class.getName() );
|
||||||
assertNotNull( entityBinding.getEntityIdentifier() );
|
assertIdAndSimpleProperty( entityBinding );
|
||||||
assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() );
|
|
||||||
assertNotNull( entityBinding.getVersioningValueBinding() );
|
assertNotNull( entityBinding.getVersioningValueBinding() );
|
||||||
assertNotNull( entityBinding.getVersioningValueBinding().getAttribute() );
|
assertNotNull( entityBinding.getVersioningValueBinding().getAttribute() );
|
||||||
|
|
||||||
AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" );
|
|
||||||
assertNotNull( idAttributeBinding );
|
|
||||||
assertSame( idAttributeBinding, entityBinding.getEntityIdentifier().getValueBinding() );
|
|
||||||
assertNotNull( idAttributeBinding.getAttribute() );
|
|
||||||
assertNotNull( idAttributeBinding.getValue() );
|
|
||||||
assertTrue( idAttributeBinding.getValue() instanceof Column );
|
|
||||||
|
|
||||||
AttributeBinding nameBinding = entityBinding.getAttributeBinding( "name" );
|
|
||||||
assertNotNull( nameBinding );
|
|
||||||
assertNotNull( nameBinding.getAttribute() );
|
|
||||||
assertNotNull( nameBinding.getValue() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityWithManyToOneMapping() {
|
public void testEntityWithManyToOneMapping() {
|
||||||
MetadataImplementor metadata = buildMetadataWithManyToOne();
|
MetadataImpl metadata = addSourcesForManyToOne( sources );
|
||||||
EntityBinding entityWithManyToOneBinding = metadata.getEntityBinding( EntityWithManyToOne.class.getName() );
|
|
||||||
EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
|
EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
|
||||||
checkSimpleEntityMapping( simpleEntityBinding );
|
assertIdAndSimpleProperty( simpleEntityBinding );
|
||||||
|
|
||||||
|
EntityBinding entityWithManyToOneBinding = metadata.getEntityBinding( ManyToOneEntity.class.getName() );
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
1 == simpleEntityBinding.getAttributeBinding( "id" ).getEntityReferencingAttributeBindings().size()
|
1 == simpleEntityBinding.getAttributeBinding( "id" ).getEntityReferencingAttributeBindings().size()
|
||||||
|
@ -127,15 +105,17 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
||||||
assertSame( entityWithManyToOneBinding.getAttributeBinding( "simpleEntity" ), it.next() );
|
assertSame( entityWithManyToOneBinding.getAttributeBinding( "simpleEntity" ), it.next() );
|
||||||
assertFalse( it.hasNext() );
|
assertFalse( it.hasNext() );
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
@Test
|
|
||||||
public void testEntityWithElementCollection() {
|
|
||||||
EntityBinding entityBinding = buildEntityWithElementCollectionBinding();
|
|
||||||
|
|
||||||
|
public abstract MetadataImpl addSourcesForSimpleVersionedEntityBinding(MetadataSources sources);
|
||||||
|
|
||||||
|
public abstract MetadataImpl addSourcesForSimpleEntityBinding(MetadataSources sources);
|
||||||
|
|
||||||
|
public abstract MetadataImpl addSourcesForManyToOne(MetadataSources sources);
|
||||||
|
|
||||||
|
protected void assertIdAndSimpleProperty(EntityBinding entityBinding) {
|
||||||
assertNotNull( entityBinding );
|
assertNotNull( entityBinding );
|
||||||
assertNotNull( entityBinding.getEntityIdentifier() );
|
assertNotNull( entityBinding.getEntityIdentifier() );
|
||||||
assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() );
|
assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() );
|
||||||
assertNull( entityBinding.getVersioningValueBinding() );
|
|
||||||
|
|
||||||
AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" );
|
AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" );
|
||||||
assertNotNull( idAttributeBinding );
|
assertNotNull( idAttributeBinding );
|
||||||
|
@ -149,13 +129,4 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
||||||
assertNotNull( nameBinding.getAttribute() );
|
assertNotNull( nameBinding.getAttribute() );
|
||||||
assertNotNull( nameBinding.getValue() );
|
assertNotNull( nameBinding.getValue() );
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
public abstract EntityBinding buildSimpleVersionedEntityBinding();
|
|
||||||
|
|
||||||
public abstract EntityBinding buildSimpleEntityBinding();
|
|
||||||
|
|
||||||
public abstract MetadataImplementor buildMetadataWithManyToOne();
|
|
||||||
|
|
||||||
//public abstract EntityBinding buildEntityWithElementCollectionBinding();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
|
||||||
import org.hibernate.service.ServiceRegistryBuilder;
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,26 +41,20 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
|
||||||
super.testEntityWithManyToOneMapping();
|
super.testEntityWithManyToOneMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityBinding buildSimpleEntityBinding() {
|
public MetadataImpl addSourcesForSimpleEntityBinding(MetadataSources sources) {
|
||||||
MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
|
|
||||||
sources.addAnnotatedClass( SimpleEntity.class );
|
sources.addAnnotatedClass( SimpleEntity.class );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
return (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
return metadata.getEntityBinding( SimpleEntity.class.getSimpleName() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityBinding buildSimpleVersionedEntityBinding() {
|
public MetadataImpl addSourcesForSimpleVersionedEntityBinding(MetadataSources sources) {
|
||||||
MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
|
|
||||||
sources.addAnnotatedClass( SimpleVersionedEntity.class );
|
sources.addAnnotatedClass( SimpleVersionedEntity.class );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
return (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
return metadata.getEntityBinding( SimpleVersionedEntity.class.getSimpleName() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetadataImplementor buildMetadataWithManyToOne() {
|
public MetadataImpl addSourcesForManyToOne(MetadataSources sources) {
|
||||||
MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
|
sources.addAnnotatedClass( ManyToOneEntity.class );
|
||||||
sources.addAnnotatedClass( EntityWithManyToOne.class );
|
sources.addAnnotatedClass( SimpleEntity.class );
|
||||||
sources.addAnnotatedClass( SimpleVersionedEntity.class );
|
return (MetadataImpl) sources.buildMetadata();
|
||||||
return (MetadataImplementor) sources.buildMetadata();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,6 @@ package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic tests of {@code hbm.xml} binding code
|
* Basic tests of {@code hbm.xml} binding code
|
||||||
|
@ -35,33 +32,19 @@ import static org.junit.Assert.assertEquals;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class BasicHbmBindingTests extends AbstractBasicBindingTests {
|
public class BasicHbmBindingTests extends AbstractBasicBindingTests {
|
||||||
public EntityBinding buildSimpleEntityBinding() {
|
public MetadataImpl addSourcesForSimpleEntityBinding(MetadataSources sources) {
|
||||||
return getEntityBinding(
|
sources.addResource( "org/hibernate/metamodel/binding/SimpleEntity.hbm.xml" );
|
||||||
"org/hibernate/metamodel/binding/SimpleEntity.hbm.xml",
|
return (MetadataImpl) sources.buildMetadata();
|
||||||
SimpleEntity.class.getName()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityBinding buildSimpleVersionedEntityBinding() {
|
public MetadataImpl addSourcesForSimpleVersionedEntityBinding(MetadataSources sources) {
|
||||||
return getEntityBinding(
|
sources.addResource( "org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml" );
|
||||||
"org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml",
|
return (MetadataImpl) sources.buildMetadata();
|
||||||
SimpleVersionedEntity.class.getName()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetadataImplementor buildMetadataWithManyToOne() {
|
public MetadataImpl addSourcesForManyToOne(MetadataSources sources) {
|
||||||
MetadataSources metadataSources = new MetadataSources( basicServiceRegistry() );
|
sources.addResource( "org/hibernate/metamodel/binding/ManyToOneEntity.hbm.xml" );
|
||||||
metadataSources.addResource( "org/hibernate/metamodel/binding/EntityWithManyToOne.hbm.xml" );
|
sources.addResource( "org/hibernate/metamodel/binding/SimpleEntity.hbm.xml" );
|
||||||
metadataSources.addResource( "org/hibernate/metamodel/binding/SimpleEntity.hbm.xml" );
|
return (MetadataImpl) sources.buildMetadata();
|
||||||
assertEquals( 2, metadataSources.getJaxbRootList().size() );
|
|
||||||
return ( MetadataImplementor ) metadataSources.buildMetadata();
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityBinding getEntityBinding(String resourceName, String entityName ) {
|
|
||||||
MetadataSources metadataSources = new MetadataSources( basicServiceRegistry() );
|
|
||||||
metadataSources.addResource( resourceName );
|
|
||||||
assertEquals( 1, metadataSources.getJaxbRootList().size() );
|
|
||||||
MetadataImpl metadata = ( MetadataImpl ) metadataSources.buildMetadata();
|
|
||||||
return metadata.getEntityBinding( entityName );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<hhh:hibernate-mapping package="org.hibernate.metamodel.binding" xmlns:hhh="http://www.hibernate.org/xsd/hibernate-mapping"
|
|
||||||
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
||||||
|
|
||||||
<class name="EntityWithManyToOne">
|
|
||||||
|
|
||||||
<id name="id">
|
|
||||||
<generator class="increment"/>
|
|
||||||
</id>
|
|
||||||
<property name="name"/>
|
|
||||||
<many-to-one name="simpleEntity"/>
|
|
||||||
</class>
|
|
||||||
|
|
||||||
</hhh:hibernate-mapping>
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<hhh:hibernate-mapping package="org.hibernate.metamodel.binding"
|
||||||
|
xmlns:hhh="http://www.hibernate.org/xsd/hibernate-mapping"
|
||||||
|
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
|
||||||
|
<class name="ManyToOneEntity">
|
||||||
|
<id name="id">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
<property name="name"/>
|
||||||
|
<many-to-one name="simpleEntity"/>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hhh:hibernate-mapping>
|
|
@ -23,9 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.binding;
|
package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
|
|
||||||
|
@ -35,17 +32,18 @@ import org.hibernate.annotations.Entity;
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
public class EntityWithManyToOne {
|
public class ManyToOneEntity {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
private String theName;
|
private String theName;
|
||||||
|
@ManyToOne
|
||||||
SimpleEntity simpleEntity;
|
SimpleEntity simpleEntity;
|
||||||
|
|
||||||
public EntityWithManyToOne() {
|
public ManyToOneEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityWithManyToOne(String name) {
|
public ManyToOneEntity(String name) {
|
||||||
this.theName = theName;
|
this.theName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
@ -61,10 +59,9 @@ public class EntityWithManyToOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.theName = theName;
|
this.theName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
public SimpleEntity getSimpleEntity() {
|
public SimpleEntity getSimpleEntity() {
|
||||||
return simpleEntity;
|
return simpleEntity;
|
||||||
}
|
}
|
||||||
|
@ -72,4 +69,15 @@ public class EntityWithManyToOne {
|
||||||
public void setSimpleEntity(SimpleEntity simpleEntity) {
|
public void setSimpleEntity(SimpleEntity simpleEntity) {
|
||||||
this.simpleEntity = simpleEntity;
|
this.simpleEntity = simpleEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append( "EntityWithManyToOne" );
|
||||||
|
sb.append( "{id=" ).append( id );
|
||||||
|
sb.append( ", theName='" ).append( theName ).append( '\'' );
|
||||||
|
sb.append( ", simpleEntity=" ).append( simpleEntity );
|
||||||
|
sb.append( '}' );
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ public class MiscAnnotationBindingTest extends BaseUnitTestCase {
|
||||||
sources.addAnnotatedClass( Foo.class );
|
sources.addAnnotatedClass( Foo.class );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
EntityBinding binding = metadata.getEntityBinding( MiscAnnotationBindingTest.class.getSimpleName() + "$" + Foo.class.getSimpleName() );
|
EntityBinding binding = metadata.getEntityBinding( MiscAnnotationBindingTest.class.getName() + "$" + Foo.class.getSimpleName() );
|
||||||
assertEquals( "Wrong where filter", "1=1", binding.getWhereFilter() );
|
assertEquals( "Wrong where filter", "1=1", binding.getWhereFilter() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,11 @@ public class CacheBindingTests extends BaseUnitTestCase {
|
||||||
EntityBinding binding = getEntityBinding( JpaCacheEntity.class, SharedCacheMode.ALL );
|
EntityBinding binding = getEntityBinding( JpaCacheEntity.class, SharedCacheMode.ALL );
|
||||||
assertNotNull( "There should be a cache binding", binding.getCaching() );
|
assertNotNull( "There should be a cache binding", binding.getCaching() );
|
||||||
Caching caching = binding.getCaching();
|
Caching caching = binding.getCaching();
|
||||||
assertEquals( "Wrong region", "CacheBindingTests$JpaCacheEntity", caching.getRegion() );
|
assertEquals(
|
||||||
|
"Wrong region",
|
||||||
|
this.getClass().getName() + "$" + JpaCacheEntity.class.getSimpleName(),
|
||||||
|
caching.getRegion()
|
||||||
|
);
|
||||||
assertEquals( "Wrong lazy properties configuration", true, caching.isCacheLazyProperties() );
|
assertEquals( "Wrong lazy properties configuration", true, caching.isCacheLazyProperties() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +85,7 @@ public class CacheBindingTests extends BaseUnitTestCase {
|
||||||
sources.getMetadataBuilder().with( cacheMode );
|
sources.getMetadataBuilder().with( cacheMode );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
return metadata.getEntityBinding( this.getClass().getSimpleName() + "$" + clazz.getSimpleName() );
|
return metadata.getEntityBinding( this.getClass().getName() + "$" + clazz.getSimpleName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class InheritanceTypeTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testDiscriminatorValue() {
|
public void testDiscriminatorValue() {
|
||||||
MetadataImpl meta = buildMetadata( RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class );
|
MetadataImpl meta = buildMetadata( RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class );
|
||||||
EntityBinding entityBinding = meta.getEntityBinding( SubclassOfSingleTableInheritance.class.getSimpleName() );
|
EntityBinding entityBinding = meta.getEntityBinding( SubclassOfSingleTableInheritance.class.getName() );
|
||||||
assertEquals( "Wrong discriminator value", "foo", entityBinding.getDiscriminatorValue() );
|
assertEquals( "Wrong discriminator value", "foo", entityBinding.getDiscriminatorValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class InheritanceTypeTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityBinding getEntityBindingForInnerClass(MetadataImpl meta, Class<?> clazz) {
|
private EntityBinding getEntityBindingForInnerClass(MetadataImpl meta, Class<?> clazz) {
|
||||||
return meta.getEntityBinding( this.getClass().getSimpleName() + "$" + clazz.getSimpleName() );
|
return meta.getEntityBinding( this.getClass().getName() + "$" + clazz.getSimpleName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
Loading…
Reference in New Issue