Skip to content

Commit 7f4e673

Browse files
support for is_test, is_suite, has_suites - but disabled
not working in v3.1.7. enable containsUtplsqlTest999 to see issues
1 parent 5422697 commit 7f4e673

File tree

2 files changed

+123
-9
lines changed

2 files changed

+123
-9
lines changed

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

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class UtplsqlDao {
3535
public static val UTPLSQL_PACKAGE_NAME = "UT"
3636
public static val FIRST_VERSION_WITH_INTERNAL_ANNOTATION_API = 3000004
3737
public static val FIRST_VERSION_WITH_ANNOTATION_API = 3001003
38+
public static val NOT_YET_AVAILABLE = 9009009
3839
var Connection conn
3940
var JdbcTemplate jdbcTemplate
4041
// cache fields
@@ -173,16 +174,41 @@ class UtplsqlDao {
173174
*/
174175
def boolean containsUtplsqlTest(String owner, String objectName, String subobjectName) {
175176
try {
176-
var Integer found
177-
if (normalizedUtPlsqlVersionNumber >= FIRST_VERSION_WITH_ANNOTATION_API) {
178-
// using API available since 3.1.3
177+
if (normalizedUtPlsqlVersionNumber >= NOT_YET_AVAILABLE && objectName !== null && subobjectName !== null) {
178+
// use faster check function available since v3.1.3 (FIRST_VERSION_WITH_ANNOTATION_API)
179+
// disabled (NOT_YET_AVAILABLE) due to wrong results in v3.1.7
180+
val sql = '''
181+
DECLARE
182+
l_return VARCHAR2(1) := '0';
183+
BEGIN
184+
IF ut_runner.is_test(?, ?, ?) THEN
185+
l_return := '1';
186+
END IF;
187+
? := l_return;
188+
END;
189+
'''
190+
val ret = jdbcTemplate.execute(sql, new CallableStatementCallback<Boolean>() {
191+
override Boolean doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
192+
cs.setString(1, owner)
193+
cs.setString(2, objectName)
194+
cs.setString(3, subobjectName)
195+
cs.registerOutParameter(4, Types.VARCHAR);
196+
cs.execute
197+
val ret = cs.getString(4)
198+
return ret == "1"
199+
}
200+
})
201+
return ret
202+
} else if (normalizedUtPlsqlVersionNumber >= FIRST_VERSION_WITH_ANNOTATION_API) {
203+
// using API available since 3.1.3, can handle nulls in objectName and subobjectName
179204
val sql = '''
180205
SELECT count(*)
181206
FROM TABLE(ut_runner.get_suites_info(upper(?), upper(?)))
182207
WHERE item_type IN ('UT_TEST', 'UT_SUITE')
183208
AND (item_name = upper(?) or ? IS NULL)
184209
'''
185-
found = jdbcTemplate.queryForObject(sql, Integer, #[owner, objectName, subobjectName, subobjectName])
210+
val found = jdbcTemplate.queryForObject(sql, Integer, #[owner, objectName, subobjectName, subobjectName])
211+
return found > 0
186212
} else {
187213
// using internal API (deprecated)
188214
val sql = '''
@@ -209,20 +235,71 @@ class UtplsqlDao {
209235
END
210236
) > 0
211237
'''
212-
found = jdbcTemplate.queryForObject(sql, Integer, #[subobjectName, subobjectName, owner, objectName, objectName])
213-
}
214-
return found > 0
238+
val found = jdbcTemplate.queryForObject(sql, Integer, #[subobjectName, subobjectName, owner, objectName, objectName])
239+
return found > 0
240+
}
215241
} catch (EmptyResultDataAccessException e) {
216242
return false
217243
}
218244
}
219245

220246
def boolean containsUtplsqlTest(String owner) {
221-
return containsUtplsqlTest(owner, null, null)
247+
if (normalizedUtPlsqlVersionNumber >= NOT_YET_AVAILABLE) {
248+
// use faster check function available since v3.1.3 (FIRST_VERSION_WITH_ANNOTATION_API)
249+
// disabled (NOT_YET_AVAILABLE) due to wrong results in v3.1.7
250+
val sql = '''
251+
DECLARE
252+
l_return VARCHAR2(1) := '0';
253+
BEGIN
254+
IF ut_runner.has_suites(?) THEN
255+
l_return := '1';
256+
END IF;
257+
? := l_return;
258+
END;
259+
'''
260+
val ret = jdbcTemplate.execute(sql, new CallableStatementCallback<Boolean>() {
261+
override Boolean doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
262+
cs.setString(1, owner)
263+
cs.registerOutParameter(2, Types.VARCHAR);
264+
cs.execute
265+
val ret = cs.getString(2)
266+
return ret == "1"
267+
}
268+
})
269+
return ret
270+
} else {
271+
return containsUtplsqlTest(owner, null, null)
272+
}
222273
}
223274

224275
def boolean containsUtplsqlTest(String owner, String objectName) {
225-
return containsUtplsqlTest(owner, objectName, null)
276+
if (normalizedUtPlsqlVersionNumber >= NOT_YET_AVAILABLE) {
277+
// use faster check function available since v3.1.3 (FIRST_VERSION_WITH_ANNOTATION_API)
278+
// disabled (NOT_YET_AVAILABLE) due to wrong results in v3.1.7
279+
val sql = '''
280+
DECLARE
281+
l_return VARCHAR2(1) := '0';
282+
BEGIN
283+
IF ut_runner.is_suite(?, ?) THEN
284+
l_return := '1';
285+
END IF;
286+
? := l_return;
287+
END;
288+
'''
289+
val ret = jdbcTemplate.execute(sql, new CallableStatementCallback<Boolean>() {
290+
override Boolean doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
291+
cs.setString(1, owner)
292+
cs.setString(2, objectName)
293+
cs.registerOutParameter(3, Types.VARCHAR);
294+
cs.execute
295+
val ret = cs.getString(3)
296+
return ret == "1"
297+
}
298+
})
299+
return ret
300+
} else {
301+
return containsUtplsqlTest(owner, objectName, null)
302+
}
226303
}
227304

228305
/**

sqldev/src/test/java/org/utplsql/sqldev/test/dal/DalTest.xtend

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.springframework.jdbc.BadSqlGrammarException
2525
import org.utplsql.sqldev.dal.UtplsqlDao
2626
import org.utplsql.sqldev.model.ut.Annotation
2727
import org.utplsql.sqldev.test.AbstractJdbcTest
28+
import org.junit.Ignore
2829

2930
class DalTest extends AbstractJdbcTest {
3031

@@ -142,6 +143,12 @@ class DalTest extends AbstractJdbcTest {
142143
containsUtplsqlTest("3.1.3")
143144
}
144145

146+
@Test
147+
@Ignore
148+
def void containsUtplsqlTest999() {
149+
containsUtplsqlTest("9.9.9")
150+
}
151+
145152
def void annotations(String utPlsqlVersion) {
146153
val dao = new UtplsqlDao(dataSource.connection)
147154
dao.utPlsqlVersion = utPlsqlVersion
@@ -192,6 +199,11 @@ class DalTest extends AbstractJdbcTest {
192199
annotations("3.1.3")
193200
}
194201

202+
@Test
203+
def void annotations999() {
204+
annotations("9.9.9")
205+
}
206+
195207
def void testablesPackages(String utPlsqlVersion) {
196208
val dao = new UtplsqlDao(dataSource.connection)
197209
dao.utPlsqlVersion = utPlsqlVersion
@@ -230,6 +242,11 @@ class DalTest extends AbstractJdbcTest {
230242
testablesPackages("3.1.3")
231243
}
232244

245+
@Test
246+
def void testablesPackages999() {
247+
testablesPackages("9.9.9")
248+
}
249+
233250
def void testablesTypes(String utPlsqlVersion) {
234251
val dao = new UtplsqlDao(dataSource.connection)
235252
dao.utPlsqlVersion = utPlsqlVersion
@@ -261,6 +278,11 @@ class DalTest extends AbstractJdbcTest {
261278
testablesTypes("3.1.3")
262279
}
263280

281+
@Test
282+
def void testablesTypes999() {
283+
testablesTypes("9.9.9")
284+
}
285+
264286
def void testablesFunctions(String utPlsqlVersion) {
265287
val dao = new UtplsqlDao(dataSource.connection)
266288
dao.utPlsqlVersion = utPlsqlVersion
@@ -285,6 +307,11 @@ class DalTest extends AbstractJdbcTest {
285307
testablesFunctions("3.1.3")
286308
}
287309

310+
@Test
311+
def void testablesFunctions999() {
312+
testablesFunctions("9.9.9")
313+
}
314+
288315
def void testablesProcedures(String utPlsqlVersion) {
289316
val dao = new UtplsqlDao(dataSource.connection)
290317
dao.utPlsqlVersion = utPlsqlVersion
@@ -309,6 +336,11 @@ class DalTest extends AbstractJdbcTest {
309336
testablesProcedures("3.1.3")
310337
}
311338

339+
@Test
340+
def void testablesProcedures999() {
341+
testablesProcedures("9.9.9")
342+
}
343+
312344
def void runnables(String utPlsqlVersion) {
313345
val dao = new UtplsqlDao(dataSource.connection)
314346
dao.utPlsqlVersion = utPlsqlVersion
@@ -367,6 +399,11 @@ class DalTest extends AbstractJdbcTest {
367399
def void runnables313() {
368400
runnables("3.1.3")
369401
}
402+
403+
@Test
404+
def void runnables999() {
405+
runnables("9.9.9")
406+
}
370407

371408
@Test
372409
def void dbmsOutput() {

0 commit comments

Comments
 (0)