Skip to content

Commit 695829f

Browse files
data access for code coverage and include candidates
1 parent bec82af commit 695829f

File tree

1 file changed

+84
-6
lines changed

1 file changed

+84
-6
lines changed

sqldev/src/main/java/org/utplsql/sqldev/dal/UtplsqlDao.xtend

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ class UtplsqlDao {
479479
return nodes
480480
}
481481

482+
/**
483+
* enable DBMS_OUTPUT
484+
*
485+
* @throws DataAccessException if there is a problem
486+
*/
482487
def void enableDbmsOutput() {
483488
// equivalent to "set serveroutput on size unlimited"
484489
jdbcTemplate.update('''
@@ -487,7 +492,12 @@ class UtplsqlDao {
487492
END;
488493
''')
489494
}
490-
495+
496+
/**
497+
* disable DBMS_OUTPUT
498+
*
499+
* @throws DataAccessException if there is a problem
500+
*/
491501
def void disableDbmsOutput() {
492502
jdbcTemplate.update('''
493503
BEGIN
@@ -496,10 +506,22 @@ class UtplsqlDao {
496506
''')
497507
}
498508

509+
/**
510+
* return the content of DBMS_OUTPUT as String
511+
*
512+
* @throws DataAccessException if there is a problem
513+
*/
499514
def String getDbmsOutput() {
500515
return getDbmsOutput(1000)
501516
}
502517

518+
/**
519+
* return the content of DBMS_OUTPUT as String
520+
521+
* @param bufferSize maximum number of rows to be read from the DBMS_OUTPUT buffer in one network round trip
522+
* @return content of DBMS_OUTPUT as String
523+
* @throws DataAccessException if there is a problem
524+
*/
503525
def String getDbmsOutput(int bufferSize) {
504526
val sb = new StringBuffer
505527
val sql = '''
@@ -531,18 +553,49 @@ class UtplsqlDao {
531553
} while (ret.numlines > 0)
532554
return sb.toString
533555
}
534-
535-
def String htmlCodeCoverage(List<String> pathList) {
556+
557+
/**
558+
* gets the HTML code coverage report as String
559+
*
560+
* @param pathList utPLSQL path list
561+
* @param schemaList list of schemas under tests. Current schema, if empty
562+
* @param includeObjectList list of objects to be included for coverage analysis. All, if empty
563+
* @param excludeObjectList list of objects to be excluded from coverage analysis. None, if empty
564+
* @return HTML code coverage report in HTML format
565+
* @throws DataAccessException if there is a problem
566+
*/
567+
def String htmlCodeCoverage(List<String> pathList, List<String> schemaList, List<String> includeObjectList, List<String> excludeObjectList) {
536568
enableDbmsOutput
537569
val sql = '''
538570
BEGIN
539571
ut.run(
540-
ut_varchar2_list(
541-
«FOR path : pathList SEPARATOR ","»
572+
a_paths => ut_varchar2_list(
573+
«FOR path : pathList SEPARATOR ",
542574
'«path»'
543575
«ENDFOR»
544576
),
545-
ut_coverage_html_reporter()
577+
«IF schemaList.size > 0»
578+
a_coverage_schemes => ut_varchar2_list(
579+
«FOR schema : schemaList SEPARATOR ", "»
580+
'«schema»'
581+
«ENDFOR»
582+
),
583+
«ENDIF»
584+
«IF includeObjectList.size > 0»
585+
a_include_objects => ut_varchar2_list(
586+
«FOR includeObject : includeObjectList SEPARATOR ", "»
587+
'«includeObject»'
588+
«ENDFOR»
589+
),
590+
«ENDIF»
591+
«IF excludeObjectList.size > 0»
592+
a_exclude_objects => ut_varchar2_list(
593+
«FOR excludeObject : excludeObjectList SEPARATOR ", "»
594+
'«excludeObject»'
595+
«ENDFOR»
596+
),
597+
«ENDIF»
598+
a_reporter => ut_coverage_html_reporter()
546599
);
547600
END;
548601
'''
@@ -552,4 +605,29 @@ class UtplsqlDao {
552605
return ret
553606
}
554607

608+
/**
609+
* gets dependencies of a given object.
610+
*
611+
* The result can be used as input for the includeObjectList in htmlCodeCoverage
612+
* The scope is reduced to the current schema.
613+
* This is useful when test packages are installed in the code schema.
614+
* The result may include test packages
615+
*
616+
* @param name test package name
617+
* @return list of dependencies in the current schema
618+
*/
619+
def List<String> includes(String name) {
620+
val sql = '''
621+
select referenced_name
622+
from «IF dbaViewAccessible»dba«ELSE»all«ENDIF»_dependencies
623+
WHERE owner = user
624+
AND name = upper(?)
625+
AND referenced_owner = user
626+
AND referenced_type IN ('PACKAGE', 'TYPE', 'PROCEDURE', 'FUNCTION', 'TRIGGER')
627+
'''
628+
val jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(conn, true))
629+
val deps = jdbcTemplate.queryForList(sql, String, #[name])
630+
return deps
631+
}
632+
555633
}

0 commit comments

Comments
 (0)