@@ -28,24 +28,37 @@ class UtplsqlDao {
2828 public static val UTPLSQL_PACKAGE_NAME = " UT"
2929 private var Connection conn
3030 private var JdbcTemplate jdbcTemplate
31+ // cache fields
32+ private Boolean cachedDbaViewAccessible
33+ private String cachedUtplsqlSchema
34+ private Boolean cachedUtAnnotationManagerInstalled
3135
3236 new (Connection conn) {
3337 this . conn = conn
3438 this . jdbcTemplate = new JdbcTemplate (new SingleConnectionDataSource (conn, true ))
3539 }
3640
41+ def void resetCache () {
42+ cachedDbaViewAccessible = null
43+ cachedUtplsqlSchema = null
44+ cachedUtAnnotationManagerInstalled = null
45+ }
46+
3747 def boolean isDbaViewAccessible () {
38- try {
39- val sql = ' ' '
40- SELECT 1
41- FROM dba_objects
42- WHERE 1=2
43- ' ' '
44- jdbcTemplate. execute(sql)
45- return true
46- } catch (DataAccessException e) {
47- return false
48+ if (cachedDbaViewAccessible == = null ) {
49+ try {
50+ val sql = ' ' '
51+ SELECT 1
52+ FROM dba_objects
53+ WHERE 1=2
54+ ' ' '
55+ jdbcTemplate. execute(sql)
56+ cachedDbaViewAccessible = true
57+ } catch (DataAccessException e) {
58+ cachedDbaViewAccessible = false
59+ }
4860 }
61+ return cachedDbaViewAccessible. booleanValue
4962 }
5063
5164 /**
@@ -55,19 +68,22 @@ class UtplsqlDao {
5568 * @throws DataAccessException if there is a problem
5669 */
5770 def String getUtplsqlSchema () {
58- val sql = ' ' '
59- SELECT table_owner
60- FROM «IF dbaViewAccessible»dba«ELSE»all«ENDIF»_synonyms
61- WHERE owner = ' PUBLIC '
62- AND synonym_name = ' «UTPLSQL_PACKAGE_NAME »'
63- AND table_name = ' «UTPLSQL_PACKAGE_NAME »'
64- ' ' '
65- try {
66- val schema = jdbcTemplate. queryForObject(sql, String )
67- return schema
68- } catch (EmptyResultDataAccessException e) {
69- return null
71+ if (cachedUtplsqlSchema == = null ) {
72+ val sql = ' ' '
73+ SELECT table_owner
74+ FROM «IF dbaViewAccessible»dba«ELSE»all«ENDIF»_synonyms
75+ WHERE owner = ' PUBLIC '
76+ AND synonym_name = ' «UTPLSQL_PACKAGE_NAME »'
77+ AND table_name = ' «UTPLSQL_PACKAGE_NAME »'
78+ ' ' '
79+ try {
80+ val schema = jdbcTemplate. queryForObject(sql, String )
81+ cachedUtplsqlSchema = schema
82+ } catch (EmptyResultDataAccessException e) {
83+ cachedUtplsqlSchema = null
84+ }
7085 }
86+ return cachedUtplsqlSchema
7187 }
7288
7389 /**
@@ -80,18 +96,21 @@ class UtplsqlDao {
8096 * @throws DataAccessException if there is a problem
8197 */
8298 def boolean isUtAnnotationManagerInstalled () {
83- if (utplsqlSchema !== null ) {
84- val sql = ' ' '
85- SELECT count(*)
86- FROM all_objects
87- WHERE owner = ' «utplsqlSchema»'
88- AND object_type = ' PACKAGE '
89- AND object_name = ' UT_ANNOTATION_MANAGER '
90- ' ' '
91- val found = jdbcTemplate. queryForObject(sql, Integer )
92- return found == 1
99+ if (cachedUtAnnotationManagerInstalled == = null ) {
100+ cachedUtAnnotationManagerInstalled = false
101+ if (utplsqlSchema !== null ) {
102+ val sql = ' ' '
103+ SELECT count(*)
104+ FROM «IF dbaViewAccessible»dba«ELSE»all«ENDIF»_objects
105+ WHERE owner = ' «utplsqlSchema»'
106+ AND object_type = ' PACKAGE '
107+ AND object_name = ' UT_ANNOTATION_MANAGER '
108+ ' ' '
109+ val found = jdbcTemplate. queryForObject(sql, Integer )
110+ cachedUtAnnotationManagerInstalled = found == 1
111+ }
93112 }
94- return false
113+ return cachedUtAnnotationManagerInstalled
95114 }
96115
97116 /**
0 commit comments