Skip to content

Commit

Permalink
HHH-17377 - Migrate to JPA 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Nov 17, 2023
1 parent 0cfd3c1 commit 71bd6b0
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 319 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.cfg.internal;

import org.hibernate.internal.util.StringHelper;

import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.spi.PersistenceUnitTransactionType;

/**
* @author Steve Ebersole
*/
public class SharedCacheModeMarshalling {
public static SharedCacheMode fromXml(String name) {
if ( StringHelper.isEmpty( name ) ) {
return SharedCacheMode.UNSPECIFIED;
}
return SharedCacheMode.valueOf( name );
}

public static String toXml(SharedCacheMode sharedCacheMode) {
if ( sharedCacheMode == null ) {
return null;
}
return sharedCacheMode.name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.cfg.internal;

import org.hibernate.internal.util.StringHelper;

import jakarta.persistence.AccessType;
import jakarta.persistence.spi.PersistenceUnitTransactionType;

/**
* @author Steve Ebersole
*/
public class TransactionTypeMarshalling {
public static PersistenceUnitTransactionType fromXml(String name) {
if ( StringHelper.isEmpty( name ) ) {
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
return PersistenceUnitTransactionType.valueOf( name );
}

public static String toXml(PersistenceUnitTransactionType transactionType) {
if ( transactionType == null ) {
return null;
}
return transactionType.name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.cfg.internal;

import org.hibernate.internal.util.StringHelper;

import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;

/**
* @author Steve Ebersole
*/
public class ValidationModeMarshalling {
public static ValidationMode fromXml(String name) {
if ( StringHelper.isEmpty( name ) ) {
return ValidationMode.AUTO;
}
return ValidationMode.valueOf( name );
}

public static String toXml(ValidationMode validationMode) {
if ( validationMode == null ) {
return null;
}
return validationMode.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ private Iterator<Namespace> existingXmlNamespacesIterator(StartElement startElem
}

private Namespace mapNamespace(Namespace originalNamespace) {
if ( XsdHelper.shouldBeMappedToLatestJpaDescriptor( originalNamespace.getNamespaceURI() ) ) {
if ( shouldBeMappedToLatestJpaDescriptor( originalNamespace.getNamespaceURI() ) ) {
// this is a namespace "to map" so map it
return xmlEventFactory.createNamespace( originalNamespace.getPrefix(), xsdDescriptor.getNamespaceUri() );
}

return originalNamespace;
}

protected abstract boolean shouldBeMappedToLatestJpaDescriptor(String uri);

private XMLEvent wrap(EndElement endElement) {
final List<Namespace> targetNamespaces = mapNamespaces( existingXmlNamespacesIterator( endElement ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ public class ConfigurationEventReader extends AbstractEventReader {
public ConfigurationEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory) {
super(
ROOT_ELEMENT_NAME,
ConfigXsdSupport.getJPA32(),
ConfigXsdSupport.configurationXsd(),
reader,
xmlEventFactory
);
}

@Override
protected boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
return !ConfigXsdSupport.configurationXsd().getNamespaceUri().equals( uri );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public MappingEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory
super( ROOT_ELEMENT_NAME, MappingXsdSupport.latestDescriptor(), reader, xmlEventFactory );
}

@Override
protected boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
return !MappingXsdSupport.latestDescriptor().getNamespaceUri().equals( uri );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ public XsdDescriptor latestJpaDescriptor() {
}

public static boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
// JPA 1.0 and 2.0 share the same namespace URI
return getJPA10().getNamespaceUri().matches( uri );
// Any namespace prior to move to Jakarta (3.0) needs to be remapped
// NOTE:
// - JPA 1.0 and 2.0 share the same namespace URI
// - JPA 2.1 and 2.2 share the same namespace URI
return !configurationXsd().getNamespaceUri().equals( uri );

}

public XsdDescriptor jpaXsd(String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static boolean isValidJpaVersion(String version) {

public static boolean shouldBeMappedToLatestJpaDescriptor(String uri) {
// JPA 1.0 and 2.0 share the same namespace URI
// JPA 2.1 and 2.2 share the same namespace URI
return MappingXsdSupport.jpa10.getNamespaceUri().equals( uri );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;
import jakarta.persistence.spi.PersistenceUnitTransactionType;

import org.hibernate.boot.archive.internal.ArchiveHelper;
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
import org.hibernate.bytecode.spi.ClassTransformer;

import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;
import jakarta.persistence.spi.PersistenceUnitTransactionType;

/**
* Describes the information gleaned from a {@code <persistence-unit/>} element in a {@code persistence.xml} file
* whether parsed directly by Hibernate or passed to us by an EE container as a
Expand Down Expand Up @@ -130,17 +130,25 @@ public ValidationMode getValidationMode() {
return validationMode;
}

public void setValidationMode(ValidationMode validationMode) {
this.validationMode = validationMode;
}

public void setValidationMode(String validationMode) {
this.validationMode = ValidationMode.valueOf( validationMode );
setValidationMode( ValidationMode.valueOf( validationMode ) );
}

@Override
public SharedCacheMode getSharedCacheMode() {
return sharedCacheMode;
}

public void setSharedCacheMode(SharedCacheMode sharedCacheMode) {
this.sharedCacheMode = sharedCacheMode;
}

public void setSharedCacheMode(String sharedCacheMode) {
this.sharedCacheMode = SharedCacheMode.valueOf( sharedCacheMode );
setSharedCacheMode( SharedCacheMode.valueOf( sharedCacheMode ) );
}

@Override
Expand Down Expand Up @@ -178,6 +186,12 @@ public void addJarFileUrl(URL jarFileUrl) {
jarFileUrls.add( jarFileUrl );
}

public void addJarFileUrls(List<String> jarFiles) {
jarFiles.forEach( (jarFile) -> {
addJarFileUrl( ArchiveHelper.getURLFromPath( jarFile ) );
} );
}

@Override
public ClassLoader getClassLoader() {
return null;
Expand Down

0 comments on commit 71bd6b0

Please sign in to comment.