Skip to content

Commit 3d48df7

Browse files
authored
Merge pull request #52 from utPLSQL/bugfix/adjustable_fetchsize
Bugfix/adjustable fetchsize
2 parents 8b3d668 + 3cb54cc commit 3d48df7

File tree

6 files changed

+79
-1
lines changed

6 files changed

+79
-1
lines changed

src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import org.utplsql.api.Version;
44
import org.utplsql.api.exception.InvalidVersionException;
55

6+
import java.sql.Connection;
7+
import java.sql.SQLException;
8+
69
public enum OptionalFeatures {
710

811
FAIL_ON_ERROR("3.0.3", null),
@@ -33,4 +36,9 @@ public boolean isAvailableFor(Version version ) {
3336
return false; // We have no optional features for invalid versions
3437
}
3538
}
39+
40+
public boolean isAvailableFor(Connection conn) throws SQLException {
41+
CompatibilityProxy proxy = new CompatibilityProxy(conn);
42+
return isAvailableFor(proxy.getDatabaseVersion());
43+
}
3644
}

src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
abstract class AbstractOutputBuffer implements OutputBuffer {
2121

2222
private Reporter reporter;
23+
private int fetchSize = 100;
2324

2425
/**
2526
* Creates a new DefaultOutputBuffer.
@@ -40,6 +41,11 @@ public Reporter getReporter() {
4041
return reporter;
4142
}
4243

44+
@Override
45+
public void setFetchSize(int fetchSize) {
46+
this.fetchSize = fetchSize;
47+
}
48+
4349
/**
4450
* Print the lines as soon as they are produced and write to a PrintStream.
4551
* @param conn DB connection
@@ -77,7 +83,7 @@ public void fetchAvailable(Connection conn, Consumer<String> onLineFetched) thro
7783

7884
try (CallableStatement cstmt = getLinesCursorStatement(conn)) {
7985
cstmt.execute();
80-
cstmt.setFetchSize(1);
86+
cstmt.setFetchSize(fetchSize);
8187

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

99105
cstmt.execute();
106+
cstmt.setFetchSize(fetchSize);
100107

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

src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public Reporter getReporter() {
2626
return reporter;
2727
}
2828

29+
@Override
30+
public void setFetchSize(int fetchSize) {
31+
32+
}
33+
2934
@Override
3035
public void printAvailable(Connection conn, PrintStream ps) throws SQLException {
3136
List<PrintStream> printStreams = new ArrayList<>(1);

src/main/java/org/utplsql/api/outputBuffer/OutputBuffer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ public interface OutputBuffer {
1212

1313
Reporter getReporter();
1414

15+
/** Override the fetchSize of the OutputBuffer
16+
*
17+
* @param fetchSize the ResultSet fetch-size.
18+
*/
19+
void setFetchSize( int fetchSize );
20+
1521
/**
1622
* Print the lines as soon as they are produced and write to a PrintStream.
1723
* @param conn DB connection
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.utplsql.api;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.utplsql.api.compatibility.CompatibilityProxy;
5+
import org.utplsql.api.compatibility.OptionalFeatures;
6+
import org.utplsql.api.exception.InvalidVersionException;
7+
8+
import java.sql.SQLException;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
12+
public class OptionalFeaturesIT extends AbstractDatabaseTest {
13+
14+
15+
private Version getDatabaseVersion() throws SQLException {
16+
return new CompatibilityProxy(getConnection()).getDatabaseVersion();
17+
}
18+
19+
@Test
20+
public void failOnError() throws SQLException, InvalidVersionException {
21+
22+
boolean available = OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(getConnection());
23+
24+
if (getDatabaseVersion().isGreaterOrEqualThan(new Version("3.0.3")))
25+
assertEquals(true, available);
26+
else
27+
assertEquals(false, available);
28+
}
29+
30+
@Test
31+
public void frameworkCompatibilityCheck() throws SQLException, InvalidVersionException {
32+
33+
boolean available = OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(getConnection());
34+
35+
if (getDatabaseVersion().isGreaterOrEqualThan(new Version("3.0.3")))
36+
assertEquals(true, available);
37+
else
38+
assertEquals(false, available);
39+
}
40+
41+
@Test
42+
public void customReporters() throws SQLException, InvalidVersionException {
43+
44+
boolean available = OptionalFeatures.CUSTOM_REPORTERS.isAvailableFor(getConnection());
45+
46+
if (getDatabaseVersion().isGreaterOrEqualThan(new Version("3.1.0")))
47+
assertEquals(true, available);
48+
else
49+
assertEquals(false, available);
50+
}
51+
}

src/test/java/org/utplsql/api/OutputBufferIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void printAvailableLines() throws SQLException {
5959
printStreams.add(System.out);
6060
printStreams.add(new PrintStream(fileOutStream));
6161

62+
reporter.getOutputBuffer().setFetchSize(1);
6263
reporter.getOutputBuffer().printAvailable(newConnection(), printStreams);
6364

6465
return Boolean.TRUE;

0 commit comments

Comments
 (0)