Skip to content

Commit 61b9b83

Browse files
add getObjectType - required for linking within SQLDev
1 parent 6190239 commit 61b9b83

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,4 +897,30 @@ class UtplsqlDao {
897897
})
898898
return ret
899899
}
900+
901+
/**
902+
* gets the object type of a database object
903+
*
904+
* The object types "PACKAGE BODY", "TYPE BODY" have higher priority.
905+
* "PACKAGE" OR "TYPE" will be returned only when no body exists.
906+
*
907+
* @param owner owner of the object (schema)
908+
* @param objectName name of the object
909+
* @return the object type, e.g. PACKAGE BODY, TYPE BODY, PROCEDURE, FUNCTION
910+
*/
911+
def getObjectType(String owner, String objectName) {
912+
val sql = '''
913+
SELECT object_type
914+
FROM (
915+
SELECT object_type
916+
FROM «IF dbaViewAccessible»dba«ELSE»all«ENDIF»_objects
917+
WHERE owner = ?
918+
AND object_name = ?
919+
ORDER BY decode(object_type, 'PACKAGE', 10, 'TYPE', 10, 'SYNONYM', 20, 1)
920+
)
921+
WHERE rownum = 1
922+
'''
923+
val objectType = jdbcTemplate.queryForObject(sql, #[owner, objectName], String)
924+
return objectType
925+
}
900926
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,5 +514,21 @@ class DalTest extends AbstractJdbcTest {
514514
Assert.assertTrue(actual.contains("PROCEDURE p1 IS"))
515515
jdbcTemplate.execute("DROP PACKAGE BODY junit_utplsql_test_pkg")
516516
}
517+
518+
@Test
519+
def void getObjectType() {
520+
val dao = new UtplsqlDao(dataSource.connection)
521+
jdbcTemplate.execute('''
522+
CREATE OR REPLACE PACKAGE junit_utplsql_test_pkg IS
523+
-- %suite
524+
525+
-- %test
526+
PROCEDURE p1;
527+
END junit_utplsql_test_pkg;
528+
''')
529+
val actual = dao.getObjectType("SCOTT", "JUNIT_UTPLSQL_TEST_PKG")
530+
Assert.assertEquals("PACKAGE", actual)
531+
jdbcTemplate.execute("DROP PACKAGE junit_utplsql_test_pkg")
532+
}
517533

518534
}

0 commit comments

Comments
 (0)