← 返回首页
Refactored Reporter to be more clear · utPLSQL/utPLSQL-java-api@2593fd7 · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Commit 2593fd7

Browse files
committed
Refactored Reporter to be more clear
1 parent fdb940b commit 2593fd7

4 files changed

Lines changed: 105 additions & 47 deletions

File tree

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.utplsql.api.reporter;
22

3-
import org.utplsql.api.CustomTypes;
43
import org.utplsql.api.ResourceUtil;
54

65
import java.io.IOException;
@@ -9,9 +8,6 @@
98
import java.nio.file.Files;
109
import java.nio.file.Path;
1110
import java.nio.file.Paths;
12-
import java.sql.SQLException;
13-
import java.sql.SQLInput;
14-
import java.sql.SQLOutput;
1511
import java.util.List;
1612
import java.util.function.Consumer;
1713

@@ -32,6 +28,26 @@ public CoverageHTMLReporter(String selfType, Object[] attributes) {
3228
super(selfType, attributes);
3329
}
3430

31+
@Override
32+
protected void setAttributes(Object[] attributes) {
33+
super.setAttributes(attributes);
34+
35+
if ( attributes != null ) {
36+
projectName = String.valueOf(attributes[3]);
37+
assetsPath = String.valueOf(attributes[4]);
38+
}
39+
}
40+
41+
@Override
42+
protected Object[] getAttributes() {
43+
Object[] attributes = super.getAttributes();
44+
45+
attributes[3] = projectName;
46+
attributes[4] = assetsPath;
47+
48+
return attributes;
49+
}
50+
3551
public String getProjectName() {
3652
return projectName;
3753
}

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.utplsql.api.reporter;
22

3-
import java.sql.SQLException;
4-
import java.sql.SQLInput;
5-
import java.sql.SQLOutput;
3+
import java.math.BigDecimal;
64

75
public class DocumentationReporter extends Reporter {
86

@@ -17,6 +15,24 @@ public DocumentationReporter(String selfType, Object[] attributes ) {
1715
super(selfType, attributes);
1816
}
1917

18+
@Override
19+
protected void setAttributes(Object[] attributes) {
20+
super.setAttributes(attributes);
21+
22+
if ( attributes != null ) {
23+
lvl = ((BigDecimal)attributes[3]).intValue();
24+
failed = ((BigDecimal)attributes[4]).intValue();
25+
}
26+
}
27+
28+
@Override
29+
protected Object[] getAttributes() {
30+
Object[] attributes = super.getAttributes();
31+
attributes[3] = lvl;
32+
attributes[4] = failed;
33+
return attributes;
34+
}
35+
2036
public int getLvl() {
2137
return lvl;
2238
}

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

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,24 @@
77
import oracle.sql.ORAData;
88
import oracle.sql.STRUCT;
99
import oracle.sql.StructDescriptor;
10-
import org.utplsql.api.DBHelper;
1110

1211
import java.sql.*;
13-
import java.util.Calendar;
1412

15-
/**
16-
* Created by Vinicius on 13/04/2017.
13+
/** This is a basic Reporter implementation, using ORAData interface
14+
*
15+
* @author pesse
1716
*/
1817
public class Reporter implements ORAData {
1918

20-
protected String selfType;
21-
protected String id;
22-
protected Object[] attributes;
19+
private String selfType;
20+
private String id;
21+
private Object[] attributes;
22+
private boolean hasOutput = false;
23+
private boolean init = false;
2324

2425
public Reporter( String typeName, Object[] attributes ) {
25-
selfType = typeName;
26-
27-
if ( attributes != null ) {
28-
this.id = String.valueOf(attributes[1]);
29-
}
30-
this.attributes = attributes;
26+
setTypeName(typeName);
27+
setAttributes( attributes );
3128
}
3229

3330
private void setTypeName( String typeName ) {
@@ -42,19 +39,69 @@ public Reporter init( Connection con ) throws SQLException {
4239

4340
OracleConnection oraConn = con.unwrap(OracleConnection.class);
4441

42+
initDbReporter( oraConn );
43+
initHasOutput( oraConn );
44+
45+
init = true;
46+
47+
return this;
48+
}
49+
50+
/** Initializes the Reporter from database
51+
* This is necessary because we set up OutputBuffer (and maybe other stuff) we don't want to know and care about
52+
* in the java API. Let's just do the instantiation of the Reporter in the database and map it into this object.
53+
*
54+
* @param oraConn
55+
* @throws SQLException
56+
*/
57+
private void initDbReporter( OracleConnection oraConn ) throws SQLException {
4558
OracleCallableStatement callableStatement = (OracleCallableStatement) oraConn.prepareCall("{? = call " + selfType + "()}");
4659
callableStatement.registerOutParameter(1, OracleTypes.STRUCT, "UT_REPORTER_BASE");
4760
callableStatement.execute();
4861

4962
Reporter obj = (Reporter) callableStatement.getORAData(1, ReporterFactory.getInstance());
5063

51-
// TODO: Really override things
52-
this.attributes = obj.attributes;
64+
setAttributes(obj.getAttributes());
65+
}
66+
67+
/** Checks whether the Reporter has an output or not
68+
*
69+
* @param oraConn
70+
* @throws SQLException
71+
*/
72+
private void initHasOutput( OracleConnection oraConn ) throws SQLException {
73+
OracleCallableStatement cstmt = (OracleCallableStatement)oraConn.prepareCall("{? = call ?.has_output()}");
74+
75+
cstmt.registerOutParameter(1, OracleTypes.INTEGER);
76+
cstmt.setORAData(2, this);
77+
cstmt.execute();
78+
79+
Integer i = cstmt.getInt(1);
80+
if ( i != null && i == 1 ) {
81+
hasOutput = true;
82+
}
83+
else {
84+
hasOutput = false;
85+
}
86+
}
5387

54-
// Check whether we have output or not
88+
protected void setAttributes(Object[] attributes ) {
89+
if (attributes != null) {
90+
this.id = String.valueOf(attributes[1]);
91+
}
92+
this.attributes = attributes;
93+
}
5594

95+
protected Object[] getAttributes() {
96+
return attributes;
97+
}
5698

57-
return this;
99+
public boolean hasOutput() {
100+
return hasOutput;
101+
}
102+
103+
public boolean isInit() {
104+
return init;
58105
}
59106

60107
public String getTypeName() {
@@ -69,8 +116,8 @@ public String getId() {
69116
public Datum toDatum(Connection c) throws SQLException
70117
{
71118
StructDescriptor sd =
72-
StructDescriptor.createDescriptor(selfType, c);
73-
return new STRUCT(sd, c, attributes);
119+
StructDescriptor.createDescriptor(getTypeName(), c);
120+
return new STRUCT(sd, c, getAttributes());
74121
}
75122

76123
}

‎src/test/java/org/utplsql/api/OraDataIT.java‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,8 @@ public void myTest2() throws SQLException {
2020

2121
OracleConnection oraConn = getConnection().unwrap(OracleConnection.class);
2222

23-
/*String sql = "{? = call ut_documentation_reporter()}";
24-
25-
OracleCallableStatement callableStatement = null;
26-
27-
callableStatement = (OracleCallableStatement) oraConn.prepareCall(sql);
28-
callableStatement.registerOutParameter(1, OracleTypes.STRUCT, "UT_REPORTER_BASE");
29-
//callableStatement.registerOutParameter(1, OracleTypes.REF, "UT_REPORTER_BASE");
30-
callableStatement.execute();
31-
32-
Reporter obj = (Reporter) callableStatement.getORAData(1, ReporterFactory.getInstance());
33-
34-
*/
3523
Reporter obj = new DocumentationReporter().init(oraConn);
3624

37-
OracleCallableStatement cstmt = (OracleCallableStatement)oraConn.prepareCall("{? = call ?.has_output()}");
38-
39-
cstmt.registerOutParameter(1, OracleTypes.INTEGER);
40-
cstmt.setORAData(2, obj);
41-
42-
cstmt.execute();
43-
44-
int hasOutput = cstmt.getInt(1);
45-
4625
String runnerSql = "begin ut_runner.run( a_paths => ut_varchar2_list('app'), a_reporters => ?); end;";
4726

4827
CallableStatement stmt = oraConn.prepareCall(runnerSql);

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.