Skip to content

Commit 2660a86

Browse files
committed
Allow custom slq statements in PreparedStatement, but without parameters substitution
1 parent 843b0f5 commit 2660a86

File tree

4 files changed

+556
-8
lines changed

4 files changed

+556
-8
lines changed

Diff for: driver/src/main/java/com/intellij/CouchbaseBaseStatement.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static com.intellij.DriverPropertyInfoHelper.ScanConsistency.getQueryScanConsistency;
2222

23+
@SuppressWarnings("RedundantThrows")
2324
public abstract class CouchbaseBaseStatement implements Statement {
2425
protected final Cluster cluster;
2526
protected final Properties properties;
@@ -56,7 +57,7 @@ void checkClosed() throws SQLException {
5657
}
5758

5859
@Override
59-
public boolean isClosed() {
60+
public boolean isClosed() throws SQLException {
6061
return isClosed;
6162
}
6263

@@ -79,7 +80,7 @@ protected void setNewResultSet(@Nullable ResultSet resultSet) throws SQLExceptio
7980
}
8081

8182
@Override
82-
public boolean getMoreResults() {
83+
public boolean getMoreResults() throws SQLException {
8384
return false;
8485
}
8586

@@ -145,7 +146,7 @@ public int getMaxRows() throws SQLException {
145146
}
146147

147148
@Override
148-
public void setMaxRows(int max) {
149+
public void setMaxRows(int max) throws SQLException {
149150
// todo
150151
}
151152

@@ -170,12 +171,12 @@ public void cancel() throws SQLException {
170171
}
171172

172173
@Override
173-
public SQLWarning getWarnings() {
174+
public SQLWarning getWarnings() throws SQLException {
174175
return null; // todo
175176
}
176177

177178
@Override
178-
public void clearWarnings() {
179+
public void clearWarnings() throws SQLException {
179180
// todo
180181
}
181182

@@ -191,12 +192,12 @@ public void setFetchDirection(int direction) throws SQLException {
191192
}
192193

193194
@Override
194-
public int getFetchDirection() {
195+
public int getFetchDirection() throws SQLException {
195196
return ResultSet.FETCH_FORWARD;
196197
}
197198

198199
@Override
199-
public void setFetchSize(int rows) {
200+
public void setFetchSize(int rows) throws SQLException {
200201
this.fetchSize = rows;
201202
}
202203

Diff for: driver/src/main/java/com/intellij/CouchbaseConnection.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.intellij;
22

33
import com.couchbase.client.java.Cluster;
4+
import com.intellij.executor.CouchbaseCustomStatementExecutor;
45
import org.jetbrains.annotations.NotNull;
56

67
import java.sql.Array;
@@ -11,6 +12,7 @@
1112
import java.sql.DatabaseMetaData;
1213
import java.sql.NClob;
1314
import java.sql.PreparedStatement;
15+
import java.sql.ResultSet;
1416
import java.sql.SQLException;
1517
import java.sql.SQLFeatureNotSupportedException;
1618
import java.sql.SQLWarning;
@@ -92,6 +94,9 @@ public Statement createStatement(int resultSetType, int resultSetConcurrency, in
9294
public PreparedStatement prepareStatement(String sql) throws SQLException {
9395
checkClosed();
9496
try {
97+
if (CouchbaseCustomStatementExecutor.mayExecute(sql)) {
98+
return new CouchbaseNoParamsPrepared(sql, new CouchbaseStatement(cluster, properties, isReadOnly));
99+
}
95100
return new CouchbasePreparedStatement(cluster, sql, properties, isReadOnly);
96101
} catch (Throwable t) {
97102
throw new SQLException(t.getMessage(), t);
@@ -195,7 +200,11 @@ public void clearWarnings() throws SQLException {
195200
@Override
196201
public PreparedStatement prepareStatement(String sql, int resultSetType,
197202
int resultSetConcurrency) throws SQLException {
198-
throw new SQLFeatureNotSupportedException();
203+
checkClosed();
204+
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
205+
throw new SQLFeatureNotSupportedException();
206+
}
207+
return prepareStatement(sql);
199208
}
200209

201210
@Override

0 commit comments

Comments
 (0)