Skip to content

Commit 26cd62f

Browse files
committed
get rid of TruthValue and use Boolean
clean it up a bit
1 parent 424460a commit 26cd62f

File tree

17 files changed

+82
-178
lines changed

17 files changed

+82
-178
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/TruthValue.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSecondaryTableType;
2323
import org.hibernate.boot.jaxb.hbm.spi.SecondaryTableContainer;
2424
import org.hibernate.boot.model.CustomSql;
25-
import org.hibernate.boot.model.TruthValue;
2625
import org.hibernate.boot.model.source.spi.AttributePath;
2726
import org.hibernate.boot.model.source.spi.AttributeRole;
2827
import org.hibernate.boot.model.source.spi.AttributeSource;
@@ -391,10 +390,4 @@ public List<JaxbHbmNamedNativeQueryType> getNamedNativeQueries() {
391390
return jaxbEntityMapping.getSqlQuery();
392391
}
393392

394-
@Override
395-
public TruthValue quoteIdentifiersLocalToEntity() {
396-
// HBM does not allow for this
397-
return TruthValue.UNKNOWN;
398-
}
399-
400393
}

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ColumnAttributeSourceImpl.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.util.Set;
88

9-
import org.hibernate.boot.model.TruthValue;
109
import org.hibernate.boot.model.source.spi.ColumnSource;
1110
import org.hibernate.boot.model.source.spi.JdbcDataType;
1211
import org.hibernate.boot.model.source.spi.SizeSource;
@@ -24,8 +23,8 @@ class ColumnAttributeSourceImpl
2423
private final String tableName;
2524
private final String columnName;
2625
private final SizeSource sizeSource;
27-
private final TruthValue nullable;
28-
private final TruthValue unique;
26+
private final Boolean nullable;
27+
private final Boolean unique;
2928
private final Set<String> indexConstraintNames;
3029
private final Set<String> ukConstraintNames;
3130

@@ -34,8 +33,8 @@ class ColumnAttributeSourceImpl
3433
String tableName,
3534
String columnName,
3635
SizeSource sizeSource,
37-
TruthValue nullable,
38-
TruthValue unique,
36+
Boolean nullable,
37+
Boolean unique,
3938
Set<String> indexConstraintNames,
4039
Set<String> ukConstraintNames) {
4140
super( mappingDocument );
@@ -64,7 +63,7 @@ public String getName() {
6463
}
6564

6665
@Override
67-
public TruthValue isNullable() {
66+
public Boolean isNullable() {
6867
return nullable;
6968
}
7069

@@ -100,7 +99,7 @@ public String getWriteFragment() {
10099

101100
@Override
102101
public boolean isUnique() {
103-
return unique == TruthValue.TRUE;
102+
return unique == Boolean.TRUE;
104103
}
105104

106105
@Override

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ColumnSourceImpl.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
package org.hibernate.boot.model.source.internal.hbm;
66

77

8-
import java.util.Collections;
98
import java.util.HashSet;
109
import java.util.Set;
1110

1211
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmColumnType;
13-
import org.hibernate.boot.model.TruthValue;
1412
import org.hibernate.boot.model.source.spi.ColumnSource;
1513
import org.hibernate.boot.model.source.spi.JdbcDataType;
1614
import org.hibernate.boot.model.source.spi.SizeSource;
1715

16+
import static java.util.Collections.addAll;
1817
import static org.hibernate.internal.util.StringHelper.splitAtCommas;
1918

2019
/**
@@ -25,7 +24,7 @@ class ColumnSourceImpl
2524
implements ColumnSource {
2625
private final String tableName;
2726
private final JaxbHbmColumnType columnElement;
28-
private final TruthValue nullable;
27+
private final Boolean nullable;
2928
private final Set<String> indexConstraintNames;
3029
private final Set<String> ukConstraintNames;
3130

@@ -39,27 +38,19 @@ class ColumnSourceImpl
3938
mappingDocument,
4039
tableName,
4140
columnElement,
42-
interpretNotNullToNullability( columnElement.isNotNull() ),
41+
columnElement.isNotNull() == null
42+
? null
43+
: !columnElement.isNotNull(),
4344
indexConstraintNames,
4445
ukConstraintNames
4546
);
4647
}
4748

48-
private static TruthValue interpretNotNullToNullability(Boolean notNull) {
49-
if ( notNull == null ) {
50-
return TruthValue.UNKNOWN;
51-
}
52-
else {
53-
// not-null == nullable, so the booleans are reversed
54-
return notNull ? TruthValue.FALSE : TruthValue.TRUE;
55-
}
56-
}
57-
5849
ColumnSourceImpl(
5950
MappingDocument mappingDocument,
6051
String tableName,
6152
JaxbHbmColumnType columnElement,
62-
TruthValue nullable,
53+
Boolean nullable,
6354
Set<String> indexConstraintNames,
6455
Set<String> ukConstraintNames) {
6556
super( mappingDocument );
@@ -86,7 +77,7 @@ public String getName() {
8677
}
8778

8879
@Override
89-
public TruthValue isNullable() {
80+
public Boolean isNullable() {
9081
return nullable;
9182
}
9283

@@ -126,8 +117,8 @@ public String getWriteFragment() {
126117

127118
@Override
128119
public boolean isUnique() {
129-
// TODO: should TruthValue be returned instead of boolean?
130-
return columnElement.isUnique() != null && columnElement.isUnique().booleanValue();
120+
return columnElement.isUnique() != null
121+
&& columnElement.isUnique();
131122
}
132123

133124
@Override
@@ -160,8 +151,8 @@ public static Set<String> splitAndCombine(Set<String> stringSet, String values)
160151
return stringSet;
161152
}
162153
else {
163-
HashSet<String> set = new HashSet<>( stringSet );
164-
Collections.addAll( set, splitAtCommas( values ) );
154+
final HashSet<String> set = new HashSet<>( stringSet );
155+
addAll( set, splitAtCommas( values ) );
165156
return set;
166157
}
167158
}

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalObjectBinder.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Collections;
88
import java.util.List;
99

10-
import org.hibernate.boot.model.TruthValue;
1110
import org.hibernate.boot.model.naming.Identifier;
1211
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
1312
import org.hibernate.boot.model.relational.Database;
@@ -150,7 +149,8 @@ public void bindColumn(
150149
}
151150
}
152151

153-
column.setNullable( interpretNullability( columnSource.isNullable(), areColumnsNullableByDefault ) );
152+
final Boolean nullable = columnSource.isNullable();
153+
column.setNullable( nullable == null ? areColumnsNullableByDefault : nullable );
154154

155155
column.setUnique( columnSource.isUnique() );
156156
if ( columnSource.isUnique() && table != null ) {
@@ -182,15 +182,6 @@ public void bindColumn(
182182
}
183183
}
184184

185-
private static boolean interpretNullability(TruthValue nullable, boolean areColumnsNullableByDefault) {
186-
if ( nullable == null || nullable == TruthValue.UNKNOWN ) {
187-
return areColumnsNullableByDefault;
188-
}
189-
else {
190-
return nullable == TruthValue.TRUE;
191-
}
192-
}
193-
194185
public void bindFormulas(
195186
MappingDocument sourceDocument,
196187
List<DerivedValueSource> formulaSources,

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
import org.hibernate.boot.MappingException;
1414
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmColumnType;
15-
import org.hibernate.boot.model.TruthValue;
1615
import org.hibernate.boot.model.source.spi.ColumnSource;
1716
import org.hibernate.boot.model.source.spi.DerivedValueSource;
1817
import org.hibernate.boot.model.source.spi.RelationalValueSource;
1918
import org.hibernate.boot.model.source.spi.SizeSource;
20-
import org.hibernate.internal.util.StringHelper;
2119
import org.hibernate.internal.util.collections.CollectionHelper;
2220

21+
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
22+
2323
/**
2424
* @author Steve Ebersole
2525
*/
@@ -152,7 +152,7 @@ public static RelationalValueSource buildValueSource(
152152
if ( sources.size() > 1 ) {
153153
final String errorMessage;
154154
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
155-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
155+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
156156
errorMessage = String.format(
157157
Locale.ENGLISH,
158158
"Expecting just a single formula/column in context of <%s name=\"%s\"/>",
@@ -197,7 +197,7 @@ public static ColumnSource buildColumnSource(
197197
if ( sources.size() > 1 ) {
198198
final String errorMessage;
199199
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
200-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
200+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
201201
errorMessage = String.format(
202202
Locale.ENGLISH,
203203
"Expecting just a single formula/column in context of <%s name=\"%s\"/>",
@@ -219,7 +219,7 @@ public static ColumnSource buildColumnSource(
219219
if ( !(result instanceof ColumnSource) ) {
220220
final String errorMessage;
221221
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
222-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
222+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
223223
errorMessage = String.format(
224224
Locale.ENGLISH,
225225
"Expecting single column in context of <%s name=\"%s\"/>, but found formula [%s]",
@@ -267,7 +267,7 @@ public static List<ColumnSource> buildColumnSources(
267267
if ( !(source instanceof ColumnSource) ) {
268268
final String errorMessage;
269269
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
270-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
270+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
271271
errorMessage = String.format(
272272
Locale.ENGLISH,
273273
"Expecting only columns in context of <%s name=\"%s\"/>, but found formula [%s]",
@@ -307,7 +307,7 @@ public static List<RelationalValueSource> buildValueSources(
307307
ColumnsAndFormulasSource columnsAndFormulasSource) {
308308
List<RelationalValueSource> result = new ArrayList<>();
309309

310-
if ( StringHelper.isNotEmpty( columnsAndFormulasSource.getFormulaAttribute() ) ) {
310+
if ( isNotEmpty( columnsAndFormulasSource.getFormulaAttribute() ) ) {
311311
// we have an explicit formula attribute (i.e., <SOMETHING formula="abc"/>)
312312
validateUseOfFormulaAttribute( mappingDocument, columnsAndFormulasSource );
313313

@@ -359,8 +359,8 @@ else if ( selectable instanceof String ) {
359359
containingTableName,
360360
columnsAndFormulasSource.getColumnAttribute(),
361361
columnsAndFormulasSource.getSizeSource(),
362-
interpretNullabilityToTruthValue( columnsAndFormulasSource.isNullable() ),
363-
columnsAndFormulasSource.isUnique() ? TruthValue.TRUE : TruthValue.FALSE,
362+
columnsAndFormulasSource.isNullable(),
363+
columnsAndFormulasSource.isUnique(),
364364
columnsAndFormulasSource.getIndexConstraintNames(),
365365
columnsAndFormulasSource.getUniqueKeyConstraintNames()
366366
)
@@ -370,23 +370,14 @@ else if ( selectable instanceof String ) {
370370
return result;
371371
}
372372

373-
private static TruthValue interpretNullabilityToTruthValue(Boolean nullable) {
374-
if ( nullable == null ) {
375-
return TruthValue.UNKNOWN;
376-
}
377-
else {
378-
return nullable ? TruthValue.TRUE : TruthValue.FALSE;
379-
}
380-
}
381-
382373
private static void validateUseOfFormulaAttribute(
383374
MappingDocument sourceDocument,
384375
ColumnsAndFormulasSource columnsAndFormulasSource) {
385376
// 1) make sure there is no column attribute
386-
if ( StringHelper.isNotEmpty( columnsAndFormulasSource.getColumnAttribute() ) ) {
377+
if ( isNotEmpty( columnsAndFormulasSource.getColumnAttribute() ) ) {
387378
final String errorMessage;
388379
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
389-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
380+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
390381
errorMessage = String.format(
391382
Locale.ENGLISH,
392383
"column attribute and formula attribute may not be specified together near <%s name=\"%s\" column=\"%s\" formula=\"%s\" />",
@@ -411,7 +402,7 @@ private static void validateUseOfFormulaAttribute(
411402
if ( CollectionHelper.isNotEmpty( columnsAndFormulasSource.getColumnOrFormulaElements() ) ) {
412403
final String errorMessage;
413404
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
414-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
405+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
415406
errorMessage = String.format(
416407
Locale.ENGLISH,
417408
"formula attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name=\"%s\" formula=\"%s\" />",
@@ -435,10 +426,10 @@ private static void validateUseOfFormulaAttribute(
435426
private static void validateUseOfColumnOrFormulaNestedElements(
436427
MappingDocument sourceDocument,
437428
ColumnsAndFormulasSource columnsAndFormulasSource) {
438-
if ( StringHelper.isNotEmpty( columnsAndFormulasSource.getColumnAttribute() ) ) {
429+
if ( isNotEmpty( columnsAndFormulasSource.getColumnAttribute() ) ) {
439430
final String errorMessage;
440431
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
441-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
432+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
442433
errorMessage = String.format(
443434
Locale.ENGLISH,
444435
"column attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name=\"%s\" column=\"%s\" />",
@@ -467,7 +458,7 @@ private static void validateCustomWriteFragment(
467458
if ( customWrite != null && !customWrite.matches("[^?]*\\?[^?]*") ) {
468459
final String errorMessage;
469460
if ( columnsAndFormulasSource.getSourceType().canBeNamed()
470-
&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
461+
&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
471462
errorMessage = String.format(
472463
Locale.ENGLISH,
473464
"write expression must contain exactly one value placeholder ('?') character near <column name=\"%s\" ... write=\"%s\" /> for <%s name=\"%s\" />",

0 commit comments

Comments
 (0)