25
25
import java .sql .SQLException ;
26
26
import java .sql .Time ;
27
27
import java .sql .Timestamp ;
28
- import java .sql .Types ;
29
28
import java .time .LocalDate ;
30
29
import java .time .LocalDateTime ;
31
30
import java .time .LocalTime ;
@@ -42,67 +41,64 @@ public class ArrayTypeHandler extends BaseTypeHandler<Object> {
42
41
private static final ConcurrentHashMap <Class <?>, String > STANDARD_MAPPING ;
43
42
static {
44
43
STANDARD_MAPPING = new ConcurrentHashMap <>();
45
- STANDARD_MAPPING .put (BigDecimal .class , " NUMERIC" );
46
- STANDARD_MAPPING .put (BigInteger .class , " BIGINT" );
47
- STANDARD_MAPPING .put (boolean .class , " BOOLEAN" );
48
- STANDARD_MAPPING .put (Boolean .class , " BOOLEAN" );
49
- STANDARD_MAPPING .put (byte [].class , " VARBINARY" );
50
- STANDARD_MAPPING .put (byte .class , " TINYINT" );
51
- STANDARD_MAPPING .put (Byte .class , " TINYINT" );
52
- STANDARD_MAPPING .put (Calendar .class , " TIMESTAMP" );
53
- STANDARD_MAPPING .put (java .sql .Date .class , " DATE" );
54
- STANDARD_MAPPING .put (java .util .Date .class , " TIMESTAMP" );
55
- STANDARD_MAPPING .put (double .class , " DOUBLE" );
56
- STANDARD_MAPPING .put (Double .class , " DOUBLE" );
57
- STANDARD_MAPPING .put (float .class , " REAL" );
58
- STANDARD_MAPPING .put (Float .class , " REAL" );
59
- STANDARD_MAPPING .put (int .class , " INTEGER" );
60
- STANDARD_MAPPING .put (Integer .class , " INTEGER" );
61
- STANDARD_MAPPING .put (LocalDate .class , " DATE" );
62
- STANDARD_MAPPING .put (LocalDateTime .class , " TIMESTAMP" );
63
- STANDARD_MAPPING .put (LocalTime .class , " TIME" );
64
- STANDARD_MAPPING .put (long .class , " BIGINT" );
65
- STANDARD_MAPPING .put (Long .class , " BIGINT" );
66
- STANDARD_MAPPING .put (OffsetDateTime .class , " TIMESTAMP_WITH_TIMEZONE" );
67
- STANDARD_MAPPING .put (OffsetTime .class , " TIME_WITH_TIMEZONE" );
68
- STANDARD_MAPPING .put (Short .class , " SMALLINT" );
69
- STANDARD_MAPPING .put (String .class , " VARCHAR" );
70
- STANDARD_MAPPING .put (Time .class , " TIME" );
71
- STANDARD_MAPPING .put (Timestamp .class , " TIMESTAMP" );
72
- STANDARD_MAPPING .put (URL .class , " DATALINK" );
73
- };
74
-
44
+ STANDARD_MAPPING .put (BigDecimal .class , JdbcType . NUMERIC . name () );
45
+ STANDARD_MAPPING .put (BigInteger .class , JdbcType . BIGINT . name () );
46
+ STANDARD_MAPPING .put (boolean .class , JdbcType . BOOLEAN . name () );
47
+ STANDARD_MAPPING .put (Boolean .class , JdbcType . BOOLEAN . name () );
48
+ STANDARD_MAPPING .put (byte [].class , JdbcType . VARBINARY . name () );
49
+ STANDARD_MAPPING .put (byte .class , JdbcType . TINYINT . name () );
50
+ STANDARD_MAPPING .put (Byte .class , JdbcType . TINYINT . name () );
51
+ STANDARD_MAPPING .put (Calendar .class , JdbcType . TIMESTAMP . name () );
52
+ STANDARD_MAPPING .put (java .sql .Date .class , JdbcType . DATE . name () );
53
+ STANDARD_MAPPING .put (java .util .Date .class , JdbcType . TIMESTAMP . name () );
54
+ STANDARD_MAPPING .put (double .class , JdbcType . DOUBLE . name () );
55
+ STANDARD_MAPPING .put (Double .class , JdbcType . DOUBLE . name () );
56
+ STANDARD_MAPPING .put (float .class , JdbcType . REAL . name () );
57
+ STANDARD_MAPPING .put (Float .class , JdbcType . REAL . name () );
58
+ STANDARD_MAPPING .put (int .class , JdbcType . INTEGER . name () );
59
+ STANDARD_MAPPING .put (Integer .class , JdbcType . INTEGER . name () );
60
+ STANDARD_MAPPING .put (LocalDate .class , JdbcType . DATE . name () );
61
+ STANDARD_MAPPING .put (LocalDateTime .class , JdbcType . TIMESTAMP . name () );
62
+ STANDARD_MAPPING .put (LocalTime .class , JdbcType . TIME . name () );
63
+ STANDARD_MAPPING .put (long .class , JdbcType . BIGINT . name () );
64
+ STANDARD_MAPPING .put (Long .class , JdbcType . BIGINT . name () );
65
+ STANDARD_MAPPING .put (OffsetDateTime .class , JdbcType . TIMESTAMP_WITH_TIMEZONE . name () );
66
+ STANDARD_MAPPING .put (OffsetTime .class , JdbcType . TIME_WITH_TIMEZONE . name () );
67
+ STANDARD_MAPPING .put (Short .class , JdbcType . SMALLINT . name () );
68
+ STANDARD_MAPPING .put (String .class , JdbcType . VARCHAR . name () );
69
+ STANDARD_MAPPING .put (Time .class , JdbcType . TIME . name () );
70
+ STANDARD_MAPPING .put (Timestamp .class , JdbcType . TIMESTAMP . name () );
71
+ STANDARD_MAPPING .put (URL .class , JdbcType . DATALINK . name () );
72
+ }
73
+
75
74
public ArrayTypeHandler () {
76
75
super ();
77
76
}
78
77
79
78
@ Override
80
- protected void setNullParameter (PreparedStatement ps , int i , JdbcType jdbcType ) throws SQLException {
81
- ps .setNull (i , Types .ARRAY );
82
- }
83
-
84
- @ Override
85
- public void setNonNullParameter (PreparedStatement ps , int i , Object parameter , JdbcType jdbcType ) throws SQLException {
79
+ public void setNonNullParameter (PreparedStatement ps , int i , Object parameter , JdbcType jdbcType )
80
+ throws SQLException {
86
81
if (parameter instanceof Array ) {
87
82
// it's the user's responsibility to properly free() the Array instance
88
- ps .setArray (i , (Array )parameter );
89
- }
90
- else {
83
+ ps .setArray (i , (Array ) parameter );
84
+ } else {
91
85
if (!parameter .getClass ().isArray ()) {
92
- throw new TypeException ("ArrayType Handler requires SQL array or java array parameter and does not support type " + parameter .getClass ());
86
+ throw new TypeException (
87
+ "ArrayType Handler requires SQL array or java array parameter and does not support type "
88
+ + parameter .getClass ());
93
89
}
94
90
Class <?> componentType = parameter .getClass ().getComponentType ();
95
91
String arrayTypeName = resolveTypeName (componentType );
96
- Array array = ps .getConnection ().createArrayOf (arrayTypeName , (Object [])parameter );
92
+ Array array = ps .getConnection ().createArrayOf (arrayTypeName , (Object []) parameter );
97
93
ps .setArray (i , array );
98
94
array .free ();
99
95
}
100
96
}
101
97
102
98
protected String resolveTypeName (Class <?> type ) {
103
- return STANDARD_MAPPING .getOrDefault (type , " JAVA_OBJECT" );
99
+ return STANDARD_MAPPING .getOrDefault (type , JdbcType . JAVA_OBJECT . name () );
104
100
}
105
-
101
+
106
102
@ Override
107
103
public Object getNullableResult (ResultSet rs , String columnName ) throws SQLException {
108
104
return extractArray (rs .getArray (columnName ));
0 commit comments