@@ -1,6 +1,5 @@ | |||
| 1 | 1 | package org.utplsql.api.reporter; | |
| 2 | 2 | ||
| 3 | - import org.utplsql.api.CustomTypes; | ||
| 4 | 3 | import org.utplsql.api.ResourceUtil; | |
| 5 | 4 | ||
| 6 | 5 | import java.io.IOException; | |
@@ -9,9 +8,6 @@ | |||
| 9 | 8 | import java.nio.file.Files; | |
| 10 | 9 | import java.nio.file.Path; | |
| 11 | 10 | import java.nio.file.Paths; | |
| 12 | - import java.sql.SQLException; | ||
| 13 | - import java.sql.SQLInput; | ||
| 14 | - import java.sql.SQLOutput; | ||
| 15 | 11 | import java.util.List; | |
| 16 | 12 | import java.util.function.Consumer; | |
| 17 | 13 | ||
@@ -32,6 +28,26 @@ public CoverageHTMLReporter(String selfType, Object[] attributes) { | |||
| 32 | 28 | super(selfType, attributes); | |
| 33 | 29 | } | |
| 34 | 30 | ||
| 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 | + | ||
| 35 | 51 | public String getProjectName() { | |
| 36 | 52 | return projectName; | |
| 37 | 53 | } | |
@@ -1,8 +1,6 @@ | |||
| 1 | 1 | package org.utplsql.api.reporter; | |
| 2 | 2 | ||
| 3 | - import java.sql.SQLException; | ||
| 4 | - import java.sql.SQLInput; | ||
| 5 | - import java.sql.SQLOutput; | ||
| 3 | + import java.math.BigDecimal; | ||
| 6 | 4 | ||
| 7 | 5 | public class DocumentationReporter extends Reporter { | |
| 8 | 6 | ||
@@ -17,6 +15,24 @@ public DocumentationReporter(String selfType, Object[] attributes ) { | |||
| 17 | 15 | super(selfType, attributes); | |
| 18 | 16 | } | |
| 19 | 17 | ||
| 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 | + | ||
| 20 | 36 | public int getLvl() { | |
| 21 | 37 | return lvl; | |
| 22 | 38 | } | |
@@ -7,27 +7,24 @@ | |||
| 7 | 7 | import oracle.sql.ORAData; | |
| 8 | 8 | import oracle.sql.STRUCT; | |
| 9 | 9 | import oracle.sql.StructDescriptor; | |
| 10 | - import org.utplsql.api.DBHelper; | ||
| 11 | 10 | ||
| 12 | 11 | import java.sql.*; | |
| 13 | - import java.util.Calendar; | ||
| 14 | 12 | ||
| 15 | - /** | ||
| 16 | - * Created by Vinicius on 13/04/2017. | ||
| 13 | + /** This is a basic Reporter implementation, using ORAData interface | ||
| 14 | + * | ||
| 15 | + * @author pesse | ||
| 17 | 16 | */ | |
| 18 | 17 | public class Reporter implements ORAData { | |
| 19 | 18 | ||
| 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; | ||
| 23 | 24 | ||
| 24 | 25 | 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 ); | ||
| 31 | 28 | } | |
| 32 | 29 | ||
| 33 | 30 | private void setTypeName( String typeName ) { | |
@@ -42,19 +39,69 @@ public Reporter init( Connection con ) throws SQLException { | |||
| 42 | 39 | ||
| 43 | 40 | OracleConnection oraConn = con.unwrap(OracleConnection.class); | |
| 44 | 41 | ||
| 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 { | ||
| 45 | 58 | OracleCallableStatement callableStatement = (OracleCallableStatement) oraConn.prepareCall("{? = call " + selfType + "()}"); | |
| 46 | 59 | callableStatement.registerOutParameter(1, OracleTypes.STRUCT, "UT_REPORTER_BASE"); | |
| 47 | 60 | callableStatement.execute(); | |
| 48 | 61 | ||
| 49 | 62 | Reporter obj = (Reporter) callableStatement.getORAData(1, ReporterFactory.getInstance()); | |
| 50 | 63 | ||
| 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 | + } | ||
| 53 | 87 | ||
| 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 | + } | ||
| 55 | 94 | ||
| 95 | + protected Object[] getAttributes() { | ||
| 96 | + return attributes; | ||
| 97 | + } | ||
| 56 | 98 | ||
| 57 | - return this; | ||
| 99 | + public boolean hasOutput() { | ||
| 100 | + return hasOutput; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public boolean isInit() { | ||
| 104 | + return init; | ||
| 58 | 105 | } | |
| 59 | 106 | ||
| 60 | 107 | public String getTypeName() { | |
@@ -69,8 +116,8 @@ public String getId() { | |||
| 69 | 116 | public Datum toDatum(Connection c) throws SQLException | |
| 70 | 117 | { | |
| 71 | 118 | 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()); | ||
| 74 | 121 | } | |
| 75 | 122 | ||
| 76 | 123 | } | |
@@ -20,29 +20,8 @@ public void myTest2() throws SQLException { | |||
| 20 | 20 | ||
| 21 | 21 | OracleConnection oraConn = getConnection().unwrap(OracleConnection.class); | |
| 22 | 22 | ||
| 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 | - */ | ||
| 35 | 23 | Reporter obj = new DocumentationReporter().init(oraConn); | |
| 36 | 24 | ||
| 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 | - | ||
| 46 | 25 | String runnerSql = "begin ut_runner.run( a_paths => ut_varchar2_list('app'), a_reporters => ?); end;"; | |
| 47 | 26 | ||
| 48 | 27 | CallableStatement stmt = oraConn.prepareCall(runnerSql); | |
0 commit comments