HHH-6134 : merge with master
This commit is contained in:
parent
eb414295aa
commit
1dbb1237e3
|
@ -31,8 +31,8 @@ import org.jboss.jandex.Index;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.hibernate.mapping.FetchProfile;
|
|
||||||
import org.hibernate.mapping.MetadataSource;
|
import org.hibernate.mapping.MetadataSource;
|
||||||
|
import org.hibernate.metamodel.binding.FetchProfile;
|
||||||
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
|
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
|
|
||||||
|
|
|
@ -187,19 +187,6 @@ public class JaxbHelper {
|
||||||
return new JaxbRoot( target, origin );
|
return new JaxbRoot( target, origin );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object createTarget(Document document, Origin origin, Schema validationSchema, Class targetClass ) {
|
|
||||||
final Object target;
|
|
||||||
try {
|
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance( targetClass );
|
|
||||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
|
||||||
unmarshaller.setSchema( validationSchema );
|
|
||||||
return unmarshaller.unmarshal( new DOMSource( document ) );
|
|
||||||
}
|
|
||||||
catch (JAXBException e) {
|
|
||||||
throw new MappingException( "Unable to perform unmarshalling", e, origin );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Schema resolveSupportedOrmXsd(String explicitVersion) {
|
private Schema resolveSupportedOrmXsd(String explicitVersion) {
|
||||||
final String xsdVersionString = explicitVersion == null ? ASSUMED_ORM_XSD_VERSION : explicitVersion;
|
final String xsdVersionString = explicitVersion == null ? ASSUMED_ORM_XSD_VERSION : explicitVersion;
|
||||||
if ( "1.0".equals( xsdVersionString ) ) {
|
if ( "1.0".equals( xsdVersionString ) ) {
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.hibernate.InvalidMappingException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.cfg.MetadataSourceType;
|
import org.hibernate.cfg.MetadataSourceType;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.metamodel.source.hbm.HibernateMappingJaxbRoot;
|
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.HibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.HibernateMapping;
|
||||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||||
|
|
||||||
|
@ -91,11 +90,12 @@ public class MetadataSourceQueue implements Serializable {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void add(HibernateMappingJaxbRoot jaxbRoot) {
|
public void add(JaxbRoot jaxbRoot) {
|
||||||
final HibernateMapping hibernateMapping = jaxbRoot.getRoot();
|
// TODO: does this have to work for EntityMappings also?
|
||||||
|
final HibernateMapping hibernateMapping = ( HibernateMapping ) jaxbRoot.getRoot();
|
||||||
String defaultPackage = MappingHelper.getStringValue( hibernateMapping.getPackage(), "" );
|
String defaultPackage = MappingHelper.getStringValue( hibernateMapping.getPackage(), "" );
|
||||||
Set<String> entityNames = new HashSet<String>();
|
Set<String> entityNames = new HashSet<String>();
|
||||||
findClassNames( defaultPackage, jaxbRoot.getRoot().getClazzOrSubclassOrJoinedSubclass(), entityNames );
|
findClassNames( defaultPackage, hibernateMapping.getClazzOrSubclassOrJoinedSubclass(), entityNames );
|
||||||
for ( String entity : entityNames ) {
|
for ( String entity : entityNames ) {
|
||||||
hbmMetadataByEntityNameXRef.put( entity, jaxbRoot );
|
hbmMetadataByEntityNameXRef.put( entity, jaxbRoot );
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,13 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.binding;
|
package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import java.util.Collections;
|
||||||
import org.xml.sax.InputSource;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.internal.util.ConfigHelper;
|
import org.jboss.logging.Logger;
|
||||||
import org.hibernate.internal.util.xml.MappingReader;
|
|
||||||
import org.hibernate.internal.util.xml.Origin;
|
import org.hibernate.metamodel.source.MetadataSources;
|
||||||
import org.hibernate.internal.util.xml.XMLHelper;
|
|
||||||
import org.hibernate.internal.util.xml.XmlDocument;
|
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.HibernateMapping;
|
|
||||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
|
|
||||||
|
@ -50,33 +48,23 @@ public class BasicHbmBindingTests extends AbstractBasicBindingTests {
|
||||||
public EntityBinding buildSimpleEntityBinding() {
|
public EntityBinding buildSimpleEntityBinding() {
|
||||||
return getEntityBinding(
|
return getEntityBinding(
|
||||||
"org/hibernate/metamodel/binding/SimpleEntity.hbm.xml",
|
"org/hibernate/metamodel/binding/SimpleEntity.hbm.xml",
|
||||||
SimpleEntity.class
|
SimpleEntity.class.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityBinding buildSimpleVersionedEntityBinding() {
|
public EntityBinding buildSimpleVersionedEntityBinding() {
|
||||||
return getEntityBinding(
|
return getEntityBinding(
|
||||||
"org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml",
|
"org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml",
|
||||||
SimpleVersionedEntity.class
|
SimpleVersionedEntity.class.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private EntityBinding getEntityBinding(String resourceName, String entityName ) {
|
||||||
@SuppressWarnings({ "unchecked" })
|
MetadataSources metadataSources = new MetadataSources( basicServiceRegistry() );
|
||||||
public void testJaxbApproach() {
|
metadataSources.addResource( resourceName );
|
||||||
final String resourceName = "org/hibernate/metamodel/binding/SimpleVersionedEntity.xml";
|
MetadataImpl metadata = ( MetadataImpl ) metadataSources.buildMetadata();
|
||||||
metadata.addResource( resourceName );
|
assertEquals( 1, metadataSources.getJaxbRootList().size() );
|
||||||
assertEquals( 1, metadata.getJaxbRootList().size() );
|
metadata.getHibernateXmlBinder().bindRoot( metadataSources.getJaxbRootList().get( 0 ) );
|
||||||
JaxbRoot jaxbRoot = metadata.getJaxbRootList().get( 0 );
|
return metadata.getEntityBinding( entityName );
|
||||||
metadata.getHibernateXmlBinder().bindRoot( jaxbRoot );
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityBinding getEntityBinding(String resourceName, Class entityClass ) {
|
|
||||||
final MetadataImpl metadata = new MetadataImpl( basicServiceRegistry() );
|
|
||||||
metadata.addResource( resourceName );
|
|
||||||
assertEquals( 1, metadata.getJaxbRootList().size() );
|
|
||||||
JaxbRoot jaxbRoot = metadata.getJaxbRootList().get( 0 );
|
|
||||||
metadata.getHibernateXmlBinder().bindRoot( jaxbRoot );
|
|
||||||
return metadata.getEntityBinding( entityClass.getName() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
FetchProfileBinder.bindFetchProfiles( meta, index );
|
FetchProfileBinder.bindFetchProfiles( meta, index );
|
||||||
|
|
||||||
Iterator<org.hibernate.mapping.FetchProfile> mappedFetchProfiles = meta.getFetchProfiles().iterator();
|
Iterator<org.hibernate.metamodel.binding.FetchProfile> mappedFetchProfiles = meta.getFetchProfiles().iterator();
|
||||||
assertTrue( mappedFetchProfiles.hasNext() );
|
assertTrue( mappedFetchProfiles.hasNext() );
|
||||||
org.hibernate.mapping.FetchProfile profile = mappedFetchProfiles.next();
|
org.hibernate.metamodel.binding.FetchProfile profile = mappedFetchProfiles.next();
|
||||||
assertEquals( "Wrong fetch profile name", "foo", profile.getName() );
|
assertEquals( "Wrong fetch profile name", "foo", profile.getName() );
|
||||||
org.hibernate.mapping.FetchProfile.Fetch fetch = profile.getFetches().iterator().next();
|
org.hibernate.metamodel.binding.FetchProfile.Fetch fetch = profile.getFetches().iterator().next();
|
||||||
assertEquals( "Wrong association name", "bar", fetch.getAssociation() );
|
assertEquals( "Wrong association name", "bar", fetch.getAssociation() );
|
||||||
assertEquals( "Wrong association type", Foo.class.getName(), fetch.getEntity() );
|
assertEquals( "Wrong association type", Foo.class.getName(), fetch.getEntity() );
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,9 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
|
||||||
Index index = JandexHelper.indexForClass( service, FooBar.class );
|
Index index = JandexHelper.indexForClass( service, FooBar.class );
|
||||||
FetchProfileBinder.bindFetchProfiles( meta, index );
|
FetchProfileBinder.bindFetchProfiles( meta, index );
|
||||||
|
|
||||||
Iterator<org.hibernate.mapping.FetchProfile> mappedFetchProfiles = meta.getFetchProfiles().iterator();
|
Iterator<org.hibernate.metamodel.binding.FetchProfile> mappedFetchProfiles = meta.getFetchProfiles().iterator();
|
||||||
assertTrue( mappedFetchProfiles.hasNext() );
|
assertTrue( mappedFetchProfiles.hasNext() );
|
||||||
org.hibernate.mapping.FetchProfile profile = mappedFetchProfiles.next();
|
org.hibernate.metamodel.binding.FetchProfile profile = mappedFetchProfiles.next();
|
||||||
assertProfiles( profile );
|
assertProfiles( profile );
|
||||||
|
|
||||||
assertTrue( mappedFetchProfiles.hasNext() );
|
assertTrue( mappedFetchProfiles.hasNext() );
|
||||||
|
@ -79,14 +79,14 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
|
||||||
assertProfiles( profile );
|
assertProfiles( profile );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertProfiles(org.hibernate.mapping.FetchProfile profile) {
|
private void assertProfiles(org.hibernate.metamodel.binding.FetchProfile profile) {
|
||||||
if ( profile.getName().equals( "foobar" ) ) {
|
if ( profile.getName().equals( "foobar" ) ) {
|
||||||
org.hibernate.mapping.FetchProfile.Fetch fetch = profile.getFetches().iterator().next();
|
org.hibernate.metamodel.binding.FetchProfile.Fetch fetch = profile.getFetches().iterator().next();
|
||||||
assertEquals( "Wrong association name", "foobar", fetch.getAssociation() );
|
assertEquals( "Wrong association name", "foobar", fetch.getAssociation() );
|
||||||
assertEquals( "Wrong association type", FooBar.class.getName(), fetch.getEntity() );
|
assertEquals( "Wrong association type", FooBar.class.getName(), fetch.getEntity() );
|
||||||
}
|
}
|
||||||
else if ( profile.getName().equals( "fubar" ) ) {
|
else if ( profile.getName().equals( "fubar" ) ) {
|
||||||
org.hibernate.mapping.FetchProfile.Fetch fetch = profile.getFetches().iterator().next();
|
org.hibernate.metamodel.binding.FetchProfile.Fetch fetch = profile.getFetches().iterator().next();
|
||||||
assertEquals( "Wrong association name", "fubar", fetch.getAssociation() );
|
assertEquals( "Wrong association name", "fubar", fetch.getAssociation() );
|
||||||
assertEquals( "Wrong association type", FooBar.class.getName(), fetch.getEntity() );
|
assertEquals( "Wrong association type", FooBar.class.getName(), fetch.getEntity() );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue