Author: steve.ebersole(a)jboss.com
Date: 2010-09-08 23:34:41 -0400 (Wed, 08 Sep 2010)
New Revision: 20324
Modified:
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
Log:
HHH-5543 - JEE bootstrapping should only parse and validate mapping files once
Modified:
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
---
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-09-09
02:53:03 UTC (rev 20323)
+++
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-09-09
03:34:41 UTC (rev 20324)
@@ -757,7 +757,7 @@
}
@Override
- protected void add(org.dom4j.Document doc) throws MappingException {
+ public void add(org.dom4j.Document doc) throws MappingException {
boolean ejb3Xml = "entity-mappings".equals( doc.getRootElement().getName()
);
if ( inSecondPass ) {
//if in second pass bypass the queueing, getExtendedQueue reuse this method
Modified:
core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
---
core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2010-09-09
02:53:03 UTC (rev 20323)
+++
core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2010-09-09
03:34:41 UTC (rev 20324)
@@ -58,20 +58,16 @@
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
-import org.dom4j.DocumentException;
import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
import org.hibernate.MappingNotFoundException;
-import org.hibernate.ObjectNotFoundException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
@@ -102,7 +98,6 @@
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
-import org.hibernate.util.XMLHelper;
import org.hibernate.util.xml.MappingReader;
import org.hibernate.util.xml.OriginImpl;
import org.hibernate.util.xml.XmlDocument;
@@ -125,13 +120,13 @@
* @author Emmanuel Bernard
*/
public class Ejb3Configuration implements Serializable, Referenceable {
+ private final Logger log = LoggerFactory.getLogger( Ejb3Configuration.class );
private static final String IMPLEMENTATION_NAME = HibernatePersistence.class.getName();
private static final String META_INF_ORM_XML = "META-INF/orm.xml";
- private final Logger log = LoggerFactory.getLogger( Ejb3Configuration.class );
+ private static final String PARSED_MAPPING_DOMS =
"hibernate.internal.mapping_doms";
+
private static EntityNotFoundDelegate ejb3EntityNotFoundDelegate = new
Ejb3EntityNotFoundDelegate();
private static Configuration DEFAULT_CONFIGURATION = new AnnotationConfiguration();
- private String persistenceUnitName;
- private String cfgXmlResource;
private static class Ejb3EntityNotFoundDelegate implements EntityNotFoundDelegate,
Serializable {
public void handleEntityNotFound(String entityName, Serializable id) {
@@ -146,6 +141,9 @@
Version.touch();
}
+ private String persistenceUnitName;
+ private String cfgXmlResource;
+
private AnnotationConfiguration cfg;
private SettingsFactory settingsFactory;
//made transient and not restored in deserialization on purpose, should no longer be
called after restoration
@@ -568,6 +566,7 @@
List<NamedInputStream> hbmFiles = new ArrayList<NamedInputStream>();
List<String> packages = new ArrayList<String>();
List<String> xmlFiles = new ArrayList<String>( 50 );
+ List<XmlDocument> xmlDocuments = new ArrayList<XmlDocument>( 50 );
if ( info.getMappingFileNames() != null ) {
xmlFiles.addAll( info.getMappingFileNames() );
}
@@ -598,7 +597,7 @@
//FIXME entities is used to enhance classes and to collect annotated entities this
should not be mixed
//fill up entities with the on found in xml files
- addXMLEntities( xmlFiles, info, entities );
+ addXMLEntities( xmlFiles, info, entities, xmlDocuments );
//FIXME send the appropriate entites.
if ( "true".equalsIgnoreCase( properties.getProperty(
AvailableSettings.USE_CLASS_ENHANCER ) ) ) {
@@ -608,8 +607,12 @@
workingVars.put( AvailableSettings.CLASS_NAMES, entities );
workingVars.put( AvailableSettings.PACKAGE_NAMES, packages );
workingVars.put( AvailableSettings.XML_FILE_NAMES, xmlFiles );
- if ( hbmFiles.size() > 0 ) workingVars.put( AvailableSettings.HBXML_FILES, hbmFiles
);
+ workingVars.put( PARSED_MAPPING_DOMS, xmlDocuments );
+ if ( hbmFiles.size() > 0 ) {
+ workingVars.put( AvailableSettings.HBXML_FILES, hbmFiles );
+ }
+
// validation factory
final Object validationFactory = integration.get( AvailableSettings.VALIDATION_FACTORY
);
if ( validationFactory != null ) {
@@ -693,7 +696,23 @@
return this;
}
- private void addXMLEntities(List<String> xmlFiles, PersistenceUnitInfo info,
List<String> entities) {
+ /**
+ * Processes {@code xmlFiles} argument and populates:<ul>
+ * <li>the {@code entities} list with encountered classnames</li>
+ * <li>the {@code xmlDocuments} list with parsed/validated {@link XmlDocument}
corrolary to each xml file</li>
+ * </ul>
+ *
+ * @param xmlFiles The XML resource names; these will be resolved by classpath lookup
and parsed/validated.
+ * @param info The PUI
+ * @param entities (output) The names of all encountered "mapped" classes
+ * @param xmlDocuments (output) The list of {@link XmlDocument} instances of each entry
in {@code xmlFiles}
+ */
+ @SuppressWarnings({ "unchecked" })
+ private void addXMLEntities(
+ List<String> xmlFiles,
+ PersistenceUnitInfo info,
+ List<String> entities,
+ List<XmlDocument> xmlDocuments) {
//TODO handle inputstream related hbm files
ClassLoader classLoaderToUse = info.getNewTempClassLoader();
if ( classLoaderToUse == null ) {
@@ -714,6 +733,7 @@
inputSource,
new OriginImpl( "persistence-unit-info", xmlFile )
);
+ xmlDocuments.add( xmlDocument );
Element rootElement = xmlDocument.getDocumentTree().getRootElement();
if ( rootElement != null && "entity-mappings".equals(
rootElement.getName() ) ) {
Element element = rootElement.element( "package" );
@@ -753,6 +773,7 @@
}
}
}
+ xmlFiles.clear();
}
private void defineTransactionType(Object overridenTxType, Map workingVars) {
@@ -1084,6 +1105,7 @@
return this;
}
+ @SuppressWarnings({ "unchecked" })
private void addClassesToSessionFactory(Map workingVars) {
if ( workingVars.containsKey( AvailableSettings.CLASS_NAMES ) ) {
Collection<String> classNames = (Collection<String>) workingVars.get(
@@ -1091,6 +1113,14 @@
);
addNamedAnnotatedClasses( this, classNames, workingVars );
}
+
+ if ( workingVars.containsKey( PARSED_MAPPING_DOMS ) ) {
+ Collection<XmlDocument> xmlDocuments = (Collection<XmlDocument>)
workingVars.get( PARSED_MAPPING_DOMS );
+ for ( XmlDocument xmlDocument : xmlDocuments ) {
+ cfg.add( xmlDocument.getDocumentTree() );
+ }
+ }
+
//TODO apparently only used for Tests, get rid of it?
if ( workingVars.containsKey( AvailableSettings.LOADED_CLASSES ) ) {
Collection<Class> classes = (Collection<Class>) workingVars.get(
AvailableSettings.LOADED_CLASSES );