15
15
*/
16
16
package org.utplsql.sqldev.dal
17
17
18
+ import java.sql.CallableStatement
18
19
import java.sql.Connection
20
+ import java.sql.SQLException
21
+ import java.sql.Types
19
22
import java.util.List
20
23
import org.oddgen.sqldev.generators.model.Node
21
24
import org.springframework.dao.DataAccessException
22
25
import org.springframework.dao.EmptyResultDataAccessException
23
26
import org.springframework.jdbc.core.BeanPropertyRowMapper
27
+ import org.springframework.jdbc.core.CallableStatementCallback
24
28
import org.springframework.jdbc.core.JdbcTemplate
25
29
import org.springframework.jdbc.datasource.SingleConnectionDataSource
26
30
import org.utplsql.sqldev.model.ut.Annotation
31
+ import org.utplsql.sqldev.model.ut.OutputLines
27
32
28
33
class UtplsqlDao {
29
34
public static val UTPLSQL_PACKAGE_NAME = " UT"
@@ -472,6 +477,79 @@ class UtplsqlDao {
472
477
val jdbcTemplate = new JdbcTemplate (new SingleConnectionDataSource (conn, true ))
473
478
val nodes = jdbcTemplate. query(sql, new BeanPropertyRowMapper<Node > (Node ))
474
479
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
+ }
476
554
477
555
}
0 commit comments