Moving xml mapping files into resources folder. Creating subpackages for some tests

This commit is contained in:
Hardy Ferentschik 2012-07-23 17:02:43 +02:00
parent 58b5b7038b
commit 72af04524a
14 changed files with 54 additions and 79 deletions

View File

@ -35,17 +35,17 @@ import javax.persistence.OneToMany;
* @author Gail Badner * @author Gail Badner
*/ */
@Entity @Entity
public class EntityWithUnidirectionalManyToManys { public class EntityWithUnidirectionalManyToMany {
private Long id; private Long id;
private String name; private String name;
private Collection<SimpleEntity> theBag = new ArrayList<SimpleEntity>(); private Collection<SimpleEntity> theBag = new ArrayList<SimpleEntity>();
private Set<SimpleEntity> theSet = new HashSet<SimpleEntity>(); private Set<SimpleEntity> theSet = new HashSet<SimpleEntity>();
private Collection<SimpleEntity> thePropertyRefBag = new ArrayList<SimpleEntity>(); private Collection<SimpleEntity> thePropertyRefBag = new ArrayList<SimpleEntity>();
public EntityWithUnidirectionalManyToManys() { public EntityWithUnidirectionalManyToMany() {
} }
public EntityWithUnidirectionalManyToManys(String name) { public EntityWithUnidirectionalManyToMany(String name) {
this.name = name; this.name = name;
} }

View File

@ -23,35 +23,23 @@
*/ */
package org.hibernate.metamodel.spi.binding; package org.hibernate.metamodel.spi.binding;
import java.util.Collection;
import java.util.Set;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.internal.MetadataImpl; import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.spi.binding.EntityWithUnidirectionalManyToMany;
import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.ForeignKey;
import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.metamodel.spi.relational.Identifier;
import org.hibernate.metamodel.spi.relational.Value;
import org.hibernate.service.ServiceRegistryBuilder; import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.StandardServiceRegistryImpl; import org.hibernate.service.internal.StandardServiceRegistryImpl;
import org.hibernate.testing.FailureExpected; import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.type.BagType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.SetType;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/** /**
* @author Gail Badner * @author Gail Badner
@ -86,7 +74,7 @@ public class UnidirectionalManyToManyBindingTests extends BaseUnitTestCase {
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" ); sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" );
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata(); MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToManys.class.getName() ); final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToMany.class.getName() );
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() ); final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
assertNotNull( entityBinding ); assertNotNull( entityBinding );

View File

@ -1,27 +1,4 @@
/* package org.hibernate.metamodel.spi.binding.onetomany;
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.spi.binding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -34,11 +11,13 @@ import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import org.hibernate.metamodel.spi.binding.SimpleEntity;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@Entity @Entity
public class EntityWithUnidirectionalOneToManys { public class EntityWithUnidirectionalOneToMany {
private Long id; private Long id;
private String name; private String name;
private Collection<SimpleEntity> theBag = new ArrayList<SimpleEntity>(); private Collection<SimpleEntity> theBag = new ArrayList<SimpleEntity>();
@ -47,13 +26,6 @@ public class EntityWithUnidirectionalOneToManys {
private Map<String, SimpleEntity> theMap = new HashMap<String, SimpleEntity>(); private Map<String, SimpleEntity> theMap = new HashMap<String, SimpleEntity>();
private Collection<SimpleEntity> thePropertyRefBag = new ArrayList<SimpleEntity>(); private Collection<SimpleEntity> thePropertyRefBag = new ArrayList<SimpleEntity>();
public EntityWithUnidirectionalOneToManys() {
}
public EntityWithUnidirectionalOneToManys(String name) {
this.name = name;
}
@Id @Id
public Long getId() { public Long getId() {
return id; return id;
@ -116,3 +88,5 @@ public class EntityWithUnidirectionalOneToManys {
this.thePropertyRefBag = thePropertyRefSet; this.thePropertyRefBag = thePropertyRefSet;
} }
} }

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.metamodel.spi.binding; package org.hibernate.metamodel.spi.binding.onetomany;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -36,6 +37,13 @@ import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.internal.MetadataImpl; import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature;
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
import org.hibernate.metamodel.spi.binding.SimpleEntity;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.ForeignKey; import org.hibernate.metamodel.spi.relational.ForeignKey;
import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.metamodel.spi.relational.Identifier;
@ -64,7 +72,7 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
@Before @Before
public void setUp() { public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry(); serviceRegistry = ( StandardServiceRegistryImpl ) new ServiceRegistryBuilder().buildServiceRegistry();
} }
@After @After
@ -85,22 +93,25 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
private void doTest(MetadataSourceProcessingOrder processingOrder) { private void doTest(MetadataSourceProcessingOrder processingOrder) {
MetadataSources sources = new MetadataSources( serviceRegistry ); MetadataSources sources = new MetadataSources( serviceRegistry );
// sources.addAnnotatedClass( EntityWithBasicCollections.class ); // sources.addAnnotatedClass( EntityWithBasicCollections.class );
sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalOneToManys.hbm.xml" ); sources.addResource( "org/hibernate/metamodel/spi/binding/onetomany/EntityWithUnidirectionalOneToMany.hbm.xml" );
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" ); sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" );
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata(); MetadataImpl metadata = ( MetadataImpl ) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalOneToManys.class.getName() ); final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalOneToMany.class.getName() );
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() ); final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
assertNotNull( entityBinding ); assertNotNull( entityBinding );
assertEquals( Identifier.toIdentifier( "SimpleEntity" ), simpleEntityBinding.getPrimaryTable().getLogicalName() ); assertEquals(
Identifier.toIdentifier( "SimpleEntity" ),
simpleEntityBinding.getPrimaryTable().getLogicalName()
);
assertEquals( 1, simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() ); assertEquals( 1, simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() );
Column simpleEntityIdColumn = simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumns().get( 0 ); Column simpleEntityIdColumn = simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumns().get( 0 );
assertEquals( Identifier.toIdentifier("id") , simpleEntityIdColumn.getColumnName() ); assertEquals( Identifier.toIdentifier( "id" ), simpleEntityIdColumn.getColumnName() );
checkResult( checkResult(
entityBinding, entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theBag" ), metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theBag" ),
BagType.class, BagType.class,
Collection.class, Collection.class,
simpleEntityBinding, simpleEntityBinding,
@ -112,7 +123,7 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
checkResult( checkResult(
entityBinding, entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theSet" ), metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theSet" ),
SetType.class, SetType.class,
Set.class, Set.class,
simpleEntityBinding, simpleEntityBinding,
@ -124,7 +135,7 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
checkResult( checkResult(
entityBinding, entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theList" ), metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theList" ),
ListType.class, ListType.class,
List.class, List.class,
simpleEntityBinding, simpleEntityBinding,
@ -136,7 +147,7 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
checkResult( checkResult(
entityBinding, entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theMap" ), metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theMap" ),
MapType.class, MapType.class,
Map.class, Map.class,
simpleEntityBinding, simpleEntityBinding,
@ -148,11 +159,11 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
checkResult( checkResult(
entityBinding, entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".thePropertyRefBag" ), metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".thePropertyRefBag" ),
BagType.class, BagType.class,
Collection.class, Collection.class,
simpleEntityBinding, simpleEntityBinding,
(SingularAttributeBinding) entityBinding.locateAttributeBinding( "name" ), ( SingularAttributeBinding ) entityBinding.locateAttributeBinding( "name" ),
Identifier.toIdentifier( "ownerName" ), Identifier.toIdentifier( "ownerName" ),
FetchTiming.EXTRA_DELAYED, FetchTiming.EXTRA_DELAYED,
false false
@ -169,11 +180,14 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
Identifier expectedKeySourceColumnName, Identifier expectedKeySourceColumnName,
FetchTiming expectedFetchTiming, FetchTiming expectedFetchTiming,
boolean expectedNullableCollectionKey) { boolean expectedNullableCollectionKey) {
assertEquals( Assert.assertEquals(
PluralAttributeElementNature.ONE_TO_MANY, PluralAttributeElementNature.ONE_TO_MANY,
collectionBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() collectionBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature()
); );
assertSame( collectionBinding, collectionOwnerBinding.locateAttributeBinding( collectionBinding.getAttribute().getName() ) ); assertSame(
collectionBinding,
collectionOwnerBinding.locateAttributeBinding( collectionBinding.getAttribute().getName() )
);
assertEquals( expectedFetchTiming, collectionBinding.getFetchTiming() ); assertEquals( expectedFetchTiming, collectionBinding.getFetchTiming() );
assertEquals( expectedFetchTiming != FetchTiming.IMMEDIATE, collectionBinding.isLazy() ); assertEquals( expectedFetchTiming != FetchTiming.IMMEDIATE, collectionBinding.isLazy() );
@ -213,7 +227,7 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
assertEquals( 1, fk.getTargetColumns().size() ); assertEquals( 1, fk.getTargetColumns().size() );
SingularAttributeBinding keySourceAttributeBinding = SingularAttributeBinding keySourceAttributeBinding =
( SingularAttributeBinding) expectedElementEntityBinding.locateAttributeBinding( ( SingularAttributeBinding ) expectedElementEntityBinding.locateAttributeBinding(
"_" + role + "BackRef" "_" + role + "BackRef"
); );
assertEquals( expectedNullableCollectionKey, keyBinding.isNullable() ); assertEquals( expectedNullableCollectionKey, keyBinding.isNullable() );
@ -224,7 +238,7 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
assertEquals( 1, keySourceAttributeBinding.getRelationalValueBindings().size() ); assertEquals( 1, keySourceAttributeBinding.getRelationalValueBindings().size() );
Value keySourceValue = keySourceAttributeBinding.getRelationalValueBindings().get( 0 ).getValue(); Value keySourceValue = keySourceAttributeBinding.getRelationalValueBindings().get( 0 ).getValue();
assertTrue( keySourceValue instanceof Column ); assertTrue( keySourceValue instanceof Column );
Column keySourceColumn = (Column) keySourceValue; Column keySourceColumn = ( Column ) keySourceValue;
assertEquals( expectedKeySourceColumnName, keySourceColumn.getColumnName() ); assertEquals( expectedKeySourceColumnName, keySourceColumn.getColumnName() );
assertSame( keySourceColumn, fk.getColumns().get( 0 ) ); assertSame( keySourceColumn, fk.getColumns().get( 0 ) );
assertSame( keySourceColumn, fk.getSourceColumns().get( 0 ) ); assertSame( keySourceColumn, fk.getSourceColumns().get( 0 ) );

View File

@ -4,7 +4,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<class name="SimpleEntity"> <class name="SimpleEntity">
<id name="id"> <id name="id">
<generator class="increment"/> <generator class="increment"/>
</id> </id>

View File

@ -1,35 +1,35 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<hibernate-mapping package="org.hibernate.metamodel.spi.binding" <hibernate-mapping package="org.hibernate.metamodel.spi.binding.onetomany"
xmlns="http://www.hibernate.org/xsd/hibernate-mapping" xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd" xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<class name="EntityWithUnidirectionalOneToManys"> <class name="EntityWithUnidirectionalOneToMany">
<id name="id"> <id name="id">
<generator class="increment"/> <generator class="increment"/>
</id> </id>
<property name="name"/> <property name="name"/>
<bag name="theBag"> <bag name="theBag">
<key column="theBagOwner"/> <key column="theBagOwner"/>
<one-to-many class="SimpleEntity"/> <one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</bag> </bag>
<set name="theSet" lazy="false"> <set name="theSet" lazy="false">
<key column="theSetOwner" not-null="true"/> <key column="theSetOwner" not-null="true"/>
<one-to-many class="SimpleEntity"/> <one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</set> </set>
<list name="theList" lazy="false"> <list name="theList" lazy="false">
<key column="theListOwner" not-null="true"/> <key column="theListOwner" not-null="true"/>
<list-index column="list_index"/> <list-index column="list_index"/>
<one-to-many class="SimpleEntity"/> <one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</list> </list>
<map name="theMap"> <map name="theMap">
<key column="theMapOwner" not-null="true"/> <key column="theMapOwner" not-null="true"/>
<map-key column="map_key" type="string"/> <map-key column="map_key" type="string"/>
<one-to-many class="SimpleEntity"/> <one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</map> </map>
<bag name="thePropertyRefBag" lazy="extra"> <bag name="thePropertyRefBag" lazy="extra">
<key column="ownerName" property-ref="name" not-null="true"/> <key column="ownerName" property-ref="name" not-null="true"/>
<one-to-many class="SimpleEntity"/> <one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</bag> </bag>
</class> </class>