[hg] main-silver: #205819: Allow to run partial queries not only...

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #205819: Allow to run partial queries not only...
  • Date: Thu, 21 Feb 2013 19:38:43 -0800

changeset e2f17410b099 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/e2f17410b099
description:
        #205819: Allow to run partial queries not only from context menu

diffstat:

 db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java        
              |   36 ++++++++-
 
db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
        |   24 ++++++
 db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml     
              |    8 +-
 
db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/runsql-partial.png
          |    0 
 
db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/RunSQLSelectionAction.java
 |    7 +
 5 files changed, 68 insertions(+), 7 deletions(-)

diffs (152 lines):

diff --git 
a/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java 
b/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
--- a/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
+++ b/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
@@ -168,18 +168,42 @@
                 return allStatements;
             }
             // Just the statement at offset startOffset.
-            for (StatementInfo stmt : allStatements) {
-                if (stmt.getRawStartOffset() <= startOffset && 
stmt.getRawEndOffset() >= endOffset) {
-                    return Collections.singletonList(stmt);
-                }
-            }
-            return Collections.emptyList();
+            StatementInfo foundStatement = findStatementAtOffset(
+                    allStatements, startOffset, script);
+            return foundStatement == null
+                    ? Collections.<StatementInfo>emptyList()
+                    : Collections.singletonList(foundStatement);
         } else {
             // Just execute the selected subscript.
             return split(script.substring(startOffset, endOffset), 
useHashComments);
         }
     }
         
+    static StatementInfo findStatementAtOffset(List<StatementInfo> 
statements,
+            int offset, String script) {
+
+        StatementInfo prev = null;
+        for (StatementInfo stmt : statements) {
+            if (offset <= stmt.getRawEndOffset()) {
+                if (offset >= stmt.getStartOffset()) {
+                    return stmt; //directly in the script
+                } else if (offset >= stmt.getRawStartOffset()) {
+                    if (prev == null) {
+                        return stmt;
+                    } else {
+                        // check whether we are on the same line as the end 
of
+                        // previous statement
+                        String between = script.substring(
+                                prev.getRawEndOffset(), offset);
+                        return between.contains("\n") ? stmt : prev;    
//NOI18N
+                    }
+                }
+            }
+            prev = stmt;
+        }
+        return prev;
+    }
+        
     public static List<StatementInfo> split(String script) {
         return split(script, true);
     }
diff --git 
a/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
 
b/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
--- 
a/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
+++ 
b/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
@@ -166,4 +166,28 @@
             assertEquals(expected[i].getRawEndOffset(), 
stmts.get(i).getRawEndOffset());
         }
     }
+
+    public void testFindStatementAtOffset() {
+        String sql = "select * from APP.JHTEST; \n"
+                + "select * from APP.JHTEST where COL_NUMERIC = 2;";
+        List<StatementInfo> l = SQLExecuteHelper.split(sql, false);
+
+        StatementInfo s1 = l.get(0);
+        StatementInfo s2 = l.get(1);
+
+        assertSame(s1, SQLExecuteHelper.findStatementAtOffset(l, 24, sql)); 
//;
+        assertSame(s1, SQLExecuteHelper.findStatementAtOffset(l, 25, sql)); 
//_
+        assertSame(s1, SQLExecuteHelper.findStatementAtOffset(l, 26, sql)); 
//\n
+        assertSame(s2, SQLExecuteHelper.findStatementAtOffset(l, 27, sql)); 
//s
+        assertSame(s2, SQLExecuteHelper.findStatementAtOffset(l, 28, sql)); 
//e
 }
+
+    public void testFindStatementAtOffsetAtTheEndOfFile() {
+        String sql = "select * from APP.JHTEST;\n"
+                + "select * from APP.JHTEST;";
+        List<StatementInfo> l = SQLExecuteHelper.split(sql, false);
+
+        StatementInfo s2 = l.get(1);
+        assertSame(s2, SQLExecuteHelper.findStatementAtOffset(l, 51, sql));
+    }
+}
diff --git 
a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml 
b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
--- a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
+++ b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
@@ -51,7 +51,9 @@
                 <!-- #128873 - to show icon in toolbar (keep in sync with 
RunSQLAction.ICON_PATH) -->
                 <attr name="iconBase" 
stringvalue="org/netbeans/modules/db/sql/editor/resources/runsql.png"/>
             </file>
-            <file 
name="org-netbeans-modules-db-sql-editor-ui-actions-RunSQLSelectionAction.instance"/>
+            <file 
name="org-netbeans-modules-db-sql-editor-ui-actions-RunSQLSelectionAction.instance">
+                <attr name="iconBase" 
stringvalue="org/netbeans/modules/db/sql/editor/resources/runsql-partial.png"/>
+            </file>
             <file 
name="org-netbeans-modules-db-sql-editor-ui-actions-SQLHistoryAction.instance">
                 <!-- #128873 - to show icon in toolbar (keep in sync with 
SQLHistoryAction.ICON_PATH) -->
                 <attr name="iconBase" 
stringvalue="org/netbeans/modules/db/sql/editor/resources/sql_history_16.png"/>
@@ -116,6 +118,10 @@
                             <attr name="originalFile" 
stringvalue="Actions/System/org-netbeans-modules-db-sql-editor-ui-actions-RunSQLAction.instance"/>
                             <attr name="position" intvalue="800"/>
                         </file>
+                        <file 
name="org-netbeans-modules-db-sql-editor-ui-actions-RunSQLSelectionAction.shadow">
+                            <attr name="originalFile" 
stringvalue="Actions/System/org-netbeans-modules-db-sql-editor-ui-actions-RunSQLSelectionAction.instance"/>
+                            <attr name="position" intvalue="850"/>
+                        </file>
                         <file 
name="org-netbeans-modules-db-sql-editor-ui-actions-SelectInExplorerAction.instance">
                             <attr name="position" intvalue="900"/>
                         </file>
diff --git 
a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/runsql-partial.png
 
b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/runsql-partial.png
new file mode 100644
index 
0000000000000000000000000000000000000000..4cf3057cb38fbcfb64b7e640e2f6d3431cbcc783
GIT binary patch
literal 712
zc$@*q0yq7MP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004XF*Lt006O%
z3;baP00006VoOIv0Pz6v0P*sx8UFwP010qNS#tmY3ljhU3ljkVnw%H_000McNliru
z-2xO0D=3W+nhpQ}0!2wgK~y-)eUs0N%~2S}Kks|acjitr<|Yg2`Ui|gYD$(YjHQ&V
zW`#_OtYj^XL=ux^L75fB#*Y%Q@M9JfDN=*XP%_v2ym#FDJ?Fd@cYJe+r%q43bv`{k
z?>Pc+bY#@{hb$#TweVj$eq>kxJU~i`-8;A8RajVDpxJ1ks)#5C<av(wj;>M{h;sGD
zy#iDKN~IEBg*@b_NE^U8hxd+BsRW{J30r^|an6x>hj&Ku0aXV?R2}8sZop9WbaZrM
zX6=BOBC3k_MzvaIdb&)O2_m5CIPiWA7#v@Bm#zI9X@=$>fDjSDd#KgAs8&1Z>;w_O
zj1=I--meT^9$@9F^P~_9fC9uAaLys3cn?{Y$g+g@hR+}cm|A?zouP5|+~2{x|MWMY
zRT`uugdpU(U?w;x#2o5jj)}Q(#`k^TQTZYRr`S9;Hs%x{gn$T`DdjR$DzJLB(ANjs
z2aVK(dOkxvpW)5-2Rs{o%hx5Io}L^UT<#!XmWa`_c5R(XrIpA`nVl0t6Y62Ui2ZW<
z4o?ogV$;bDw_AYN+JbY!%uIuNeF^V9s)7o{1~lSg+x`cRZJ6kMr)P@<&N<A$IVH;+
z&M6{-iYx<a#pV5@Ba}XJX6j}-*D5h3R0I*h%t$F=W|$c<C1TzJG-8dz7tXW(+ZMju
z<XqcJOxE(Ao)z@=_M)oAi8<uy2ZzpHVr1J19^IM*9s(c$yM~7U`5OTq%Qb4u(*I*K
uYdZS@xPE0+3IH&`|5aJ`&%e!{1N;Pg;08oVjmFpj0000<MNUMnLSTYe%{agS

diff --git 
a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/RunSQLSelectionAction.java
 
b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/RunSQLSelectionAction.java
--- 
a/db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/RunSQLSelectionAction.java
+++ 
b/db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/RunSQLSelectionAction.java
@@ -63,12 +63,19 @@
 
     private static final Logger LOGGER = 
Logger.getLogger(RunSQLSelectionAction.class.getName());
     private static final boolean LOG = LOGGER.isLoggable(Level.FINE);
+    private static final String ICON_PATH =
+            
"org/netbeans/modules/db/sql/editor/resources/runsql-partial.png"; // NOI18N
 
     protected void initialize() {
         putValue(Action.NAME, 
NbBundle.getMessage(RunSQLSelectionAction.class, 
"LBL_RunSQLSelectionAction"));
         putValue("noIconInMenu", Boolean.TRUE);
     }
 
+    @Override
+    protected String getIconBase() {
+        return ICON_PATH;
+    }
+
     public String getDisplayName(SQLExecution sqlExecution) {
         if (sqlExecution == null || sqlExecution.isSelection()) {
             return NbBundle.getMessage(RunSQLSelectionAction.class, 
"LBL_RunSelectionAction");

[hg] main-silver: #205819: Allow to run partial queries not only...

Jaroslav Havlin 02/22/2013

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close