1616package org.utplsql.sqldev
1717
1818import java.util.ArrayList
19+ import java.util.HashSet
1920import java.util.List
2021import java.util.logging.Logger
22+ import java.util.regex.Pattern
2123import javax.swing.JSplitPane
2224import oracle.dbtools.raptor.utils.Connections
2325import oracle.dbtools.worksheet.editor.OpenWorksheetWizard
@@ -57,6 +59,30 @@ class UtplsqlWorksheet {
5759 }
5860 }
5961
62+ private def dedupPathList () {
63+ val set = new HashSet<String >
64+ for (path : pathList) {
65+ set. add(path)
66+ }
67+ val ret = new ArrayList<String >
68+ val p = Pattern . compile(" ((((\\ w+)\\ .)?\\ w+)\\ .)?\\ w+" )
69+ for (path : set) {
70+ val m = p. matcher(path)
71+ if (m. matches()) {
72+ val parent1 = m. group(4 ) // user
73+ val parent2 = m. group(2 ) // user.package
74+ if (parent1 == = null || ! set. contains(parent1)) {
75+ if (parent2 == = null || ! set. contains(parent2)) {
76+ ret. add(path)
77+ }
78+ }
79+ } else {
80+ logger. severe(' ' ' path: «path» did not pattern «p.toString», this is unexected!' ' ' )
81+ }
82+ }
83+ return ret
84+ }
85+
6086 private def getCode () '''
6187 «IF preferences.resetPackage»
6288 EXECUTE dbms_session.reset_package;
@@ -65,10 +91,11 @@ class UtplsqlWorksheet {
6591 «IF preferences. clearScreen»
6692 CLEAR SCREEN
6793 «ENDIF »
68- «IF pathList. size == 1 »
69- EXECUTE ut. run(' «pathList.get(0)»' );
94+ «val paths = dedupPathList»
95+ «IF paths. size == 1 »
96+ EXECUTE ut. run(' «paths.get(0)»' );
7097 «ELSE »
71- EXECUTE ut. run(ut_varchar2_list(«FOR path : pathList SEPARATOR ' , ' »' «path»' «ENDFOR »));
98+ EXECUTE ut. run(ut_varchar2_list(«FOR path : paths SEPARATOR ' , ' »' «path»' «ENDFOR »));
7299 «ENDIF »
73100 ' ' '
74101
@@ -117,7 +144,7 @@ class UtplsqlWorksheet {
117144 thread.start
118145 }
119146
120- def static void openWithCode(String code, String connectionName) {
147+ static def void openWithCode(String code, String connectionName) {
121148 val worksheet = OpenWorksheetWizard.openNewTempWorksheet(connectionName, code) as Worksheet
122149 if (connectionName === null) {
123150 worksheet.comboConnection = null
0 commit comments