Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b98edf

Browse files
committed
Initial work on OutputBuffer abstraction
1 parent08ffc6a commit3b98edf

13 files changed

+203
-127
lines changed

‎src/main/java/org/utplsql/api/CustomTypes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public final class CustomTypes {
1818
publicstaticfinalStringUT_COVERAGE_SONAR_REPORTER ="UT_COVERAGE_SONAR_REPORTER";
1919
publicstaticfinalStringUT_SONAR_TEST_REPORTER ="UT_SONAR_TEST_REPORTER";
2020

21+
publicstaticfinalStringUT_OUTPUT_BUFFER_BASE ="UT_OUTPUT_BUFFER_BASE";
22+
publicstaticfinalStringUT_OUTPUT_TABLE_BUFFER ="UT_OUTPUT_TABLE_BUFFER";
23+
2124
publicstaticfinalStringUT_FILE_MAPPING ="UT_FILE_MAPPING";
2225
publicstaticfinalStringUT_FILE_MAPPINGS ="UT_FILE_MAPPINGS";
2326

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

Lines changed: 19 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,41 @@
11
packageorg.utplsql.api;
22

3-
importorg.utplsql.api.reporter.Reporter;
4-
importoracle.jdbc.OracleTypes;
5-
63
importjava.io.PrintStream;
74
importjava.sql.*;
8-
importjava.util.ArrayList;
95
importjava.util.List;
106

11-
/**
12-
* Fetches the lines produced by a reporter.
13-
*/
14-
publicclassOutputBuffer {
7+
publicabstractclassOutputBufferimplementsSQLData {
158

16-
privateReporterreporter;
9+
privateStringoutputId;
1710

18-
/**
19-
* Creates a new OutputBuffer.
20-
* @param reporter the reporter to be used
21-
*/
22-
publicOutputBuffer(Reporterreporter) {
23-
this.reporter =reporter;
11+
publicOutputBuffer(StringoutputId) {
12+
this.outputId =outputId;
2413
}
2514

26-
/**
27-
* Returns the reporter used by this buffer.
28-
* @return the reporter instance
29-
*/
30-
publicReportergetReporter() {
31-
returnreporter;
15+
publicStringgetOutputId() {
16+
returnoutputId;
3217
}
3318

34-
/**
35-
* Print the lines as soon as they are produced and write to a PrintStream.
36-
* @param conn DB connection
37-
* @param ps the PrintStream to be used, e.g: System.out
38-
* @throws SQLException any sql errors
39-
*/
40-
publicvoidprintAvailable(Connectionconn,PrintStreamps)throwsSQLException {
41-
List<PrintStream>printStreams =newArrayList<>(1);
42-
printStreams.add(ps);
43-
printAvailable(conn,printStreams);
19+
privatevoidsetOutputId(StringoutputId) {
20+
this.outputId =outputId;
4421
}
4522

46-
/**
47-
* Print the lines as soon as they are produced and write to a list of PrintStreams.
48-
* @param conn DB connection
49-
* @param printStreams the PrintStream list to be used, e.g: System.out, new PrintStream(new FileOutputStream)
50-
* @throws SQLException any sql errors
51-
*/
52-
publicvoidprintAvailable(Connectionconn,List<PrintStream>printStreams)throwsSQLException {
53-
fetchAvailable(conn,s -> {
54-
for (PrintStreamps :printStreams)
55-
ps.println(s);
56-
});
57-
}
23+
publicabstractvoidprintAvailable(Connectionconn,PrintStreamps)throwsSQLException;
5824

59-
/**
60-
* Print the lines as soon as they are produced and call the callback passing the new line.
61-
* @param conn DB connection
62-
* @param cb the callback to be called
63-
* @throws SQLException any sql errors
64-
*/
65-
publicvoidfetchAvailable(Connectionconn,Callbackcb)throwsSQLException {
66-
PreparedStatementpreparedStatement =null;
67-
ResultSetresultSet =null;
68-
try {
69-
preparedStatement =conn.prepareStatement("SELECT * FROM table(ut_output_buffer.get_lines(?))");
70-
preparedStatement.setString(1,getReporter().getReporterId());
71-
resultSet =preparedStatement.executeQuery();
25+
publicabstractvoidprintAvailable(Connectionconn,List<PrintStream>printStreams)throwsSQLException;
7226

73-
while (resultSet.next())
74-
cb.onLineFetched(resultSet.getString(1));
75-
}finally {
76-
if (resultSet !=null)
77-
resultSet.close();
78-
if (preparedStatement !=null)
79-
preparedStatement.close();
80-
}
81-
}
27+
publicabstractvoidfetchAvailable(Connectionconn,Callbackcb)throwsSQLException;
8228

83-
/**
84-
* Get all lines from output buffer and return it as a list of strings.
85-
* @param conn DB connection
86-
* @return the lines
87-
* @throws SQLException any sql errors
88-
*/
89-
publicList<String>fetchAll(Connectionconn)throwsSQLException {
90-
CallableStatementcallableStatement =null;
91-
ResultSetresultSet =null;
92-
try {
93-
callableStatement =conn.prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;");
94-
callableStatement.registerOutParameter(1,OracleTypes.CURSOR);
95-
callableStatement.setString(2,getReporter().getReporterId());
96-
callableStatement.execute();
29+
publicabstractList<String>fetchAll(Connectionconn)throwsSQLException;
9730

98-
resultSet = (ResultSet)callableStatement.getObject(1);
31+
@Override
32+
publicvoidreadSQL(SQLInputstream,StringtypeName)throwsSQLException {
33+
setOutputId(stream.readString());
34+
}
9935

100-
List<String>outputLines =newArrayList<>();
101-
while (resultSet.next()) {
102-
outputLines.add(resultSet.getString("text"));
103-
}
104-
returnoutputLines;
105-
}finally {
106-
if (resultSet !=null)
107-
resultSet.close();
108-
if (callableStatement !=null)
109-
callableStatement.close();
110-
}
36+
@Override
37+
publicvoidwriteSQL(SQLOutputstream)throwsSQLException {
38+
stream.writeString(getOutputId());
11139
}
11240

11341
/**
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
packageorg.utplsql.api;
2+
3+
importoracle.jdbc.OracleTypes;
4+
5+
importjava.io.PrintStream;
6+
importjava.sql.*;
7+
importjava.util.ArrayList;
8+
importjava.util.Calendar;
9+
importjava.util.List;
10+
11+
publicclassTableOutputBufferextendsOutputBuffer {
12+
13+
privatejava.sql.DatestartDate;
14+
15+
publicTableOutputBuffer(StringoutputId) {
16+
super(outputId);
17+
setStartDate(newjava.sql.Date(Calendar.getInstance().getTimeInMillis()));
18+
}
19+
20+
publicDategetStartDate() {
21+
returnstartDate;
22+
}
23+
24+
privatevoidsetStartDate(DatestartDate) {
25+
this.startDate =startDate;
26+
}
27+
28+
@Override
29+
publicStringgetSQLTypeName()throwsSQLException {
30+
returnCustomTypes.UT_OUTPUT_TABLE_BUFFER;
31+
}
32+
33+
@Override
34+
publicvoidreadSQL(SQLInputstream,StringtypeName)throwsSQLException {
35+
super.readSQL(stream,typeName);
36+
setStartDate(stream.readDate());
37+
}
38+
39+
@Override
40+
publicvoidwriteSQL(SQLOutputstream)throwsSQLException {
41+
super.writeSQL(stream);
42+
stream.writeDate(getStartDate());
43+
}
44+
45+
/**
46+
* Print the lines as soon as they are produced and write to a PrintStream.
47+
* @param conn DB connection
48+
* @param ps the PrintStream to be used, e.g: System.out
49+
* @throws SQLException any sql errors
50+
*/
51+
publicvoidprintAvailable(Connectionconn,PrintStreamps)throwsSQLException {
52+
List<PrintStream>printStreams =newArrayList<>(1);
53+
printStreams.add(ps);
54+
printAvailable(conn,printStreams);
55+
}
56+
57+
/**
58+
* Print the lines as soon as they are produced and write to a list of PrintStreams.
59+
* @param conn DB connection
60+
* @param printStreams the PrintStream list to be used, e.g: System.out, new PrintStream(new FileOutputStream)
61+
* @throws SQLException any sql errors
62+
*/
63+
publicvoidprintAvailable(Connectionconn,List<PrintStream>printStreams)throwsSQLException {
64+
fetchAvailable(conn,s -> {
65+
for (PrintStreamps :printStreams)
66+
ps.println(s);
67+
});
68+
}
69+
70+
/**
71+
* Print the lines as soon as they are produced and call the callback passing the new line.
72+
* @param conn DB connection
73+
* @param cb the callback to be called
74+
* @throws SQLException any sql errors
75+
*/
76+
publicvoidfetchAvailable(Connectionconn,OutputBuffer.Callbackcb)throwsSQLException {
77+
PreparedStatementpreparedStatement =null;
78+
ResultSetresultSet =null;
79+
try {
80+
preparedStatement =conn.prepareStatement("SELECT * FROM table(ut_output_table_buffer(?).get_lines())");
81+
preparedStatement.setString(1,getOutputId());
82+
resultSet =preparedStatement.executeQuery();
83+
84+
while (resultSet.next())
85+
cb.onLineFetched(resultSet.getString(1));
86+
}finally {
87+
if (resultSet !=null)
88+
resultSet.close();
89+
if (preparedStatement !=null)
90+
preparedStatement.close();
91+
}
92+
}
93+
94+
/**
95+
* Get all lines from output buffer and return it as a list of strings.
96+
* @param conn DB connection
97+
* @return the lines
98+
* @throws SQLException any sql errors
99+
*/
100+
publicList<String>fetchAll(Connectionconn)throwsSQLException {
101+
CallableStatementcallableStatement =null;
102+
ResultSetresultSet =null;
103+
try {
104+
callableStatement =conn.prepareCall("BEGIN ? := ut_output_table_buffer(?).get_lines_cursor(); END;");
105+
callableStatement.registerOutParameter(1,OracleTypes.CURSOR);
106+
callableStatement.setString(2,getOutputId());
107+
callableStatement.execute();
108+
109+
resultSet = (ResultSet)callableStatement.getObject(1);
110+
111+
List<String>outputLines =newArrayList<>();
112+
while (resultSet.next()) {
113+
outputLines.add(resultSet.getString("text"));
114+
}
115+
returnoutputLines;
116+
}finally {
117+
if (resultSet !=null)
118+
resultSet.close();
119+
if (callableStatement !=null)
120+
callableStatement.close();
121+
}
122+
}
123+
124+
}

‎src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
importjava.sql.SQLInput;
77
importjava.sql.SQLOutput;
88

9-
publicclassCoverageHTMLReporterextendsReporter {
9+
publicclassCoverageHTMLReporterextendsOutputReporter {
1010

1111
// Could override Reporter.init and call ut_coverage_report_html_helper.get_default_html_assets_path from database,
1212
// but had permissions issues.

‎src/main/java/org/utplsql/api/reporter/CoverageSonarReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
importjava.sql.SQLException;
66

7-
publicclassCoverageSonarReporterextendsReporter {
7+
publicclassCoverageSonarReporterextendsOutputReporter {
88

99
@Override
1010
publicStringgetSQLTypeName()throwsSQLException {

‎src/main/java/org/utplsql/api/reporter/CoverallsReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
importjava.sql.SQLException;
66

7-
publicclassCoverallsReporterextendsReporter {
7+
publicclassCoverallsReporterextendsOutputReporter {
88

99
@Override
1010
publicStringgetSQLTypeName()throwsSQLException {

‎src/main/java/org/utplsql/api/reporter/DocumentationReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
importjava.sql.SQLInput;
77
importjava.sql.SQLOutput;
88

9-
publicclassDocumentationReporterextendsReporter {
9+
publicclassDocumentationReporterextendsOutputReporter {
1010

1111
privateintlvl;
1212
privateintfailed;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
packageorg.utplsql.api.reporter;
2+
3+
importorg.utplsql.api.CustomTypes;
4+
importorg.utplsql.api.DBHelper;
5+
importorg.utplsql.api.OutputBuffer;
6+
importorg.utplsql.api.TableOutputBuffer;
7+
8+
importjava.sql.Connection;
9+
importjava.sql.SQLException;
10+
11+
publicclassOutputReporterextendsReporter {
12+
13+
privateOutputBufferoutputBuffer;
14+
15+
publicOutputReporterinit(Connectionconn)throwsSQLException {
16+
returninit(conn,newTableOutputBuffer(DBHelper.newSysGuid(conn)));
17+
}
18+
19+
publicOutputReporterinit(Connectionconn,OutputBufferoutputBuffer)throwsSQLException {
20+
super.init(conn);
21+
setOutputBuffer(outputBuffer);
22+
returnthis;
23+
}
24+
25+
publicOutputBuffergetOutputBuffer() {
26+
returnoutputBuffer;
27+
}
28+
29+
publicvoidsetOutputBuffer(OutputBufferoutputBuffer) {
30+
this.outputBuffer =outputBuffer;
31+
}
32+
33+
@Override
34+
publicStringgetSQLTypeName()throwsSQLException {
35+
returnCustomTypes.UT_OUTPUT_TABLE_BUFFER;
36+
}
37+
38+
}
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
packageorg.utplsql.api.reporter;
22

3-
importorg.utplsql.api.DBHelper;
4-
53
importjava.sql.*;
6-
importjava.util.Calendar;
74

85
/**
96
* Created by Vinicius on 13/04/2017.
@@ -12,14 +9,12 @@ public abstract class Reporter implements SQLData {
129

1310
privateStringselfType;
1411
privateStringreporterId;
15-
privatejava.sql.DatestartDate;
1612

1713
publicReporter() {}
1814

1915
publicReporterinit(Connectionconn)throwsSQLException {
2016
setSelfType(getSQLTypeName());
21-
setStartDate(newjava.sql.Date(Calendar.getInstance().getTimeInMillis()));
22-
setReporterId(DBHelper.newSysGuid(conn));
17+
setReporterId(null);
2318
returnthis;
2419
}
2520

@@ -39,26 +34,16 @@ private void setReporterId(String reporterId) {
3934
this.reporterId =reporterId;
4035
}
4136

42-
publicjava.sql.DategetStartDate() {
43-
returnthis.startDate;
44-
}
45-
46-
privatevoidsetStartDate(java.sql.DatestartDate) {
47-
this.startDate =startDate;
48-
}
49-
5037
@Override
5138
publicvoidreadSQL(SQLInputstream,StringtypeName)throwsSQLException {
5239
setSelfType(stream.readString());
5340
setReporterId(stream.readString());
54-
setStartDate(stream.readDate());
5541
}
5642

5743
@Override
5844
publicvoidwriteSQL(SQLOutputstream)throwsSQLException {
5945
stream.writeString(getSelfType());
6046
stream.writeString(getReporterId());
61-
stream.writeDate(getStartDate());
6247
}
6348

6449
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp