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