1515 */
1616 package org.utplsql.sqldev.dal
1717
18+ import java.sql.CallableStatement
1819import java.sql.Connection
20+ import java.sql.SQLException
21+ import java.sql.Types
1922import java.util.List
2023import org.oddgen.sqldev.generators.model.Node
2124import org.springframework.dao.DataAccessException
2225import org.springframework.dao.EmptyResultDataAccessException
2326import org.springframework.jdbc.core.BeanPropertyRowMapper
27+ import org.springframework.jdbc.core.CallableStatementCallback
2428import org.springframework.jdbc.core.JdbcTemplate
2529import org.springframework.jdbc.datasource.SingleConnectionDataSource
2630import org.utplsql.sqldev.model.ut.Annotation
31+ import org.utplsql.sqldev.model.ut.OutputLines
2732
2833class UtplsqlDao {
2934 public static val UTPLSQL_PACKAGE_NAME = " UT"
@@ -472,6 +477,79 @@ class UtplsqlDao {
472477 val jdbcTemplate = new JdbcTemplate (new SingleConnectionDataSource (conn, true ))
473478 val nodes = jdbcTemplate. query(sql, new BeanPropertyRowMapper<Node > (Node ))
474479 return nodes
475- }
480+ }
481+
482+ def void enableDbmsOutput () {
483+ // equivalent to "set serveroutput on size unlimited"
484+ jdbcTemplate. update(' ' '
485+ BEGIN
486+ sys.dbms_output.enable(NULL);
487+ END;
488+ ' ' ' )
489+ }
490+
491+ def void disableDbmsOutput () {
492+ jdbcTemplate. update(' ' '
493+ BEGIN
494+ sys.dbms_output.disable;
495+ END;
496+ ' ' ' )
497+ }
498+
499+ def String getDbmsOutput () {
500+ return getDbmsOutput(1000 )
501+ }
502+
503+ def String getDbmsOutput (int bufferSize ) {
504+ val sb = new StringBuffer
505+ val sql = ' ' '
506+ BEGIN
507+ sys.dbms_output.get_lines(?, ?);
508+ END;
509+ ' ' '
510+ var OutputLines ret
511+ do {
512+ ret = jdbcTemplate. execute(sql, new CallableStatementCallback<OutputLines > () {
513+ override OutputLines doInCallableStatement(CallableStatement cs) throws SQLException , DataAccessException {
514+ cs. registerOutParameter(1 , Types . ARRAY , " DBMSOUTPUT_LINESARRAY" );
515+ cs. registerOutParameter(2 , Types . INTEGER )
516+ cs. setInt(2 , bufferSize)
517+ cs. execute
518+ val out = new OutputLines
519+ out. lines = cs. getArray(1 ). array as String []
520+ out. numlines = cs. getInt(2 )
521+ return out
522+ }
523+ })
524+ for (i : 0 .. < ret. numlines) {
525+ val line = ret. lines. get(i)
526+ if (line !== null ) {
527+ sb. append(ret. lines. get(i))
528+ }
529+ sb. append(System . lineSeparator)
530+ }
531+ } while (ret. numlines > 0 )
532+ return sb. toString
533+ }
534+
535+ def String htmlCodeCoverage (List<String > pathList ) {
536+ enableDbmsOutput
537+ val sql = ' ' '
538+ BEGIN
539+ ut.run(
540+ ut_varchar2_list(
541+ «FOR path : pathList SEPARATOR ","»
542+ ' «path»'
543+ «ENDFOR»
544+ ),
545+ ut_coverage_html_reporter()
546+ );
547+ END;
548+ ' ' '
549+ jdbcTemplate. update(sql)
550+ val ret = getDbmsOutput
551+ disableDbmsOutput
552+ return ret
553+ }
476554
477555}
0 commit comments