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.annotations.FetchMode;
|
||||
import org.hibernate.mapping.FetchProfile;
|
||||
import org.hibernate.mapping.MetadataSource;
|
||||
import org.hibernate.metamodel.binding.FetchProfile;
|
||||
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
|
||||
|
|
|
@ -187,19 +187,6 @@ public class JaxbHelper {
|
|||
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) {
|
||||
final String xsdVersionString = explicitVersion == null ? ASSUMED_ORM_XSD_VERSION : explicitVersion;
|
||||
if ( "1.0".equals( xsdVersionString ) ) {
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.hibernate.InvalidMappingException;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cfg.MetadataSourceType;
|
||||
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.util.MappingHelper;
|
||||
|
||||
|
@ -91,11 +90,12 @@ public class MetadataSourceQueue implements Serializable {
|
|||
}
|
||||
*/
|
||||
|
||||
public void add(HibernateMappingJaxbRoot jaxbRoot) {
|
||||
final HibernateMapping hibernateMapping = jaxbRoot.getRoot();
|
||||
public void add(JaxbRoot jaxbRoot) {
|
||||
// TODO: does this have to work for EntityMappings also?
|
||||
final HibernateMapping hibernateMapping = ( HibernateMapping ) jaxbRoot.getRoot();
|
||||
String defaultPackage = MappingHelper.getStringValue( hibernateMapping.getPackage(), "" );
|
||||
Set<String> entityNames = new HashSet<String>();
|
||||
findClassNames( defaultPackage, jaxbRoot.getRoot().getClazzOrSubclassOrJoinedSubclass(), entityNames );
|
||||
findClassNames( defaultPackage, hibernateMapping.getClazzOrSubclassOrJoinedSubclass(), entityNames );
|
||||
for ( String entity : entityNames ) {
|
||||
hbmMetadataByEntityNameXRef.put( entity, jaxbRoot );
|
||||
}
|
||||
|
|
|
@ -23,15 +23,13 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.xml.sax.InputSource;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.internal.util.ConfigHelper;
|
||||
import org.hibernate.internal.util.xml.MappingReader;
|
||||
import org.hibernate.internal.util.xml.Origin;
|
||||
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.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
|
||||
|
@ -50,33 +48,23 @@ public class BasicHbmBindingTests extends AbstractBasicBindingTests {
|
|||
public EntityBinding buildSimpleEntityBinding() {
|
||||
return getEntityBinding(
|
||||
"org/hibernate/metamodel/binding/SimpleEntity.hbm.xml",
|
||||
SimpleEntity.class
|
||||
SimpleEntity.class.getName()
|
||||
);
|
||||
}
|
||||
|
||||
public EntityBinding buildSimpleVersionedEntityBinding() {
|
||||
return getEntityBinding(
|
||||
"org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml",
|
||||
SimpleVersionedEntity.class
|
||||
SimpleVersionedEntity.class.getName()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testJaxbApproach() {
|
||||
final String resourceName = "org/hibernate/metamodel/binding/SimpleVersionedEntity.xml";
|
||||
metadata.addResource( resourceName );
|
||||
assertEquals( 1, metadata.getJaxbRootList().size() );
|
||||
JaxbRoot jaxbRoot = metadata.getJaxbRootList().get( 0 );
|
||||
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() );
|
||||
private EntityBinding getEntityBinding(String resourceName, String entityName ) {
|
||||
MetadataSources metadataSources = new MetadataSources( basicServiceRegistry() );
|
||||
metadataSources.addResource( resourceName );
|
||||
MetadataImpl metadata = ( MetadataImpl ) metadataSources.buildMetadata();
|
||||
assertEquals( 1, metadataSources.getJaxbRootList().size() );
|
||||
metadata.getHibernateXmlBinder().bindRoot( metadataSources.getJaxbRootList().get( 0 ) );
|
||||
return metadata.getEntityBinding( entityName );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
|
|||
|
||||
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() );
|
||||
org.hibernate.mapping.FetchProfile profile = mappedFetchProfiles.next();
|
||||
org.hibernate.metamodel.binding.FetchProfile profile = mappedFetchProfiles.next();
|
||||
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 type", Foo.class.getName(), fetch.getEntity() );
|
||||
}
|
||||
|
@ -69,9 +69,9 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
|
|||
Index index = JandexHelper.indexForClass( service, FooBar.class );
|
||||
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() );
|
||||
org.hibernate.mapping.FetchProfile profile = mappedFetchProfiles.next();
|
||||
org.hibernate.metamodel.binding.FetchProfile profile = mappedFetchProfiles.next();
|
||||
assertProfiles( profile );
|
||||
|
||||
assertTrue( mappedFetchProfiles.hasNext() );
|
||||
|
@ -79,14 +79,14 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
|
|||
assertProfiles( profile );
|
||||
}
|
||||
|
||||
private void assertProfiles(org.hibernate.mapping.FetchProfile profile) {
|
||||
private void assertProfiles(org.hibernate.metamodel.binding.FetchProfile profile) {
|
||||
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 type", FooBar.class.getName(), fetch.getEntity() );
|
||||
}
|
||||
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 type", FooBar.class.getName(), fetch.getEntity() );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue