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 98853f9 commit bedad42
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainer;
import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainerImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCacheInclusionTypeImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCachingImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCascadeTypeImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCheckConstraintImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionTableImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResultImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCustomLoaderImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbCustomSqlImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbDatabaseObjectImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbDatabaseObjectScopeImpl;
Expand Down Expand Up @@ -330,7 +328,7 @@ private void transferFilterDefinitions() {
final String condition = ( (String) content ).trim();
if (! StringHelper.isEmpty( condition )) {
foundCondition = true;
filterDef.setCondition( condition );
filterDef.setDefaultCondition( condition );
}
}
else {
Expand All @@ -343,7 +341,7 @@ private void transferFilterDefinitions() {
}

if ( !foundCondition ) {
filterDef.setCondition( hbmFilterDef.getCondition() );
filterDef.setDefaultCondition( hbmFilterDef.getCondition() );
}
}
}
Expand Down Expand Up @@ -833,9 +831,9 @@ private void transferRootEntity(JaxbHbmRootEntityType hbmClass, JaxbEntityImpl e
}

if ( hbmClass.getLoader() != null ) {
entity.setLoader( new JaxbCustomLoaderImpl() );
entity.getLoader().setQueryRef( hbmClass.getLoader().getQueryRef() );
throw new UnsupportedOperationException( "<loader/> is not supported in mapping.xsd - use <sql-select/> or <hql-select/> instead" );
}

if ( hbmClass.getSqlInsert() != null ) {
entity.setSqlInsert( new JaxbCustomSqlImpl() );
entity.getSqlInsert().setValue( hbmClass.getSqlInsert().getValue() );
Expand Down Expand Up @@ -947,20 +945,20 @@ private void transformEntityCaching(JaxbHbmRootEntityType hbmClass, JaxbEntityIm
entity.setCaching( new JaxbCachingImpl() );
entity.getCaching().setRegion( hbmClass.getCache().getRegion() );
entity.getCaching().setAccess( hbmClass.getCache().getUsage() );
entity.getCaching().setInclude( convert( hbmClass.getCache().getInclude() ) );
entity.getCaching().setIncludeLazy( convert( hbmClass.getCache().getInclude() ) );
}

private JaxbCacheInclusionTypeImpl convert(JaxbHbmCacheInclusionEnum hbmInclusion) {
private boolean convert(JaxbHbmCacheInclusionEnum hbmInclusion) {
if ( hbmInclusion == null ) {
return null;
return true;
}

if ( hbmInclusion == JaxbHbmCacheInclusionEnum.NON_LAZY ) {
return JaxbCacheInclusionTypeImpl.NON_LAZY;
return false;
}

if ( hbmInclusion == JaxbHbmCacheInclusionEnum.ALL ) {
return JaxbCacheInclusionTypeImpl.ALL;
return true;
}

throw new IllegalArgumentException( "Unrecognized cache-inclusions value : " + hbmInclusion );
Expand Down Expand Up @@ -2308,7 +2306,7 @@ private JaxbHbmFilterImpl convert(JaxbHbmFilterType hbmFilter) {
aliasMapping.setAlias( hbmAliasMapping.getAlias() );
aliasMapping.setEntity( hbmAliasMapping.getEntity() );
aliasMapping.setTable( hbmAliasMapping.getTable() );
filter.getContent().add( aliasMapping );
filter.getAliases().add( aliasMapping );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class CacheAccessTypeMarshalling {
public static AccessType fromXml(String name) {
return name == null ? null : AccessType.fromExternalName( name );
return name == null ? null : AccessType.valueOf( name );
}

public static String toXml(AccessType accessType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@
*/
public class CacheModeMarshalling {
public static CacheMode fromXml(String name) {
for ( CacheMode mode : CacheMode.values() ) {
if ( mode.name().equalsIgnoreCase( name ) ) {
return mode;
}
}
return CacheMode.NORMAL;
return name == null ? CacheMode.NORMAL : CacheMode.valueOf( name );
}

public static String toXml(CacheMode cacheMode) {
return cacheMode == null ? null : cacheMode.name().toLowerCase( Locale.ENGLISH );
return cacheMode == null ? null : cacheMode.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
public class CollectionClassificationMarshalling {
public static CollectionClassification fromXml(String name) {
return name == null ? null : CollectionClassification.interpretSetting( name.replace( '-', '_' ) );
return name == null ? null : CollectionClassification.valueOf( name );
}

public static String toXml(CollectionClassification classification) {
return classification == null ? null : classification.name().replace( '_', '-' );
return classification == null ? null : classification.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package org.hibernate.boot.jaxb.mapping.internal;

import java.util.Locale;

import org.hibernate.tuple.GenerationTiming;

/**
Expand All @@ -17,12 +15,10 @@
*/
public class GenerationTimingMarshalling {
public static GenerationTiming fromXml(String name) {
return name == null ? null : GenerationTiming.parseFromName( name );
return name == null ? null : GenerationTiming.valueOf( name );
}

public static String toXml(GenerationTiming generationTiming) {
return ( null == generationTiming ) ?
null :
generationTiming.name().toLowerCase( Locale.ENGLISH );
return null == generationTiming ? null : generationTiming.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
*/
public class LimitedCollectionClassificationMarshalling {
public static LimitedCollectionClassification fromXml(String name) {
return name == null ? null : LimitedCollectionClassification.valueOf( name.toUpperCase( Locale.ROOT ) );
return name == null ? null : LimitedCollectionClassification.valueOf( name );
}

public static String toXml(LimitedCollectionClassification classification) {
return classification == null ? null : classification.name().toLowerCase( Locale.ROOT );
return classification == null ? null : classification.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*/
public class OnDeleteActionMarshalling {
public static OnDeleteAction fromXml(String name) {
return name == null ? null : OnDeleteAction.fromExternalForm( name );
return name == null ? null : OnDeleteAction.valueOf( name );
}

public static String toXml(OnDeleteAction accessType) {
return accessType == null ? null : accessType.getAlternativeName();
return accessType == null ? null : accessType.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
public class OptimisticLockStyleMarshalling {
public static OptimisticLockStyle fromXml(String name) {
return name == null ? null : OptimisticLockStyle.valueOf( name.toUpperCase( Locale.ENGLISH ) );
return name == null ? null : OptimisticLockStyle.valueOf( name );
}

public static String toXml(OptimisticLockStyle lockMode) {
return lockMode == null ? null : lockMode.name().toLowerCase( Locale.ENGLISH );
return lockMode == null ? null : lockMode.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*/
public class PolymorphismTypeMarshalling {
public static PolymorphismType fromXml(String value) {
return value == null ? null : PolymorphismType.fromExternalValue( value );
return value == null ? null : PolymorphismType.valueOf( value );
}

public static String toXml(PolymorphismType value) {
return value == null ? null : value.getExternalForm();
return value == null ? null : value.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
public class ResultCheckStyleMarshalling {
public static ExecuteUpdateResultCheckStyle fromXml(String name) {
return name == null ? null : ExecuteUpdateResultCheckStyle.fromExternalName( name );
return name == null ? null : ExecuteUpdateResultCheckStyle.valueOf( name );
}

public static String toXml(ExecuteUpdateResultCheckStyle style) {
return style == null ? null : style.externalName();
return style == null ? null : style.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
*/
package org.hibernate.boot.jaxb.mapping.internal;

import java.util.Locale;

import org.hibernate.annotations.UuidGenerator;

/**
* JAXB marshalling for {@link UuidGenerator.Style}
*/
public class UuidGeneratorStyleMarshalling {
public static UuidGenerator.Style fromXml(String name) {
return name == null ? null : UuidGenerator.Style.valueOf( name.toUpperCase( Locale.ROOT ) );
return name == null ? null : UuidGenerator.Style.valueOf( name );
}

public static String toXml(UuidGenerator.Style style) {
return style == null ? null : style.name().toLowerCase( Locale.ROOT );
return style == null ? null : style.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public interface JaxbEntity extends JaxbEntityOrMappedSuperclass {
String getSqlRestriction();
void setSqlRestriction(String value);

JaxbCustomLoaderImpl getLoader();
void setLoader(JaxbCustomLoaderImpl value);
JaxbSqlSelectImpl getSqlSelect();
String getHqlSelect();

JaxbCustomSqlImpl getSqlInsert();
void setSqlInsert(JaxbCustomSqlImpl value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ public interface JaxbNaturalId extends JaxbBaseAttributesContainer {
* The cache config associated with this natural-id
*/
JaxbCachingImpl getCaching();

/**
* Whether the natural-id (all attributes which are part of it) should
* be considered mutable or immutable.
*/
boolean isMutable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ private Cache getCaching(JaxbManagedType root, XMLContext.Default defaults) {
final AnnotationDescriptor ad = new AnnotationDescriptor( Cache.class );
ad.setValue( "usage", CacheConcurrencyStrategy.fromAccessType( caching.getAccess() ) );
ad.setValue( "region", caching.getRegion() );
ad.setValue( "include", caching.getInclude().value() );
ad.setValue( "includeLazy", caching.isIncludeLazy() );
return AnnotationFactory.create( ad );
}
}
Expand Down

0 comments on commit bedad42

Please sign in to comment.