203
203
204
204
import static org .hibernate .boot .jaxb .hbm .transform .HbmTransformationLogging .TRANSFORMATION_LOGGER ;
205
205
import static org .hibernate .internal .util .StringHelper .isNotEmpty ;
206
+ import static org .hibernate .internal .util .StringHelper .nullIfEmpty ;
206
207
207
208
/**
208
209
* Transforms {@code hbm.xml} {@linkplain JaxbHbmHibernateMapping JAXB} bindings into
@@ -1205,7 +1206,7 @@ else if ( !source.getColumnOrFormula().isEmpty() ) {
1205
1206
}
1206
1207
}
1207
1208
}
1208
- else if ( StringHelper . isNotEmpty ( tableName ) ) {
1209
+ else if ( isNotEmpty ( tableName ) ) {
1209
1210
// this is the case of transforming a <join/> where the property did not specify columns or formula.
1210
1211
// we need to create a column still to pass along the secondary table name
1211
1212
final TargetColumnAdapter column = target .makeColumnAdapter ( columnDefaults );
@@ -1590,7 +1591,7 @@ public Boolean isUpdateable() {
1590
1591
}
1591
1592
1592
1593
private JaxbUserTypeImpl interpretBasicType (String typeName , JaxbHbmConfigParameterContainer typeLocalParams , JaxbHbmTypeDefinitionType typeDef ) {
1593
- assert StringHelper . isNotEmpty ( typeName );
1594
+ assert isNotEmpty ( typeName );
1594
1595
1595
1596
final JaxbUserTypeImpl typeNode = new JaxbUserTypeImpl ();
1596
1597
@@ -1624,7 +1625,7 @@ private JaxbEmbeddableImpl applyEmbeddable(
1624
1625
JaxbHbmCompositeAttributeType hbmComponent ,
1625
1626
ComponentTypeInfo componentTypeInfo ) {
1626
1627
final String embeddableClassName = componentTypeInfo .getComponent ().getComponentClassName ();
1627
- if ( StringHelper . isNotEmpty ( embeddableClassName ) ) {
1628
+ if ( isNotEmpty ( embeddableClassName ) ) {
1628
1629
final JaxbEmbeddableImpl existing = jaxbEmbeddableByClassName .get ( embeddableClassName );
1629
1630
if ( existing != null ) {
1630
1631
return existing ;
@@ -1641,7 +1642,7 @@ private JaxbEmbeddableImpl applyEmbeddable(
1641
1642
);
1642
1643
mappingXmlBinding .getRoot ().getEmbeddables ().add ( jaxbEmbeddable );
1643
1644
1644
- if ( StringHelper . isNotEmpty ( embeddableClassName ) ) {
1645
+ if ( isNotEmpty ( embeddableClassName ) ) {
1645
1646
jaxbEmbeddableByClassName .put ( embeddableClassName , jaxbEmbeddable );
1646
1647
}
1647
1648
@@ -1668,7 +1669,7 @@ private JaxbEmbeddableImpl convertEmbeddable(
1668
1669
1669
1670
private int counter = 1 ;
1670
1671
private String determineEmbeddableName (String componentClassName , String attributeName ) {
1671
- if ( StringHelper . isNotEmpty ( componentClassName ) ) {
1672
+ if ( isNotEmpty ( componentClassName ) ) {
1672
1673
return componentClassName ;
1673
1674
}
1674
1675
return attributeName + "_" + counter ++;
@@ -1692,7 +1693,7 @@ private void transferOneToOne(JaxbHbmOneToOneType hbmOneToOne, PropertyInfo prop
1692
1693
oneToOne .setOrphanRemoval ( isOrphanRemoval ( hbmOneToOne .getCascade () ) );
1693
1694
oneToOne .setForeignKey ( new JaxbForeignKeyImpl () );
1694
1695
oneToOne .getForeignKey ().setName ( hbmOneToOne .getForeignKey () );
1695
- if ( StringHelper . isNotEmpty ( hbmOneToOne .getPropertyRef () ) ) {
1696
+ if ( isNotEmpty ( hbmOneToOne .getPropertyRef () ) ) {
1696
1697
oneToOne .setPropertyRef ( new JaxbPropertyRefImpl () );
1697
1698
oneToOne .getPropertyRef ().setName ( hbmOneToOne .getPropertyRef () );
1698
1699
}
@@ -1736,7 +1737,7 @@ private JaxbManyToOneImpl transformManyToOne(JaxbHbmManyToOneType hbmNode, Prope
1736
1737
jaxbManyToOne .setAttributeAccessor ( hbmNode .getAccess () );
1737
1738
jaxbManyToOne .setCascade ( convertCascadeType ( hbmNode .getCascade () ) );
1738
1739
1739
- if ( StringHelper . isNotEmpty ( hbmNode .getPropertyRef () ) ) {
1740
+ if ( isNotEmpty ( hbmNode .getPropertyRef () ) ) {
1740
1741
jaxbManyToOne .setPropertyRef ( new JaxbPropertyRefImpl () );
1741
1742
jaxbManyToOne .getPropertyRef ().setName ( hbmNode .getPropertyRef () );
1742
1743
}
@@ -1905,23 +1906,23 @@ private void transferCollectionCommonInfo(PluralAttributeInfo source, JaxbPlural
1905
1906
target .setFetchMode ( convert ( source .getFetch () ) );
1906
1907
target .setFetch ( convert ( source .getLazy () ) );
1907
1908
1908
- if ( StringHelper . isNotEmpty ( source .getCollectionType () ) ) {
1909
+ if ( isNotEmpty ( source .getCollectionType () ) ) {
1909
1910
final JaxbCollectionUserTypeImpl jaxbCollectionUserType = new JaxbCollectionUserTypeImpl ();
1910
1911
target .setCollectionType ( jaxbCollectionUserType );
1911
1912
jaxbCollectionUserType .setType ( source .getCollectionType () );
1912
1913
}
1913
1914
1914
1915
if ( source instanceof JaxbHbmSetType set ) {
1915
1916
final String sort = set .getSort ();
1916
- if ( StringHelper . isNotEmpty ( sort ) && !"unsorted" .equals ( sort ) ) {
1917
+ if ( isNotEmpty ( sort ) && !"unsorted" .equals ( sort ) ) {
1917
1918
target .setSort ( sort );
1918
1919
}
1919
1920
target .setOrderBy ( set .getOrderBy () );
1920
1921
target .setClassification ( LimitedCollectionClassification .SET );
1921
1922
}
1922
1923
else if ( source instanceof JaxbHbmMapType map ) {
1923
1924
final String sort = map .getSort ();
1924
- if ( StringHelper . isNotEmpty ( sort ) && !"unsorted" .equals ( sort ) ) {
1925
+ if ( isNotEmpty ( sort ) && !"unsorted" .equals ( sort ) ) {
1925
1926
target .setSort ( sort );
1926
1927
}
1927
1928
target .setOrderBy ( map .getOrderBy () );
@@ -2025,7 +2026,7 @@ else if ( source.getMapKey() != null ) {
2025
2026
return ;
2026
2027
}
2027
2028
2028
- if ( StringHelper . isNotEmpty ( source .getMapKey ().getNode () ) ) {
2029
+ if ( isNotEmpty ( source .getMapKey ().getNode () ) ) {
2029
2030
handleUnsupported (
2030
2031
"Transformation of `node` attribute is not supported - %s" ,
2031
2032
origin ()
@@ -2040,7 +2041,7 @@ else if ( source.getMapKey() != null ) {
2040
2041
jaxbMapKeyType .setValue ( mapKeyType );
2041
2042
}
2042
2043
2043
- if ( StringHelper . isNotEmpty ( source .getMapKey ().getColumnAttribute () ) ) {
2044
+ if ( isNotEmpty ( source .getMapKey ().getColumnAttribute () ) ) {
2044
2045
final JaxbMapKeyColumnImpl mapKeyColumn = new JaxbMapKeyColumnImpl ();
2045
2046
mapKeyColumn .setName ( source .getMapKey ().getColumnAttribute () );
2046
2047
target .setMapKeyColumn ( mapKeyColumn );
@@ -2049,38 +2050,32 @@ else if ( source.getMapKey() != null ) {
2049
2050
}
2050
2051
2051
2052
private String resolveMapKeyType (JaxbHbmMapKeyBasicType mapKey ) {
2052
- if ( StringHelper . isNotEmpty ( mapKey .getTypeAttribute () ) ) {
2053
+ if ( isNotEmpty ( mapKey .getTypeAttribute () ) ) {
2053
2054
return mapKey .getTypeAttribute ();
2054
2055
}
2055
-
2056
- if ( mapKey .getType () != null ) {
2057
- return StringHelper .nullIfEmpty ( mapKey .getType ().getName () );
2056
+ else if ( mapKey .getType () != null ) {
2057
+ return nullIfEmpty ( mapKey .getType ().getName () );
2058
+ }
2059
+ else {
2060
+ return null ;
2058
2061
}
2059
-
2060
- return null ;
2061
2062
}
2062
2063
2063
2064
private Boolean invert (Boolean value ) {
2064
- return invert ( value , null );
2065
- }
2066
-
2067
- private Boolean invert (Boolean value , Boolean defaultValue ) {
2068
- if ( value == null ) {
2069
- return defaultValue ;
2070
- }
2071
- return !value ;
2065
+ return value == null ? null : !value ;
2072
2066
}
2073
2067
2074
2068
private JaxbPluralFetchModeImpl convert (JaxbHbmFetchStyleWithSubselectEnum fetch ) {
2075
- if ( fetch != null ) {
2069
+ if ( fetch == null ) {
2070
+ return null ;
2071
+ }
2072
+ else {
2076
2073
return switch ( fetch ) {
2077
2074
case SELECT -> JaxbPluralFetchModeImpl .SELECT ;
2078
2075
case JOIN -> JaxbPluralFetchModeImpl .JOIN ;
2079
2076
case SUBSELECT -> JaxbPluralFetchModeImpl .SUBSELECT ;
2080
2077
};
2081
2078
}
2082
-
2083
- return null ;
2084
2079
}
2085
2080
2086
2081
@@ -2181,7 +2176,7 @@ private void transferElementInfo(
2181
2176
final ComponentTypeInfo componentTypeInfo = transformationState .getEmbeddableInfoByRole ().get ( partRole );
2182
2177
2183
2178
target .setTarget ( embeddableName );
2184
- if ( StringHelper . isNotEmpty ( embeddableClassName ) ) {
2179
+ if ( isNotEmpty ( embeddableClassName ) ) {
2185
2180
target .setTargetClass ( embeddableClassName );
2186
2181
}
2187
2182
@@ -2217,7 +2212,7 @@ private void transferOneToManyInfo(
2217
2212
}
2218
2213
2219
2214
transferCollectionCommonInfo ( hbmAttributeInfo , target );
2220
- target .setTargetEntity ( StringHelper . isNotEmpty ( hbmOneToMany .getClazz () ) ? hbmOneToMany .getClazz () : hbmOneToMany .getEntityName () );
2215
+ target .setTargetEntity ( isNotEmpty ( hbmOneToMany .getClazz () ) ? hbmOneToMany .getClazz () : hbmOneToMany .getEntityName () );
2221
2216
2222
2217
final Property bootModelProperty = propertyInfo .bootModelProperty ();
2223
2218
final Collection bootModelValue = (Collection ) bootModelProperty .getValue ();
@@ -2291,7 +2286,7 @@ public void addFormula(String formula) {
2291
2286
target .getFilters ().add ( convert ( hbmFilter ) );
2292
2287
}
2293
2288
2294
- if ( StringHelper . isNotEmpty ( hbmAttributeInfo .getWhere () ) ) {
2289
+ if ( isNotEmpty ( hbmAttributeInfo .getWhere () ) ) {
2295
2290
target .setSqlRestriction ( hbmAttributeInfo .getWhere () );
2296
2291
}
2297
2292
if ( hbmAttributeInfo .getSqlInsert () != null ) {
@@ -2320,7 +2315,7 @@ private String resolveMappedBy(
2320
2315
PluralAttributeInfo hbmAttributeInfo ,
2321
2316
Property bootModelProperty ,
2322
2317
Collection bootModelValue ) {
2323
- if ( StringHelper . isNotEmpty ( bootModelValue .getMappedByProperty () ) ) {
2318
+ if ( isNotEmpty ( bootModelValue .getMappedByProperty () ) ) {
2324
2319
return bootModelValue .getMappedByProperty ();
2325
2320
}
2326
2321
@@ -2369,8 +2364,8 @@ private boolean matches(KeyValue collectionKey, List<Selectable> candidate) {
2369
2364
2370
2365
final Column collectionKeyColumn = (Column ) collectionKeySelectable ;
2371
2366
final Column candidateColumn = (Column ) candidateSelectable ;
2372
- assert StringHelper . isNotEmpty ( collectionKeyColumn .getCanonicalName () );
2373
- assert StringHelper . isNotEmpty ( candidateColumn .getCanonicalName () );
2367
+ assert isNotEmpty ( collectionKeyColumn .getCanonicalName () );
2368
+ assert isNotEmpty ( candidateColumn .getCanonicalName () );
2374
2369
if ( !collectionKeyColumn .getCanonicalName ().equals ( candidateColumn .getCanonicalName () ) ) {
2375
2370
return false ;
2376
2371
}
@@ -2400,7 +2395,7 @@ private void transferManyToManyInfo(
2400
2395
if ( manyToMany .isEmbedXml () != null ) {
2401
2396
handleUnsupported ( "`embed-xml` no longer supported" );
2402
2397
}
2403
- if ( StringHelper . isNotEmpty ( manyToMany .getNode () ) ) {
2398
+ if ( isNotEmpty ( manyToMany .getNode () ) ) {
2404
2399
handleUnsupported ( "`node` no longer supported" );
2405
2400
}
2406
2401
@@ -2409,7 +2404,7 @@ private void transferManyToManyInfo(
2409
2404
2410
2405
final JaxbJoinTableImpl joinTable = new JaxbJoinTableImpl ();
2411
2406
final String tableName = hbmCollection .getTable ();
2412
- if ( StringHelper . isNotEmpty ( tableName ) ) {
2407
+ if ( isNotEmpty ( tableName ) ) {
2413
2408
joinTable .setName ( tableName );
2414
2409
}
2415
2410
target .setJoinTable ( joinTable );
@@ -2503,7 +2498,7 @@ public void addFormula(String formula) {
2503
2498
);
2504
2499
2505
2500
transferCollectionCommonInfo ( hbmCollection , target );
2506
- target .setTargetEntity ( StringHelper . isNotEmpty ( manyToMany .getClazz () ) ? manyToMany .getClazz () : manyToMany .getEntityName () );
2501
+ target .setTargetEntity ( isNotEmpty ( manyToMany .getClazz () ) ? manyToMany .getClazz () : manyToMany .getEntityName () );
2507
2502
2508
2503
if ( manyToMany .getNotFound () == JaxbHbmNotFoundEnum .IGNORE ) {
2509
2504
target .setNotFound ( NotFoundAction .IGNORE );
@@ -2513,7 +2508,7 @@ public void addFormula(String formula) {
2513
2508
target .getFilters ().add ( convert ( hbmFilter ) );
2514
2509
}
2515
2510
2516
- if ( StringHelper . isNotEmpty ( hbmCollection .getWhere () ) ) {
2511
+ if ( isNotEmpty ( hbmCollection .getWhere () ) ) {
2517
2512
target .setSqlRestriction ( hbmCollection .getWhere () );
2518
2513
}
2519
2514
if ( hbmCollection .getSqlInsert () != null ) {
@@ -2664,7 +2659,7 @@ private JaxbEmbeddableImpl transformEmbeddedIdEmbeddable(
2664
2659
EntityTypeInfo bootEntityInfo ,
2665
2660
Property idProperty ) {
2666
2661
final String embeddableClassName = hbmCompositeId .getClazz ();
2667
- if ( StringHelper . isNotEmpty ( embeddableClassName ) ) {
2662
+ if ( isNotEmpty ( embeddableClassName ) ) {
2668
2663
final JaxbEmbeddableImpl existing = jaxbEmbeddableByClassName .get ( embeddableClassName );
2669
2664
if ( existing != null ) {
2670
2665
return existing ;
0 commit comments