Skip to content

Commit

Permalink
Merge 45265c5 into 56f1d41
Browse files Browse the repository at this point in the history
  • Loading branch information
wenweibin committed Sep 22, 2020
2 parents 56f1d41 + 45265c5 commit 176fb3e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
Expand Up @@ -39,6 +39,8 @@ public abstract class AbstractStatementAdapter extends AbstractUnsupportedOperat
private boolean poolable;

private int fetchSize;

private int fecthDirection;

private final ForceExecuteTemplate<Statement> forceExecuteTemplate = new ForceExecuteTemplate<>();

Expand Down Expand Up @@ -83,6 +85,18 @@ public final void setFetchSize(final int rows) throws SQLException {
recordMethodInvocation(targetClass, "setFetchSize", new Class[] {int.class}, new Object[] {rows});
forceExecuteTemplate.execute((Collection) getRoutedStatements(), statement -> statement.setFetchSize(rows));
}

@Override
public int getFetchDirection() throws SQLException {
return fecthDirection;
}

@Override
public void setFetchDirection(final int direction) throws SQLException {
this.fecthDirection = direction;
recordMethodInvocation(targetClass, "setFetchDirection", new Class[] {int.class}, new Object[] {direction});
forceExecuteTemplate.execute((Collection) getRoutedStatements(), statement -> statement.setFetchDirection(direction));
}

@SuppressWarnings("unchecked")
@Override
Expand Down
Expand Up @@ -27,17 +27,7 @@
* Unsupported {@code Statement} methods.
*/
public abstract class AbstractUnsupportedOperationStatement extends WrapperAdapter implements Statement {

@Override
public final int getFetchDirection() throws SQLException {
throw new SQLFeatureNotSupportedException("getFetchDirection");
}

@Override
public final void setFetchDirection(final int direction) throws SQLException {
throw new SQLFeatureNotSupportedException("setFetchDirection");
}


@Override
public final void addBatch(final String sql) throws SQLException {
throw new SQLFeatureNotSupportedException("addBatch sql");
Expand Down
Expand Up @@ -121,7 +121,26 @@ private void assertFetchSize(final ShardingSphereStatement actual, final int fet
assertThat(each.getFetchSize(), is(fetchSize));
}
}


@Test
public void assertSetFetchDirection() throws SQLException {
for (Statement each : statements.values()) {
each.setFetchDirection(ResultSet.FETCH_FORWARD);
each.executeQuery(sql);
assertFetchDirection((ShardingSphereStatement) each, ResultSet.FETCH_FORWARD);
each.setFetchDirection(ResultSet.FETCH_REVERSE);
assertFetchDirection((ShardingSphereStatement) each, ResultSet.FETCH_REVERSE);
}
}

private void assertFetchDirection(final ShardingSphereStatement actual, final int fetchDirection) throws SQLException {
assertThat(actual.getFetchDirection(), is(fetchDirection));
for (Statement each : actual.getRoutedStatements()) {
// H2,MySQL getFetchDirection() always return ResultSet.FETCH_FORWARD
assertThat(each.getFetchDirection(), is(ResultSet.FETCH_FORWARD));
}
}

@Test
public void assertSetEscapeProcessing() throws SQLException {
for (Statement each : statements.values()) {
Expand Down
Expand Up @@ -23,7 +23,6 @@
import org.junit.Before;
import org.junit.Test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
Expand Down Expand Up @@ -52,21 +51,7 @@ public void close() throws SQLException {
each.close();
}
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertGetFetchDirection() throws SQLException {
for (Statement each : statements) {
each.getFetchDirection();
}
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetFetchDirection() throws SQLException {
for (Statement each : statements) {
each.setFetchDirection(ResultSet.FETCH_UNKNOWN);
}
}


@Test(expected = SQLFeatureNotSupportedException.class)
public void assertAddBatch() throws SQLException {
for (Statement each : statements) {
Expand Down
Expand Up @@ -23,6 +23,7 @@

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;

/**
Expand Down Expand Up @@ -97,7 +98,16 @@ public void setFetchSize(final int rows) {
public int getFetchSize() {
return 0;
}


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

@Override
public void setFetchDirection(final int direction) throws SQLException {
}

@Override
public int getResultSetConcurrency() {
return ResultSet.CONCUR_READ_ONLY;
Expand Down

0 comments on commit 176fb3e

Please sign in to comment.