HHH-12514 Avoid repeated creations of costly Xsd definitions and definition lookups
This commit is contained in:
parent
01ba7d9565
commit
1c14f1a1db
|
@ -38,7 +38,6 @@ public class MappingBinder extends AbstractBinder {
|
||||||
private static final Logger log = Logger.getLogger( MappingBinder.class );
|
private static final Logger log = Logger.getLogger( MappingBinder.class );
|
||||||
|
|
||||||
private final XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance();
|
private final XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance();
|
||||||
private final MappingXsdSupport xsdSupport = new MappingXsdSupport();
|
|
||||||
|
|
||||||
private JAXBContext hbmJaxbContext;
|
private JAXBContext hbmJaxbContext;
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ public class MappingBinder extends AbstractBinder {
|
||||||
log.debugf( "Performing JAXB binding of hbm.xml document : %s", origin.toString() );
|
log.debugf( "Performing JAXB binding of hbm.xml document : %s", origin.toString() );
|
||||||
|
|
||||||
XMLEventReader hbmReader = new HbmEventReader( staxEventReader, xmlEventFactory );
|
XMLEventReader hbmReader = new HbmEventReader( staxEventReader, xmlEventFactory );
|
||||||
JaxbHbmHibernateMapping hbmBindings = jaxb( hbmReader, xsdSupport.hbmXsd().getSchema(), hbmJaxbContext(), origin );
|
JaxbHbmHibernateMapping hbmBindings = jaxb( hbmReader, MappingXsdSupport.INSTANCE.hbmXsd().getSchema(), hbmJaxbContext(), origin );
|
||||||
return new Binding<>( hbmBindings, origin );
|
return new Binding<>( hbmBindings, origin );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -23,6 +23,10 @@ public class ConfigXsdSupport {
|
||||||
*/
|
*/
|
||||||
public static final ConfigXsdSupport INSTANCE = new ConfigXsdSupport();
|
public static final ConfigXsdSupport INSTANCE = new ConfigXsdSupport();
|
||||||
|
|
||||||
|
private ConfigXsdSupport() {
|
||||||
|
//Do not construct new instances
|
||||||
|
}
|
||||||
|
|
||||||
private final XsdDescriptor jpa10 = LocalXsdResolver.buildXsdDescriptor(
|
private final XsdDescriptor jpa10 = LocalXsdResolver.buildXsdDescriptor(
|
||||||
"org/hibernate/jpa/persistence_1_0.xsd",
|
"org/hibernate/jpa/persistence_1_0.xsd",
|
||||||
"1.0",
|
"1.0",
|
||||||
|
|
|
@ -50,6 +50,10 @@ public class MappingXsdSupport {
|
||||||
"http://www.hibernate.org/xsd/orm/hbm"
|
"http://www.hibernate.org/xsd/orm/hbm"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private MappingXsdSupport() {
|
||||||
|
//Do not construct new instances
|
||||||
|
}
|
||||||
|
|
||||||
public XsdDescriptor latestJpaDescriptor() {
|
public XsdDescriptor latestJpaDescriptor() {
|
||||||
return jpa22;
|
return jpa22;
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,6 @@ public class PersistenceXmlParser {
|
||||||
return parser.persistenceUnits;
|
return parser.persistenceUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ConfigXsdSupport xsdSupport = new ConfigXsdSupport();
|
|
||||||
private final ClassLoaderService classLoaderService;
|
private final ClassLoaderService classLoaderService;
|
||||||
private final PersistenceUnitTransactionType defaultTransactionType;
|
private final PersistenceUnitTransactionType defaultTransactionType;
|
||||||
private final Map<String, ParsedPersistenceXmlDescriptor> persistenceUnits;
|
private final Map<String, ParsedPersistenceXmlDescriptor> persistenceUnits;
|
||||||
|
@ -465,7 +464,7 @@ public class PersistenceXmlParser {
|
||||||
// todo : add ability to disable validation...
|
// todo : add ability to disable validation...
|
||||||
|
|
||||||
final String version = document.getDocumentElement().getAttribute( "version" );
|
final String version = document.getDocumentElement().getAttribute( "version" );
|
||||||
final Validator validator = xsdSupport.jpaXsd( version ).getSchema().newValidator();
|
final Validator validator = ConfigXsdSupport.INSTANCE.jpaXsd( version ).getSchema().newValidator();
|
||||||
|
|
||||||
List<SAXException> errors = new ArrayList<>();
|
List<SAXException> errors = new ArrayList<>();
|
||||||
validator.setErrorHandler( new ErrorHandlerImpl( errors ) );
|
validator.setErrorHandler( new ErrorHandlerImpl( errors ) );
|
||||||
|
|
Loading…
Reference in New Issue