Skip to content

Commit 880aeba

Browse files
committed
Extracted based logic of result set to BaseYdbResultSet
1 parent a449973 commit 880aeba

File tree

10 files changed

+465
-419
lines changed

10 files changed

+465
-419
lines changed

jdbc/src/main/java/tech/ydb/jdbc/YdbResultSet.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,10 @@
22

33
import java.sql.ResultSet;
44
import java.sql.SQLException;
5-
import java.util.Optional;
65

7-
import tech.ydb.table.result.ResultSetReader;
86
import tech.ydb.table.values.Value;
97

108
public interface YdbResultSet extends ResultSet {
11-
12-
/**
13-
* Return YDB result set reader for direct processing
14-
*
15-
* @return YDB original result set reader
16-
*/
17-
ResultSetReader getYdbResultSetReader();
18-
19-
//
20-
219
/**
2210
* Returns native YDB value, extracted from optional value.
2311
* Please note that this method will create value object for each method call.
@@ -26,7 +14,7 @@ public interface YdbResultSet extends ResultSet {
2614
* @return value if available; return empty if value is optional and no value provided
2715
* @throws SQLException if column cannot be read
2816
*/
29-
Optional<Value<?>> getNativeColumn(int columnIndex) throws SQLException;
17+
Value<?> getNativeColumn(int columnIndex) throws SQLException;
3018

3119
/**
3220
* Return native YDB value.
@@ -36,7 +24,7 @@ public interface YdbResultSet extends ResultSet {
3624
* @return value if available
3725
* @throws SQLException if column cannot be read
3826
*/
39-
Optional<Value<?>> getNativeColumn(String columnLabel) throws SQLException;
27+
Value<?> getNativeColumn(String columnLabel) throws SQLException;
4028

4129
//
4230

jdbc/src/main/java/tech/ydb/jdbc/YdbResultSetMetaData.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import java.sql.ResultSetMetaData;
44
import java.sql.SQLException;
5-
import java.util.ArrayList;
6-
import java.util.Collection;
7-
import java.util.List;
85

96
import tech.ydb.table.values.Type;
107

@@ -15,31 +12,7 @@ public interface YdbResultSetMetaData extends ResultSetMetaData {
1512
*
1613
* @param column column, 1..N
1714
* @return YDB type
15+
* @throws java.sql.SQLException
1816
*/
1917
Type getYdbType(int column) throws SQLException;
20-
21-
/**
22-
* Returns column index by it's name, could be useful sometimes; basically because in YDB you should always
23-
* work with names (columns or parameters), indexes are just internal details
24-
*
25-
* @param columnName column name to find
26-
* @return column (1..N)
27-
* @throws SQLException if column is unknown
28-
*/
29-
int getColumnIndex(String columnName) throws SQLException;
30-
31-
/**
32-
* Returns all column names
33-
*
34-
* @return column names
35-
* @throws SQLException in case something bad happens
36-
*/
37-
default Collection<String> getColumnNames() throws SQLException {
38-
int count = getColumnCount();
39-
List<String> columns = new ArrayList<>(count);
40-
for (int i = 0; i < count; i++) {
41-
columns.add(getColumnName(i + 1));
42-
}
43-
return columns;
44-
}
4518
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package tech.ydb.jdbc.common;
2+
3+
import tech.ydb.table.values.PrimitiveType;
4+
import tech.ydb.table.values.Type;
5+
6+
/**
7+
*
8+
* @author Aleksandr Gorshenin
9+
*/
10+
public class ColumnInfo {
11+
private final String name;
12+
private final Type ydbType;
13+
private final MappingGetters.SqlType sqlType;
14+
private final MappingGetters.Getters getters;
15+
16+
private final boolean isOptional;
17+
private final boolean isTimestamp;
18+
private final boolean isNumber;
19+
private final boolean isNull;
20+
21+
public ColumnInfo(String name, Type type) {
22+
this.name = name;
23+
24+
TypeDescription desc = TypeDescription.of(type);
25+
this.sqlType = desc.sqlType();
26+
this.getters = desc.getters();
27+
this.isOptional = desc.isOptional();
28+
this.ydbType = desc.ydbType();
29+
30+
this.isTimestamp = type == PrimitiveType.Timestamp;
31+
this.isNumber = type == PrimitiveType.Int8 || type == PrimitiveType.Uint8
32+
|| type == PrimitiveType.Int16 || type == PrimitiveType.Uint16
33+
|| type == PrimitiveType.Int32 || type == PrimitiveType.Uint32
34+
|| type == PrimitiveType.Int64 || type == PrimitiveType.Uint64;
35+
this.isNull = type.getKind() == Type.Kind.NULL || type.getKind() == Type.Kind.VOID;
36+
}
37+
38+
public String getName() {
39+
return this.name;
40+
}
41+
42+
public Type getYdbType() {
43+
return this.ydbType;
44+
}
45+
46+
public boolean isNull() {
47+
return isNull;
48+
}
49+
50+
public boolean isTimestamp() {
51+
return isTimestamp;
52+
}
53+
54+
public boolean isNumber() {
55+
return isNumber;
56+
}
57+
58+
public boolean isOptional() {
59+
return isOptional;
60+
}
61+
62+
public MappingGetters.SqlType getSqlType() {
63+
return this.sqlType;
64+
}
65+
66+
public MappingGetters.Getters getGetters() {
67+
return this.getters;
68+
}
69+
}

0 commit comments

Comments
 (0)