5
5
*/
6
6
package org .elasticsearch .xpack .sql .jdbc .net .client ;
7
7
8
- import org .elasticsearch .action .main .MainResponse ;
9
8
import org .elasticsearch .common .collect .Tuple ;
10
9
import org .elasticsearch .common .unit .TimeValue ;
11
10
import org .elasticsearch .xpack .sql .client .HttpClient ;
12
11
import org .elasticsearch .xpack .sql .jdbc .jdbc .JdbcConfiguration ;
13
12
import org .elasticsearch .xpack .sql .jdbc .net .protocol .ColumnInfo ;
14
13
import org .elasticsearch .xpack .sql .jdbc .net .protocol .InfoResponse ;
15
- import org .elasticsearch .xpack .sql .plugin .AbstractSqlQueryRequest ;
16
- import org .elasticsearch .xpack .sql .plugin .AbstractSqlRequest ;
17
- import org .elasticsearch .xpack .sql .plugin .SqlQueryRequest ;
18
- import org .elasticsearch .xpack .sql .plugin .SqlQueryResponse ;
19
- import org .elasticsearch .xpack .sql .plugin .SqlTypedParamValue ;
14
+ import org .elasticsearch .xpack .sql .proto .Mode ;
15
+ import org .elasticsearch .xpack .sql .proto .Protocol ;
16
+ import org .elasticsearch .xpack .sql .proto .SqlQueryRequest ;
17
+ import org .elasticsearch .xpack .sql .proto .MainResponse ;
18
+ import org .elasticsearch .xpack .sql .proto .SqlQueryResponse ;
19
+ import org .elasticsearch .xpack .sql .proto .SqlTypedParamValue ;
20
20
21
21
import java .sql .SQLException ;
22
22
import java .util .List ;
23
- import java .util .TimeZone ;
24
23
import java .util .stream .Collectors ;
25
24
26
25
import static org .elasticsearch .xpack .sql .client .shared .StringUtils .EMPTY ;
@@ -34,6 +33,10 @@ public class JdbcHttpClient {
34
33
private final JdbcConfiguration conCfg ;
35
34
private InfoResponse serverInfo ;
36
35
36
+ /**
37
+ * The SQLException is the only type of Exception the JDBC API can throw (and that the user expects).
38
+ * If we remove it, we need to make sure no other types of Exceptions (runtime or otherwise) are thrown
39
+ */
37
40
public JdbcHttpClient (JdbcConfiguration conCfg ) throws SQLException {
38
41
httpClient = new HttpClient (conCfg );
39
42
this .conCfg = conCfg ;
@@ -45,9 +48,9 @@ public boolean ping(long timeoutInMs) throws SQLException {
45
48
46
49
public Cursor query (String sql , List <SqlTypedParamValue > params , RequestMeta meta ) throws SQLException {
47
50
int fetch = meta .fetchSize () > 0 ? meta .fetchSize () : conCfg .pageSize ();
48
- SqlQueryRequest sqlRequest = new SqlQueryRequest (AbstractSqlRequest . Mode .JDBC , sql , params , null ,
49
- AbstractSqlQueryRequest . DEFAULT_TIME_ZONE ,
50
- fetch , TimeValue .timeValueMillis (meta .timeoutInMs ()), TimeValue .timeValueMillis (meta .queryTimeoutInMs ()), "" );
51
+ SqlQueryRequest sqlRequest = new SqlQueryRequest (Mode .JDBC , sql , params , null ,
52
+ Protocol . TIME_ZONE ,
53
+ fetch , TimeValue .timeValueMillis (meta .timeoutInMs ()), TimeValue .timeValueMillis (meta .queryTimeoutInMs ()));
51
54
SqlQueryResponse response = httpClient .query (sqlRequest );
52
55
return new DefaultCursor (this , response .cursor (), toJdbcColumnInfo (response .columns ()), response .rows (), meta );
53
56
}
@@ -57,10 +60,8 @@ public Cursor query(String sql, List<SqlTypedParamValue> params, RequestMeta met
57
60
* the scroll id to use to fetch the next page.
58
61
*/
59
62
public Tuple <String , List <List <Object >>> nextPage (String cursor , RequestMeta meta ) throws SQLException {
60
- SqlQueryRequest sqlRequest = new SqlQueryRequest ().cursor (cursor );
61
- sqlRequest .mode (AbstractSqlRequest .Mode .JDBC );
62
- sqlRequest .requestTimeout (TimeValue .timeValueMillis (meta .timeoutInMs ()));
63
- sqlRequest .pageTimeout (TimeValue .timeValueMillis (meta .queryTimeoutInMs ()));
63
+ SqlQueryRequest sqlRequest = new SqlQueryRequest (Mode .JDBC , cursor , TimeValue .timeValueMillis (meta .timeoutInMs ()),
64
+ TimeValue .timeValueMillis (meta .queryTimeoutInMs ()));
64
65
SqlQueryResponse response = httpClient .query (sqlRequest );
65
66
return new Tuple <>(response .cursor (), response .rows ());
66
67
}
@@ -78,13 +79,13 @@ public InfoResponse serverInfo() throws SQLException {
78
79
79
80
private InfoResponse fetchServerInfo () throws SQLException {
80
81
MainResponse mainResponse = httpClient .serverInfo ();
81
- return new InfoResponse (mainResponse .getClusterName (). value () , mainResponse .getVersion ().major , mainResponse .getVersion ().minor );
82
+ return new InfoResponse (mainResponse .getClusterName (), mainResponse .getVersion ().major , mainResponse .getVersion ().minor );
82
83
}
83
84
84
85
/**
85
86
* Converts REST column metadata into JDBC column metadata
86
87
*/
87
- private List <ColumnInfo > toJdbcColumnInfo (List <org .elasticsearch .xpack .sql .plugin .ColumnInfo > columns ) {
88
+ private List <ColumnInfo > toJdbcColumnInfo (List <org .elasticsearch .xpack .sql .proto .ColumnInfo > columns ) {
88
89
return columns .stream ().map (columnInfo ->
89
90
new ColumnInfo (columnInfo .name (), columnInfo .jdbcType (), EMPTY , EMPTY , EMPTY , EMPTY , columnInfo .displaySize ())
90
91
).collect (Collectors .toList ());
0 commit comments