Skip to content

Commit 42b0d1a

Browse files
add runnables DAO
to be used from the oddgen generator only
1 parent dfa0150 commit 42b0d1a

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed

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

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,216 @@ class UtplsqlDao {
262262
val nodes = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Node>(Node), #[objectType])
263263
return nodes
264264
}
265+
266+
/**
267+
* Gets a list of oddgen's nodes as candidates to run utPLSQL tests.
268+
*
269+
* This functions must be called from an oddgen generator only, since the Node is not
270+
* defined in the utPLSQL extension.
271+
*
272+
* @return list of oddgen nodes (complete hierarchy loaded eagerly)
273+
* @throws DataAccessException if there is a problem
274+
*/
275+
def List<Node> runnables() {
276+
var sql = '''
277+
WITH
278+
base AS (
279+
SELECT rownum AS an_id,
280+
o.object_owner,
281+
o.object_type,
282+
o.object_name,
283+
lower(a.name) AS name,
284+
a.text,
285+
a.subobject_name
286+
FROM table(ut3.ut_annotation_manager.get_annotated_objects(user, 'PACKAGE')) o
287+
CROSS JOIN table(o.annotations) a
288+
WHERE lower(a.name) in ('suite','suitepath', 'endcontext','test')
289+
OR lower(a.name) = 'context' AND regexp_like(text, '(\w+)(\.\w+)*')
290+
),
291+
suite AS (
292+
SELECT object_owner, object_type, object_name, text AS suite_description
293+
FROM base
294+
WHERE name = 'suite'
295+
),
296+
suitepath as (
297+
SELECT object_owner, object_type, object_name, text as suitepath
298+
FROM base
299+
WHERE name = 'suitepath'
300+
),
301+
context_base AS (
302+
SELECT an_id,
303+
lead(an_id) over (partition by object_owner, object_type, object_name order by an_id) an_id_end,
304+
object_owner,
305+
object_type,
306+
object_name,
307+
name,
308+
lead(name) over (partition by object_owner, object_type, object_name order by an_id) name_end,
309+
text as context
310+
FROM base
311+
WHERE name IN ('context', 'endcontext')
312+
),
313+
context as (
314+
SELECT an_id, an_id_end, object_owner, object_type, object_name, context
315+
FROM context_base
316+
WHERE name = 'context'
317+
AND name_end = 'endcontext'
318+
),
319+
test AS (
320+
SELECT b.an_id,
321+
b.object_owner,
322+
b.object_type,
323+
b.object_name,
324+
p.suitepath,
325+
c.context,
326+
b.subobject_name,
327+
b.text AS test_description
328+
FROM base b
329+
LEFT JOIN suitepath p
330+
ON p.object_owner = b.object_owner
331+
AND p.object_type = b.object_type
332+
AND p.object_name = b.object_name
333+
LEFT JOIN context c
334+
ON c.object_owner = b.object_owner
335+
AND c.object_type = b.object_type
336+
AND c.object_name = b.object_name
337+
AND b.an_id BETWEEN c.an_id AND c.an_id_end
338+
WHERE name = 'test'
339+
AND (b.object_owner, b.object_type, b.object_name) IN (
340+
select object_owner, object_type, object_name
341+
from suite
342+
)
343+
),
344+
suite_tree AS (
345+
SELECT null AS parent_id,
346+
'SUITE' AS id,
347+
'All Suites' AS name,
348+
'All utPLSQL test suites' AS description,
349+
'PACKAGE_FOLDER_ICON' AS iconName,
350+
'No' AS leaf,
351+
'Yes' AS generatable,
352+
'Yes' AS multiselectable,
353+
'Yes' AS relevant
354+
FROM dual
355+
UNION ALL
356+
SELECT DISTINCT
357+
'SUITE' AS parent_id,
358+
object_owner || '.' || object_name AS id,
359+
object_name AS name,
360+
null AS description,
361+
'PACKAGE_ICON' AS iconName,
362+
'No' AS leaf,
363+
'Yes' AS generatable,
364+
'Yes' AS multiselectable,
365+
'Yes' AS relevant
366+
FROM test
367+
UNION ALL
368+
SELECT object_owner || '.' || object_name AS parent_id,
369+
object_owner || '.' || object_name || '.' || subobject_name AS id,
370+
subobject_name AS name,
371+
null AS description,
372+
'PROCEDURE_ICON' AS iconName,
373+
'Yes' AS leaf,
374+
'Yes' AS generatable,
375+
'Yes' AS multiselectable,
376+
'Yes' AS relevant
377+
FROM test
378+
),
379+
suitepath_base AS (
380+
SELECT DISTINCT
381+
suitepath
382+
FROM suitepath
383+
),
384+
gen AS (
385+
SELECT rownum AS pos
386+
FROM xmltable('1 to 100')
387+
),
388+
suitepath_part AS (
389+
SELECT DISTINCT
390+
substr(suitepath, 1, instr(suitepath || '.', '.', 1, g.pos) -1) AS suitepath
391+
FROM suitepath_base b
392+
JOIN gen g
393+
On g.pos <= regexp_count(suitepath, '\w+')
394+
),
395+
suitepath_tree AS (
396+
SELECT NULL AS parent_id,
397+
'SUITEPATH' AS id,
398+
'All Suitepaths' AS name,
399+
'All utPLSQL test suitepathes' AS description,
400+
'FOLDER_ICON' AS iconName,
401+
'No' AS leaf,
402+
'Yes' AS generatable,
403+
'Yes' AS multiselectable,
404+
'Yes' AS relevant
405+
FROM dual
406+
UNION ALL
407+
SELECT CASE
408+
WHEN regexp_replace(suitepath,'\.?\w+$','') IS NULL THEN
409+
'SUITEPATH'
410+
ELSE
411+
USER || ':' || regexp_replace(suitepath,'\.?\w+$','')
412+
END AS parent_id,
413+
USER || ':' || suitepath AS id,
414+
regexp_substr(suitepath, '\.?(\w+$)', 1, 1, NULL, 1) AS name,
415+
null AS description,
416+
'FOLDER_ICON' AS iconName,
417+
'No' AS leaf,
418+
'Yes' AS generatable,
419+
'Yes' AS multiselectable,
420+
'Yes' AS relevant
421+
FROM suitepath_part
422+
UNION ALL
423+
SELECT DISTINCT
424+
object_owner || ':' || suitepath AS parent_id,
425+
object_owner || ':' || suitepath || '.' || object_name AS id,
426+
object_name AS name,
427+
null AS description,
428+
'PACKAGE_ICON' AS iconName,
429+
'No' AS leaf,
430+
'Yes' AS generatable,
431+
'Yes' AS multiselectable,
432+
'Yes' AS relevant
433+
FROM test
434+
WHERE suitepath IS NOT NULL
435+
UNION ALL
436+
SELECT DISTINCT
437+
object_owner || ':' || suitepath || '.' || object_name AS parent_id,
438+
object_owner || ':' || suitepath || '.' || object_name || '.' || context AS id,
439+
context AS name,
440+
null AS description,
441+
'FOLDER_ICON' AS iconName,
442+
'No' AS leaf,
443+
'Yes' AS generatable,
444+
'Yes' AS multiselectable,
445+
'Yes' AS relevant
446+
FROM test
447+
WHERE suitepath IS NOT NULL
448+
AND context IS NOT NULL
449+
UNION ALL
450+
SELECT object_owner || ':' || suitepath || '.' || object_name || CASE WHEN context IS NOT NULL THEN '.' || context END AS parent_id,
451+
object_owner || ':' || suitepath || '.' || object_name || CASE WHEN context IS NOT NULL THEN '.' || context END || '.' || subobject_name AS id,
452+
subobject_name AS name,
453+
null AS description,
454+
'PROCEDURE_ICON' AS iconName,
455+
'Yes' AS leaf,
456+
'Yes' AS generatable,
457+
'Yes' AS multiselectable,
458+
'Yes' AS relevant
459+
FROM test
460+
WHERE suitepath IS NOT NULL
461+
),
462+
tree AS (
463+
SELECT parent_id, id, name, description, iconName, leaf, generatable, multiselectable, relevant
464+
FROM suite_tree
465+
UNION ALL
466+
SELECT parent_id, id, name, description, iconName, leaf, generatable, multiselectable, relevant
467+
FROM suitepath_tree
468+
)
469+
SELECT parent_id, id, name, description, iconName, leaf, generatable, multiselectable, relevant
470+
FROM tree
471+
'''
472+
val jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(conn, true))
473+
val nodes = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Node>(Node))
474+
return nodes
475+
}
476+
265477
}

0 commit comments

Comments
 (0)