Skip to content

Commit 9811c23

Browse files
committed
Small api changes
1 parent b04f4be commit 9811c23

File tree

6 files changed

+101
-34
lines changed

6 files changed

+101
-34
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
- docker
66

77
jdk:
8-
- oraclejdk7
8+
# - oraclejdk7
99
- oraclejdk8
1010

1111
env:

pom.xml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@
3030
</dependency>
3131
</dependencies>
3232

33-
<build>
34-
<plugins>
35-
<plugin>
36-
<groupId>net.orfjackal.retrolambda</groupId>
37-
<artifactId>retrolambda-maven-plugin</artifactId>
38-
<version>2.5.1</version>
39-
<executions>
40-
<execution>
41-
<goals>
42-
<goal>process-main</goal>
43-
<goal>process-test</goal>
44-
</goals>
45-
</execution>
46-
</executions>
47-
</plugin>
48-
</plugins>
49-
</build>
33+
<!--<build>-->
34+
<!--<plugins>-->
35+
<!--<plugin>-->
36+
<!--<groupId>net.orfjackal.retrolambda</groupId>-->
37+
<!--<artifactId>retrolambda-maven-plugin</artifactId>-->
38+
<!--<version>2.5.1</version>-->
39+
<!--<executions>-->
40+
<!--<execution>-->
41+
<!--<goals>-->
42+
<!--<goal>process-main</goal>-->
43+
<!--<goal>process-test</goal>-->
44+
<!--</goals>-->
45+
<!--</execution>-->
46+
<!--</executions>-->
47+
<!--</plugin>-->
48+
<!--</plugins>-->
49+
<!--</build>-->
5050

5151
<repositories>
5252
<repository>

src/main/java/io/github/utplsql/OutputBuffer.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import oracle.jdbc.OracleTypes;
44

55
import java.sql.CallableStatement;
6+
import java.sql.PreparedStatement;
67
import java.sql.ResultSet;
78
import java.sql.SQLException;
89
import java.util.ArrayList;
@@ -11,19 +12,54 @@
1112
/**
1213
* Created by Vinicius on 13/04/2017.
1314
*/
14-
public final class OutputBuffer {
15+
public class OutputBuffer {
1516

16-
private OutputBuffer() {}
17+
private String reporterId;
1718

18-
public static List<String> getAllLines(String reporterId) throws SQLException {
19+
public OutputBuffer(String reporterId) {
20+
this.reporterId = reporterId;
21+
}
22+
23+
public String getReporterId() {
24+
return reporterId;
25+
}
26+
27+
public void setReporterId(String reporterId) {
28+
this.reporterId = reporterId;
29+
}
30+
31+
public List<String> getLines() throws SQLException {
32+
PreparedStatement preparedStatement = null;
33+
ResultSet resultSet = null;
34+
try {
35+
preparedStatement = UTPLSQL.getConnection()
36+
.prepareStatement("SELECT * FROM TABLE(ut_output_buffer.get_lines(?, 1))");
37+
38+
preparedStatement.setString(1, getReporterId());
39+
resultSet = preparedStatement.executeQuery();
40+
41+
List<String> outputLines = new ArrayList<>();
42+
while (resultSet.next()) {
43+
outputLines.add(resultSet.getString(1));
44+
}
45+
return outputLines;
46+
} finally {
47+
if (resultSet != null)
48+
resultSet.close();
49+
if (preparedStatement != null)
50+
preparedStatement.close();
51+
}
52+
}
53+
54+
public List<String> getAllLines() throws SQLException {
1955
CallableStatement callableStatement = null;
2056
ResultSet resultSet = null;
2157
try {
2258
callableStatement = UTPLSQL.getConnection()
2359
.prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;");
2460

2561
callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
26-
callableStatement.setString(2, reporterId);
62+
callableStatement.setString(2, getReporterId());
2763
callableStatement.execute();
2864

2965
resultSet = (ResultSet) callableStatement.getObject(1);

src/main/java/io/github/utplsql/TestRunner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
/**
99
* Created by Vinicius Avellar on 12/04/2017.
1010
*/
11-
public final class TestRunner {
11+
public class TestRunner {
1212

13-
private TestRunner() {}
13+
public TestRunner() {}
1414

15-
public static void run() throws SQLException {
15+
public void run() throws SQLException {
1616
CallableStatement callableStatement = null;
1717
try {
1818
callableStatement = UTPLSQL.getConnection()
@@ -24,7 +24,7 @@ public static void run() throws SQLException {
2424
}
2525
}
2626

27-
public static void run(String path, BaseReporter reporter) throws SQLException {
27+
public void run(String path, BaseReporter reporter) throws SQLException {
2828
if (reporter.getReporterId() == null || reporter.getReporterId().isEmpty()) {
2929
reporter.setReporterId(UTPLSQL.newSysGuid());
3030
}

src/test/java/io/github/utplsql/OutputBufferTest.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,48 @@ public class OutputBufferTest {
1818
@ClassRule
1919
public static final DatabaseRule sInitialization = new DatabaseRule();
2020

21+
private BaseReporter currentReporter = null;
22+
23+
public BaseReporter createReporter() throws SQLException {
24+
BaseReporter reporter = new DocumentationReporter();
25+
reporter.setReporterId(UTPLSQL.newSysGuid());
26+
System.out.println("Reporter ID: " + reporter.getReporterId());
27+
return reporter;
28+
}
29+
2130
@Test
2231
public void getLinesFromOutputBuffer() {
2332
try {
24-
BaseReporter reporter = new DocumentationReporter();
25-
reporter.setReporterId(UTPLSQL.newSysGuid());
26-
TestRunner.run("", reporter);
33+
final BaseReporter reporter = createReporter();
34+
// new TestRunner().run("", reporter);
35+
new Thread(() -> {
36+
try {
37+
new TestRunner().run("", reporter);
38+
} catch (SQLException e) {
39+
e.printStackTrace();
40+
}
41+
}).start();
42+
43+
List<String> outputLines = new OutputBuffer(reporter.getReporterId())
44+
.getLines();
45+
46+
for (int i = 0; i < outputLines.size(); i++) {
47+
System.out.println(outputLines.get(i));
48+
}
49+
} catch (SQLException e) {
50+
Assert.fail(e.getMessage());
51+
}
52+
}
53+
54+
@Test
55+
public void getAllLinesFromOutputBuffer() {
56+
try {
57+
final BaseReporter reporter = createReporter();
58+
new TestRunner().run("", reporter);
2759

28-
List<String> outputLines = OutputBuffer.getAllLines(reporter.getReporterId());
60+
List<String> outputLines = new OutputBuffer(reporter.getReporterId())
61+
.getAllLines();
2962

30-
// Debug
31-
System.out.println("Reporter ID: " + reporter.getReporterId());
3263
for (int i = 0; i < outputLines.size(); i++) {
3364
System.out.println(outputLines.get(i));
3465
}

src/test/java/io/github/utplsql/TestRunnerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TestRunnerTest {
2020
@Test
2121
public void runWithoutParams() {
2222
try {
23-
TestRunner.run();
23+
new TestRunner().run();
2424
} catch (SQLException e) {
2525
Assert.fail(e.getMessage());
2626
}
@@ -30,7 +30,7 @@ public void runWithoutParams() {
3030
public void runWithDocumentationReporter() {
3131
try {
3232
BaseReporter reporter = new DocumentationReporter();
33-
TestRunner.run("", reporter);
33+
new TestRunner().run("", reporter);
3434
Assert.assertNotNull(reporter.getReporterId());
3535
} catch (SQLException e) {
3636
Assert.fail(e.getMessage());

0 commit comments

Comments
 (0)