HHH-2578 - redesign SessionFactory building
This commit is contained in:
parent
99cec1404f
commit
cfb4f1ded8
|
@ -22,15 +22,11 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.metamodel.source;
|
||||
package org.hibernate.metamodel;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Metadata {
|
||||
public static enum ProcessingOrder {
|
||||
ANNOTATIONS_FIRST,
|
||||
HBM_FIRST
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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;
|
||||
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface MetadataBuilder {
|
||||
public MetadataBuilder with(NamingStrategy namingStrategy);
|
||||
public MetadataBuilder with(SourceProcessingOrder sourceProcessingOrder);
|
||||
public Metadata buildMetadata();
|
||||
}
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source;
|
||||
package org.hibernate.metamodel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -43,9 +43,13 @@ import org.xml.sax.EntityResolver;
|
|||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.EJB3NamingStrategy;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.metamodel.source.MappingException;
|
||||
import org.hibernate.metamodel.source.MappingNotFoundException;
|
||||
import org.hibernate.metamodel.source.Origin;
|
||||
import org.hibernate.metamodel.source.SourceType;
|
||||
import org.hibernate.metamodel.source.internal.JaxbHelper;
|
||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.internal.MetadataBuilderImpl;
|
||||
import org.hibernate.service.BasicServiceRegistry;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
|
||||
|
@ -97,12 +101,12 @@ public class MetadataSources {
|
|||
return namingStrategy;
|
||||
}
|
||||
|
||||
public Metadata buildMetadata() {
|
||||
return buildMetadata( Metadata.ProcessingOrder.ANNOTATIONS_FIRST );
|
||||
public MetadataBuilder getMetadataBuilder() {
|
||||
return new MetadataBuilderImpl( this );
|
||||
}
|
||||
|
||||
public Metadata buildMetadata(Metadata.ProcessingOrder preferredProcessingOrder) {
|
||||
return new MetadataImpl( this, preferredProcessingOrder );
|
||||
public Metadata buildMetadata() {
|
||||
return getMetadataBuilder().buildMetadata();
|
||||
}
|
||||
|
||||
/**
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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;
|
||||
|
||||
/**
|
||||
* Enumeration of the possible orders for processing metadata sources. The implication is in terms of precedence;
|
||||
* for duplicate information in different sources, whichever is processed first has precedence.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum SourceProcessingOrder {
|
||||
ANNOTATIONS_FIRST,
|
||||
HBM_FIRST
|
||||
}
|
|
@ -50,8 +50,8 @@ import org.w3c.dom.Document;
|
|||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.MappingException;
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.metamodel.source.Origin;
|
||||
import org.hibernate.metamodel.source.XsdException;
|
||||
import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings;
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.source.internal;
|
||||
|
||||
import org.hibernate.cfg.EJB3NamingStrategy;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.metamodel.Metadata;
|
||||
import org.hibernate.metamodel.MetadataBuilder;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.SourceProcessingOrder;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class MetadataBuilderImpl implements MetadataBuilder {
|
||||
private final MetadataSources sources;
|
||||
|
||||
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
|
||||
private SourceProcessingOrder sourceProcessingOrder = SourceProcessingOrder.HBM_FIRST;
|
||||
|
||||
public MetadataBuilderImpl(MetadataSources sources) {
|
||||
this.sources = sources;
|
||||
}
|
||||
|
||||
public MetadataSources getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
public NamingStrategy getNamingStrategy() {
|
||||
return namingStrategy;
|
||||
}
|
||||
|
||||
public SourceProcessingOrder getSourceProcessingOrder() {
|
||||
return sourceProcessingOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder with(NamingStrategy namingStrategy) {
|
||||
this.namingStrategy = namingStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder with(SourceProcessingOrder sourceProcessingOrder) {
|
||||
this.sourceProcessingOrder = sourceProcessingOrder;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata buildMetadata() {
|
||||
return new MetadataImpl( this );
|
||||
}
|
||||
}
|
|
@ -40,13 +40,13 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.mapping.MetadataSource;
|
||||
import org.hibernate.metamodel.SourceProcessingOrder;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.EntityReferencingAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.FetchProfile;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.relational.Database;
|
||||
import org.hibernate.metamodel.source.Metadata;
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.metamodel.Metadata;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings;
|
||||
import org.hibernate.metamodel.source.annotations.AnnotationBinder;
|
||||
import org.hibernate.metamodel.source.annotations.xml.OrmXmlParser;
|
||||
|
@ -76,12 +76,14 @@ public class MetadataImpl implements Metadata, MetadataImplementor, Serializable
|
|||
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||
private Map<String, String> imports;
|
||||
|
||||
public MetadataImpl(MetadataSources metadataSources, ProcessingOrder preferredProcessingOrder) {
|
||||
public MetadataImpl(MetadataBuilderImpl builder) {
|
||||
final MetadataSources metadataSources = builder.getSources();
|
||||
|
||||
this.serviceRegistry = metadataSources.getServiceRegistry();
|
||||
this.namingStrategy = metadataSources.getNamingStrategy();
|
||||
this.namingStrategy = builder.getNamingStrategy();
|
||||
|
||||
final ArrayList<String> processedEntityNames = new ArrayList<String>();
|
||||
if ( preferredProcessingOrder == ProcessingOrder.HBM_FIRST ) {
|
||||
if ( builder.getSourceProcessingOrder() == SourceProcessingOrder.HBM_FIRST ) {
|
||||
applyHibernateMappings( metadataSources, processedEntityNames );
|
||||
applyAnnotationMappings( metadataSources, processedEntityNames );
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ package org.hibernate.metamodel.binding;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.metamodel.source.Metadata;
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
|
|
|
@ -23,14 +23,10 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
@ -39,8 +35,6 @@ import static org.junit.Assert.assertEquals;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicHbmBindingTests extends AbstractBasicBindingTests {
|
||||
private static final Logger log = Logger.getLogger( BasicHbmBindingTests.class.getName() );
|
||||
|
||||
public EntityBinding buildSimpleEntityBinding() {
|
||||
return getEntityBinding(
|
||||
"org/hibernate/metamodel/binding/SimpleEntity.hbm.xml",
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.FetchProfile;
|
||||
import org.hibernate.annotations.FetchProfiles;
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
|
|
|
@ -25,8 +25,8 @@ package org.hibernate.metamodel.source.annotations.xml;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.source.MappingException;
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
|
|
@ -28,8 +28,8 @@ import java.util.Iterator;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.binding.FetchProfile;
|
||||
import org.hibernate.metamodel.source.MetadataSources;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
|
|
Loading…
Reference in New Issue