Skip to content

Commit

Permalink
Merge pull request #111 from aws/lyndon/fix-false-positive-cancellati…
Browse files Browse the repository at this point in the history
…on-exception

Fix for false positive exception on statement shutdown
  • Loading branch information
lyndonbauto authored Dec 15, 2021
2 parents d3819b7 + b317955 commit 5c6df45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/main/java/software/aws/neptune/jdbc/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void addBatch(final String sql) throws SQLException {
@Override
public void cancel() throws SQLException {
verifyOpen();
queryExecutor.cancelQuery();
queryExecutor.cancelQuery(false);
}

@Override
Expand All @@ -87,8 +87,7 @@ public void close() throws SQLException {
if (!this.isClosed.getAndSet(true)) {
LOGGER.debug("Cancelling running queries.");
try {
// TODO: Only cancel if query currently in progress?
queryExecutor.cancelQuery();
queryExecutor.cancelQuery(true);
} catch (final SQLException e) {
LOGGER.warn("Error occurred while closing Statement. Failed to cancel running query: '"
+ e.getMessage() + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@ protected <T> java.sql.ResultSet runCancellableQuery(final Constructor<?> constr
}
}
}
//
// project("country","region","elev","elev","elev","elev","lat","lat","lat","lat")
// .choose(__.has("country"),__.values("country"),__.constant(""))
// .choose(__.has("region"),__.values("region"),__.constant(""))
// Sub traversal:
// unfold().choose(__.has("elev"),__.values("elev"),__.constant(""))

private void resetQueryState() {
queryState = QueryState.NOT_STARTED;
Expand All @@ -217,9 +211,12 @@ private void resetQueryState() {
*
* @throws SQLException if query cancellation fails.
*/
public void cancelQuery() throws SQLException {
public void cancelQuery(final boolean isClosing) throws SQLException {
synchronized (lock) {
if (queryState.equals(QueryState.NOT_STARTED)) {
if (isClosing) {
return;
}
throw SqlError.createSQLException(
LOGGER,
SqlState.OPERATION_CANCELED,
Expand Down

0 comments on commit 5c6df45

Please sign in to comment.