HHH-6107 - Metamodel dependence on ServiceRegistry

This commit is contained in:
Steve Ebersole 2011-04-11 18:10:47 -05:00
parent 9d93e1188e
commit 55ff0d2f07
4 changed files with 40 additions and 13 deletions

View File

@ -42,6 +42,7 @@ import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.relational.Database;
import org.hibernate.metamodel.source.annotations.AnnotationBinder;
import org.hibernate.metamodel.source.hbm.HibernateXmlBinder;
import org.hibernate.service.BasicServiceRegistry;
/**
* Container for configuration data while building and binding the metamodel
@ -49,15 +50,17 @@ import org.hibernate.metamodel.source.hbm.HibernateXmlBinder;
* @author Steve Ebersole
*/
public class Metadata implements Serializable {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class, Metadata.class.getName()
);
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, Metadata.class.getName() );
private final BasicServiceRegistry serviceRegistry;
private final AnnotationBinder annotationBinder;
private final HibernateXmlBinder hibernateXmlBinder;
private final Database database = new Database();
private final ExtendsQueue extendsQueue;
private final MetadataSourceQueue metadataSourceQueue;
private final Database database = new Database();
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
@ -65,11 +68,12 @@ public class Metadata implements Serializable {
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
private Map<String, String> imports;
public Metadata() {
annotationBinder = new AnnotationBinder( this );
hibernateXmlBinder = new HibernateXmlBinder( this );
extendsQueue = new ExtendsQueue( this );
metadataSourceQueue = new MetadataSourceQueue( this );
public Metadata(BasicServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
this.annotationBinder = new AnnotationBinder( this );
this.hibernateXmlBinder = new HibernateXmlBinder( this );
this.extendsQueue = new ExtendsQueue( this );
this.metadataSourceQueue = new MetadataSourceQueue( this );
}
public HibernateXmlBinder getHibernateXmlBinder() {

View File

@ -23,9 +23,16 @@
*/
package org.hibernate.metamodel.binding;
import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.metamodel.relational.Column;
import org.hibernate.service.BasicServiceRegistry;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.assertNotNull;
@ -40,6 +47,22 @@ import static org.junit.Assert.assertTrue;
*/
public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
private BasicServiceRegistryImpl serviceRegistry;
@Before
public void setUp() {
serviceRegistry = new BasicServiceRegistryImpl( Collections.emptyMap() );
}
@After
public void tearDown() {
serviceRegistry.destroy();
}
protected BasicServiceRegistry basicServiceRegistry() {
return serviceRegistry;
}
@Test
public void testSimpleEntityMapping() {
EntityBinding entityBinding = buildSimpleEntityBinding();

View File

@ -56,7 +56,7 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
public EntityBinding buildSimpleEntityBinding() {
Index index = indexForClass( SimpleEntity.class );
Metadata metadata = new Metadata();
Metadata metadata = new Metadata( basicServiceRegistry() );
metadata.getAnnotationBinder().bindMappedClasses( index );
return metadata.getEntityBinding( SimpleEntity.class.getSimpleName() );
@ -64,7 +64,7 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
public EntityBinding buildSimpleVersionedEntityBinding() {
Index index = indexForClass( SimpleEntity.class );
Metadata metadata = new Metadata();
Metadata metadata = new Metadata( basicServiceRegistry() );
metadata.getAnnotationBinder().bindMappedClasses( index );
return metadata.getEntityBinding( SimpleVersionedEntity.class.getSimpleName() );

View File

@ -49,7 +49,7 @@ public class BasicHbmBindingTests extends AbstractBasicBindingTests {
private static final Logger log = Logger.getLogger( BasicHbmBindingTests.class.getName() );
public EntityBinding buildSimpleEntityBinding() {
Metadata metadata = new Metadata();
Metadata metadata = new Metadata( basicServiceRegistry() );
XmlDocument xmlDocument = readResource( "/org/hibernate/metamodel/binding/SimpleEntity.hbm.xml" );
metadata.getHibernateXmlBinder().bindRoot( xmlDocument );
@ -57,7 +57,7 @@ public class BasicHbmBindingTests extends AbstractBasicBindingTests {
}
public EntityBinding buildSimpleVersionedEntityBinding() {
Metadata metadata = new Metadata();
Metadata metadata = new Metadata( basicServiceRegistry() );
String fileName = "/org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml";
XmlDocument xmlDocument = readResource( fileName );