5
5
6
6
import java .sql .ResultSetMetaData ;
7
7
import java .sql .SQLException ;
8
- import java .sql .SQLFeatureNotSupportedException ;
9
8
import java .sql .SQLNonTransientException ;
10
- import java .sql .Types ;
11
9
import java .util .List ;
12
10
13
11
public class SQLResultSetMetaData implements ResultSetMetaData {
14
12
15
13
private final List <SqlProtoUtils .SQLMetaData > sqlMetadata ;
14
+ private final boolean readOnly ;
16
15
17
- public SQLResultSetMetaData (List <SqlProtoUtils .SQLMetaData > sqlMetaData ) {
16
+ public SQLResultSetMetaData (List <SqlProtoUtils .SQLMetaData > sqlMetaData , boolean readOnly ) {
18
17
this .sqlMetadata = sqlMetaData ;
18
+ this .readOnly = readOnly ;
19
19
}
20
20
21
21
@ Override
@@ -25,37 +25,59 @@ public int getColumnCount() throws SQLException {
25
25
26
26
@ Override
27
27
public boolean isAutoIncrement (int column ) throws SQLException {
28
- throw new SQLFeatureNotSupportedException ();
28
+ checkColumnIndex (column );
29
+ // extra flag or, at least table ID is required in meta
30
+ // to be able to fetch an the flag indirectly.
31
+ return false ;
29
32
}
30
33
31
34
@ Override
32
35
public boolean isCaseSensitive (int column ) throws SQLException {
33
- throw new SQLFeatureNotSupportedException ();
36
+ checkColumnIndex (column );
37
+ return sqlMetadata .get (column - 1 ).getType ().isCaseSensitive ();
34
38
}
35
39
40
+ /**
41
+ * {@inheritDoc}
42
+ * <p>
43
+ * All the types can be used in {@literal WHERE} clause.
44
+ */
36
45
@ Override
37
46
public boolean isSearchable (int column ) throws SQLException {
38
- throw new SQLFeatureNotSupportedException ();
47
+ checkColumnIndex (column );
48
+ return true ;
39
49
}
40
50
51
+ /**
52
+ * {@inheritDoc}
53
+ * <p>
54
+ * Always {@literal false} because
55
+ * Tarantool does not have monetary types.
56
+ */
41
57
@ Override
42
58
public boolean isCurrency (int column ) throws SQLException {
43
- throw new SQLFeatureNotSupportedException ();
59
+ checkColumnIndex (column );
60
+ return false ;
44
61
}
45
62
46
63
@ Override
47
64
public int isNullable (int column ) throws SQLException {
48
- throw new SQLFeatureNotSupportedException ();
65
+ checkColumnIndex (column );
66
+ // extra nullability flag or, at least table ID is required in meta
67
+ // to be able to fetch an the flag indirectly.
68
+ return ResultSetMetaData .columnNullableUnknown ;
49
69
}
50
70
51
71
@ Override
52
72
public boolean isSigned (int column ) throws SQLException {
53
- throw new SQLFeatureNotSupportedException ();
73
+ checkColumnIndex (column );
74
+ return sqlMetadata .get (column - 1 ).getType ().isSigned ();
54
75
}
55
76
56
77
@ Override
57
78
public int getColumnDisplaySize (int column ) throws SQLException {
58
- throw new SQLFeatureNotSupportedException ();
79
+ checkColumnIndex (column );
80
+ return sqlMetadata .get (column - 1 ).getType ().getDisplaySize ();
59
81
}
60
82
61
83
@ Override
@@ -64,6 +86,15 @@ public String getColumnLabel(int column) throws SQLException {
64
86
return sqlMetadata .get (column - 1 ).getName ();
65
87
}
66
88
89
+ /**
90
+ * {@inheritDoc}
91
+ * <p>
92
+ * Name always has the same value as label
93
+ * because Tarantool does not differentiate
94
+ * column names and aliases.
95
+ *
96
+ * @see #getColumnLabel(int)
97
+ */
67
98
@ Override
68
99
public String getColumnName (int column ) throws SQLException {
69
100
checkColumnIndex (column );
@@ -72,65 +103,77 @@ public String getColumnName(int column) throws SQLException {
72
103
73
104
@ Override
74
105
public String getSchemaName (int column ) throws SQLException {
75
- return null ;
106
+ checkColumnIndex (column );
107
+ return "" ;
76
108
}
77
109
78
110
@ Override
79
111
public int getPrecision (int column ) throws SQLException {
80
- throw new SQLFeatureNotSupportedException ();
112
+ checkColumnIndex (column );
113
+ return sqlMetadata .get (column - 1 ).getType ().getPrecision ();
81
114
}
82
115
116
+
83
117
@ Override
84
118
public int getScale (int column ) throws SQLException {
85
- throw new SQLFeatureNotSupportedException ();
119
+ checkColumnIndex (column );
120
+ return sqlMetadata .get (column - 1 ).getType ().getScale ();
86
121
}
87
122
88
123
@ Override
89
124
public String getTableName (int column ) throws SQLException {
90
- throw new SQLFeatureNotSupportedException ();
125
+ checkColumnIndex (column );
126
+ // extra table name or, at least table ID is required in meta
127
+ // to be able to fetch the table name.
128
+ return "" ;
91
129
}
92
130
93
131
@ Override
94
132
public String getCatalogName (int column ) throws SQLException {
95
- return null ;
133
+ checkColumnIndex (column );
134
+ return "" ;
96
135
}
97
136
98
137
@ Override
99
138
public int getColumnType (int column ) throws SQLException {
100
- return Types .OTHER ;
139
+ checkColumnIndex (column );
140
+ return sqlMetadata .get (column - 1 ).getType ().getJdbcType ().getTypeNumber ();
101
141
}
102
142
103
143
@ Override
104
144
public String getColumnTypeName (int column ) throws SQLException {
105
- return "scalar" ;
145
+ checkColumnIndex (column );
146
+ return sqlMetadata .get (column - 1 ).getType ().getTypeName ();
106
147
}
107
148
108
149
@ Override
109
150
public boolean isReadOnly (int column ) throws SQLException {
110
- throw new SQLFeatureNotSupportedException ();
151
+ checkColumnIndex (column );
152
+ return readOnly ;
111
153
}
112
154
113
155
@ Override
114
156
public boolean isWritable (int column ) throws SQLException {
115
- throw new SQLFeatureNotSupportedException ( );
157
+ return ! isReadOnly ( column );
116
158
}
117
159
118
160
@ Override
119
161
public boolean isDefinitelyWritable (int column ) throws SQLException {
120
- throw new SQLFeatureNotSupportedException () ;
162
+ return false ;
121
163
}
122
164
123
165
@ Override
124
166
public String getColumnClassName (int column ) throws SQLException {
125
- throw new SQLFeatureNotSupportedException ();
167
+ checkColumnIndex (column );
168
+ return sqlMetadata .get (column - 1 ).getType ().getJdbcType ().getJavaType ().getName ();
126
169
}
127
170
128
171
@ Override
129
172
public <T > T unwrap (Class <T > type ) throws SQLException {
130
173
if (isWrapperFor (type )) {
131
174
return type .cast (this );
132
175
}
133
- throw new SQLNonTransientException ("ResultSetMetadata does not wrap " + type .getName ());
176
+ throw new SQLNonTransientException ("SQLResultSetMetadata does not wrap " + type .getName ());
134
177
}
135
178
136
179
@ Override
@@ -150,7 +193,7 @@ void checkColumnIndex(int columnIndex) throws SQLException {
150
193
@ Override
151
194
public String toString () {
152
195
return "SQLResultSetMetaData{" +
153
- "sqlMetadata=" + sqlMetadata +
154
- '}' ;
196
+ "sqlMetadata=" + sqlMetadata +
197
+ '}' ;
155
198
}
156
199
}
0 commit comments