40
40
import static org .tarantool .jdbc .SQLDriver .PROP_SOCKET_TIMEOUT ;
41
41
import static org .tarantool .jdbc .SQLDriver .PROP_USER ;
42
42
43
- @ SuppressWarnings ("Since15" )
43
+ /**
44
+ * Tarantool {@link Connection} implementation
45
+ * <p>
46
+ * Supports creating {@link Statement} and {@link PreparedStatement} instances
47
+ */
44
48
public class SQLConnection implements Connection {
45
49
46
50
private static final int UNSET_HOLDABILITY = 0 ;
@@ -91,6 +95,7 @@ public class SQLConnection implements Connection {
91
95
* to honor this timeout for the following read/write operations as well.
92
96
*
93
97
* @return Connected socket.
98
+ *
94
99
* @throws SQLException if failed.
95
100
*/
96
101
protected Socket getConnectedSocket () throws SQLException {
@@ -140,7 +145,9 @@ protected Socket makeSocket() {
140
145
* @param user User name.
141
146
* @param pass Password.
142
147
* @param socket Connected socket.
148
+ *
143
149
* @return Native tarantool connection.
150
+ *
144
151
* @throws IOException if failed.
145
152
*/
146
153
protected TarantoolConnection makeConnection (String user , String pass , Socket socket ) throws IOException {
@@ -171,7 +178,7 @@ public String nativeSQL(String sql) throws SQLException {
171
178
172
179
@ Override
173
180
public void setAutoCommit (boolean autoCommit ) throws SQLException {
174
- if (autoCommit == false ) {
181
+ if (! autoCommit ) {
175
182
throw new SQLFeatureNotSupportedException ();
176
183
}
177
184
}
@@ -319,7 +326,7 @@ public Statement createStatement(int resultSetType,
319
326
int resultSetConcurrency ,
320
327
int resultSetHoldability ) throws SQLException {
321
328
checkNotClosed ();
322
- checkHoldabilitySupport ( resultSetHoldability );
329
+ checkStatementParams ( resultSetType , resultSetConcurrency , resultSetHoldability );
323
330
return new SQLStatement (this , resultSetType , resultSetConcurrency , resultSetHoldability );
324
331
}
325
332
@@ -329,7 +336,7 @@ public PreparedStatement prepareStatement(String sql,
329
336
int resultSetConcurrency ,
330
337
int resultSetHoldability ) throws SQLException {
331
338
checkNotClosed ();
332
- checkHoldabilitySupport ( resultSetHoldability );
339
+ checkStatementParams ( resultSetType , resultSetConcurrency , resultSetHoldability );
333
340
return new SQLPreparedStatement (this , sql , resultSetType , resultSetConcurrency , resultSetHoldability );
334
341
}
335
342
@@ -540,12 +547,68 @@ private void handleException(Exception e) {
540
547
}
541
548
}
542
549
550
+ /**
551
+ * Checks all params required to make statements
552
+ *
553
+ * @param resultSetType scroll type
554
+ * @param resultSetConcurrency concurrency level
555
+ * @param resultSetHoldability holdability type
556
+ *
557
+ * @throws SQLFeatureNotSupportedException if any param is not supported
558
+ * @throws SQLNonTransientException if any param has an invalid value
559
+ */
560
+ private void checkStatementParams (int resultSetType ,
561
+ int resultSetConcurrency ,
562
+ int resultSetHoldability ) throws SQLException {
563
+ checkResultSetType (resultSetType );
564
+ checkResultSetConcurrency (resultSetType , resultSetConcurrency );
565
+ checkHoldabilitySupport (resultSetHoldability );
566
+ }
567
+
568
+ /**
569
+ * Checks whether <code>resultSetType</code> is supported
570
+ *
571
+ * @param resultSetType param to be checked
572
+ *
573
+ * @throws SQLFeatureNotSupportedException param is not supported
574
+ * @throws SQLNonTransientException param has invalid value
575
+ */
576
+ private void checkResultSetType (int resultSetType ) throws SQLException {
577
+ if (resultSetType != ResultSet .TYPE_FORWARD_ONLY
578
+ && resultSetType != ResultSet .TYPE_SCROLL_INSENSITIVE
579
+ && resultSetType != ResultSet .TYPE_SCROLL_SENSITIVE ) {
580
+ throw new SQLNonTransientException ("" , SQLStates .INVALID_PARAMETER_VALUE .getSqlState ());
581
+ }
582
+ if (!getMetaData ().supportsResultSetType (resultSetType )) {
583
+ throw new SQLFeatureNotSupportedException ();
584
+ }
585
+ }
586
+
587
+ /**
588
+ * Checks whether <code>resultSetType</code> is supported
589
+ *
590
+ * @param resultSetConcurrency param to be checked
591
+ *
592
+ * @throws SQLFeatureNotSupportedException param is not supported
593
+ * @throws SQLNonTransientException param has invalid value
594
+ */
595
+ private void checkResultSetConcurrency (int resultSetType , int resultSetConcurrency ) throws SQLException {
596
+ if (resultSetConcurrency != ResultSet .CONCUR_READ_ONLY
597
+ && resultSetConcurrency != ResultSet .CONCUR_UPDATABLE ) {
598
+ throw new SQLNonTransientException ("" , SQLStates .INVALID_PARAMETER_VALUE .getSqlState ());
599
+ }
600
+ if (!getMetaData ().supportsResultSetConcurrency (resultSetType , resultSetConcurrency )) {
601
+ throw new SQLFeatureNotSupportedException ();
602
+ }
603
+ }
604
+
543
605
/**
544
606
* Checks whether <code>holdability</code> is supported
545
607
*
546
608
* @param holdability param to be checked
609
+ *
547
610
* @throws SQLFeatureNotSupportedException param is not supported
548
- * @throws SQLNonTransientException param has invalid value
611
+ * @throws SQLNonTransientException param has invalid value
549
612
*/
550
613
private void checkHoldabilitySupport (int holdability ) throws SQLException {
551
614
if (holdability != ResultSet .CLOSE_CURSORS_AT_COMMIT
@@ -562,6 +625,7 @@ private void checkHoldabilitySupport(int holdability) throws SQLException {
562
625
*
563
626
* @param sql SQL Text.
564
627
* @param params Parameters of the SQL statement.
628
+ *
565
629
* @return Formatted error message.
566
630
*/
567
631
private static String formatError (String sql , Object ... params ) {
0 commit comments