Skip to content

Bugfix/adjustable fetchsize #52

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.utplsql.api.Version;
import org.utplsql.api.exception.InvalidVersionException;

import java.sql.Connection;
import java.sql.SQLException;

public enum OptionalFeatures {

FAIL_ON_ERROR("3.0.3", null),
Expand Down Expand Up @@ -33,4 +36,9 @@ public boolean isAvailableFor(Version version ) {
return false; // We have no optional features for invalid versions
}
}

public boolean isAvailableFor(Connection conn) throws SQLException {
CompatibilityProxy proxy = new CompatibilityProxy(conn);
return isAvailableFor(proxy.getDatabaseVersion());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
abstract class AbstractOutputBuffer implements OutputBuffer {

private Reporter reporter;
private int fetchSize = 100;

/**
* Creates a new DefaultOutputBuffer.
Expand All @@ -40,6 +41,11 @@ public Reporter getReporter() {
return reporter;
}

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

/**
* Print the lines as soon as they are produced and write to a PrintStream.
* @param conn DB connection
Expand Down Expand Up @@ -77,7 +83,7 @@ public void fetchAvailable(Connection conn, Consumer<String> onLineFetched) thro

try (CallableStatement cstmt = getLinesCursorStatement(conn)) {
cstmt.execute();
cstmt.setFetchSize(1);
cstmt.setFetchSize(fetchSize);

try ( ResultSet resultSet = (ResultSet) cstmt.getObject(1)) {
while (resultSet.next())
Expand All @@ -97,6 +103,7 @@ public List<String> fetchAll(Connection conn) throws SQLException {
try (CallableStatement cstmt = getLinesCursorStatement(conn)) {

cstmt.execute();
cstmt.setFetchSize(fetchSize);

try ( ResultSet resultSet = (ResultSet) cstmt.getObject(1)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public Reporter getReporter() {
return reporter;
}

@Override
public void setFetchSize(int fetchSize) {

}

@Override
public void printAvailable(Connection conn, PrintStream ps) throws SQLException {
List<PrintStream> printStreams = new ArrayList<>(1);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/utplsql/api/outputBuffer/OutputBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public interface OutputBuffer {

Reporter getReporter();

/** Override the fetchSize of the OutputBuffer
*
* @param fetchSize the ResultSet fetch-size.
*/
void setFetchSize( int fetchSize );

/**
* Print the lines as soon as they are produced and write to a PrintStream.
* @param conn DB connection
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/org/utplsql/api/OptionalFeaturesIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.utplsql.api;

import org.junit.jupiter.api.Test;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.compatibility.OptionalFeatures;
import org.utplsql.api.exception.InvalidVersionException;

import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class OptionalFeaturesIT extends AbstractDatabaseTest {


private Version getDatabaseVersion() throws SQLException {
return new CompatibilityProxy(getConnection()).getDatabaseVersion();
}

@Test
public void failOnError() throws SQLException, InvalidVersionException {

boolean available = OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(getConnection());

if (getDatabaseVersion().isGreaterOrEqualThan(new Version("3.0.3")))
assertEquals(true, available);
else
assertEquals(false, available);
}

@Test
public void frameworkCompatibilityCheck() throws SQLException, InvalidVersionException {

boolean available = OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(getConnection());

if (getDatabaseVersion().isGreaterOrEqualThan(new Version("3.0.3")))
assertEquals(true, available);
else
assertEquals(false, available);
}

@Test
public void customReporters() throws SQLException, InvalidVersionException {

boolean available = OptionalFeatures.CUSTOM_REPORTERS.isAvailableFor(getConnection());

if (getDatabaseVersion().isGreaterOrEqualThan(new Version("3.1.0")))
assertEquals(true, available);
else
assertEquals(false, available);
}
}
1 change: 1 addition & 0 deletions src/test/java/org/utplsql/api/OutputBufferIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void printAvailableLines() throws SQLException {
printStreams.add(System.out);
printStreams.add(new PrintStream(fileOutStream));

reporter.getOutputBuffer().setFetchSize(1);
reporter.getOutputBuffer().printAvailable(newConnection(), printStreams);

return Boolean.TRUE;
Expand Down