11/*
2- * Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
2+ * Copyright (c) 2011-2022 Contributors to the Eclipse Foundation
33 *
44 * This program and the accompanying materials are made available under the
55 * terms of the Eclipse Public License 2.0 which is available at
1010 */
1111package io .vertx .oracleclient .impl ;
1212
13+ import io .netty .util .collection .IntObjectHashMap ;
14+ import io .netty .util .collection .IntObjectMap ;
1315import io .vertx .sqlclient .desc .ColumnDescriptor ;
1416import io .vertx .sqlclient .impl .RowDesc ;
17+ import oracle .sql .TIMESTAMPTZ ;
1518
1619import java .sql .JDBCType ;
1720import java .sql .ResultSetMetaData ;
1821import java .sql .SQLException ;
1922import java .util .ArrayList ;
23+ import java .util .HashMap ;
2024import java .util .List ;
25+ import java .util .Map ;
2126
2227public class OracleColumnDesc implements ColumnDescriptor {
2328
29+ private static final IntObjectMap <JDBCType > TYPES_BY_VENDOR_TYPE_NUMBER ;
30+ private static final Map <String , JDBCType > TYPES_BY_CLASSNAME ;
31+
32+ static {
33+ TYPES_BY_VENDOR_TYPE_NUMBER = new IntObjectHashMap <>();
34+ for (JDBCType type : JDBCType .values ()) {
35+ TYPES_BY_VENDOR_TYPE_NUMBER .put (type .getVendorTypeNumber (), type );
36+ }
37+ TYPES_BY_CLASSNAME = new HashMap <>();
38+ TYPES_BY_CLASSNAME .put (TIMESTAMPTZ .class .getName (), JDBCType .TIMESTAMP_WITH_TIMEZONE );
39+ }
40+
2441 public static RowDesc rowDesc (ResultSetMetaData metaData ) throws SQLException {
2542 int cols = metaData .getColumnCount ();
2643 List <String > columnNames = new ArrayList <>(cols );
@@ -37,18 +54,19 @@ public static RowDesc rowDesc(ResultSetMetaData metaData) throws SQLException {
3754 private final JDBCType type ;
3855
3956 public OracleColumnDesc (ResultSetMetaData md , int idx ) throws SQLException {
40- this . name = md .getColumnLabel (idx );
41- this . typeName = md .getColumnTypeName (idx );
42- this . type = find (md . getColumnType ( idx ) );
57+ name = md .getColumnLabel (idx );
58+ typeName = md .getColumnTypeName (idx );
59+ type = find (md , idx );
4360 }
4461
45- private static JDBCType find (int vendorTypeNumber ) {
46- for (JDBCType jdbcType : JDBCType .values ()) {
47- if (jdbcType .getVendorTypeNumber () == vendorTypeNumber ) {
48- return jdbcType ;
62+ private JDBCType find (ResultSetMetaData md , int idx ) throws SQLException {
63+ JDBCType res ;
64+ if ((res = TYPES_BY_VENDOR_TYPE_NUMBER .get (md .getColumnType (idx ))) == null ) {
65+ if ((res = TYPES_BY_CLASSNAME .get (md .getColumnClassName (idx ))) == null ) {
66+ res = JDBCType .OTHER ;
4967 }
5068 }
51- return JDBCType . OTHER ;
69+ return res ;
5270 }
5371
5472 @ Override
0 commit comments