3
3
* Copyright Red Hat Inc. and Hibernate Authors
4
4
*/
5
5
package org .hibernate .dialect ;
6
-
7
6
import java .lang .reflect .Array ;
8
7
import java .sql .CallableStatement ;
9
8
import java .sql .ResultSet ;
57
56
* is probably not very efficient.
58
57
*
59
58
* @author liubao
60
- * <p>
59
+ *
61
60
* Notes: Original code of this class is based on AbstractPostgreSQLStructJdbcType.
62
61
*/
63
62
public abstract class AbstractGaussDBStructJdbcType implements StructuredJdbcType {
64
63
65
64
private static final DateTimeFormatter LOCAL_DATE_TIME ;
66
-
67
65
static {
68
66
LOCAL_DATE_TIME = new DateTimeFormatterBuilder ()
69
67
.parseCaseInsensitive ()
70
- .append ( DateTimeFormatter .ISO_LOCAL_DATE )
71
- .appendLiteral ( ' ' )
72
- .append ( DateTimeFormatter .ISO_LOCAL_TIME )
68
+ .append (DateTimeFormatter .ISO_LOCAL_DATE )
69
+ .appendLiteral (' ' )
70
+ .append (DateTimeFormatter .ISO_LOCAL_TIME )
73
71
.optionalStart ()
74
72
.appendOffset ( "+HH:mm" , "+00" )
75
73
.toFormatter ();
76
74
}
77
75
78
76
// Need a custom formatter for parsing what PostgresPlus/EDB produces
79
77
private static final DateTimeFormatter LOCAL_DATE ;
80
-
81
78
static {
82
79
LOCAL_DATE = new DateTimeFormatterBuilder ()
83
80
.parseCaseInsensitive ()
84
- .append ( DateTimeFormatter .ISO_LOCAL_DATE )
81
+ .append (DateTimeFormatter .ISO_LOCAL_DATE )
85
82
.optionalStart ()
86
- .appendLiteral ( ' ' )
87
- .append ( DateTimeFormatter .ISO_LOCAL_TIME )
83
+ .appendLiteral (' ' )
84
+ .append (DateTimeFormatter .ISO_LOCAL_TIME )
88
85
.optionalStart ()
89
86
.appendOffset ( "+HH:mm" , "+00" )
90
87
.toFormatter ();
91
88
}
92
-
93
89
private final String typeName ;
94
90
private final int [] orderMapping ;
95
91
private final int [] inverseOrderMapping ;
@@ -166,7 +162,7 @@ private X getObject(Object object, WrapperOptions options) throws SQLException {
166
162
if ( object == null ) {
167
163
return null ;
168
164
}
169
- return ((AbstractGaussDBStructJdbcType ) getJdbcType ()).fromString (
165
+ return ( (AbstractGaussDBStructJdbcType ) getJdbcType () ).fromString (
170
166
object .toString (),
171
167
getJavaType (),
172
168
options
@@ -189,14 +185,12 @@ protected <X> X fromString(String string, JavaType<X> javaType, WrapperOptions o
189
185
array = values .toArray ();
190
186
}
191
187
else {
192
- array = new Object [embeddableMappingType .getJdbcValueCount () + (embeddableMappingType .isPolymorphic () ? 1
193
- : 0 )];
188
+ array = new Object [embeddableMappingType .getJdbcValueCount () + ( embeddableMappingType .isPolymorphic () ? 1 : 0 )];
194
189
end = deserializeStruct ( string , 0 , 0 , array , returnEmbeddable , options );
195
190
}
196
191
assert end == string .length ();
197
192
if ( returnEmbeddable ) {
198
- final StructAttributeValues attributeValues = getAttributeValues ( embeddableMappingType , orderMapping ,
199
- array , options );
193
+ final StructAttributeValues attributeValues = getAttributeValues ( embeddableMappingType , orderMapping , array , options );
200
194
//noinspection unchecked
201
195
return (X ) instantiate ( embeddableMappingType , attributeValues );
202
196
}
@@ -330,15 +324,15 @@ private int deserializeStruct(
330
324
// Fall-through since a backslash is an escaping mechanism for a start quote within arrays
331
325
case '"' :
332
326
if ( inQuote ) {
333
- if ( isDoubleQuote ( string , i , 1 << (quotes + 1 ) ) ) {
327
+ if ( isDoubleQuote ( string , i , 1 << ( quotes + 1 ) ) ) {
334
328
// Skip quote escaping as that will be unescaped later
335
329
if ( escapingSb == null ) {
336
330
escapingSb = new StringBuilder ();
337
331
}
338
332
escapingSb .append ( string , start , i );
339
333
escapingSb .append ( '"' );
340
334
// Move forward to the last quote
341
- i += (1 << (quotes + 1 ) ) - 1 ;
335
+ i += ( 1 << ( quotes + 1 ) ) - 1 ;
342
336
start = i + 1 ;
343
337
continue ;
344
338
}
@@ -406,7 +400,7 @@ private int deserializeStruct(
406
400
case SqlTypes .VARBINARY :
407
401
case SqlTypes .LONGVARBINARY :
408
402
case SqlTypes .LONG32VARBINARY :
409
- final int backslashes = 1 << (quotes + 1 );
403
+ final int backslashes = 1 << ( quotes + 1 );
410
404
assert repeatsChar ( string , start , backslashes , '\\' );
411
405
final int xCharPosition = start + backslashes ;
412
406
assert string .charAt ( xCharPosition ) == 'x' ;
@@ -475,8 +469,7 @@ private int deserializeStruct(
475
469
subValues ,
476
470
options
477
471
);
478
- values [column ] = instantiate ( structJdbcType .embeddableMappingType ,
479
- attributeValues );
472
+ values [column ] = instantiate ( structJdbcType .embeddableMappingType , attributeValues );
480
473
}
481
474
else {
482
475
if ( structJdbcType .inverseOrderMapping != null ) {
@@ -561,7 +554,7 @@ else if ( string.charAt( i + 1 ) == '{' ) {
561
554
);
562
555
}
563
556
else if ( jdbcMapping .getJavaTypeDescriptor ().getJavaTypeClass ().isEnum ()
564
- && jdbcMapping .getJdbcType ().isInteger () ) {
557
+ && jdbcMapping .getJdbcType ().isInteger () ) {
565
558
values [column ] = fromRawObject (
566
559
jdbcMapping ,
567
560
IntegerJavaType .INSTANCE .fromEncodedString ( string , start , i ),
@@ -597,7 +590,7 @@ else if ( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass().isEnum()
597
590
);
598
591
}
599
592
else if ( jdbcMapping .getJavaTypeDescriptor ().getJavaTypeClass ().isEnum ()
600
- && jdbcMapping .getJdbcType ().isInteger () ) {
593
+ && jdbcMapping .getJdbcType ().isInteger () ) {
601
594
values [column ] = fromRawObject (
602
595
jdbcMapping ,
603
596
IntegerJavaType .INSTANCE .fromEncodedString ( string , start , i ),
@@ -619,8 +612,7 @@ else if ( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass().isEnum()
619
612
break ;
620
613
case '{' :
621
614
if ( !inQuote ) {
622
- final BasicPluralType <?, ?> pluralType = (BasicPluralType <?, ?>) getJdbcValueSelectable (
623
- column ).getJdbcMapping ();
615
+ final BasicPluralType <?, ?> pluralType = (BasicPluralType <?, ?>) getJdbcValueSelectable ( column ).getJdbcMapping ();
624
616
final ArrayList <Object > arrayList = new ArrayList <>();
625
617
//noinspection unchecked
626
618
i = deserializeArray (
@@ -718,15 +710,15 @@ private int deserializeArray(
718
710
// Fall-through since a backslash is an escaping mechanism for a start quote within arrays
719
711
case '"' :
720
712
if ( inQuote ) {
721
- if ( isDoubleQuote ( string , i , 1 << (quotes + 1 ) ) ) {
713
+ if ( isDoubleQuote ( string , i , 1 << ( quotes + 1 ) ) ) {
722
714
// Skip quote escaping as that will be unescaped later
723
715
if ( escapingSb == null ) {
724
716
escapingSb = new StringBuilder ();
725
717
}
726
718
escapingSb .append ( string , start , i );
727
719
escapingSb .append ( '"' );
728
720
// Move forward to the last quote
729
- i += (1 << (quotes + 1 ) ) - 1 ;
721
+ i += ( 1 << ( quotes + 1 ) ) - 1 ;
730
722
start = i + 1 ;
731
723
continue ;
732
724
}
@@ -801,7 +793,7 @@ private int deserializeArray(
801
793
case SqlTypes .VARBINARY :
802
794
case SqlTypes .LONGVARBINARY :
803
795
case SqlTypes .LONG32VARBINARY :
804
- final int backslashes = 1 << (quotes + 1 );
796
+ final int backslashes = 1 << ( quotes + 1 );
805
797
assert repeatsChar ( string , start , backslashes , '\\' );
806
798
final int xCharPosition = start + backslashes ;
807
799
assert string .charAt ( xCharPosition ) == 'x' ;
@@ -912,7 +904,7 @@ private int deserializeArray(
912
904
case SqlTypes .LONGVARBINARY :
913
905
case SqlTypes .LONG32VARBINARY :
914
906
// Skip past the backslashes in the binary literal, this will be handled later
915
- final int backslashes = 1 << (quotes + 1 );
907
+ final int backslashes = 1 << ( quotes + 1 );
916
908
assert repeatsChar ( string , start , backslashes , '\\' );
917
909
i += backslashes ;
918
910
break ;
@@ -934,7 +926,7 @@ private int deserializeArray(
934
926
);
935
927
}
936
928
else if ( elementType .getJavaTypeDescriptor ().getJavaTypeClass ().isEnum ()
937
- && elementType .getJdbcType ().isInteger () ) {
929
+ && elementType .getJdbcType ().isInteger () ) {
938
930
values .add (
939
931
fromRawObject (
940
932
elementType ,
@@ -973,7 +965,7 @@ else if ( elementType.getJavaTypeDescriptor().getJavaTypeClass().isEnum()
973
965
);
974
966
}
975
967
else if ( elementType .getJavaTypeDescriptor ().getJavaTypeClass ().isEnum ()
976
- && elementType .getJdbcType ().isInteger () ) {
968
+ && elementType .getJdbcType ().isInteger () ) {
977
969
values .add (
978
970
fromRawObject (
979
971
elementType ,
@@ -1005,15 +997,14 @@ else if ( elementType.getJavaTypeDescriptor().getJavaTypeClass().isEnum()
1005
997
private SelectableMapping getJdbcValueSelectable (int jdbcValueSelectableIndex ) {
1006
998
if ( orderMapping != null ) {
1007
999
final int numberOfAttributeMappings = embeddableMappingType .getNumberOfAttributeMappings ();
1008
- final int size = numberOfAttributeMappings + (embeddableMappingType .isPolymorphic () ? 1 : 0 );
1000
+ final int size = numberOfAttributeMappings + ( embeddableMappingType .isPolymorphic () ? 1 : 0 );
1009
1001
int count = 0 ;
1010
1002
for ( int i = 0 ; i < size ; i ++ ) {
1011
1003
final ValuedModelPart modelPart = getEmbeddedPart ( embeddableMappingType , orderMapping [i ] );
1012
1004
if ( modelPart .getMappedType () instanceof EmbeddableMappingType embeddableMappingType ) {
1013
1005
final SelectableMapping aggregateMapping = embeddableMappingType .getAggregateMapping ();
1014
1006
if ( aggregateMapping == null ) {
1015
- final SelectableMapping subSelectable = embeddableMappingType .getJdbcValueSelectable (
1016
- jdbcValueSelectableIndex - count );
1007
+ final SelectableMapping subSelectable = embeddableMappingType .getJdbcValueSelectable ( jdbcValueSelectableIndex - count );
1017
1008
if ( subSelectable != null ) {
1018
1009
return subSelectable ;
1019
1010
}
@@ -1055,7 +1046,7 @@ private static boolean isDoubleQuote(String string, int start, int escapes) {
1055
1046
if ( escapes == 1 ) {
1056
1047
return string .charAt ( start ) == '"' ;
1057
1048
}
1058
- assert (escapes & 1 ) == 0 : "Only an even number of escapes allowed" ;
1049
+ assert ( escapes & 1 ) == 0 : "Only an even number of escapes allowed" ;
1059
1050
final int end = start + escapes ;
1060
1051
if ( end < string .length () ) {
1061
1052
for ( ; start < end ; start += 2 ) {
@@ -1186,8 +1177,7 @@ protected <X> String toString(X value, JavaType<X> javaType, WrapperOptions opti
1186
1177
return sb .toString ();
1187
1178
}
1188
1179
1189
- private void serializeStructTo (PostgreSQLAppender appender , Object value , WrapperOptions options )
1190
- throws SQLException {
1180
+ private void serializeStructTo (PostgreSQLAppender appender , Object value , WrapperOptions options ) throws SQLException {
1191
1181
serializeDomainValueTo ( appender , options , value , '(' );
1192
1182
appender .append ( ')' );
1193
1183
}
@@ -1306,7 +1296,7 @@ private void serializeConvertedBasicTo(
1306
1296
byte [].class ,
1307
1297
options
1308
1298
);
1309
- appender .ensureCanFit ( appender .quote + 1 + (bytes .length << 1 ) );
1299
+ appender .ensureCanFit ( appender .quote + 1 + ( bytes .length << 1 ) );
1310
1300
appender .append ( '\\' );
1311
1301
appender .append ( '\\' );
1312
1302
appender .append ( 'x' );
@@ -1362,8 +1352,7 @@ private void serializeConvertedBasicTo(
1362
1352
}
1363
1353
break ;
1364
1354
default :
1365
- throw new UnsupportedOperationException (
1366
- "Unsupported JdbcType nested in struct: " + jdbcMapping .getJdbcType () );
1355
+ throw new UnsupportedOperationException ( "Unsupported JdbcType nested in struct: " + jdbcMapping .getJdbcType () );
1367
1356
}
1368
1357
}
1369
1358
@@ -1373,7 +1362,7 @@ private StructAttributeValues getAttributeValues(
1373
1362
Object [] rawJdbcValues ,
1374
1363
WrapperOptions options ) throws SQLException {
1375
1364
final int numberOfAttributeMappings = embeddableMappingType .getNumberOfAttributeMappings ();
1376
- final int size = numberOfAttributeMappings + (embeddableMappingType .isPolymorphic () ? 1 : 0 );
1365
+ final int size = numberOfAttributeMappings + ( embeddableMappingType .isPolymorphic () ? 1 : 0 );
1377
1366
final StructAttributeValues attributeValues = new StructAttributeValues (
1378
1367
numberOfAttributeMappings ,
1379
1368
orderMapping != null ?
@@ -1500,8 +1489,7 @@ else if ( value instanceof java.util.Calendar calendar ) {
1500
1489
appendAsTimestampWithMillis ( appender , calendar , jdbcTimeZone );
1501
1490
}
1502
1491
else if ( value instanceof TemporalAccessor temporalAccessor ) {
1503
- appendAsTimestampWithMicros ( appender , temporalAccessor ,
1504
- temporalAccessor .isSupported ( ChronoField .OFFSET_SECONDS ), jdbcTimeZone );
1492
+ appendAsTimestampWithMicros ( appender , temporalAccessor , temporalAccessor .isSupported ( ChronoField .OFFSET_SECONDS ), jdbcTimeZone );
1505
1493
}
1506
1494
else {
1507
1495
appendAsTimestampWithMicros (
@@ -1517,7 +1505,6 @@ else if ( value instanceof TemporalAccessor temporalAccessor ) {
1517
1505
1518
1506
appender .append ( '"' );
1519
1507
}
1520
-
1521
1508
private static TimeZone getJdbcTimeZone (WrapperOptions options ) {
1522
1509
return options == null || options .getJdbcTimeZone () == null
1523
1510
? TimeZone .getDefault ()
0 commit comments