-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
PostgresType.java
150 lines (137 loc) · 3.97 KB
/
PostgresType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2023 Airbyte, Inc., all rights reserved.
*/
package io.airbyte.integrations.source.postgres;
import java.sql.SQLType;
import java.sql.Types;
import java.util.Map;
public enum PostgresType implements SQLType {
BIT(Types.BIT),
TINYINT(Types.TINYINT),
SMALLINT(Types.SMALLINT),
INTEGER(Types.INTEGER),
BIGINT(Types.BIGINT),
FLOAT(Types.FLOAT),
REAL(Types.REAL),
DOUBLE(Types.DOUBLE),
NUMERIC(Types.NUMERIC),
DECIMAL(Types.DECIMAL),
CHAR(Types.CHAR),
VARCHAR(Types.VARCHAR),
LONGVARCHAR(Types.LONGVARCHAR),
DATE(Types.DATE),
TIME(Types.TIME),
TIMESTAMP(Types.TIMESTAMP),
BINARY(Types.BINARY),
VARBINARY(Types.VARBINARY),
LONGVARBINARY(Types.LONGVARBINARY),
NULL(Types.NULL),
OTHER(Types.OTHER),
JAVA_OBJECT(Types.JAVA_OBJECT),
DISTINCT(Types.DISTINCT),
STRUCT(Types.STRUCT),
ARRAY(Types.ARRAY),
BLOB(Types.BLOB),
CLOB(Types.CLOB),
REF(Types.REF),
DATALINK(Types.DATALINK),
BOOLEAN(Types.BOOLEAN),
ROWID(Types.ROWID),
NCHAR(Types.NCHAR),
NVARCHAR(Types.NVARCHAR),
LONGNVARCHAR(Types.LONGNVARCHAR),
NCLOB(Types.NCLOB),
SQLXML(Types.SQLXML),
REF_CURSOR(Types.REF_CURSOR),
TIME_WITH_TIMEZONE(Types.TIME_WITH_TIMEZONE),
TIMESTAMP_WITH_TIMEZONE(Types.TIMESTAMP_WITH_TIMEZONE),
VARCHAR_ARRAY(Types.ARRAY),
TEXT_ARRAY(Types.ARRAY),
INTEGER_ARRAY(Types.ARRAY),
NUMERIC_ARRAY(Types.ARRAY),
TIMESTAMPTZ_ARRAY(Types.ARRAY),
TIMESTAMP_ARRAY(Types.ARRAY),
TIMETZ_ARRAY(Types.ARRAY),
TIME_ARRAY(Types.ARRAY),
DATE_ARRAY(Types.ARRAY),
BIT_ARRAY(Types.ARRAY),
BOOL_ARRAY(Types.ARRAY),
NAME_ARRAY(Types.ARRAY),
CHAR_ARRAY(Types.ARRAY),
BPCHAR_ARRAY(Types.ARRAY),
INT4_ARRAY(Types.ARRAY),
INT2_ARRAY(Types.ARRAY),
INT8_ARRAY(Types.ARRAY),
MONEY_ARRAY(Types.ARRAY),
OID_ARRAY(Types.ARRAY),
FLOAT4_ARRAY(Types.ARRAY),
FLOAT8_ARRAY(Types.ARRAY),
BYTEA_ARRAY(Types.ARRAY);
/**
* The Integer value for the JDBCType. It maps to a value in {@code Types.java}
*/
protected Integer type;
/**
* Constructor to specify the data type value from {@code Types) for
* this data type. @param type The value from {@code Types) for this data type
*/
PostgresType(final Integer type) {
this.type = type;
}
/**
* {@inheritDoc }
*
* @return The name of this {@code SQLType}.
*/
public String getName() {
return name();
}
/**
* Returns the name of the vendor that supports this data type.
*
* @return The name of the vendor for this data type which is {@literal java.sql} for JDBCType.
*/
public String getVendor() {
return "java.sql";
}
/**
* Returns the vendor specific type number for the data type.
*
* @return An Integer representing the data type. For {@code JDBCType}, the value will be the same
* value as in {@code Types} for the data type.
*/
public Integer getVendorTypeNumber() {
return type;
}
/**
* Returns true if the PostgresType is an array type, false otherwise.
*
* @return true if the PostgresType is an array type, false otherwise.
*/
public boolean isArrayType() {
return type == Types.ARRAY;
}
/**
* Returns the {@code JDBCType} that corresponds to the specified {@code Types} value
*
* @param type {@code Types} value
* @return The {@code JDBCType} constant
* @throws IllegalArgumentException if this enum type has no constant with the specified
* {@code Types} value
* @see Types
*/
public static PostgresType valueOf(final int type, final Map<Integer, PostgresType> postgresTypeMap) {
if (postgresTypeMap.containsKey(type)) {
return postgresTypeMap.get(type);
}
throw new IllegalArgumentException("Type:" + type + " is not a valid "
+ "Types.java value.");
}
public static PostgresType safeGetJdbcType(final int columnTypeInt, final Map<Integer, PostgresType> postgresTypeMap) {
try {
return PostgresType.valueOf(columnTypeInt, postgresTypeMap);
} catch (final Exception e) {
return PostgresType.VARCHAR;
}
}
}