Skip to content

Commit

Permalink
Allow custom slq statements in PreparedStatement, but without paramet…
Browse files Browse the repository at this point in the history
…ers substitution
  • Loading branch information
dxahtepb committed Aug 2, 2020
1 parent 843b0f5 commit 2660a86
Show file tree
Hide file tree
Showing 4 changed files with 556 additions and 8 deletions.
15 changes: 8 additions & 7 deletions driver/src/main/java/com/intellij/CouchbaseBaseStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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

@SuppressWarnings("RedundantThrows")
public abstract class CouchbaseBaseStatement implements Statement {
protected final Cluster cluster;
protected final Properties properties;
Expand Down Expand Up @@ -56,7 +57,7 @@ void checkClosed() throws SQLException {
}

@Override
public boolean isClosed() {
public boolean isClosed() throws SQLException {
return isClosed;
}

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

@Override
public boolean getMoreResults() {
public boolean getMoreResults() throws SQLException {
return false;
}

Expand Down Expand Up @@ -145,7 +146,7 @@ public int getMaxRows() throws SQLException {
}

@Override
public void setMaxRows(int max) {
public void setMaxRows(int max) throws SQLException {
// todo
}

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

@Override
public SQLWarning getWarnings() {
public SQLWarning getWarnings() throws SQLException {
return null; // todo
}

@Override
public void clearWarnings() {
public void clearWarnings() throws SQLException {
// todo
}

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

@Override
public int getFetchDirection() {
public int getFetchDirection() throws SQLException {
return ResultSet.FETCH_FORWARD;
}

@Override
public void setFetchSize(int rows) {
public void setFetchSize(int rows) throws SQLException {
this.fetchSize = rows;
}

Expand Down
11 changes: 10 additions & 1 deletion driver/src/main/java/com/intellij/CouchbaseConnection.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.intellij;

import com.couchbase.client.java.Cluster;
import com.intellij.executor.CouchbaseCustomStatementExecutor;
import org.jetbrains.annotations.NotNull;

import java.sql.Array;
Expand All @@ -11,6 +12,7 @@
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
Expand Down Expand Up @@ -92,6 +94,9 @@ public Statement createStatement(int resultSetType, int resultSetConcurrency, in
public PreparedStatement prepareStatement(String sql) throws SQLException {
checkClosed();
try {
if (CouchbaseCustomStatementExecutor.mayExecute(sql)) {
return new CouchbaseNoParamsPrepared(sql, new CouchbaseStatement(cluster, properties, isReadOnly));
}
return new CouchbasePreparedStatement(cluster, sql, properties, isReadOnly);
} catch (Throwable t) {
throw new SQLException(t.getMessage(), t);
Expand Down Expand Up @@ -195,7 +200,11 @@ public void clearWarnings() throws SQLException {
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency) throws SQLException {
throw new SQLFeatureNotSupportedException();
checkClosed();
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
throw new SQLFeatureNotSupportedException();
}
return prepareStatement(sql);
}

@Override
Expand Down
Loading

0 comments on commit 2660a86

Please sign in to comment.