Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into wip/6.0_merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Apr 16, 2021
2 parents df9d285 + 2aa2bee commit badc997
Show file tree
Hide file tree
Showing 99 changed files with 11,425 additions and 275 deletions.
Expand Up @@ -51,12 +51,11 @@ public void testLifecycle() {
}

@Override
protected Configuration constructAndConfigureConfiguration() {
Configuration configuration = super.constructAndConfigureConfiguration();
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> {
typeContributions.contributeType( new CommaDelimitedStringsType() );
} );
return configuration;
}

//tag::collections-comma-delimited-collection-example[]
Expand Down
Expand Up @@ -32,14 +32,13 @@ protected Class<?>[] getAnnotatedClasses() {
}

@Override
protected Configuration constructAndConfigureConfiguration() {
Configuration configuration = super.constructAndConfigureConfiguration();
protected void configure(Configuration configuration) {
super.configure( configuration );
//tag::basic-custom-type-register-BasicType-example[]
configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> {
typeContributions.contributeType( BitSetType.INSTANCE );
} );
//end::basic-custom-type-register-BasicType-example[]
return configuration;
}

@Test
Expand Down
Expand Up @@ -36,14 +36,13 @@ protected Class<?>[] getAnnotatedClasses() {
}

@Override
protected Configuration constructAndConfigureConfiguration() {
Configuration configuration = super.constructAndConfigureConfiguration();
protected void configure(Configuration configuration) {
super.configure( configuration );
//tag::basic-custom-type-register-UserType-example[]
configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> {
typeContributions.contributeType( BitSetUserType.INSTANCE, "bitset");
} );
//end::basic-custom-type-register-UserType-example[]
return configuration;
}

@Test
Expand Down
5 changes: 5 additions & 0 deletions hibernate-core/hibernate-core.gradle
Expand Up @@ -202,6 +202,11 @@ xjc {
xjcBinding = file( 'src/main/xjb/hbm-mapping-bindings.xjb' )
xjcExtensions = ['inheritance', 'simplify']
}
mapping {
xsd = file( 'src/main/resources/org/hibernate/jpa/orm_2_2.xsd' )
xjcBinding = file( 'src/main/xjb/mapping-bindings.xjb' )
xjcExtensions = ['inheritance']
}
}
}

Expand Down
Expand Up @@ -388,6 +388,18 @@ public MetadataSources addFile(File file) {
return this;
}

/**
* Add XML mapping bindings created from an arbitrary source by the {@link #getXmlMappingBinderAccess() binder}.
*
* @param binding The binding.
*
* @return this (for method chaining purposes)
*/
public MetadataSources addXmlBinding(Binding<?> binding) {
getXmlBindingsForWrite().add( binding );
return this;
}

/**
* See {@link #addCacheableFile(java.io.File)} for description
*
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
import org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenMetadataProvider;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.jpa.internal.MutableJpaComplianceImpl;
import org.hibernate.jpa.spi.MutableJpaCompliance;
Expand Down Expand Up @@ -319,7 +320,13 @@ public void addCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition

private JavaReflectionManager generateHcannReflectionManager() {
final JavaReflectionManager reflectionManager = new JavaReflectionManager();
reflectionManager.setMetadataProvider( new JPAMetadataProvider( this ) );
if ( metadataBuildingOptions.getXmlMappingOptions().isPreferJaxb() ) {
reflectionManager.setMetadataProvider( new JPAXMLOverriddenMetadataProvider( this ) );
}
else {
// Legacy implementation based on DOM4J, for backwards compatibility.
reflectionManager.setMetadataProvider( new JPAMetadataProvider( this ) );
}
return reflectionManager;
}

Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
import org.hibernate.boot.cfgxml.spi.MappingReference;
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.TypeContributor;
Expand Down Expand Up @@ -554,7 +555,7 @@ public static class MetadataBuildingOptionsImpl
private IdGeneratorInterpreterImpl idGenerationTypeInterpreter = new IdGeneratorInterpreterImpl();

private String schemaCharset;
private boolean xmlMappingEnabled;
private final XmlMappingOptions xmlMappingOptions;

public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
Expand All @@ -566,11 +567,7 @@ public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {

this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() );

this.xmlMappingEnabled = configService.getSetting(
AvailableSettings.XML_MAPPING_ENABLED,
StandardConverters.BOOLEAN,
true
);
xmlMappingOptions = XmlMappingOptions.get( serviceRegistry );

this.implicitDiscriminatorsForJoinedInheritanceSupported = configService.getSetting(
AvailableSettings.IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS,
Expand Down Expand Up @@ -843,8 +840,8 @@ public String getSchemaCharset() {
}

@Override
public boolean isXmlMappingEnabled() {
return xmlMappingEnabled;
public XmlMappingOptions getXmlMappingOptions() {
return xmlMappingOptions;
}

/**
Expand Down
@@ -0,0 +1,12 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.boot.jaxb.internal;

import org.hibernate.boot.jaxb.spi.XmlMappingOptions;

public class DefaultXmlMappingOptions implements XmlMappingOptions {
}
Expand Up @@ -20,7 +20,9 @@
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
import org.hibernate.boot.jaxb.internal.stax.HbmEventReader;
import org.hibernate.boot.jaxb.internal.stax.JpaOrmXmlEventReader;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
import org.hibernate.boot.jaxb.spi.Binding;
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.xsd.MappingXsdSupport;
import org.hibernate.internal.util.config.ConfigurationException;
Expand All @@ -39,15 +41,14 @@ public class MappingBinder extends AbstractBinder {

private final XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance();

private JAXBContext hbmJaxbContext;
private final XmlMappingOptions options;

@SuppressWarnings("unused")
public MappingBinder(ClassLoaderService classLoaderService) {
this( classLoaderService, true );
}
private JAXBContext hbmJaxbContext;
private JAXBContext entityMappingsJaxbContext;

public MappingBinder(ClassLoaderService classLoaderService, boolean validateXml) {
public MappingBinder(ClassLoaderService classLoaderService, boolean validateXml, XmlMappingOptions options) {
super( classLoaderService, validateXml );
this.options = options;
}

@Override
Expand All @@ -66,12 +67,20 @@ protected Binding<?> doBind(
return new Binding<>( hbmBindings, origin );
}
else {
// final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader );
// return jaxb( reader, LocalSchema.MAPPING.getSchema(), JaxbEntityMappings.class, origin );

try {
final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory );
return new Binding<>( toDom4jDocument( reader, origin ), origin );
if ( options.isPreferJaxb() ) {
log.debugf( "Performing JAXB binding of orm.xml document : %s", origin.toString() );

XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory );
JaxbEntityMappings bindingRoot = jaxb( reader, MappingXsdSupport.INSTANCE.latestJpaDescriptor().getSchema(), entityMappingsJaxbContext(), origin );
return new Binding<>( bindingRoot, origin );
}
else {
log.debugf( "Performing DOM4J binding of orm.xml document : %s", origin.toString() );

final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory );
return new Binding<>( toDom4jDocument( reader, origin ), origin );
}
}
catch (JpaOrmXmlEventReader.BadVersionException e) {
throw new UnsupportedOrmXsdVersionException( e.getRequestedVersion(), origin );
Expand All @@ -91,6 +100,18 @@ private JAXBContext hbmJaxbContext() {
return hbmJaxbContext;
}

private JAXBContext entityMappingsJaxbContext() {
if ( entityMappingsJaxbContext == null ) {
try {
entityMappingsJaxbContext = JAXBContext.newInstance( JaxbEntityMappings.class );
}
catch ( JAXBException e ) {
throw new ConfigurationException( "Unable to build orm.xml JAXBContext", e );
}
}
return entityMappingsJaxbContext;
}

private Document toDom4jDocument(XMLEventReader jpaOrmXmlEventReader, Origin origin) {
// todo : do we need to build a DocumentFactory instance for use here?
// historically we did that to set TCCL since, iirc, dom4j uses TCCL
Expand Down
@@ -0,0 +1,24 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.boot.jaxb.mapping.internal;

import javax.persistence.AccessType;

/**
* Marshalling support for dealing with JPA AccessType enums. Plugged into JAXB for binding
*
* @author Steve Ebersole
*/
public class AccessTypeMarshalling {
public static AccessType fromXml(String name) {
return AccessType.valueOf( name );
}

public static String toXml(AccessType accessType) {
return accessType.name();
}
}
@@ -0,0 +1,24 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.boot.jaxb.mapping.internal;

import javax.persistence.ConstraintMode;

/**
* Marshalling support for dealing with JPA ConstraintMode enums. Plugged into JAXB for binding
*
* @author Steve Ebersole
*/
public class ConstraintModeMarshalling {
public static ConstraintMode fromXml(String name) {
return ConstraintMode.valueOf( name );
}

public static String toXml(ConstraintMode accessType) {
return accessType.name();
}
}
@@ -0,0 +1,24 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.boot.jaxb.mapping.internal;

import javax.persistence.DiscriminatorType;

/**
* Marshalling support for dealing with JPA DiscriminatorType enums. Plugged into JAXB for binding
*
* @author Steve Ebersole
*/
public class DiscriminatorTypeMarshalling {
public static DiscriminatorType fromXml(String name) {
return DiscriminatorType.valueOf( name );
}

public static String toXml(DiscriminatorType discriminatorType) {
return discriminatorType.name();
}
}
@@ -0,0 +1,24 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.boot.jaxb.mapping.internal;

import javax.persistence.EnumType;

/**
* Marshalling support for dealing with JPA EnumType enums. Plugged into JAXB for binding
*
* @author Steve Ebersole
*/
public class EnumTypeMarshalling {
public static EnumType fromXml(String name) {
return EnumType.valueOf( name );
}

public static String toXml(EnumType enumType) {
return enumType.name();
}
}
@@ -0,0 +1,24 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.boot.jaxb.mapping.internal;

import javax.persistence.FetchType;

/**
* Marshalling support for dealing with JPA FetchType enums. Plugged into JAXB for binding
*
* @author Steve Ebersole
*/
public class FetchTypeMarshalling {
public static FetchType fromXml(String name) {
return FetchType.valueOf( name );
}

public static String toXml(FetchType fetchType) {
return fetchType.name();
}
}
@@ -0,0 +1,24 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.boot.jaxb.mapping.internal;

import javax.persistence.GenerationType;

/**
* Marshalling support for dealing with JPA GenerationType enums. Plugged into JAXB for binding
*
* @author Steve Ebersole
*/
public class GenerationTypeMarshalling {
public static GenerationType fromXml(String name) {
return GenerationType.valueOf( name );
}

public static String toXml(GenerationType accessType) {
return accessType.name();
}
}

0 comments on commit badc997

Please sign in to comment.