1
1
package org .zalando .typemapper .core .db ;
2
2
3
+ import com .google .common .base .Preconditions ;
4
+ import com .google .common .collect .ImmutableMap ;
5
+ import org .slf4j .Logger ;
6
+ import org .slf4j .LoggerFactory ;
7
+
3
8
import java .sql .Connection ;
4
9
import java .sql .PreparedStatement ;
5
10
import java .sql .ResultSet ;
6
11
import java .sql .SQLException ;
7
-
8
12
import java .util .Arrays ;
9
13
import java .util .HashMap ;
10
14
import java .util .LinkedList ;
13
17
import java .util .Map .Entry ;
14
18
import java .util .concurrent .ConcurrentHashMap ;
15
19
16
- import org .slf4j .Logger ;
17
- import org .slf4j .LoggerFactory ;
18
-
19
- import com .google .common .base .Preconditions ;
20
- import com .google .common .collect .ImmutableMap ;
21
-
22
20
public class DbTypeRegister {
23
21
24
22
private static final Logger LOG = LoggerFactory .getLogger (DbTypeRegister .class );
@@ -36,18 +34,18 @@ public class DbTypeRegister {
36
34
37
35
private final Map <String , String > typeFQN ;
38
36
39
- private final Map <Integer , String > typeIdToFQN ;
37
+ private final Map <Long , String > typeIdToFQN ;
40
38
41
39
public DbTypeRegister (final Connection connection ) throws SQLException {
42
40
PreparedStatement statement = null ;
43
41
ResultSet resultSet = null ;
44
42
try {
45
43
searchPath = getSearchPath (connection );
46
- typeByName = new HashMap <String , DbType >();
44
+ typeByName = new HashMap <>();
47
45
48
46
typeIdToFQN = new ConcurrentHashMap <>();
49
47
50
- final HashMap <String , List <String >> typeNameToFQN = new HashMap <String , List < String > >();
48
+ final HashMap <String , List <String >> typeNameToFQN = new HashMap <>();
51
49
52
50
//J-
53
51
statement = connection .prepareStatement (
@@ -81,15 +79,15 @@ public DbTypeRegister(final Connection connection) throws SQLException {
81
79
int i = 1 ;
82
80
final String typeSchema = resultSet .getString (i ++);
83
81
final String typeName = resultSet .getString (i ++);
84
- final int typeId = resultSet .getInt (i ++);
82
+ final long typeId = resultSet .getLong (i ++);
85
83
final String typeType = resultSet .getString (i ++);
86
84
final String fieldName = resultSet .getString (i ++);
87
85
final String fieldType = resultSet .getString (i ++);
88
86
final String fieldTypeName = resultSet .getString (i ++);
89
- final int fieldTypeId = resultSet .getInt (i ++);
87
+ final long fieldTypeId = resultSet .getLong (i ++);
90
88
final int fieldPosition = resultSet .getInt (i ++);
91
89
final boolean isArray = resultSet .getBoolean (i ++);
92
- final int typeElem = resultSet .getInt (i ++);
90
+ final long typeElem = resultSet .getLong (i ++);
93
91
94
92
addField (typeSchema , typeName , typeId , fieldName , fieldPosition , fieldType , fieldTypeName , fieldTypeId ,
95
93
typeType , isArray , typeNameToFQN , typeElem );
@@ -123,10 +121,10 @@ public Map<String, DbType> getTypes() {
123
121
return typeByName ;
124
122
}
125
123
126
- private void addField (final String typeSchema , final String typeName , final int typeId , final String fieldName ,
127
- final int fieldPosition , final String fieldType , final String fieldTypeName , final int fieldTypeId ,
128
- final String typeType , final boolean isArray , final Map <String , List <String >> typeNameToFQN ,
129
- final int typeElem ) {
124
+ private void addField (final String typeSchema , final String typeName , final long typeId , final String fieldName ,
125
+ final int fieldPosition , final String fieldType , final String fieldTypeName , final long fieldTypeId ,
126
+ final String typeType , final boolean isArray , final Map <String , List <String >> typeNameToFQN ,
127
+ final long typeElem ) {
130
128
131
129
if (isArray ) {
132
130
@@ -210,7 +208,7 @@ public static DbType getDbType(final String name, final Connection connection) t
210
208
return fqName == null ? null : register .typeByName .get (fqName );
211
209
}
212
210
213
- public static DbType getDbType (final int id , final Connection connection ) throws SQLException {
211
+ public static DbType getDbType (final long id , final Connection connection ) throws SQLException {
214
212
final DbTypeRegister register = getRegistry (connection );
215
213
DbType type = null ;
216
214
@@ -241,7 +239,7 @@ public static DbType getDbType(final int id, final Connection connection) throws
241
239
PreparedStatement ps = null ;
242
240
try {
243
241
ps = connection .prepareStatement (sql );
244
- ps .setInt (1 , id );
242
+ ps .setLong (1 , id );
245
243
res = ps .executeQuery ();
246
244
if (res .next ()) {
247
245
typeFQN = getTypeIdentifier (res .getString (1 ), res .getString (2 ));
0 commit comments