Have the same title name in output window as in editor tab release701
authorSasanka Dharmasena <sasankad@netbeans.org>
Wed, 19 Oct 2011 11:31:38 +0530
branchrelease701
changeset 48db176eabc5b4
parent 47 1d287135db68
child 49 cc34c3c258f1
Have the same title name in output window as in editor tab
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CreateTestBlockAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/ViewDataAction.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/ui/SQLCommandWindow.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/ui/SQLExecutionAction.java
     1.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CreateTestBlockAction.java	Mon Oct 17 15:09:02 2011 +0530
     1.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CreateTestBlockAction.java	Wed Oct 19 11:31:38 2011 +0530
     1.3 @@ -78,587 +78,587 @@
     1.4  
     1.5  public final class CreateTestBlockAction extends CookieAction {
     1.6  
     1.7 -   private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
     1.8 -   private PlsqlBlock selectedBlock = null;
     1.9 -   private String selectedName = "";
    1.10 -   private String parentName = "";
    1.11 -   private DataObject dataObject = null;
    1.12 -   private Document doc = null;
    1.13 -   private int position = -1;
    1.14 +    private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    1.15 +    private static final String TEST_BLOCK_NAME_PREFIX = "TestBlock: ";
    1.16 +    private PlsqlBlock selectedBlock = null;
    1.17 +    private String selectedName = "";
    1.18 +    private String parentName = "";
    1.19 +    private DataObject dataObject = null;
    1.20 +    private Document doc = null;
    1.21 +    private int position = -1;
    1.22  
    1.23 -   /**
    1.24 -    * Create a SQL execution window for the selected method
    1.25 -    * @param activatedNodes
    1.26 -    */
    1.27 -   @Override
    1.28 -   protected void performAction(Node[] activatedNodes) {
    1.29 -      if (selectedName.equals("")) {
    1.30 -         return;
    1.31 -      }
    1.32 +    /**
    1.33 +     * Create a SQL execution window for the selected method
    1.34 +     * @param activatedNodes
    1.35 +     */
    1.36 +    @Override
    1.37 +    protected void performAction(Node[] activatedNodes) {
    1.38 +        if (selectedName.equals("")) {
    1.39 +            return;
    1.40 +        }
    1.41  
    1.42 -      String tempTemplate = "";
    1.43 +        String tempTemplate = "";
    1.44  
    1.45 -      Project project = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
    1.46 -      if (project == null) {
    1.47 -         return;
    1.48 -      }
    1.49 -      DatabaseConnectionManager dbConnectionProvider = DatabaseConnectionManager.getInstance(project);
    1.50 -      if (project == null || dbConnectionProvider == null) {
    1.51 -         return;
    1.52 -      }
    1.53 -      DatabaseConnection databaseConnection = dbConnectionProvider != null ? dbConnectionProvider.getPooledDatabaseConnection(false) : null;
    1.54 -      try {
    1.55 -         if (selectedBlock != null && selectedBlock.getType() == VIEW) {
    1.56 -            tempTemplate = "SELECT ${*} FROM " + selectedName + ";\n${cursor}";
    1.57 -         } else if (selectedBlock != null && selectedBlock.getType() == CURSOR) {
    1.58 -            try {
    1.59 -               tempTemplate = doc.getText(selectedBlock.getStartOffset(), selectedBlock.getEndOffset() - selectedBlock.getStartOffset());
    1.60 -            } catch (BadLocationException ex) {
    1.61 -               //Failed to extract statement from cursor. This shouldn't happen, but if it does - do nothing;
    1.62 -               return;
    1.63 +        Project project = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
    1.64 +        if (project == null) {
    1.65 +            return;
    1.66 +        }
    1.67 +        DatabaseConnectionManager dbConnectionProvider = DatabaseConnectionManager.getInstance(project);
    1.68 +        if (project == null || dbConnectionProvider == null) {
    1.69 +            return;
    1.70 +        }
    1.71 +        DatabaseConnection databaseConnection = dbConnectionProvider != null ? dbConnectionProvider.getPooledDatabaseConnection(false) : null;
    1.72 +        try {
    1.73 +            if (selectedBlock != null && selectedBlock.getType() == VIEW) {
    1.74 +                tempTemplate = "SELECT ${*} FROM " + selectedName + ";\n${cursor}";
    1.75 +            } else if (selectedBlock != null && selectedBlock.getType() == CURSOR) {
    1.76 +                try {
    1.77 +                    tempTemplate = doc.getText(selectedBlock.getStartOffset(), selectedBlock.getEndOffset() - selectedBlock.getStartOffset());
    1.78 +                } catch (BadLocationException ex) {
    1.79 +                    //Failed to extract statement from cursor. This shouldn't happen, but if it does - do nothing;
    1.80 +                    return;
    1.81 +                }
    1.82 +                tempTemplate = tempTemplate.substring(tempTemplate.indexOf("SELECT"));
    1.83 +                tempTemplate = tempTemplate.replaceAll("(\\w*_\\b)", "\\${$0}") + "\n${cursor";
    1.84 +            } else {
    1.85 +                try {
    1.86 +                    if (selectedBlock == null && !parentName.equals("")) {
    1.87 +                        //Find the selected block
    1.88 +                        DataObject data = PlsqlFileUtil.openExistingFile(doc, parentName, PACKAGE, project);
    1.89 +                        if (data == null) {
    1.90 +                            data = PlsqlFileUtil.openExistingFile(doc, parentName, PACKAGE, project);
    1.91 +                        }
    1.92 +                        if (data == null) {
    1.93 +                            data = PlsqlFileUtil.fetchAsTempFile(parentName, PACKAGE, databaseConnection, project, dataObject);
    1.94 +                        }
    1.95 +
    1.96 +                        if (data != null) {
    1.97 +                            Document referredDoc = PlsqlFileUtil.getDocument(data);
    1.98 +                            selectMatchingBlock(data, referredDoc, position);
    1.99 +                        }
   1.100 +
   1.101 +                        //selected block in package body   
   1.102 +                    } else if (selectedBlock != null && (selectedBlock.getType() == PROCEDURE_IMPL
   1.103 +                            || selectedBlock.getType() == FUNCTION_IMPL)) {
   1.104 +                        //Find the definition of the method, we need to do this because if this is a implementation method,
   1.105 +                        //we cannot call it as Package.Method
   1.106 +                        //check whether the def block is in the same file
   1.107 +                        PlsqlBlock temp = selectedBlock;
   1.108 +                        selectedBlock = null;
   1.109 +                        DataObject dataObj = null;
   1.110 +                        PlsqlBlock block = PlsqlParserUtil.findMatchingBlock(PlsqlParserUtil.getBlockHierarchy(dataObject), doc, doc, selectedName, parentName, temp.getStartOffset(), false, false, true);
   1.111 +                        if (block == null) {
   1.112 +                            Document specDoc = getSpecDocument(doc);
   1.113 +                            if (specDoc == null) {
   1.114 +                                dataObj = PlsqlFileUtil.fetchAsTempFile(temp.getParent().getName(), PACKAGE, databaseConnection, project, dataObject);
   1.115 +                            }
   1.116 +
   1.117 +                            if (specDoc != null || dataObj != null) {
   1.118 +                                if (specDoc != null) {
   1.119 +                                    dataObj = FileExecutionUtil.getDataObject(specDoc);
   1.120 +                                } else {
   1.121 +                                    specDoc = PlsqlFileUtil.getDocument(dataObj);
   1.122 +                                }
   1.123 +                                selectMatchingBlock(dataObj, specDoc, temp.getStartOffset());
   1.124 +                            }
   1.125 +                        } else {
   1.126 +                            selectedBlock = block;
   1.127 +                        }
   1.128 +
   1.129 +                        if (selectedBlock == null) {
   1.130 +                            JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Failed creating the test block; selected method might not be there in the specification", "Error", JOptionPane.ERROR_MESSAGE);
   1.131 +                            return;
   1.132 +                        }
   1.133 +                    }
   1.134 +
   1.135 +                    if (selectedBlock.getParent() != null) {
   1.136 +                        selectedName = selectedBlock.getParent().getName() + "." + selectedBlock.getName();
   1.137 +                    }
   1.138 +                    tempTemplate = createMethodTemplate(doc);
   1.139 +                } catch (NotConnectedToDbException e) {
   1.140 +                    Exceptions.printStackTrace(e);
   1.141 +                }
   1.142              }
   1.143 -            tempTemplate = tempTemplate.substring(tempTemplate.indexOf("SELECT"));
   1.144 -            tempTemplate = tempTemplate.replaceAll("(\\w*_\\b)", "\\${$0}") + "\n${cursor";
   1.145 -         } else {
   1.146 -            try {
   1.147 -               if (selectedBlock == null && !parentName.equals("")) {
   1.148 -                  //Find the selected block
   1.149 -                  DataObject data = PlsqlFileUtil.openExistingFile(doc, parentName, PACKAGE, project);
   1.150 -                  if (data == null) {
   1.151 -                     data = PlsqlFileUtil.openExistingFile(doc, parentName, PACKAGE, project);
   1.152 -                  }
   1.153 -                  if (data == null) {
   1.154 -                     data = PlsqlFileUtil.fetchAsTempFile(parentName, PACKAGE, databaseConnection, project, dataObject);
   1.155 -                  }
   1.156 +        } finally {
   1.157 +            if (databaseConnection != null) {
   1.158 +                dbConnectionProvider.releaseDatabaseConnection(databaseConnection);
   1.159 +            }
   1.160 +        }
   1.161  
   1.162 -                  if (data != null) {
   1.163 -                     Document referredDoc = PlsqlFileUtil.getDocument(data);
   1.164 -                     selectMatchingBlock(data, referredDoc, position);
   1.165 -                  }
   1.166 -                  
   1.167 -               //selected block in package body   
   1.168 -               } else if (selectedBlock != null && (selectedBlock.getType() == PROCEDURE_IMPL
   1.169 -                       || selectedBlock.getType() == FUNCTION_IMPL)) {
   1.170 -                  //Find the definition of the method, we need to do this because if this is a implementation method,
   1.171 -                  //we cannot call it as Package.Method
   1.172 -                  //check whether the def block is in the same file
   1.173 -                  PlsqlBlock temp = selectedBlock;
   1.174 -                  selectedBlock = null;
   1.175 -                  DataObject dataObj = null;
   1.176 -                  PlsqlBlock block = PlsqlParserUtil.findMatchingBlock(PlsqlParserUtil.getBlockHierarchy(dataObject), doc, doc, selectedName, parentName, temp.getStartOffset(), false, false, true);
   1.177 -                  if (block == null) {
   1.178 -                     Document specDoc = getSpecDocument(doc);
   1.179 -                     if (specDoc == null) {
   1.180 -                        dataObj = PlsqlFileUtil.fetchAsTempFile(temp.getParent().getName(), PACKAGE, databaseConnection, project, dataObject);
   1.181 -                     }
   1.182 +        //Replace aliases where possible
   1.183 +        tempTemplate = replaceAliases(tempTemplate, dataObject.getLookup().lookup(PlsqlBlockFactory.class), '&');
   1.184  
   1.185 -                     if (specDoc != null || dataObj != null) {
   1.186 -                        if (specDoc != null) {
   1.187 -                           dataObj = FileExecutionUtil.getDataObject(specDoc);
   1.188 -                        } else {
   1.189 -                           specDoc = PlsqlFileUtil.getDocument(dataObj);
   1.190 -                        }
   1.191 -                        selectMatchingBlock(dataObj, specDoc, temp.getStartOffset());
   1.192 -                     }
   1.193 -                  } else {
   1.194 -                     selectedBlock = block;
   1.195 -                  }
   1.196 +        SQLCommandWindow.createSQLCommandWindow(activatedNodes, tempTemplate, TEST_BLOCK_NAME_PREFIX + selectedName);
   1.197 +    }
   1.198  
   1.199 -                  if (selectedBlock == null) {
   1.200 -	  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Failed creating the test block; selected method might not be there in the specification", "Error", JOptionPane.ERROR_MESSAGE);
   1.201 -	  return;
   1.202 -                  }
   1.203 -               }
   1.204 -               
   1.205 -               if (selectedBlock.getParent() != null) {
   1.206 -                  selectedName = selectedBlock.getParent().getName() + "." + selectedBlock.getName();
   1.207 -               }
   1.208 -               tempTemplate = createMethodTemplate(doc);
   1.209 -            } catch (NotConnectedToDbException e) {
   1.210 -               Exceptions.printStackTrace(e);
   1.211 +    @Override
   1.212 +    protected int mode() {
   1.213 +        return CookieAction.MODE_EXACTLY_ONE;
   1.214 +    }
   1.215 +
   1.216 +    @Override
   1.217 +    public String getName() {
   1.218 +        return NbBundle.getMessage(CreateTestBlockAction.class, "CTL_CreateTestBlockAction");
   1.219 +    }
   1.220 +
   1.221 +    @Override
   1.222 +    protected Class[] cookieClasses() {
   1.223 +        return new Class[]{DataObject.class, EditorCookie.class};
   1.224 +    }
   1.225 +
   1.226 +    @Override
   1.227 +    protected void initialize() {
   1.228 +        super.initialize();
   1.229 +        // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
   1.230 +        putValue("noIconInMenu", Boolean.TRUE);
   1.231 +    }
   1.232 +
   1.233 +    @Override
   1.234 +    public HelpCtx getHelpCtx() {
   1.235 +        return HelpCtx.DEFAULT_HELP;
   1.236 +    }
   1.237 +
   1.238 +    @Override
   1.239 +    protected boolean asynchronous() {
   1.240 +        return false;
   1.241 +    }
   1.242 +
   1.243 +    /**
   1.244 +     * Enable this action when right clicked on procedures or functions
   1.245 +     * @param arg0
   1.246 +     * @return
   1.247 +     */
   1.248 +    @Override
   1.249 +    protected boolean enable(Node[] activatedNodes) {
   1.250 +        if (!super.enable(activatedNodes)) {
   1.251 +            return false;
   1.252 +        }
   1.253 +
   1.254 +        EditorCookie editorCookie = activatedNodes[0].getLookup().lookup(EditorCookie.class);
   1.255 +        if (editorCookie == null) {
   1.256 +            return false;
   1.257 +        }
   1.258 +
   1.259 +        //Reset class variables again
   1.260 +        selectedBlock = null;
   1.261 +        selectedName = "";
   1.262 +        parentName = "";
   1.263 +        position = -1;
   1.264 +
   1.265 +        int dotOffset = -1;
   1.266 +        int markOffset = -1;
   1.267 +
   1.268 +        JEditorPane[] panes = editorCookie.getOpenedPanes();
   1.269 +        if ((panes != null) && (panes.length != 0)) {
   1.270 +            Caret caret = panes[0].getCaret();
   1.271 +            dotOffset = caret.getDot();
   1.272 +            markOffset = caret.getMark();
   1.273 +        }
   1.274 +
   1.275 +        //If we are able to take the selected position get data object and get the block factory
   1.276 +        if (dotOffset != -1 && markOffset != -1) {
   1.277 +            dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
   1.278 +            doc = editorCookie.getDocument();
   1.279 +            if (dataObject != null && doc != null) {
   1.280 +                Project project = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
   1.281 +                DatabaseConnectionManager dbConnectionProvider = DatabaseConnectionManager.getInstance(project);
   1.282 +                if (project == null || dbConnectionProvider == null) {
   1.283 +                    return false;
   1.284 +                }
   1.285 +
   1.286 +                position = dotOffset < markOffset ? dotOffset : markOffset;
   1.287 +                List<PlsqlBlock> blockHier = dataObject.getLookup().lookup(PlsqlBlockFactory.class).getBlockHierarchy();
   1.288 +                //If there is a selection check whether the selection is a method name
   1.289 +                if (validator.isValidTDB(dataObject) || validator.isValidPackageBody(dataObject)) {
   1.290 +                    boolean isSucess = checkForMethodCall(doc, dbConnectionProvider, position);
   1.291 +                    if (isSucess) {
   1.292 +                        return true;
   1.293 +                    }
   1.294 +                }
   1.295 +
   1.296 +                //If there is no selection or selection is not a method call
   1.297 +                String methodName = "";
   1.298 +                methodName = getEnclosingMethodName(blockHier, dotOffset, methodName);
   1.299 +                if (!methodName.equals("")) {
   1.300 +                    selectedName = methodName;
   1.301 +                    return true;
   1.302 +                }
   1.303              }
   1.304 -         }
   1.305 -      } finally {
   1.306 -         if (databaseConnection != null) {
   1.307 -            dbConnectionProvider.releaseDatabaseConnection(databaseConnection);
   1.308 -         }
   1.309 -      }
   1.310 +        }
   1.311 +        return false;
   1.312 +    }
   1.313  
   1.314 -      //Replace aliases where possible
   1.315 -      tempTemplate = replaceAliases(tempTemplate, dataObject.getLookup().lookup(PlsqlBlockFactory.class), '&');
   1.316 +    /**
   1.317 +     * Method that will create the template for the selected method
   1.318 +     * @param doc
   1.319 +     * @return
   1.320 +     */
   1.321 +    private String createMethodTemplate(Document doc) {
   1.322 +        String tempTemplate = "";
   1.323 +        TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
   1.324 +        @SuppressWarnings("unchecked")
   1.325 +        TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
   1.326  
   1.327 +        //If the current occurance is a variable declaration stop
   1.328 +        if (ts != null) {
   1.329 +            ts.move(selectedBlock.getStartOffset());
   1.330 +            ts.moveNext();
   1.331 +            Token<PlsqlTokenId> token = ts.token();
   1.332 +            boolean isParamStart = false;
   1.333 +            List<String> keys = new ArrayList<String>();
   1.334 +            List<String> values = new ArrayList<String>();
   1.335 +            String returnType = "";
   1.336 +            String name = "";
   1.337 +            String valueText = "";
   1.338  
   1.339 -      SQLCommandWindow.createSQLCommandWindow(activatedNodes, tempTemplate);
   1.340 -   }
   1.341 +            while (ts.moveNext()) {
   1.342 +                token = ts.token();
   1.343 +                PlsqlTokenId id = token.id();
   1.344 +                if (id == PlsqlTokenId.LPAREN) {
   1.345 +                    isParamStart = true;
   1.346 +                } else if (id == PlsqlTokenId.RPAREN) {
   1.347 +                    if (!name.equals("") && !valueText.equals("")) {
   1.348 +                        keys.add(name);
   1.349 +                        values.add(valueText);
   1.350 +                    }
   1.351  
   1.352 -   @Override
   1.353 -   protected int mode() {
   1.354 -      return CookieAction.MODE_EXACTLY_ONE;
   1.355 -   }
   1.356 -
   1.357 -   @Override
   1.358 -   public String getName() {
   1.359 -      return NbBundle.getMessage(CreateTestBlockAction.class, "CTL_CreateTestBlockAction");
   1.360 -   }
   1.361 -
   1.362 -   @Override
   1.363 -   protected Class[] cookieClasses() {
   1.364 -      return new Class[]{DataObject.class, EditorCookie.class};
   1.365 -   }
   1.366 -
   1.367 -   @Override
   1.368 -   protected void initialize() {
   1.369 -      super.initialize();
   1.370 -      // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
   1.371 -      putValue("noIconInMenu", Boolean.TRUE);
   1.372 -   }
   1.373 -
   1.374 -   @Override
   1.375 -   public HelpCtx getHelpCtx() {
   1.376 -      return HelpCtx.DEFAULT_HELP;
   1.377 -   }
   1.378 -
   1.379 -   @Override
   1.380 -   protected boolean asynchronous() {
   1.381 -      return false;
   1.382 -   }
   1.383 -
   1.384 -   /**
   1.385 -    * Enable this action when right clicked on procedures or functions
   1.386 -    * @param arg0
   1.387 -    * @return
   1.388 -    */
   1.389 -   @Override
   1.390 -   protected boolean enable(Node[] activatedNodes) {
   1.391 -      if (!super.enable(activatedNodes)) {
   1.392 -         return false;
   1.393 -      }
   1.394 -
   1.395 -      EditorCookie editorCookie = activatedNodes[0].getLookup().lookup(EditorCookie.class);
   1.396 -      if (editorCookie == null) {
   1.397 -         return false;
   1.398 -      }
   1.399 -
   1.400 -      //Reset class variables again
   1.401 -      selectedBlock = null;
   1.402 -      selectedName = "";
   1.403 -      parentName = "";
   1.404 -      position = -1;
   1.405 -
   1.406 -      int dotOffset = -1;
   1.407 -      int markOffset = -1;
   1.408 -
   1.409 -      JEditorPane[] panes = editorCookie.getOpenedPanes();
   1.410 -      if ((panes != null) && (panes.length != 0)) {
   1.411 -         Caret caret = panes[0].getCaret();
   1.412 -         dotOffset = caret.getDot();
   1.413 -         markOffset = caret.getMark();
   1.414 -      }
   1.415 -
   1.416 -      //If we are able to take the selected position get data object and get the block factory
   1.417 -      if (dotOffset != -1 && markOffset != -1) {
   1.418 -         dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
   1.419 -         doc = editorCookie.getDocument();
   1.420 -         if (dataObject != null && doc != null) {
   1.421 -            Project project = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
   1.422 -            DatabaseConnectionManager dbConnectionProvider = DatabaseConnectionManager.getInstance(project);
   1.423 -            if (project == null || dbConnectionProvider == null) {
   1.424 -               return false;
   1.425 +                    if ((selectedBlock.getType() == PROCEDURE_DEF)
   1.426 +                            || (selectedBlock.getType() == PROCEDURE_IMPL)) {
   1.427 +                        break;
   1.428 +                    }
   1.429 +                } else if (id == PlsqlTokenId.KEYWORD && token.text().toString().equalsIgnoreCase("RETURN")) {
   1.430 +                    valueText = "";
   1.431 +                    isParamStart = true;
   1.432 +                } else if (isParamStart && id == PlsqlTokenId.IDENTIFIER && name.equals("")) {
   1.433 +                    name = token.text().toString();
   1.434 +                } else if (id == PlsqlTokenId.OPERATOR && token.text().toString().equals(",")) {
   1.435 +                    keys.add(name);
   1.436 +                    values.add(valueText);
   1.437 +                    name = "";
   1.438 +                    valueText = "";
   1.439 +                } else if ((id == PlsqlTokenId.OPERATOR && token.text().toString().equals(";"))
   1.440 +                        || (id == PlsqlTokenId.KEYWORD && token.text().toString().equalsIgnoreCase("IS"))) {
   1.441 +                    if (!valueText.equals("")) {
   1.442 +                        returnType = valueText.trim();
   1.443 +                    }
   1.444 +                    break;
   1.445 +                } else if (isParamStart) {
   1.446 +                    valueText = valueText + token.text().toString();
   1.447 +                }
   1.448              }
   1.449  
   1.450 -            position = dotOffset < markOffset ? dotOffset : markOffset;
   1.451 -            List<PlsqlBlock> blockHier = dataObject.getLookup().lookup(PlsqlBlockFactory.class).getBlockHierarchy();
   1.452 -            //If there is a selection check whether the selection is a method name
   1.453 -            if (validator.isValidTDB(dataObject) || validator.isValidPackageBody(dataObject)) {
   1.454 -               boolean isSucess = checkForMethodCall(doc, dbConnectionProvider, position);
   1.455 -               if (isSucess) {
   1.456 -                  return true;
   1.457 -               }
   1.458 +            //Now we have got the parameters and types
   1.459 +            tempTemplate = "DECLARE\n";
   1.460 +            for (int i = 0; i < keys.size(); i++) {
   1.461 +                boolean out = false;
   1.462 +                boolean in = false;
   1.463 +                boolean isDefault = false;
   1.464 +                String defaultVal = null;
   1.465 +                String key = keys.get(i);
   1.466 +                String value = values.get(i);
   1.467 +                String type = "";
   1.468 +
   1.469 +                StringTokenizer tokenizer = new StringTokenizer(value, " \t\n");
   1.470 +                if (tokenizer.countTokens() == 1) {
   1.471 +                    type = value;
   1.472 +                }
   1.473 +
   1.474 +                while (tokenizer.hasMoreTokens()) {
   1.475 +                    String temp = tokenizer.nextToken();
   1.476 +                    if (temp.equalsIgnoreCase("OUT")) {
   1.477 +                        out = true;
   1.478 +                    } else if (temp.equalsIgnoreCase("IN")) {
   1.479 +                        in = true;
   1.480 +                    } else if (temp.equalsIgnoreCase("DEFAULT")) {
   1.481 +                        isDefault = true;
   1.482 +                    } else if (isDefault) {
   1.483 +                        defaultVal = temp;
   1.484 +                        isDefault = false;
   1.485 +                    } else {
   1.486 +                        type = type + " " + temp;
   1.487 +                    }
   1.488 +                }
   1.489 +
   1.490 +                //if type is VARCHAR2 specify length
   1.491 +                if (type.trim().equalsIgnoreCase("VARCHAR2")) {
   1.492 +                    type = "VARCHAR2(50)";
   1.493 +                }
   1.494 +
   1.495 +                //Now we are ready to declare variables
   1.496 +                if (out && !in) {
   1.497 +                    tempTemplate = tempTemplate + " " + key.trim() + " " + type.trim() + ";\n";
   1.498 +                } else {
   1.499 +                    if (defaultVal != null) {
   1.500 +                        tempTemplate = tempTemplate + " " + key.trim() + " " + type.trim() + ":= ${" + key + " default=\"" + defaultVal + "\"};\n";
   1.501 +                    } else {
   1.502 +                        tempTemplate = tempTemplate + " " + key.trim() + " " + type.trim() + ":= ${" + key + " default=\"&" + key + "\"};\n";
   1.503 +                    }
   1.504 +                }
   1.505              }
   1.506  
   1.507 -            //If there is no selection or selection is not a method call
   1.508 -            String methodName = "";
   1.509 -            methodName = getEnclosingMethodName(blockHier, dotOffset, methodName);
   1.510 -            if (!methodName.equals("")) {
   1.511 -               selectedName = methodName;
   1.512 -               return true;
   1.513 -            }
   1.514 -         }
   1.515 -      }
   1.516 -      return false;
   1.517 -   }
   1.518 -
   1.519 -   /**
   1.520 -    * Method that will create the template for the selected method
   1.521 -    * @param doc
   1.522 -    * @return
   1.523 -    */
   1.524 -   private String createMethodTemplate(Document doc) {
   1.525 -      String tempTemplate = "";
   1.526 -      TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
   1.527 -      @SuppressWarnings("unchecked")
   1.528 -      TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
   1.529 -
   1.530 -      //If the current occurance is a variable declaration stop
   1.531 -      if (ts != null) {
   1.532 -         ts.move(selectedBlock.getStartOffset());
   1.533 -         ts.moveNext();
   1.534 -         Token<PlsqlTokenId> token = ts.token();
   1.535 -         boolean isParamStart = false;
   1.536 -         List<String> keys = new ArrayList<String>();
   1.537 -         List<String> values = new ArrayList<String>();
   1.538 -         String returnType = "";
   1.539 -         String name = "";
   1.540 -         String valueText = "";
   1.541 -
   1.542 -         while (ts.moveNext()) {
   1.543 -            token = ts.token();
   1.544 -            PlsqlTokenId id = token.id();
   1.545 -            if (id == PlsqlTokenId.LPAREN) {
   1.546 -               isParamStart = true;
   1.547 -            } else if (id == PlsqlTokenId.RPAREN) {
   1.548 -               if (!name.equals("") && !valueText.equals("")) {
   1.549 -                  keys.add(name);
   1.550 -                  values.add(valueText);
   1.551 -               }
   1.552 -
   1.553 -               if ((selectedBlock.getType() == PROCEDURE_DEF)
   1.554 -                       || (selectedBlock.getType() == PROCEDURE_IMPL)) {
   1.555 -                  break;
   1.556 -               }
   1.557 -            } else if (id == PlsqlTokenId.KEYWORD && token.text().toString().equalsIgnoreCase("RETURN")) {
   1.558 -               valueText = "";
   1.559 -               isParamStart = true;
   1.560 -            } else if (isParamStart && id == PlsqlTokenId.IDENTIFIER && name.equals("")) {
   1.561 -               name = token.text().toString();
   1.562 -            } else if (id == PlsqlTokenId.OPERATOR && token.text().toString().equals(",")) {
   1.563 -               keys.add(name);
   1.564 -               values.add(valueText);
   1.565 -               name = "";
   1.566 -               valueText = "";
   1.567 -            } else if ((id == PlsqlTokenId.OPERATOR && token.text().toString().equals(";"))
   1.568 -                    || (id == PlsqlTokenId.KEYWORD && token.text().toString().equalsIgnoreCase("IS"))) {
   1.569 -               if (!valueText.equals("")) {
   1.570 -                  returnType = valueText.trim();
   1.571 -               }
   1.572 -               break;
   1.573 -            } else if (isParamStart) {
   1.574 -               valueText = valueText + token.text().toString();
   1.575 -            }
   1.576 -         }
   1.577 -
   1.578 -         //Now we have got the parameters and types
   1.579 -         tempTemplate = "DECLARE\n";
   1.580 -         for (int i = 0; i < keys.size(); i++) {
   1.581 -            boolean out = false;
   1.582 -            boolean in = false;
   1.583 -            boolean isDefault = false;
   1.584 -            String defaultVal = null;
   1.585 -            String key = keys.get(i);
   1.586 -            String value = values.get(i);
   1.587 -            String type = "";
   1.588 -
   1.589 -            StringTokenizer tokenizer = new StringTokenizer(value, " \t\n");
   1.590 -            if (tokenizer.countTokens() == 1) {
   1.591 -               type = value;
   1.592 +            //If we have a complex type define the result
   1.593 +            if ((!returnType.equals("")) && (!returnType.equalsIgnoreCase("NUMBER"))
   1.594 +                    && (!returnType.equalsIgnoreCase("VARCHAR2")) && (!returnType.equalsIgnoreCase("DATE"))) {
   1.595 +                tempTemplate = tempTemplate + "result_ " + "${" + returnType + " default=\"" + returnType + "\"};\n";
   1.596              }
   1.597  
   1.598 -            while (tokenizer.hasMoreTokens()) {
   1.599 -               String temp = tokenizer.nextToken();
   1.600 -               if (temp.equalsIgnoreCase("OUT")) {
   1.601 -                  out = true;
   1.602 -               } else if (temp.equalsIgnoreCase("IN")) {
   1.603 -                  in = true;
   1.604 -               } else if (temp.equalsIgnoreCase("DEFAULT")) {
   1.605 -                  isDefault = true;
   1.606 -               } else if (isDefault) {
   1.607 -                  defaultVal = temp;
   1.608 -                  isDefault = false;
   1.609 -               } else {
   1.610 -                  type = type + " " + temp;
   1.611 -               }
   1.612 +            //Complete the template now
   1.613 +            tempTemplate = tempTemplate + "BEGIN\n\t${cursor}";
   1.614 +            if (returnType.equals("")) {
   1.615 +                tempTemplate = tempTemplate + selectedName + "(" + fillVariables(keys) + ");\n";
   1.616 +            } else if (returnType.equalsIgnoreCase("NUMBER") || returnType.equalsIgnoreCase("VARCHAR2")
   1.617 +                    || returnType.equalsIgnoreCase("DATE")) {
   1.618 +                tempTemplate = tempTemplate + "Dbms_Output.Put_Line('Return value: ' || " + selectedName + "(" + fillVariables(keys) + "));\n";
   1.619 +            } else if (returnType.equalsIgnoreCase("BOOLEAN")) {
   1.620 +                tempTemplate = tempTemplate + "result_ := " + selectedName + "(" + fillVariables(keys) + ");\n";
   1.621 +                tempTemplate = tempTemplate + "-- Convert false/true/null to 0/1/null\n";
   1.622 +                tempTemplate = tempTemplate + "Dbms_Output.Put_Line('Return value: ' || sys.diutil.bool_to_int(result_));\n";
   1.623 +            } else {
   1.624 +                //we have a complex type with us
   1.625 +                tempTemplate = tempTemplate + "result_ := " + selectedName + "(" + fillVariables(keys) + ");\n";
   1.626 +                tempTemplate = tempTemplate + "Dbms_Output.Put_Line(${output default =\"'<<<Put your output of the return variable here>>>'\"});\n";
   1.627              }
   1.628  
   1.629 -            //if type is VARCHAR2 specify length
   1.630 -            if (type.trim().equalsIgnoreCase("VARCHAR2")) {
   1.631 -               type = "VARCHAR2(50)";
   1.632 +            //print variables
   1.633 +            for (int i = 0; i < keys.size(); i++) {
   1.634 +                tempTemplate = tempTemplate + "Dbms_Output.Put_Line('" + keys.get(i) + "= ' || " + keys.get(i) + ");\n";
   1.635              }
   1.636  
   1.637 -            //Now we are ready to declare variables
   1.638 -            if (out && !in) {
   1.639 -               tempTemplate = tempTemplate + " " + key.trim() + " " + type.trim() + ";\n";
   1.640 +            tempTemplate = tempTemplate + "END;\n/";
   1.641 +        }
   1.642 +
   1.643 +        return tempTemplate;
   1.644 +    }
   1.645 +
   1.646 +    /**
   1.647 +     * Method that will fill variables inside the method
   1.648 +     * @param keys
   1.649 +     * @return
   1.650 +     */
   1.651 +    private String fillVariables(List<String> keys) {
   1.652 +        String variables = "";
   1.653 +        for (int i = 0; i < keys.size(); i++) {
   1.654 +            variables = variables + keys.get(i);
   1.655 +            if (i != keys.size() - 1) {
   1.656 +                variables = variables + ",";
   1.657 +            }
   1.658 +        }
   1.659 +        return variables;
   1.660 +    }
   1.661 +
   1.662 +    /**
   1.663 +     * Method that will get the method name that encloses the given offset
   1.664 +     * @param blockHier
   1.665 +     * @param offset
   1.666 +     * @return
   1.667 +     */
   1.668 +    private String getEnclosingMethodName(List blockHier, int offset, String methodName) {
   1.669 +        for (int i = 0; i < blockHier.size(); i++) {
   1.670 +            PlsqlBlock temp = (PlsqlBlock) blockHier.get(i);
   1.671 +            if ((offset <= temp.getEndOffset()) && (offset >= temp.getStartOffset())) {
   1.672 +                //Offset is within the block, if this is not a procedure look at the children and return
   1.673 +                if ((temp.getType() == PROCEDURE_DEF)
   1.674 +                        || (temp.getType() == FUNCTION_DEF)
   1.675 +                        || (temp.getType() == CURSOR)
   1.676 +                        || (temp.getType() == VIEW)) {
   1.677 +                    if (methodName.equals("")) {
   1.678 +                        methodName = temp.getName();
   1.679 +                    } else {
   1.680 +                        methodName = methodName + "." + temp.getName();
   1.681 +                    }
   1.682 +
   1.683 +                    //Otherwise if the action is performed have to look for the block again
   1.684 +                    selectedBlock = temp;
   1.685 +                } else if ((temp.getType() == FUNCTION_IMPL)
   1.686 +                        || (temp.getType() == PROCEDURE_IMPL)) {
   1.687 +                    //check to see if there's an inner cursor that should be tested
   1.688 +                    if (temp.getChildCount() > 0) {
   1.689 +                        List children = temp.getChildBlocks();
   1.690 +                        for (int j = 0; j < children.size(); j++) {
   1.691 +                            PlsqlBlock child = (PlsqlBlock) children.get(j);
   1.692 +                            if (child.getType() == CURSOR && (offset <= child.getEndOffset()) && (offset >= child.getStartOffset())) {
   1.693 +                                methodName = "Cursor";
   1.694 +                                selectedBlock = child;
   1.695 +                                return methodName;
   1.696 +                            }
   1.697 +                        }
   1.698 +                    }
   1.699 +
   1.700 +                    methodName = temp.getName();
   1.701 +                    //Otherwise if the action is performed have to look for the block again
   1.702 +                    selectedBlock = temp;
   1.703 +                } else if ((temp.getType() == PACKAGE_BODY)
   1.704 +                        || (temp.getType() == PACKAGE)) {
   1.705 +                    methodName = temp.getName();
   1.706 +                    String tempName = getEnclosingMethodName(temp.getChildBlocks(), offset, methodName);
   1.707 +                    if (!tempName.equals(methodName)) {
   1.708 +                        methodName = tempName;
   1.709 +                    } else {
   1.710 +                        methodName = "";
   1.711 +                    }
   1.712 +                }
   1.713 +                break;
   1.714 +            }
   1.715 +        }
   1.716 +        return methodName;
   1.717 +    }
   1.718 +
   1.719 +    /**
   1.720 +     * Replace aliases in the given string
   1.721 +     * @param plsqlString
   1.722 +     * @param blockFac
   1.723 +     * @param define
   1.724 +     * @return
   1.725 +     */
   1.726 +    public String replaceAliases(String plsqlString, PlsqlBlockFactory blockFac, char define) {
   1.727 +        if (plsqlString.indexOf(define) < 0) {
   1.728 +            return plsqlString;
   1.729 +        }
   1.730 +
   1.731 +        StringBuilder newString = new StringBuilder();
   1.732 +        for (int i = 0; i < plsqlString.length(); i++) {
   1.733 +            char c = plsqlString.charAt(i);
   1.734 +            if (c == define) {
   1.735 +                for (int j = i + 1; j < plsqlString.length(); j++) {
   1.736 +                    char nextChar = plsqlString.charAt(j);
   1.737 +                    if (Character.isJavaIdentifierPart(nextChar) && j == plsqlString.length() - 1) { //we have reached the end of the text
   1.738 +                        nextChar = '.'; //this will make sure that the correct sustitution is made below by emulating an additional character
   1.739 +                        j = j + 1;
   1.740 +                    }
   1.741 +                    if (!Character.isJavaIdentifierPart(nextChar)) { //potential end of substitutionvariable
   1.742 +                        if (j > i + 1) { //substituion variable found
   1.743 +                            String name = plsqlString.substring(i, j);
   1.744 +                            String value = blockFac.getDefine(name);
   1.745 +                            newString.append(value);
   1.746 +                            if (nextChar == '.') {
   1.747 +                                i = j;
   1.748 +                            } else {
   1.749 +                                i = j - 1;
   1.750 +                            }
   1.751 +                        } else {
   1.752 +                            newString.append(c);
   1.753 +                        }
   1.754 +                        break;
   1.755 +                    }
   1.756 +                }
   1.757              } else {
   1.758 -               if (defaultVal != null) {
   1.759 -                  tempTemplate = tempTemplate + " " + key.trim() + " " + type.trim() + ":= ${" + key + " default=\"" + defaultVal + "\"};\n";
   1.760 -               } else {
   1.761 -                  tempTemplate = tempTemplate + " " + key.trim() + " " + type.trim() + ":= ${" + key + " default=\"&" + key + "\"};\n";
   1.762 -               }
   1.763 +                newString.append(c);
   1.764              }
   1.765 -         }
   1.766 +        }
   1.767 +        return newString.toString();
   1.768 +    }
   1.769  
   1.770 -         //If we have a complex type define the result
   1.771 -         if ((!returnType.equals("")) && (!returnType.equalsIgnoreCase("NUMBER"))
   1.772 -                 && (!returnType.equalsIgnoreCase("VARCHAR2")) && (!returnType.equalsIgnoreCase("DATE"))) {
   1.773 -            tempTemplate = tempTemplate + "result_ " + "${" + returnType + " default=\"" + returnType + "\"};\n";
   1.774 -         }
   1.775 +    /**
   1.776 +     * Check whether the selection is a method call
   1.777 +     * @param document
   1.778 +     * @param dbConnectionProvider
   1.779 +     * @param project
   1.780 +     * @param startOffset
   1.781 +     * @return
   1.782 +     */
   1.783 +    private boolean checkForMethodCall(Document document, DatabaseConnectionManager dbConnectionProvider, int startOffset) {
   1.784 +        DatabaseConnection databaseConnection = dbConnectionProvider != null ? dbConnectionProvider.getPooledDatabaseConnection(false) : null;
   1.785 +        try {
   1.786 +            DatabaseContentManager cache = databaseConnection != null ? DatabaseContentManager.getInstance(databaseConnection) : null;
   1.787  
   1.788 -         //Complete the template now
   1.789 -         tempTemplate = tempTemplate + "BEGIN\n\t${cursor}";
   1.790 -         if (returnType.equals("")) {
   1.791 -            tempTemplate = tempTemplate + selectedName + "(" + fillVariables(keys) + ");\n";
   1.792 -         } else if (returnType.equalsIgnoreCase("NUMBER") || returnType.equalsIgnoreCase("VARCHAR2")
   1.793 -                 || returnType.equalsIgnoreCase("DATE")) {
   1.794 -            tempTemplate = tempTemplate + "Dbms_Output.Put_Line('Return value: ' || " + selectedName + "(" + fillVariables(keys) + "));\n";
   1.795 -         } else if (returnType.equalsIgnoreCase("BOOLEAN")) {
   1.796 -            tempTemplate = tempTemplate + "result_ := " + selectedName + "(" + fillVariables(keys) + ");\n";
   1.797 -            tempTemplate = tempTemplate + "-- Convert false/true/null to 0/1/null\n";
   1.798 -            tempTemplate = tempTemplate + "Dbms_Output.Put_Line('Return value: ' || sys.diutil.bool_to_int(result_));\n";
   1.799 -         } else {
   1.800 -            //we have a complex type with us
   1.801 -            tempTemplate = tempTemplate + "result_ := " + selectedName + "(" + fillVariables(keys) + ");\n";
   1.802 -            tempTemplate = tempTemplate + "Dbms_Output.Put_Line(${output default =\"'<<<Put your output of the return variable here>>>'\"});\n";
   1.803 -         }
   1.804 +            String selected = "";
   1.805 +            String parent = "";
   1.806  
   1.807 -         //print variables
   1.808 -         for (int i = 0; i < keys.size(); i++) {
   1.809 -            tempTemplate = tempTemplate + "Dbms_Output.Put_Line('" + keys.get(i) + "= ' || " + keys.get(i) + ");\n";
   1.810 -         }
   1.811 +            //Get the current token
   1.812 +            TokenHierarchy tokenHierarchy = TokenHierarchy.get(document);
   1.813 +            @SuppressWarnings("unchecked")
   1.814 +            TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
   1.815  
   1.816 -         tempTemplate = tempTemplate + "END;\n/";
   1.817 -      }
   1.818 +            if (ts != null) {
   1.819 +                //move offset
   1.820 +                ts.move(startOffset);
   1.821 +                if (ts.moveNext()) {
   1.822 +                    Token<PlsqlTokenId> token = ts.token();
   1.823 +                    PlsqlTokenId tokenID = token.id();
   1.824  
   1.825 -      return tempTemplate;
   1.826 -   }
   1.827 +                    if (tokenID == PlsqlTokenId.IDENTIFIER) {
   1.828 +                        selected = token.text().toString();
   1.829 +                        if (ts.movePrevious()) {
   1.830 +                            token = ts.token();
   1.831 +                            if (token.id() == PlsqlTokenId.DOT && ts.movePrevious()) {
   1.832 +                                parent = ts.token().toString();
   1.833 +                            }
   1.834 +                        }
   1.835 +                    }
   1.836 +                }
   1.837 +            }
   1.838  
   1.839 -   /**
   1.840 -    * Method that will fill variables inside the method
   1.841 -    * @param keys
   1.842 -    * @return
   1.843 -    */
   1.844 -   private String fillVariables(List<String> keys) {
   1.845 -      String variables = "";
   1.846 -      for (int i = 0; i < keys.size(); i++) {
   1.847 -         variables = variables + keys.get(i);
   1.848 -         if (i != keys.size() - 1) {
   1.849 -            variables = variables + ",";
   1.850 -         }
   1.851 -      }
   1.852 -      return variables;
   1.853 -   }
   1.854 +            if (!parent.equals("")) {
   1.855 +                //If parent is a package we can think that this is a method call
   1.856 +                if (cache != null && cache.isPackage(parent, databaseConnection)) {
   1.857 +                    selectedName = selected;
   1.858 +                    parentName = parent;
   1.859 +                    return true;
   1.860 +                }
   1.861 +            } else {
   1.862 +                PlsqlBlock packageBlock = getEnclosingPackageBody(dataObject.getLookup().lookup(PlsqlBlockFactory.class).getBlockHierarchy(), startOffset);
   1.863 +                if (packageBlock != null && isMethodName(packageBlock.getChildBlocks(), selected, startOffset)) {
   1.864 +                    return true;
   1.865 +                }
   1.866 +            }
   1.867  
   1.868 -   /**
   1.869 -    * Method that will get the method name that encloses the given offset
   1.870 -    * @param blockHier
   1.871 -    * @param offset
   1.872 -    * @return
   1.873 -    */
   1.874 -   private String getEnclosingMethodName(List blockHier, int offset, String methodName) {
   1.875 -      for (int i = 0; i < blockHier.size(); i++) {
   1.876 -         PlsqlBlock temp = (PlsqlBlock) blockHier.get(i);
   1.877 -         if ((offset <= temp.getEndOffset()) && (offset >= temp.getStartOffset())) {
   1.878 -            //Offset is within the block, if this is not a procedure look at the children and return
   1.879 -            if ((temp.getType() == PROCEDURE_DEF)
   1.880 -                    || (temp.getType() == FUNCTION_DEF)
   1.881 -                    || (temp.getType() == CURSOR)
   1.882 -                    || (temp.getType() == VIEW)) {
   1.883 -               if (methodName.equals("")) {
   1.884 -                  methodName = temp.getName();
   1.885 -               } else {
   1.886 -                  methodName = methodName + "." + temp.getName();
   1.887 -               }
   1.888 +            return false;
   1.889 +        } finally {
   1.890 +            dbConnectionProvider.releaseDatabaseConnection(databaseConnection);
   1.891 +        }
   1.892 +    }
   1.893  
   1.894 -               //Otherwise if the action is performed have to look for the block again
   1.895 -               selectedBlock = temp;
   1.896 -            } else if ((temp.getType() == FUNCTION_IMPL)
   1.897 -                    || (temp.getType() == PROCEDURE_IMPL)) {
   1.898 -               //check to see if there's an inner cursor that should be tested
   1.899 -               if (temp.getChildCount() > 0) {
   1.900 -                  List children = temp.getChildBlocks();
   1.901 -                  for (int j = 0; j < children.size(); j++) {
   1.902 -                     PlsqlBlock child = (PlsqlBlock) children.get(j);
   1.903 -                     if (child.getType() == CURSOR && (offset <= child.getEndOffset()) && (offset >= child.getStartOffset())) {
   1.904 -                        methodName = "Cursor";
   1.905 -                        selectedBlock = child;
   1.906 -                        return methodName;
   1.907 -                     }
   1.908 -                  }
   1.909 -               }
   1.910 +    private Document getSpecDocument(Document doc) {
   1.911 +        DataObject dataObj = FileExecutionUtil.getDataObject(doc);
   1.912 +        if (dataObj != null) {
   1.913 +            DataObject siblingDataObject = validator.getSiblingExt(dataObject);
   1.914 +            if (siblingDataObject != null) {
   1.915 +                return PlsqlFileUtil.getDocument(siblingDataObject);
   1.916 +            }
   1.917 +        }
   1.918 +        return null;
   1.919 +    }
   1.920  
   1.921 -               methodName = temp.getName();
   1.922 -               //Otherwise if the action is performed have to look for the block again
   1.923 -               selectedBlock = temp;
   1.924 -            } else if ((temp.getType() == PACKAGE_BODY)
   1.925 -                    || (temp.getType() == PACKAGE)) {
   1.926 -               methodName = temp.getName();
   1.927 -               String tempName = getEnclosingMethodName(temp.getChildBlocks(), offset, methodName);
   1.928 -               if (!tempName.equals(methodName)) {
   1.929 -                  methodName = tempName;
   1.930 -               } else {
   1.931 -                  methodName = "";
   1.932 -               }
   1.933 +    private boolean isMethodName(List<PlsqlBlock> blockHier, String selected, int offset) {
   1.934 +        if (blockHier != null) {
   1.935 +            for (PlsqlBlock block : blockHier) {
   1.936 +                if (block.getType() == PACKAGE_BODY) {
   1.937 +                    if (isMethodName(block.getChildBlocks(), selected, offset)) {
   1.938 +                        return true;
   1.939 +                    }
   1.940 +                } else if ((block.getType() == FUNCTION_IMPL
   1.941 +                        || block.getType() == PROCEDURE_IMPL)
   1.942 +                        && block.getParent() != null
   1.943 +                        && block.getName().equalsIgnoreCase(selected) && block.getStartOffset() == offset) {
   1.944 +                    selectedBlock = block;
   1.945 +                    selectedName = block.getName();
   1.946 +                    return true;
   1.947 +                }
   1.948              }
   1.949 -            break;
   1.950 -         }
   1.951 -      }
   1.952 -      return methodName;
   1.953 -   }
   1.954 +        }
   1.955  
   1.956 -   /**
   1.957 -    * Replace aliases in the given string
   1.958 -    * @param plsqlString
   1.959 -    * @param blockFac
   1.960 -    * @param define
   1.961 -    * @return
   1.962 -    */
   1.963 -   public String replaceAliases(String plsqlString, PlsqlBlockFactory blockFac, char define) {
   1.964 -      if (plsqlString.indexOf(define) < 0) {
   1.965 -         return plsqlString;
   1.966 -      }
   1.967 +        return false;
   1.968 +    }
   1.969  
   1.970 -      StringBuilder newString = new StringBuilder();
   1.971 -      for (int i = 0; i < plsqlString.length(); i++) {
   1.972 -         char c = plsqlString.charAt(i);
   1.973 -         if (c == define) {
   1.974 -            for (int j = i + 1; j < plsqlString.length(); j++) {
   1.975 -               char nextChar = plsqlString.charAt(j);
   1.976 -               if (Character.isJavaIdentifierPart(nextChar) && j == plsqlString.length() - 1) { //we have reached the end of the text
   1.977 -                  nextChar = '.'; //this will make sure that the correct sustitution is made below by emulating an additional character
   1.978 -                  j = j + 1;
   1.979 -               }
   1.980 -               if (!Character.isJavaIdentifierPart(nextChar)) { //potential end of substitutionvariable
   1.981 -                  if (j > i + 1) { //substituion variable found
   1.982 -                     String name = plsqlString.substring(i, j);
   1.983 -                     String value = blockFac.getDefine(name);
   1.984 -                     newString.append(value);
   1.985 -                     if (nextChar == '.') {
   1.986 -                        i = j;
   1.987 -                     } else {
   1.988 -                        i = j - 1;
   1.989 -                     }
   1.990 -                  } else {
   1.991 -                     newString.append(c);
   1.992 -                  }
   1.993 -                  break;
   1.994 -               }
   1.995 +    private PlsqlBlock getEnclosingPackageBody(List<PlsqlBlock> blockHierarchy, int offset) {
   1.996 +        for (PlsqlBlock block : blockHierarchy) {
   1.997 +            if (block.getType() == PACKAGE_BODY
   1.998 +                    && block.getStartOffset() < offset
   1.999 +                    && block.getEndOffset() > offset) {
  1.1000 +                return block;
  1.1001              }
  1.1002 -         } else {
  1.1003 -            newString.append(c);
  1.1004 -         }
  1.1005 -      }
  1.1006 -      return newString.toString();
  1.1007 -   }
  1.1008 +        }
  1.1009  
  1.1010 -   /**
  1.1011 -    * Check whether the selection is a method call
  1.1012 -    * @param document
  1.1013 -    * @param dbConnectionProvider
  1.1014 -    * @param project
  1.1015 -    * @param startOffset
  1.1016 -    * @return
  1.1017 -    */
  1.1018 -   private boolean checkForMethodCall(Document document, DatabaseConnectionManager dbConnectionProvider, int startOffset) {
  1.1019 -      DatabaseConnection databaseConnection = dbConnectionProvider != null ? dbConnectionProvider.getPooledDatabaseConnection(false) : null;
  1.1020 -      try {
  1.1021 -         DatabaseContentManager cache = databaseConnection != null ? DatabaseContentManager.getInstance(databaseConnection) : null;
  1.1022 +        return null;
  1.1023 +    }
  1.1024  
  1.1025 -         String selected = "";
  1.1026 -         String parent = "";
  1.1027 -
  1.1028 -         //Get the current token
  1.1029 -         TokenHierarchy tokenHierarchy = TokenHierarchy.get(document);
  1.1030 -         @SuppressWarnings("unchecked")
  1.1031 -         TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
  1.1032 -
  1.1033 -         if (ts != null) {
  1.1034 -            //move offset
  1.1035 -            ts.move(startOffset);
  1.1036 -            if (ts.moveNext()) {
  1.1037 -               Token<PlsqlTokenId> token = ts.token();
  1.1038 -               PlsqlTokenId tokenID = token.id();
  1.1039 -
  1.1040 -               if (tokenID == PlsqlTokenId.IDENTIFIER) {
  1.1041 -                  selected = token.text().toString();
  1.1042 -                  if (ts.movePrevious()) {
  1.1043 -                     token = ts.token();
  1.1044 -                     if (token.id() == PlsqlTokenId.DOT && ts.movePrevious()) {
  1.1045 -                        parent = ts.token().toString();
  1.1046 -                     }
  1.1047 -                  }
  1.1048 -               }
  1.1049 -            }
  1.1050 -         }
  1.1051 -
  1.1052 -         if (!parent.equals("")) {
  1.1053 -            //If parent is a package we can think that this is a method call
  1.1054 -            if (cache != null && cache.isPackage(parent, databaseConnection)) {
  1.1055 -               selectedName = selected;
  1.1056 -               parentName = parent;
  1.1057 -               return true;
  1.1058 -            }
  1.1059 -         } else {
  1.1060 -            PlsqlBlock packageBlock = getEnclosingPackageBody(dataObject.getLookup().lookup(PlsqlBlockFactory.class).getBlockHierarchy(), startOffset);
  1.1061 -            if (packageBlock != null && isMethodName(packageBlock.getChildBlocks(), selected, startOffset)) {
  1.1062 -               return true;
  1.1063 -            }
  1.1064 -         }
  1.1065 -
  1.1066 -         return false;
  1.1067 -      } finally {
  1.1068 -         dbConnectionProvider.releaseDatabaseConnection(databaseConnection);
  1.1069 -      }
  1.1070 -   }
  1.1071 -
  1.1072 -   private Document getSpecDocument(Document doc) {
  1.1073 -      DataObject dataObj = FileExecutionUtil.getDataObject(doc);
  1.1074 -      if (dataObj != null) {
  1.1075 -         DataObject siblingDataObject = validator.getSiblingExt(dataObject);
  1.1076 -         if (siblingDataObject != null) {
  1.1077 -            return PlsqlFileUtil.getDocument(siblingDataObject);
  1.1078 -         }
  1.1079 -      }
  1.1080 -      return null;
  1.1081 -   }
  1.1082 -
  1.1083 -   private boolean isMethodName(List<PlsqlBlock> blockHier, String selected, int offset) {
  1.1084 -      if (blockHier != null) {
  1.1085 -         for (PlsqlBlock block : blockHier) {
  1.1086 -            if (block.getType() == PACKAGE_BODY) {
  1.1087 -               if (isMethodName(block.getChildBlocks(), selected, offset)) {
  1.1088 -                  return true;
  1.1089 -               }
  1.1090 -            } else if ((block.getType() == FUNCTION_IMPL
  1.1091 -                    || block.getType() == PROCEDURE_IMPL)
  1.1092 -                    && block.getParent() != null
  1.1093 -                    && block.getName().equalsIgnoreCase(selected) && block.getStartOffset() == offset) {
  1.1094 -               selectedBlock = block;
  1.1095 -               selectedName = block.getName();
  1.1096 -               return true;
  1.1097 -            }
  1.1098 -         }
  1.1099 -      }
  1.1100 -
  1.1101 -      return false;
  1.1102 -   }
  1.1103 -
  1.1104 -   private PlsqlBlock getEnclosingPackageBody(List<PlsqlBlock> blockHierarchy, int offset) {
  1.1105 -      for (PlsqlBlock block : blockHierarchy) {
  1.1106 -         if (block.getType() == PACKAGE_BODY
  1.1107 -                 && block.getStartOffset() < offset
  1.1108 -                 && block.getEndOffset() > offset) {
  1.1109 -            return block;
  1.1110 -         }
  1.1111 -      }
  1.1112 -
  1.1113 -      return null;
  1.1114 -   }
  1.1115 -
  1.1116 -   private void selectMatchingBlock(DataObject dataObj, Document specDoc, int offset) {
  1.1117 -      List<PlsqlBlock> newBlockHier = PlsqlParserUtil.getBlockHierarchy(dataObj);
  1.1118 -      PlsqlBlock block = PlsqlParserUtil.findMatchingBlock(newBlockHier, doc, specDoc, selectedName, parentName, offset, false, false, true);
  1.1119 -      if (block != null && block.getParent() != null) {
  1.1120 -         selectedBlock = block;
  1.1121 -         doc = specDoc;
  1.1122 -         dataObject = dataObj;
  1.1123 -      }
  1.1124 -   }
  1.1125 +    private void selectMatchingBlock(DataObject dataObj, Document specDoc, int offset) {
  1.1126 +        List<PlsqlBlock> newBlockHier = PlsqlParserUtil.getBlockHierarchy(dataObj);
  1.1127 +        PlsqlBlock block = PlsqlParserUtil.findMatchingBlock(newBlockHier, doc, specDoc, selectedName, parentName, offset, false, false, true);
  1.1128 +        if (block != null && block.getParent() != null) {
  1.1129 +            selectedBlock = block;
  1.1130 +            doc = specDoc;
  1.1131 +            dataObject = dataObj;
  1.1132 +        }
  1.1133 +    }
  1.1134  }
     2.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java	Mon Oct 17 15:09:02 2011 +0530
     2.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java	Wed Oct 19 11:31:38 2011 +0530
     2.3 @@ -90,327 +90,328 @@
     2.4  
     2.5  public class PlsqlExecuteAction extends AbstractAction implements ContextAwareAction, Presenter.Toolbar {
     2.6  
     2.7 -   private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
     2.8 -   private static final String DATABASE_CONNECTION_KEY = "databaseConnection";
     2.9 -   private DataObject dataObject;
    2.10 -   private PlsqlDataObject plsqlDataobject;
    2.11 -   private DatabaseConnectionManager connectionProvider;
    2.12 -   private DatabaseConnection connection;
    2.13 -   private PopupMenuPopulator popupMenuPopulator = null;
    2.14 -   private JPopupMenu popup;
    2.15 -   private JButton button;
    2.16 -   private ActionListener buttonListener = new ButtonListener();
    2.17 -   private boolean autoCommit = true;
    2.18 +    private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    2.19 +    private static final String DATABASE_CONNECTION_KEY = "databaseConnection";
    2.20 +    private static final String TEST_BLOCK_NAME_PREFIX = "TestBlock:";
    2.21 +    private DataObject dataObject;
    2.22 +    private PlsqlDataObject plsqlDataobject;
    2.23 +    private DatabaseConnectionManager connectionProvider;
    2.24 +    private DatabaseConnection connection;
    2.25 +    private PopupMenuPopulator popupMenuPopulator = null;
    2.26 +    private JPopupMenu popup;
    2.27 +    private JButton button;
    2.28 +    private ActionListener buttonListener = new ButtonListener();
    2.29 +    private boolean autoCommit = true;
    2.30  
    2.31 -   public PlsqlExecuteAction() {
    2.32 -      this(Utilities.actionsGlobalContext());
    2.33 -   }
    2.34 +    public PlsqlExecuteAction() {
    2.35 +        this(Utilities.actionsGlobalContext());
    2.36 +    }
    2.37  
    2.38 -   public PlsqlExecuteAction(Lookup context) {
    2.39 -      putValue(SHORT_DESCRIPTION, NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_fileExecution"));
    2.40 -      putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/execute.png")));
    2.41 +    public PlsqlExecuteAction(Lookup context) {
    2.42 +        putValue(SHORT_DESCRIPTION, NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_fileExecution"));
    2.43 +        putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/execute.png")));
    2.44  
    2.45 -      dataObject = context.lookup(DataObject.class);
    2.46 +        dataObject = context.lookup(DataObject.class);
    2.47  
    2.48 -      //Enable execution for .spec .body files in workspace (copied using 'Copy to Workspace Folder')
    2.49 -      if (dataObject != null && (validator.isValidPackageDefault(dataObject)
    2.50 -              || dataObject.getPrimaryFile().getExt().toLowerCase(Locale.ENGLISH).equals("db"))) {
    2.51 -         if (!dataObject.getPrimaryFile().canWrite()) {
    2.52 +        //Enable execution for .spec .body files in workspace (copied using 'Copy to Workspace Folder')
    2.53 +        if (dataObject != null && (validator.isValidPackageDefault(dataObject)
    2.54 +                || dataObject.getPrimaryFile().getExt().toLowerCase(Locale.ENGLISH).equals("db"))) {
    2.55 +            if (!dataObject.getPrimaryFile().canWrite()) {
    2.56 +                dataObject = null;
    2.57 +            }
    2.58 +        }
    2.59 +
    2.60 +        if (dataObject != null && dataObject.getLookup().lookup(EditorCookie.class) == null) {
    2.61              dataObject = null;
    2.62 -         }
    2.63 -      }
    2.64 +        }
    2.65  
    2.66 -      if (dataObject != null && dataObject.getLookup().lookup(EditorCookie.class) == null) {
    2.67 -         dataObject = null;
    2.68 -      }
    2.69 +        setEnabled(dataObject != null);
    2.70 +        if (validator.isValidTDB(dataObject)) {
    2.71 +            autoCommit = IfsOptionsUtilities.isCommandWindowAutoCommitEnabled();
    2.72 +        }
    2.73 +    }
    2.74  
    2.75 -      setEnabled(dataObject != null);
    2.76 -      if (validator.isValidTDB(dataObject)) {
    2.77 -         autoCommit = IfsOptionsUtilities.isCommandWindowAutoCommitEnabled();
    2.78 -      }
    2.79 -   }
    2.80 +    @Override
    2.81 +    public Action createContextAwareInstance(Lookup context) {
    2.82 +        return new PlsqlExecuteAction(context);
    2.83 +    }
    2.84  
    2.85 -   @Override
    2.86 -   public Action createContextAwareInstance(Lookup context) {
    2.87 -      return new PlsqlExecuteAction(context);
    2.88 -   }
    2.89 +    private void prepareConnection() {
    2.90 +        if (dataObject != null) {
    2.91 +            connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
    2.92 +            if (connectionProvider != null) {
    2.93 +                if (popupMenuPopulator == null) {
    2.94 +                    popupMenuPopulator = new PopupMenuPopulator();
    2.95 +                    connectionProvider.addPropertyChangeListener(popupMenuPopulator);
    2.96 +                }
    2.97 +            }
    2.98 +        }
    2.99 +    }
   2.100  
   2.101 -   private void prepareConnection() {
   2.102 -      if (dataObject != null) {
   2.103 -         connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
   2.104 -         if (connectionProvider != null) {
   2.105 -            if (popupMenuPopulator == null) {
   2.106 -               popupMenuPopulator = new PopupMenuPopulator();
   2.107 -               connectionProvider.addPropertyChangeListener(popupMenuPopulator);
   2.108 +    @Override
   2.109 +    public void actionPerformed(ActionEvent event) {
   2.110 +        if (connectionProvider == null) {
   2.111 +            prepareConnection();
   2.112 +        }
   2.113 +        if (connectionProvider == null) {
   2.114 +            return;
   2.115 +        }
   2.116 +
   2.117 +        // If autocommit OFF - take the connection from data object.
   2.118 +        if (!autoCommit) {
   2.119 +            connection = dataObject.getLookup().lookup(DatabaseConnection.class);
   2.120 +        }
   2.121 +
   2.122 +        if (connection == null) {
   2.123 +            connection = connectionProvider.getTemplateConnection();
   2.124 +        }
   2.125 +
   2.126 +        if (connection == null) {
   2.127 +            return;
   2.128 +        }
   2.129 +        saveAndExecute();
   2.130 +    }
   2.131 +
   2.132 +    @Override
   2.133 +    public Component getToolbarPresenter() {
   2.134 +        if (!isEnabled()) {
   2.135 +            return null;
   2.136 +        }
   2.137 +
   2.138 +        popup = new JPopupMenu();
   2.139 +        if (connectionProvider == null) {
   2.140 +            prepareConnection();
   2.141 +        }
   2.142 +
   2.143 +        if (connectionProvider != null) {
   2.144 +            populatePopupMenu();
   2.145 +        }
   2.146 +
   2.147 +        button = DropDownButtonFactory.createDropDownButton(
   2.148 +                new ImageIcon(new BufferedImage(32, 32, BufferedImage.TYPE_BYTE_GRAY)), popup);
   2.149 +        button.setAction(this);
   2.150 +        button.addItemListener(new ItemListener() {
   2.151 +
   2.152 +            @Override
   2.153 +            public void itemStateChanged(ItemEvent e) {
   2.154 +                if (e.getStateChange() == ItemEvent.SELECTED) {
   2.155 +                    popup.show(button, 0, button.getHeight());
   2.156 +                }
   2.157              }
   2.158 -         }
   2.159 -      }
   2.160 -   }
   2.161 +        });
   2.162  
   2.163 -   @Override
   2.164 -   public void actionPerformed(ActionEvent event) {
   2.165 -      if (connectionProvider == null) {
   2.166 -         prepareConnection();
   2.167 -      }
   2.168 -      if (connectionProvider == null) {
   2.169 -         return;
   2.170 -      }
   2.171 +        popup.addPopupMenuListener(new PopupMenuListener() {
   2.172  
   2.173 -      // If autocommit OFF - take the connection from data object.
   2.174 -      if (!autoCommit) {
   2.175 -         connection = dataObject.getLookup().lookup(DatabaseConnection.class);
   2.176 -      }
   2.177 -
   2.178 -      if (connection == null) {
   2.179 -         connection = connectionProvider.getTemplateConnection();
   2.180 -      }
   2.181 -
   2.182 -      if (connection == null) {
   2.183 -         return;
   2.184 -      }
   2.185 -      saveAndExecute();
   2.186 -   }
   2.187 -
   2.188 -   @Override
   2.189 -   public Component getToolbarPresenter() {
   2.190 -      if (!isEnabled()) {
   2.191 -         return null;
   2.192 -      }
   2.193 -
   2.194 -      popup = new JPopupMenu();
   2.195 -      if (connectionProvider == null) {
   2.196 -         prepareConnection();
   2.197 -      }
   2.198 -
   2.199 -      if (connectionProvider != null) {
   2.200 -         populatePopupMenu();
   2.201 -      }
   2.202 -
   2.203 -      button = DropDownButtonFactory.createDropDownButton(
   2.204 -              new ImageIcon(new BufferedImage(32, 32, BufferedImage.TYPE_BYTE_GRAY)), popup);
   2.205 -      button.setAction(this);
   2.206 -      button.addItemListener(new ItemListener() {
   2.207 -
   2.208 -         @Override
   2.209 -         public void itemStateChanged(ItemEvent e) {
   2.210 -            if (e.getStateChange() == ItemEvent.SELECTED) {
   2.211 -               popup.show(button, 0, button.getHeight());
   2.212 -            }
   2.213 -         }
   2.214 -      });
   2.215 -
   2.216 -      popup.addPopupMenuListener(new PopupMenuListener() {
   2.217 -
   2.218 -         @Override
   2.219 -         public void popupMenuCanceled(PopupMenuEvent e) {
   2.220 -            button.setSelected(false);
   2.221 -         }
   2.222 -
   2.223 -         @Override
   2.224 -         public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
   2.225 -            button.setSelected(false);
   2.226 -         }
   2.227 -
   2.228 -         @Override
   2.229 -         public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
   2.230 -         }
   2.231 -      });
   2.232 -
   2.233 -      return button;
   2.234 -   }
   2.235 -
   2.236 -   private void populatePopupMenu() {
   2.237 -      popup.removeAll();
   2.238 -      if (autoCommit) {
   2.239 -         for (DatabaseConnection c : connectionProvider.getDatabaseConnections()) {
   2.240 -            String url = c.getDatabaseURL();
   2.241 -            String schema = c.getUser();
   2.242 -            int pos = url.indexOf("@") + 1;
   2.243 -            if (pos > 0) {
   2.244 -               url = url.substring(pos);
   2.245 -            }
   2.246 -            url = schema + "@" + url;
   2.247 -            String alias = c.getDisplayName();
   2.248 -            if (alias != null && !alias.equals(c.getName())) {
   2.249 -               url = alias + " [" + url + "]";
   2.250 -            }
   2.251 -            JMenuItem item = new JMenuItem(url);
   2.252 -            item.putClientProperty(DATABASE_CONNECTION_KEY, c);
   2.253 -            item.addActionListener(buttonListener);
   2.254 -            popup.add(item);
   2.255 -         }
   2.256 -      }
   2.257 -   }
   2.258 -
   2.259 -   public void saveAndExecute() {
   2.260 -      if (connectionProvider == null) {
   2.261 -         prepareConnection();
   2.262 -      }
   2.263 -
   2.264 -      EditorCookie edCookie = dataObject.getLookup().lookup(EditorCookie.class);
   2.265 -      Document document = edCookie.getDocument();
   2.266 -      saveIfModified(dataObject);
   2.267 -      List<PlsqlExecutableObject> blocks = null;
   2.268 -
   2.269 -      DataObject obj = FileExecutionUtil.getDataObject(document);
   2.270 -      FileObject file = obj.getPrimaryFile();
   2.271 -      if (file == null) {
   2.272 -         return;
   2.273 -      }
   2.274 -
   2.275 -      if (autoCommit && !connectionProvider.isDefaultDatabase(connection)) {
   2.276 -         if (!IfsOptionsUtilities.isDeployNoPromptEnabled()) {
   2.277 -            String msg = "You are now connecting to a secondary database.";
   2.278 -            String title = "Connecting to a Secondary Database!";
   2.279 -            if (JOptionPane.showOptionDialog(null,
   2.280 -                    msg,
   2.281 -                    title,
   2.282 -                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
   2.283 -                    null, null, null) == JOptionPane.NO_OPTION) {
   2.284 -               return;
   2.285 -            }
   2.286 -            connectionProvider.connect(connection);
   2.287 -            try {
   2.288 -               Connection jdbcConnection = connection.getJDBCConnection();
   2.289 -               if (jdbcConnection == null || !jdbcConnection.isValid(1000)) {
   2.290 -                  return;
   2.291 -               }
   2.292 -            } catch (SQLException ex) {
   2.293 -               return;
   2.294 -            }
   2.295 -         }
   2.296 -      }
   2.297 -
   2.298 -      //if the user has selected any text in the window, create exec block using selected text only
   2.299 -      if (validator.isValidTDB(dataObject)) {
   2.300 -         JEditorPane[] panes = edCookie.getOpenedPanes();
   2.301 -         if ((panes != null) && (panes.length > 0)) {
   2.302 -            String selectedSql = panes[0].getSelectedText();
   2.303 -            if (selectedSql != null && !selectedSql.trim().equals("")) { //some text has been selected
   2.304 -               //create executable block with selected sql
   2.305 -               blocks = new ArrayList<PlsqlExecutableObject>();
   2.306 -               blocks.add(new PlsqlExecutableObject(0, selectedSql, "SQL", PlsqlExecutableObjectType.STATEMENT, 0, selectedSql.length() - 1));
   2.307 -            }
   2.308 -         }
   2.309 -      }
   2.310 -
   2.311 -      //if blocks were not created using selected text, use entire document to create exec blocks
   2.312 -      if (blocks == null) {
   2.313 -         PlsqlExecutableBlocksMaker blockMaker = new PlsqlExecutableBlocksMaker(document);
   2.314 -         blocks = blockMaker.makeExceutableObjects();
   2.315 -      }
   2.316 -      String extension = file.getExt();
   2.317 -      if (blocks.size() > 0 && "tdb".equalsIgnoreCase(extension)) {
   2.318 -         String str = blocks.get(0).getPlsqlString().replaceAll("\n", " ");
   2.319 -         dataObject.getNodeDelegate().setDisplayName(str.length() > 30 ? str.substring(0, 30) + "..." : str);
   2.320 -      }
   2.321 -      RequestProcessor processor = RequestProcessor.getDefault();
   2.322 -      processor.post(new ExecutionHandler(connectionProvider, connection, blocks, document));
   2.323 -
   2.324 -   }
   2.325 -
   2.326 -   private void saveIfModified(DataObject dataObj) {
   2.327 -      try {
   2.328 -         SaveCookie saveCookie = dataObj.getCookie(SaveCookie.class);
   2.329 -         if (saveCookie != null) {
   2.330 -            saveCookie.save();
   2.331 -         }
   2.332 -      } catch (IOException ex) {
   2.333 -         Exceptions.printStackTrace(ex);
   2.334 -      }
   2.335 -   }
   2.336 -
   2.337 -   private class ExecutionHandler implements Runnable, Cancellable {
   2.338 -
   2.339 -      private DatabaseConnectionManager connectionProvider;
   2.340 -      private DatabaseConnection connection;
   2.341 -      private List<PlsqlExecutableObject> blocks;
   2.342 -      private Document document;
   2.343 -      private PlsqlFileExecutor executor;
   2.344 -
   2.345 -      public ExecutionHandler(DatabaseConnectionManager connectionProvider, DatabaseConnection connection,
   2.346 -              List<PlsqlExecutableObject> blocks, Document doc) {
   2.347 -         this.connectionProvider = connectionProvider;
   2.348 -         this.connection = connection;
   2.349 -         this.blocks = blocks;
   2.350 -         this.document = doc;
   2.351 -      }
   2.352 -
   2.353 -      @Override
   2.354 -      public void run() {
   2.355 -         ProgressHandle handle = ProgressHandleFactory.createHandle("Executing database file...", this);
   2.356 -         DataObject obj = null;
   2.357 -         try {
   2.358 -            handle.start();
   2.359 -            if (connection == connectionProvider.getTemplateConnection()) {
   2.360 -               connection = connectionProvider.getPooledDatabaseConnection(false, true);
   2.361 -               if (connection == null) {
   2.362 -                  return;
   2.363 -               }
   2.364 +            @Override
   2.365 +            public void popupMenuCanceled(PopupMenuEvent e) {
   2.366 +                button.setSelected(false);
   2.367              }
   2.368  
   2.369 -            obj = FileExecutionUtil.getDataObject(document);
   2.370 -            FileObject file = obj.getPrimaryFile();
   2.371 -            if (file == null) {
   2.372 -               return;
   2.373 +            @Override
   2.374 +            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
   2.375 +                button.setSelected(false);
   2.376              }
   2.377  
   2.378 -            executor = new PlsqlFileExecutor(connectionProvider, connection);
   2.379 -            executor.executePLSQL(blocks, document, false, autoCommit);
   2.380 +            @Override
   2.381 +            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
   2.382 +            }
   2.383 +        });
   2.384  
   2.385 -         } finally {
   2.386 -            if (autoCommit) {
   2.387 -               connectionProvider.releaseDatabaseConnection(connection);
   2.388 -            } else {
   2.389 -               //set connection to the lookup when autocommit is OFF
   2.390 -               modifyConnection();
   2.391 +        return button;
   2.392 +    }
   2.393 +
   2.394 +    private void populatePopupMenu() {
   2.395 +        popup.removeAll();
   2.396 +        if (autoCommit) {
   2.397 +            for (DatabaseConnection c : connectionProvider.getDatabaseConnections()) {
   2.398 +                String url = c.getDatabaseURL();
   2.399 +                String schema = c.getUser();
   2.400 +                int pos = url.indexOf("@") + 1;
   2.401 +                if (pos > 0) {
   2.402 +                    url = url.substring(pos);
   2.403 +                }
   2.404 +                url = schema + "@" + url;
   2.405 +                String alias = c.getDisplayName();
   2.406 +                if (alias != null && !alias.equals(c.getName())) {
   2.407 +                    url = alias + " [" + url + "]";
   2.408 +                }
   2.409 +                JMenuItem item = new JMenuItem(url);
   2.410 +                item.putClientProperty(DATABASE_CONNECTION_KEY, c);
   2.411 +                item.addActionListener(buttonListener);
   2.412 +                popup.add(item);
   2.413              }
   2.414 -            handle.finish();
   2.415 -         }
   2.416 -      }
   2.417 +        }
   2.418 +    }
   2.419  
   2.420 -      @Override
   2.421 -      public boolean cancel() {
   2.422 -         if (executor != null) {
   2.423 -            executor.cancel();
   2.424 -         }
   2.425 -         return true;
   2.426 -      }
   2.427 +    public void saveAndExecute() {
   2.428 +        if (connectionProvider == null) {
   2.429 +            prepareConnection();
   2.430 +        }
   2.431  
   2.432 -      private void modifyConnection() {
   2.433 +        EditorCookie edCookie = dataObject.getLookup().lookup(EditorCookie.class);
   2.434 +        Document document = edCookie.getDocument();
   2.435 +        saveIfModified(dataObject);
   2.436 +        List<PlsqlExecutableObject> blocks = null;
   2.437  
   2.438 -         plsqlDataobject = (PlsqlDataObject) dataObject;
   2.439 -         plsqlDataobject.modifyLookupDatabaseConnection(connection);
   2.440 -         dataObject = plsqlDataobject;
   2.441 -      }
   2.442 -   }
   2.443 +        DataObject obj = FileExecutionUtil.getDataObject(document);
   2.444 +        FileObject file = obj.getPrimaryFile();
   2.445 +        if (file == null) {
   2.446 +            return;
   2.447 +        }
   2.448  
   2.449 -   private class ButtonListener implements ActionListener {
   2.450 +        if (autoCommit && !connectionProvider.isDefaultDatabase(connection)) {
   2.451 +            if (!IfsOptionsUtilities.isDeployNoPromptEnabled()) {
   2.452 +                String msg = "You are now connecting to a secondary database.";
   2.453 +                String title = "Connecting to a Secondary Database!";
   2.454 +                if (JOptionPane.showOptionDialog(null,
   2.455 +                        msg,
   2.456 +                        title,
   2.457 +                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
   2.458 +                        null, null, null) == JOptionPane.NO_OPTION) {
   2.459 +                    return;
   2.460 +                }
   2.461 +                connectionProvider.connect(connection);
   2.462 +                try {
   2.463 +                    Connection jdbcConnection = connection.getJDBCConnection();
   2.464 +                    if (jdbcConnection == null || !jdbcConnection.isValid(1000)) {
   2.465 +                        return;
   2.466 +                    }
   2.467 +                } catch (SQLException ex) {
   2.468 +                    return;
   2.469 +                }
   2.470 +            }
   2.471 +        }
   2.472  
   2.473 -      public ButtonListener() {
   2.474 -      }
   2.475 +        //if the user has selected any text in the window, create exec block using selected text only
   2.476 +        if (validator.isValidTDB(dataObject)) {
   2.477 +            JEditorPane[] panes = edCookie.getOpenedPanes();
   2.478 +            if ((panes != null) && (panes.length > 0)) {
   2.479 +                String selectedSql = panes[0].getSelectedText();
   2.480 +                if (selectedSql != null && !selectedSql.trim().equals("")) { //some text has been selected
   2.481 +                    //create executable block with selected sql
   2.482 +                    blocks = new ArrayList<PlsqlExecutableObject>();
   2.483 +                    blocks.add(new PlsqlExecutableObject(0, selectedSql, "SQL", PlsqlExecutableObjectType.STATEMENT, 0, selectedSql.length() - 1));
   2.484 +                }
   2.485 +            }
   2.486 +        }
   2.487  
   2.488 -      @Override
   2.489 -      public void actionPerformed(ActionEvent e) {
   2.490 +        //if blocks were not created using selected text, use entire document to create exec blocks
   2.491 +        if (blocks == null) {
   2.492 +            PlsqlExecutableBlocksMaker blockMaker = new PlsqlExecutableBlocksMaker(document);
   2.493 +            blocks = blockMaker.makeExceutableObjects();
   2.494 +        }
   2.495 +        String extension = file.getExt();
   2.496 +        if (blocks.size() > 0 && "tdb".equalsIgnoreCase(extension) && (dataObject.getNodeDelegate().getDisplayName() == null || !dataObject.getNodeDelegate().getDisplayName().contains(TEST_BLOCK_NAME_PREFIX))) {
   2.497 +            String str = blocks.get(0).getPlsqlString().replaceAll("\n", " ");
   2.498 +            dataObject.getNodeDelegate().setDisplayName(str.length() > 30 ? str.substring(0, 30) + "..." : str);
   2.499 +        }
   2.500 +        RequestProcessor processor = RequestProcessor.getDefault();
   2.501 +        processor.post(new ExecutionHandler(connectionProvider, connection, blocks, document));
   2.502  
   2.503 -         JMenuItem item = (JMenuItem) e.getSource();
   2.504 -         connection = (DatabaseConnection) item.getClientProperty(DATABASE_CONNECTION_KEY);
   2.505 -         saveAndExecute();
   2.506 +    }
   2.507  
   2.508 -      }
   2.509 -   };
   2.510 +    private void saveIfModified(DataObject dataObj) {
   2.511 +        try {
   2.512 +            SaveCookie saveCookie = dataObj.getCookie(SaveCookie.class);
   2.513 +            if (saveCookie != null) {
   2.514 +                saveCookie.save();
   2.515 +            }
   2.516 +        } catch (IOException ex) {
   2.517 +            Exceptions.printStackTrace(ex);
   2.518 +        }
   2.519 +    }
   2.520  
   2.521 -   private class PopupMenuPopulator implements PropertyChangeListener {
   2.522 +    private class ExecutionHandler implements Runnable, Cancellable {
   2.523  
   2.524 -      public PopupMenuPopulator() {
   2.525 -      }
   2.526 +        private DatabaseConnectionManager connectionProvider;
   2.527 +        private DatabaseConnection connection;
   2.528 +        private List<PlsqlExecutableObject> blocks;
   2.529 +        private Document document;
   2.530 +        private PlsqlFileExecutor executor;
   2.531  
   2.532 -      @Override
   2.533 -      public void propertyChange(PropertyChangeEvent event) {
   2.534 -         if (popup != null) {
   2.535 -            prepareConnection();
   2.536 -            populatePopupMenu();
   2.537 -         }
   2.538 -      }
   2.539 -   }
   2.540 +        public ExecutionHandler(DatabaseConnectionManager connectionProvider, DatabaseConnection connection,
   2.541 +                List<PlsqlExecutableObject> blocks, Document doc) {
   2.542 +            this.connectionProvider = connectionProvider;
   2.543 +            this.connection = connection;
   2.544 +            this.blocks = blocks;
   2.545 +            this.document = doc;
   2.546 +        }
   2.547 +
   2.548 +        @Override
   2.549 +        public void run() {
   2.550 +            ProgressHandle handle = ProgressHandleFactory.createHandle("Executing database file...", this);
   2.551 +            DataObject obj = null;
   2.552 +            try {
   2.553 +                handle.start();
   2.554 +                if (connection == connectionProvider.getTemplateConnection()) {
   2.555 +                    connection = connectionProvider.getPooledDatabaseConnection(false, true);
   2.556 +                    if (connection == null) {
   2.557 +                        return;
   2.558 +                    }
   2.559 +                }
   2.560 +
   2.561 +                obj = FileExecutionUtil.getDataObject(document);
   2.562 +                FileObject file = obj.getPrimaryFile();
   2.563 +                if (file == null) {
   2.564 +                    return;
   2.565 +                }
   2.566 +
   2.567 +                executor = new PlsqlFileExecutor(connectionProvider, connection);
   2.568 +                executor.executePLSQL(blocks, document, false, autoCommit);
   2.569 +
   2.570 +            } finally {
   2.571 +                if (autoCommit) {
   2.572 +                    connectionProvider.releaseDatabaseConnection(connection);
   2.573 +                } else {
   2.574 +                    //set connection to the lookup when autocommit is OFF
   2.575 +                    modifyConnection();
   2.576 +                }
   2.577 +                handle.finish();
   2.578 +            }
   2.579 +        }
   2.580 +
   2.581 +        @Override
   2.582 +        public boolean cancel() {
   2.583 +            if (executor != null) {
   2.584 +                executor.cancel();
   2.585 +            }
   2.586 +            return true;
   2.587 +        }
   2.588 +
   2.589 +        private void modifyConnection() {
   2.590 +
   2.591 +            plsqlDataobject = (PlsqlDataObject) dataObject;
   2.592 +            plsqlDataobject.modifyLookupDatabaseConnection(connection);
   2.593 +            dataObject = plsqlDataobject;
   2.594 +        }
   2.595 +    }
   2.596 +
   2.597 +    private class ButtonListener implements ActionListener {
   2.598 +
   2.599 +        public ButtonListener() {
   2.600 +        }
   2.601 +
   2.602 +        @Override
   2.603 +        public void actionPerformed(ActionEvent e) {
   2.604 +
   2.605 +            JMenuItem item = (JMenuItem) e.getSource();
   2.606 +            connection = (DatabaseConnection) item.getClientProperty(DATABASE_CONNECTION_KEY);
   2.607 +            saveAndExecute();
   2.608 +
   2.609 +        }
   2.610 +    };
   2.611 +
   2.612 +    private class PopupMenuPopulator implements PropertyChangeListener {
   2.613 +
   2.614 +        public PopupMenuPopulator() {
   2.615 +        }
   2.616 +
   2.617 +        @Override
   2.618 +        public void propertyChange(PropertyChangeEvent event) {
   2.619 +            if (popup != null) {
   2.620 +                prepareConnection();
   2.621 +                populatePopupMenu();
   2.622 +            }
   2.623 +        }
   2.624 +    }
   2.625  }
     3.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java	Mon Oct 17 15:09:02 2011 +0530
     3.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java	Wed Oct 19 11:31:38 2011 +0530
     3.3 @@ -100,1367 +100,1385 @@
     3.4  import org.openide.windows.TopComponent;
     3.5  
     3.6  public class PlsqlFileExecutor {
     3.7 +    
     3.8 +    private boolean cancel = false;
     3.9 +    private final RequestProcessor rp = new RequestProcessor("SQLExecution", 1, true);
    3.10 +    // execution results. Not synchronized since accessed only from rp of throughput 1.
    3.11 +    private SQLExecutionResults executionResults;
    3.12 +    private final DatabaseConnection connection;
    3.13 +    private Connection debugConnection;
    3.14 +    private DatabaseContentManager cache;
    3.15 +    private PlsqlEditor plsqlEditor;
    3.16 +    private final InputOutput preparedIO;
    3.17 +    private final DatabaseConnectionManager connectionProvider;
    3.18 +    private Savepoint firstSavepoint = null;
    3.19 +    
    3.20 +    public PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, DatabaseConnection connection) {
    3.21 +        this.connection = connection;
    3.22 +        this.preparedIO = null;
    3.23 +        this.connectionProvider = connectionProvider;
    3.24 +        this.cache = DatabaseContentManager.getInstance(connection);
    3.25 +    }
    3.26 +    
    3.27 +    public PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, Connection debugConnection, InputOutput io) {
    3.28 +        this.connection = null;
    3.29 +        this.debugConnection = debugConnection;
    3.30 +        this.preparedIO = io;
    3.31 +        this.connectionProvider = connectionProvider;
    3.32 +        this.cache = DatabaseContentManager.getInstance(connection);
    3.33 +    }
    3.34 +    
    3.35 +    public void cancel() {
    3.36 +        cancel = true;
    3.37 +    }
    3.38  
    3.39 -   private boolean cancel = false;
    3.40 -   private final RequestProcessor rp = new RequestProcessor("SQLExecution", 1, true);
    3.41 -   // execution results. Not synchronized since accessed only from rp of throughput 1.
    3.42 -   private SQLExecutionResults executionResults;
    3.43 -   private final DatabaseConnection connection;
    3.44 -   private Connection debugConnection;
    3.45 -   private DatabaseContentManager cache;   
    3.46 -   private PlsqlEditor plsqlEditor;
    3.47 -   private final InputOutput preparedIO;
    3.48 -   private final DatabaseConnectionManager connectionProvider;
    3.49 -   private Savepoint firstSavepoint = null;
    3.50 +    /**
    3.51 +     * Method that will execute Dbmb_Output.Enable();
    3.52 +     * @param con
    3.53 +     */
    3.54 +    private void enableDbmsOut(Connection con) {
    3.55 +        Statement stm = null;
    3.56 +        try {
    3.57 +            stm = con.createStatement();
    3.58 +            stm.setEscapeProcessing(false);
    3.59 +            stm.execute("DECLARE\nBEGIN\nDbms_Output.Enable;\nEND;");
    3.60 +        } catch (SQLException ex) {
    3.61 +            Exceptions.printStackTrace(ex);
    3.62 +        } finally {
    3.63 +            if (stm != null) {
    3.64 +                try {
    3.65 +                    stm.close();
    3.66 +                } catch (SQLException ex) {
    3.67 +                    Exceptions.printStackTrace(ex);
    3.68 +                }
    3.69 +            }
    3.70 +        }
    3.71 +    }
    3.72 +    
    3.73 +    private boolean executeSelect(String query, DatabaseConnection con, Document doc, String label) throws SQLException {
    3.74 +        String formattedQuery = formatQuery(query, con);
    3.75 +        DataObject obj = FileExecutionUtil.getDataObject(doc);
    3.76 +        SQLExecutor executor = new SQLExecutor(obj, con, formattedQuery, label);
    3.77 +        RequestProcessor.Task task = rp.create(executor);
    3.78 +        executor.setTask(task);
    3.79 +        task.run();
    3.80 +        return false;
    3.81 +    }
    3.82 +    final static int NORMAL = 0;
    3.83 +    final static int IN_LITERAL = 1;
    3.84 +    final static int COMMENT_CANDIDATE = 3;
    3.85 +    
    3.86 +    private String formatQuery(final String query, DatabaseConnection databaseConnection) {
    3.87 +        StringBuilder nonCommentQuery = new StringBuilder();
    3.88 +        String[] lines = query.split("\\n");
    3.89 +        char escapeCharacter = (char) 0;
    3.90 +        for (String line : lines) {
    3.91 +            int state = NORMAL;
    3.92 +            for (int i = 0; i < line.length(); i++) {
    3.93 +                if (state == NORMAL) {
    3.94 +                    if (line.charAt(i) == '\'') {
    3.95 +                        state = IN_LITERAL;
    3.96 +                        if (i > 0 && i < line.length() - 1) {
    3.97 +                            char pre = line.charAt(i - 1);
    3.98 +                            if (pre == 'q' || pre == 'Q') {
    3.99 +                                escapeCharacter = line.charAt(i + 1);
   3.100 +                            } else {
   3.101 +                                escapeCharacter = (char) 0;
   3.102 +                            }
   3.103 +                        }
   3.104 +                    } else if (line.charAt(i) == '-') {
   3.105 +                        state = COMMENT_CANDIDATE;
   3.106 +                    }
   3.107 +                } else if (state == IN_LITERAL) {
   3.108 +                    if (line.charAt(i) == '\'') {
   3.109 +                        if (escapeCharacter == (char) 0 || line.charAt(i - 1) == escapeCharacter) {
   3.110 +                            state = NORMAL;
   3.111 +                        }
   3.112 +                    } else if (line.charAt(i) == '\\') {
   3.113 +                        i++;
   3.114 +                    }
   3.115 +                } else if (state == COMMENT_CANDIDATE) {
   3.116 +                    if (line.charAt(i) == '-') {
   3.117 +                        if (i > 1) {
   3.118 +                            nonCommentQuery.append(line.substring(0, i - 1)).append("\n");
   3.119 +                        }
   3.120 +                        break;
   3.121 +                    }
   3.122 +                    state = NORMAL;
   3.123 +                }
   3.124 +            }
   3.125 +            if (state == NORMAL) {
   3.126 +                nonCommentQuery.append(line).append("\n");
   3.127 +            }
   3.128 +        }
   3.129 +        nonCommentQuery.deleteCharAt(nonCommentQuery.length() - 1);
   3.130 +        
   3.131 +        String newQuery = "";
   3.132 +        String token;
   3.133 +        boolean format = false;
   3.134 +        
   3.135 +        StringTokenizer tokenizer = new StringTokenizer(nonCommentQuery.toString(), " \t\n");
   3.136 +        while (tokenizer.hasMoreTokens()) {
   3.137 +            token = tokenizer.nextToken();
   3.138 +            
   3.139 +            if (token.equalsIgnoreCase("FROM")) {
   3.140 +                format = true;
   3.141 +            } else if (token.equalsIgnoreCase("WHERE") || token.equalsIgnoreCase("ORDER")
   3.142 +                    || token.equalsIgnoreCase("GROUP") || token.equalsIgnoreCase("HAVING")) {
   3.143 +                format = false;
   3.144 +            }
   3.145 +            
   3.146 +            if (format) {
   3.147 +                boolean isUpper = false;
   3.148 +                //Tokenize with '.'
   3.149 +                StringTokenizer dotTokenizer = new StringTokenizer(token, ".");
   3.150 +                String dotToken;
   3.151 +                while (dotTokenizer.hasMoreTokens()) {
   3.152 +                    dotToken = dotTokenizer.nextToken();
   3.153 +                    //We can safely assume that we have connected to the database here
   3.154 +                    if (cache.isTable(dotToken, databaseConnection) || cache.isView(dotToken, databaseConnection)) {
   3.155 +                        isUpper = true;
   3.156 +                    }
   3.157 +                }
   3.158 +                
   3.159 +                if (!isUpper) {
   3.160 +                    //Tokenize with ','
   3.161 +                    StringTokenizer otherTokenizer = new StringTokenizer(token, ",");
   3.162 +                    String otherToken;
   3.163 +                    while (otherTokenizer.hasMoreTokens()) {
   3.164 +                        otherToken = otherTokenizer.nextToken();
   3.165 +                        //We can safely assume that we have connected to the database here
   3.166 +                        if (!otherToken.startsWith("'")
   3.167 +                                && cache.isTable(otherToken, databaseConnection) || cache.isView(otherToken, databaseConnection)) {
   3.168 +                            isUpper = true;
   3.169 +                        }
   3.170 +                    }
   3.171 +                }
   3.172 +                
   3.173 +                if (isUpper) {
   3.174 +                    token = token.toUpperCase(Locale.ENGLISH);
   3.175 +                }
   3.176 +            }
   3.177 +            
   3.178 +            newQuery = newQuery + token + " ";
   3.179 +        }
   3.180 +        
   3.181 +        return newQuery;
   3.182 +    }
   3.183 +    
   3.184 +    private boolean describeObject(DatabaseConnection con, Document doc, StringTokenizer tokenizer, InputOutput io) throws SQLException {
   3.185 +        if (!tokenizer.hasMoreTokens()) {
   3.186 +            io.getErr().println("Syntax: DESCRIBE [object]");
   3.187 +            return false;
   3.188 +        }
   3.189 +        String objectName = tokenizer.nextToken().toUpperCase(Locale.ENGLISH);
   3.190 +        String objectOwner = null;
   3.191 +        
   3.192 +        if (objectName.contains(".")) { //handle schema.object format e.g. ifsapp.customer
   3.193 +            final String[] result = objectName.split("\\.");
   3.194 +            if (result != null && result.length == 2) {
   3.195 +                objectOwner = result[0];
   3.196 +                objectName = result[1];
   3.197 +            }
   3.198 +        }
   3.199 +        
   3.200 +        String query = "SELECT t.COLUMN_NAME \"Name\", "
   3.201 +                + "t.data_type||decode(t.data_type,'VARCHAR2','('||t.char_length||')', "
   3.202 +                + "'DATE','','NUMBER',decode(t.data_precision,null,'','('||t.data_precision||"
   3.203 +                + "decode(t.data_scale,0,'',null,'',','||t.data_scale)||')'),'') \"Type\","
   3.204 +                + "decode(t.nullable,'Y',' ','NOT NULL') \"Nullable\", "
   3.205 +                + "t.data_default \"Default\", "
   3.206 +                + "substr(to_char(t.column_id), 1, 5) \"Id\", "
   3.207 +                + "c.comments \"Comments\" "
   3.208 +                + "FROM ALL_TAB_COLUMNS t, ALL_COL_COMMENTS c "
   3.209 +                + "WHERE t.TABLE_NAME = c.TABLE_NAME "
   3.210 +                + "AND t.COLUMN_NAME = c.COLUMN_NAME "
   3.211 +                + "AND t.OWNER = c.OWNER "
   3.212 +                + ((objectOwner != null && !objectOwner.equals("")) ? "AND t.OWNER = '" + objectOwner + "' " : "") //set owner only if given by user
   3.213 +                + "AND t.TABLE_NAME = '" + objectName + "' ORDER BY t.COLUMN_ID";
   3.214 +        executeSelect(query, con, doc, objectName);
   3.215 +        return true;
   3.216 +    }
   3.217 +    
   3.218 +    private void processDbmsOutputMessages(Connection con, OutputWriter out) {
   3.219 +        String text = "BEGIN DBMS_OUTPUT.GET_LINE(?, ?); END;";
   3.220 +        CallableStatement stmt = null;
   3.221 +        try {
   3.222 +            stmt = con.prepareCall(text);
   3.223 +            stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
   3.224 +            stmt.registerOutParameter(2, java.sql.Types.NUMERIC);
   3.225 +            int status = 0;
   3.226 +            while (status == 0) {
   3.227 +                stmt.execute();
   3.228 +                String output = stmt.getString(1);
   3.229 +                status = stmt.getInt(2);
   3.230 +                if (status == 0) {
   3.231 +                    out.println(output);
   3.232 +                }
   3.233 +            }
   3.234 +        } catch (SQLException e) {
   3.235 +            out.println("!!!Errors while fetching dbms_output:");
   3.236 +            out.println(e.toString());
   3.237 +        } finally {
   3.238 +            if (stmt != null) {
   3.239 +                try {
   3.240 +                    stmt.close();
   3.241 +                } catch (SQLException ex) {
   3.242 +                    throw new RuntimeException(ex);
   3.243 +                }
   3.244 +            }
   3.245 +        }
   3.246 +    }
   3.247 +    
   3.248 +    private InputOutput initializeIO(String fileName, String displayName, DataObject dataObj) {
   3.249 +        if (this.preparedIO != null) {
   3.250 +            return this.preparedIO;
   3.251 +        }
   3.252 +        String startMsg = "Deploying " + FileExecutionUtil.getActivatedFileName(dataObj);
   3.253 +        if (fileName.endsWith(".tdb")) {
   3.254 +            startMsg = "Executing " + fileName;
   3.255 +        }
   3.256 +        InputOutput io = null;
   3.257 +        try {
   3.258 +            io = IOProvider.getDefault().getIO(displayName, false);
   3.259 +            //if the window is a pl/sql test window keep the old output. Otherwise flush
   3.260 +            if (fileName.startsWith(SQLCommandWindow.SQL_EXECUTION_FILE_PREFIX)) {
   3.261 +                if (io.isClosed()) {
   3.262 +                    //If closed previously reset and flush
   3.263 +                    io.getOut().reset();
   3.264 +                    io.getErr().reset();
   3.265 +                    io.getOut().flush();
   3.266 +                    io.getErr().flush();
   3.267 +                }
   3.268 +                io.getOut().println();
   3.269 +            } else {
   3.270 +                io.getOut().reset();
   3.271 +                io.getErr().reset();
   3.272 +                io.getOut().flush();
   3.273 +                io.getErr().flush();
   3.274 +            }
   3.275 +            io.select();
   3.276 +            io.getOut().println(startMsg);
   3.277 +            io.getOut().println("-------------------------------------------------------------");
   3.278 +        } catch (IOException ex) {
   3.279 +            Exceptions.printStackTrace(ex);
   3.280 +        }
   3.281 +        return io;
   3.282 +    }
   3.283  
   3.284 -   public PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, DatabaseConnection connection) {
   3.285 -      this.connection = connection;
   3.286 -      this.preparedIO = null;
   3.287 -      this.connectionProvider = connectionProvider;
   3.288 -      this.cache = DatabaseContentManager.getInstance(connection);
   3.289 -   }
   3.290 +    //store in object history if this is an SQL Command window (*.tdb)
   3.291 +    private void addToHistory(Document doc) {
   3.292 +        DataObject obj = FileExecutionUtil.getDataObject(doc);
   3.293 +        FileObject file = obj.getPrimaryFile();
   3.294 +        if (file == null) {
   3.295 +            return;
   3.296 +        }
   3.297 +        String extension = file.getExt();
   3.298 +        if ("tdb".equalsIgnoreCase(extension)) {
   3.299 +            StatementExecutionHistory history = obj.getLookup().lookup(StatementExecutionHistory.class);
   3.300 +            try {
   3.301 +                history.addEntry(doc.getText(0, doc.getLength()));
   3.302 +            } catch (BadLocationException ex) {
   3.303 +                Exceptions.printStackTrace(ex);
   3.304 +            }
   3.305 +        }
   3.306 +        
   3.307 +    }
   3.308 +    
   3.309 +    public InputOutput executePLSQL(List executableObjs, Document doc, boolean hidden, boolean autoCommit) {
   3.310 +        final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
   3.311 +        Project project = null;
   3.312 +        Object object = doc.getProperty(Document.StreamDescriptionProperty);
   3.313 +        if (object instanceof DataObject) {
   3.314 +            FileObject fo = ((DataObject) object).getPrimaryFile();
   3.315 +            project = FileOwnerQuery.getOwner(fo);
   3.316 +        }
   3.317  
   3.318 -   public PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, Connection debugConnection, InputOutput io) {
   3.319 -      this.connection = null;
   3.320 -      this.debugConnection = debugConnection;
   3.321 -      this.preparedIO = io;
   3.322 -      this.connectionProvider = connectionProvider;
   3.323 -      this.cache = DatabaseContentManager.getInstance(connection);
   3.324 -   }
   3.325 +        //store in object history if this is an SQL Command window (*.tdb)
   3.326 +        boolean ignoreDefines = false;
   3.327 +        addToHistory(doc);
   3.328 +        cancel = false;
   3.329 +        InputOutput io = null;
   3.330 +        boolean deploymentOk = true;
   3.331 +        if (debugConnection == null && connection.getJDBCConnection() == null) {
   3.332 +            JOptionPane.showMessageDialog(null, "Connect to the Database");
   3.333 +            return null;
   3.334 +        }
   3.335  
   3.336 -   public void cancel() {
   3.337 -      cancel = true;
   3.338 -   }
   3.339 +        //Defines and define
   3.340 +        HashMap<String, String> definesMap = new HashMap<String, String>();
   3.341 +        char define = '&';
   3.342 +        DataObject dataObj = FileExecutionUtil.getDataObject(doc);
   3.343 +        plsqlEditor = getPlsqlEditor(dataObj);
   3.344 +        String endMsg = "Done deploying " + FileExecutionUtil.getActivatedFileName(dataObj);
   3.345 +        long startTime = System.currentTimeMillis();
   3.346 +        String fileName = dataObj.getPrimaryFile().getNameExt();
   3.347 +        boolean moreRowsToBeFetched = false;
   3.348 +        //Check whether this is the excution window file
   3.349 +        if (fileName.endsWith(".tdb")) {
   3.350 +            endMsg = "Finished executing command ";
   3.351 +        }
   3.352 +        Connection con = null;
   3.353 +        Statement stm = null;
   3.354 +        String firstWord = null;
   3.355 +        boolean commit = false;
   3.356  
   3.357 -   /**
   3.358 -    * Method that will execute Dbmb_Output.Enable();
   3.359 -    * @param con
   3.360 -    */
   3.361 -   private void enableDbmsOut(Connection con) {
   3.362 -      Statement stm = null;
   3.363 -      try {
   3.364 -         stm = con.createStatement();
   3.365 -         stm.setEscapeProcessing(false);
   3.366 -         stm.execute("DECLARE\nBEGIN\nDbms_Output.Enable;\nEND;");
   3.367 -      } catch (SQLException ex) {
   3.368 -         Exceptions.printStackTrace(ex);
   3.369 -      } finally {
   3.370 -         if (stm != null) {
   3.371 -            try {
   3.372 -               stm.close();
   3.373 -            } catch (SQLException ex) {
   3.374 -               Exceptions.printStackTrace(ex);
   3.375 +        //quick & dirty fix to avoid having output tabs for the SQL Execution window (unless there's an exception)
   3.376 +        //first check to see if this is a simple select statement and if so treat it separately.
   3.377 +        if (executableObjs.size() == 1) {
   3.378 +            PlsqlExecutableObject executionObject = (PlsqlExecutableObject) executableObjs.get(0);
   3.379 +            if (executionObject.getType() == PlsqlExecutableObjectType.STATEMENT || executionObject.getType() == PlsqlExecutableObjectType.UNKNOWN) {
   3.380 +                String plsqlText = executionObject.getPlsqlString();
   3.381 +                try {
   3.382 +                    // String firstWord;
   3.383 +                    firstWord = null;
   3.384 +                    StringTokenizer tokenizer = new StringTokenizer(plsqlText, " \t\n");
   3.385 +                    if (tokenizer.hasMoreTokens()) {
   3.386 +                        firstWord = tokenizer.nextToken();
   3.387 +                    } else {
   3.388 +                        firstWord = plsqlText;
   3.389 +                    }
   3.390 +                    if (firstWord.equalsIgnoreCase("SELECT")) {
   3.391 +                        if (plsqlEditor != null) {
   3.392 +                            plsqlEditor.closeResultSetTabs();
   3.393 +                        }
   3.394 +                        //replace aliases since there are aliases in PROMPTS
   3.395 +                        if (!ignoreDefines) {
   3.396 +                            plsqlText = replaceAliases(plsqlText, definesMap, define, io);
   3.397 +                        }
   3.398 +                        moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
   3.399 +                        return null;
   3.400 +                    } else if (firstWord.equalsIgnoreCase("DESC") || firstWord.equalsIgnoreCase("DESCRIBE")) {
   3.401 +                        describeObject(connection, doc, tokenizer, io);
   3.402 +                        return null;
   3.403 +                    }
   3.404 +                    
   3.405 +                } catch (SQLException sqlEx) {
   3.406 +                    try {
   3.407 +                        io = initializeIO(fileName,getIOTabName(executableObjs, fileName, dataObj.getNodeDelegate().getDisplayName()), dataObj);
   3.408 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.409 +                        int outLine = executionObject.getStartLineNo() + errLine - 1;
   3.410 +                        String msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.411 +                        PlsqlOutputListener outList = new PlsqlOutputListener();
   3.412 +                        outList.setDocLinesArray(executionObject.getDocLinesArray());
   3.413 +                        outList.setOriginalFileName(executionObject.getOriginalFileName());
   3.414 +                        outList.setLineNo(outLine);
   3.415 +                        io.getErr().println((new StringBuilder()).append("!!!Error Executing Statement ").append(executionObject).toString());
   3.416 +                        io.getOut().println(plsqlText);
   3.417 +                        io.getErr().println(msg, outList);
   3.418 +                        io.getOut().close();
   3.419 +                        io.getErr().close();
   3.420 +                        return io;
   3.421 +                    } catch (IOException ex) {
   3.422 +                        connectionProvider.setOnline(false);
   3.423 +                        return null;
   3.424 +                    }
   3.425 +                }
   3.426              }
   3.427 -         }
   3.428 -      }
   3.429 -   }
   3.430 +        }
   3.431 +        try {
   3.432 +            
   3.433 +            
   3.434 +            io = initializeIO(fileName, getIOTabName(executableObjs, fileName,dataObj.getNodeDelegate().getDisplayName()), dataObj);
   3.435 +            con = debugConnection != null ? debugConnection : connection.getJDBCConnection();
   3.436 +            con.setAutoCommit(false);
   3.437 +            enableDbmsOut(con);
   3.438 +            firstSavepoint = con.setSavepoint();
   3.439 +            //savepointsCreated.put(new Integer(firstSavepoint.getSavepointId()),firstSavepoint);
   3.440  
   3.441 -   private boolean executeSelect(String query, DatabaseConnection con, Document doc, String label) throws SQLException {
   3.442 -      String formattedQuery = formatQuery(query, con);
   3.443 -      DataObject obj = FileExecutionUtil.getDataObject(doc);
   3.444 -      SQLExecutor executor = new SQLExecutor(obj, con, formattedQuery, label);
   3.445 -      RequestProcessor.Task task = rp.create(executor);
   3.446 -      executor.setTask(task);
   3.447 -      task.run();
   3.448 -      return false;
   3.449 -   }
   3.450 -   final static int NORMAL = 0;
   3.451 -   final static int IN_LITERAL = 1;
   3.452 -   final static int COMMENT_CANDIDATE = 3;
   3.453 -
   3.454 -   private String formatQuery(final String query, DatabaseConnection databaseConnection) {
   3.455 -      StringBuilder nonCommentQuery = new StringBuilder();
   3.456 -      String[] lines = query.split("\\n");
   3.457 -      char escapeCharacter=(char)0;
   3.458 -      for (String line : lines) {
   3.459 -         int state = NORMAL;
   3.460 -         for (int i = 0; i < line.length(); i++) {
   3.461 -            if (state == NORMAL) {
   3.462 -               if (line.charAt(i) == '\'') {
   3.463 -                  state = IN_LITERAL;
   3.464 -                  if(i>0 && i<line.length()-1) {
   3.465 -                    char pre=line.charAt(i-1);
   3.466 -                    if(pre=='q' || pre=='Q') {
   3.467 -                       escapeCharacter=line.charAt(i+1);
   3.468 -                    } else {
   3.469 -                       escapeCharacter=(char)0;
   3.470 +            stm = con.createStatement();
   3.471 +            stm.setEscapeProcessing(false);
   3.472 +            if (connectionProvider.isUsagesEnabled() && validator.isValidPackage(dataObj)) {
   3.473 +                String plsqlText = "ALTER SYSTEM SET PLSCOPE_SETTINGS = 'IDENTIFIERS:ALL' \t\n";
   3.474 +                try {
   3.475 +                    //io.getOut().println((new StringBuilder()).append("> Enabling Usages for ").append(fileName));
   3.476 +                    stm.execute(plsqlText);
   3.477 +                } catch (SQLException sqlEx) {
   3.478 +                    int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.479 +                    int outLine = errLine - 1;
   3.480 +                    String msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.481 +                    // io.getErr().println((new StringBuilder()).append("!!!Error Creating View ").append(exeObjName).toString());
   3.482 +                    io.getOut().println(plsqlText);
   3.483 +                    deploymentOk = false;
   3.484 +                }
   3.485 +            }
   3.486 +            boolean firstSelectStatement = true;
   3.487 +            for (int i = 0; i < executableObjs.size(); i++) {
   3.488 +                if (cancel) {
   3.489 +                    io.getErr().println("!!!Execution cancelled. Performing rollback");
   3.490 +                    // con.rollback();
   3.491 +                    con.rollback(firstSavepoint);
   3.492 +                    return io;
   3.493 +                }
   3.494 +                PlsqlExecutableObject exeObj = (PlsqlExecutableObject) executableObjs.get(i);
   3.495 +                int lineNumber = exeObj.getStartLineNo();
   3.496 +                String plsqlText = exeObj.getPlsqlString();
   3.497 +                
   3.498 +                String exeObjName = exeObj.getExecutableObjName().toUpperCase(Locale.ENGLISH);
   3.499 +                if ((exeObj.getType() != PlsqlExecutableObjectType.UNKNOWN) && (exeObj.getType() != PlsqlExecutableObjectType.COMMENT)) {
   3.500 +                    //replace aliases since there are aliases in PROMPTS
   3.501 +                    if (!ignoreDefines) {
   3.502 +                        plsqlText = replaceAliases(plsqlText, definesMap, define, io);
   3.503 +                        exeObjName = replaceAliases(exeObjName, definesMap, define, io);
   3.504                      }
   3.505 -                  }
   3.506 -               } else if (line.charAt(i) == '-') {
   3.507 -                  state = COMMENT_CANDIDATE;
   3.508 -               }
   3.509 -            } else if (state == IN_LITERAL) {
   3.510 -               if (line.charAt(i) == '\'') {
   3.511 -                  if(escapeCharacter==(char)0 || line.charAt(i-1)==escapeCharacter) {
   3.512 -                     state = NORMAL;
   3.513 -                  } 
   3.514 -               } else if (line.charAt(i) == '\\') {
   3.515 -                  i++;
   3.516 -               }
   3.517 -            } else if (state == COMMENT_CANDIDATE) {
   3.518 -               if (line.charAt(i) == '-') {
   3.519 -                  if(i>1) {
   3.520 -                     nonCommentQuery.append(line.substring(0, i - 1)).append("\n");
   3.521 -                  }
   3.522 -                  break;
   3.523 -               }
   3.524 -               state = NORMAL;
   3.525 -            }
   3.526 -         }
   3.527 -         if (state == NORMAL) {
   3.528 -            nonCommentQuery.append(line).append("\n");
   3.529 -         }
   3.530 -      }
   3.531 -      nonCommentQuery.deleteCharAt(nonCommentQuery.length() - 1);
   3.532 -
   3.533 -     String newQuery = "";
   3.534 -      String token;
   3.535 -      boolean format = false;
   3.536 -
   3.537 -      StringTokenizer tokenizer = new StringTokenizer(nonCommentQuery.toString(), " \t\n");
   3.538 -      while (tokenizer.hasMoreTokens()) {
   3.539 -         token = tokenizer.nextToken();
   3.540 -
   3.541 -         if (token.equalsIgnoreCase("FROM")) {
   3.542 -            format = true;
   3.543 -         } else if (token.equalsIgnoreCase("WHERE") || token.equalsIgnoreCase("ORDER")
   3.544 -                 || token.equalsIgnoreCase("GROUP") || token.equalsIgnoreCase("HAVING")) {
   3.545 -            format = false;
   3.546 -         }
   3.547 -
   3.548 -         if (format) {
   3.549 -            boolean isUpper = false;
   3.550 -            //Tokenize with '.'
   3.551 -            StringTokenizer dotTokenizer = new StringTokenizer(token, ".");
   3.552 -            String dotToken;
   3.553 -            while (dotTokenizer.hasMoreTokens()) {
   3.554 -               dotToken = dotTokenizer.nextToken();
   3.555 -               //We can safely assume that we have connected to the database here
   3.556 -               if (cache.isTable(dotToken, databaseConnection) || cache.isView(dotToken, databaseConnection)) {
   3.557 -                  isUpper = true;
   3.558 -               }
   3.559 -            }
   3.560 -
   3.561 -            if (!isUpper) {
   3.562 -               //Tokenize with ','
   3.563 -               StringTokenizer otherTokenizer = new StringTokenizer(token, ",");
   3.564 -               String otherToken;
   3.565 -               while (otherTokenizer.hasMoreTokens()) {
   3.566 -                  otherToken = otherTokenizer.nextToken();
   3.567 -                  //We can safely assume that we have connected to the database here
   3.568 -                  if (!otherToken.startsWith("'") &&
   3.569 -                        cache.isTable(otherToken, databaseConnection) || cache.isView(otherToken, databaseConnection)) {
   3.570 -                     isUpper = true;
   3.571 -                  }
   3.572 -               }
   3.573 -            }
   3.574 -
   3.575 -            if (isUpper) {
   3.576 -               token = token.toUpperCase(Locale.ENGLISH);
   3.577 -            }
   3.578 -         }
   3.579 -
   3.580 -         newQuery = newQuery + token + " ";
   3.581 -      }
   3.582 -
   3.583 -      return newQuery;
   3.584 -   }
   3.585 -
   3.586 -   private boolean describeObject(DatabaseConnection con, Document doc, StringTokenizer tokenizer, InputOutput io) throws SQLException {
   3.587 -      if (!tokenizer.hasMoreTokens()) {
   3.588 -         io.getErr().println("Syntax: DESCRIBE [object]");
   3.589 -         return false;
   3.590 -      }
   3.591 -      String objectName = tokenizer.nextToken().toUpperCase(Locale.ENGLISH);
   3.592 -      String objectOwner = null;
   3.593 -      
   3.594 -      if (objectName.contains(".")) { //handle schema.object format e.g. ifsapp.customer
   3.595 -         final String[] result = objectName.split("\\.");
   3.596 -         if (result != null && result.length == 2) {
   3.597 -             objectOwner = result[0];
   3.598 -             objectName = result[1];
   3.599 -         }
   3.600 -      }
   3.601 -
   3.602 -      String query = "SELECT t.COLUMN_NAME \"Name\", "
   3.603 -              + "t.data_type||decode(t.data_type,'VARCHAR2','('||t.char_length||')', "
   3.604 -              + "'DATE','','NUMBER',decode(t.data_precision,null,'','('||t.data_precision||"
   3.605 -              + "decode(t.data_scale,0,'',null,'',','||t.data_scale)||')'),'') \"Type\","
   3.606 -              + "decode(t.nullable,'Y',' ','NOT NULL') \"Nullable\", "
   3.607 -              + "t.data_default \"Default\", "
   3.608 -              + "substr(to_char(t.column_id), 1, 5) \"Id\", "
   3.609 -              + "c.comments \"Comments\" "
   3.610 -              + "FROM ALL_TAB_COLUMNS t, ALL_COL_COMMENTS c "
   3.611 -              + "WHERE t.TABLE_NAME = c.TABLE_NAME "
   3.612 -              + "AND t.COLUMN_NAME = c.COLUMN_NAME "
   3.613 -              + "AND t.OWNER = c.OWNER "
   3.614 -              + ((objectOwner!=null && !objectOwner.equals(""))? "AND t.OWNER = '"+ objectOwner +"' " : "") //set owner only if given by user
   3.615 -              + "AND t.TABLE_NAME = '" + objectName + "' ORDER BY t.COLUMN_ID";
   3.616 -      executeSelect(query, con, doc, objectName);
   3.617 -      return true;
   3.618 -   }
   3.619 -
   3.620 -   private void processDbmsOutputMessages(Connection con, OutputWriter out) {
   3.621 -      String text = "BEGIN DBMS_OUTPUT.GET_LINE(?, ?); END;";
   3.622 -      CallableStatement stmt = null;
   3.623 -      try {
   3.624 -         stmt = con.prepareCall(text);
   3.625 -         stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
   3.626 -         stmt.registerOutParameter(2, java.sql.Types.NUMERIC);
   3.627 -         int status = 0;
   3.628 -         while (status == 0) {
   3.629 -            stmt.execute();
   3.630 -            String output = stmt.getString(1);
   3.631 -            status = stmt.getInt(2);
   3.632 -            if (status == 0) {
   3.633 -               out.println(output);
   3.634 -            }
   3.635 -         }
   3.636 -      } catch (SQLException e) {
   3.637 -         out.println("!!!Errors while fetching dbms_output:");
   3.638 -         out.println(e.toString());
   3.639 -      } finally {
   3.640 -         if (stmt != null) {
   3.641 -            try {
   3.642 -               stmt.close();
   3.643 -            } catch (SQLException ex) {
   3.644 -               throw new RuntimeException(ex);
   3.645 -            }
   3.646 -         }
   3.647 -      }
   3.648 -   }
   3.649 -
   3.650 -   private InputOutput initializeIO(String fileName, DataObject dataObj) {
   3.651 -      if (this.preparedIO != null) {
   3.652 -         return this.preparedIO;
   3.653 -      }
   3.654 -      String startMsg = "Deploying " + FileExecutionUtil.getActivatedFileName(dataObj);
   3.655 -      if (fileName.endsWith(".tdb")) {
   3.656 -         startMsg = "Executing " + fileName;
   3.657 -      }
   3.658 -      InputOutput io = null;
   3.659 -      try {
   3.660 -         io = IOProvider.getDefault().getIO(fileName, false);
   3.661 -         //if the window is a pl/sql test window keep the old output. Otherwise flush
   3.662 -         if (fileName.startsWith(SQLCommandWindow.SQL_EXECUTION_FILE_PREFIX)) {
   3.663 -            if (io.isClosed()) {
   3.664 -               //If closed previously reset and flush
   3.665 -               io.getOut().reset();
   3.666 -               io.getErr().reset();
   3.667 -               io.getOut().flush();
   3.668 -               io.getErr().flush();
   3.669 -            }
   3.670 -            io.getOut().println();
   3.671 -         } else {
   3.672 -            io.getOut().reset();
   3.673 -            io.getErr().reset();
   3.674 -            io.getOut().flush();
   3.675 -            io.getErr().flush();
   3.676 -         }
   3.677 -         io.select();
   3.678 -         io.getOut().println(startMsg);
   3.679 -         io.getOut().println("-------------------------------------------------------------");
   3.680 -      } catch (IOException ex) {
   3.681 -         Exceptions.printStackTrace(ex);
   3.682 -      }
   3.683 -      return io;
   3.684 -   }
   3.685 -
   3.686 -   //store in object history if this is an SQL Command window (*.tdb)
   3.687 -   private void addToHistory(Document doc) {
   3.688 -      DataObject obj = FileExecutionUtil.getDataObject(doc);
   3.689 -      FileObject file = obj.getPrimaryFile();
   3.690 -      if (file == null) {
   3.691 -         return;
   3.692 -      }
   3.693 -      String extension = file.getExt();
   3.694 -      if ("tdb".equalsIgnoreCase(extension)) {
   3.695 -         StatementExecutionHistory history = obj.getLookup().lookup(StatementExecutionHistory.class);
   3.696 -         try {
   3.697 -            history.addEntry(doc.getText(0, doc.getLength()));
   3.698 -         } catch (BadLocationException ex) {
   3.699 -            Exceptions.printStackTrace(ex);
   3.700 -         }
   3.701 -      }
   3.702 -
   3.703 -   }
   3.704 -
   3.705 -   public InputOutput executePLSQL(List executableObjs, Document doc, boolean hidden, boolean autoCommit) {
   3.706 -      final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
   3.707 -      Project project = null;
   3.708 -      Object object = doc.getProperty(Document.StreamDescriptionProperty);
   3.709 -      if (object instanceof DataObject) {
   3.710 -         FileObject fo = ((DataObject) object).getPrimaryFile();
   3.711 -         project = FileOwnerQuery.getOwner(fo);
   3.712 -      }
   3.713 -      
   3.714 -      //store in object history if this is an SQL Command window (*.tdb)
   3.715 -      boolean ignoreDefines = false;
   3.716 -      addToHistory(doc);
   3.717 -      cancel = false;
   3.718 -      InputOutput io = null;
   3.719 -      boolean deploymentOk = true;
   3.720 -      if (debugConnection == null && connection.getJDBCConnection() == null) {
   3.721 -         JOptionPane.showMessageDialog(null, "Connect to the Database");
   3.722 -         return null;
   3.723 -      }
   3.724 -
   3.725 -      //Defines and define
   3.726 -      HashMap<String, String> definesMap = new HashMap<String, String>();
   3.727 -      char define = '&';
   3.728 -      DataObject dataObj = FileExecutionUtil.getDataObject(doc);
   3.729 -      plsqlEditor = getPlsqlEditor(dataObj);
   3.730 -      String endMsg = "Done deploying " + FileExecutionUtil.getActivatedFileName(dataObj);
   3.731 -      long startTime = System.currentTimeMillis();
   3.732 -      String fileName = dataObj.getPrimaryFile().getNameExt();
   3.733 -      boolean moreRowsToBeFetched = false;
   3.734 -      //Check whether this is the excution window file
   3.735 -      if (fileName.endsWith(".tdb")) {
   3.736 -         endMsg = "Finished executing command ";
   3.737 -      }
   3.738 -      Connection con = null;
   3.739 -      Statement stm = null;
   3.740 -      String firstWord = null;
   3.741 -      boolean commit = false;
   3.742 -
   3.743 -      //quick & dirty fix to avoid having output tabs for the SQL Execution window (unless there's an exception)
   3.744 -      //first check to see if this is a simple select statement and if so treat it separately.
   3.745 -      if (executableObjs.size() == 1) {
   3.746 -         PlsqlExecutableObject executionObject = (PlsqlExecutableObject) executableObjs.get(0);
   3.747 -         if (executionObject.getType() == PlsqlExecutableObjectType.STATEMENT || executionObject.getType() == PlsqlExecutableObjectType.UNKNOWN) {
   3.748 -            String plsqlText = executionObject.getPlsqlString();
   3.749 -            try {
   3.750 -               // String firstWord;
   3.751 -               firstWord = null;
   3.752 -               StringTokenizer tokenizer = new StringTokenizer(plsqlText, " \t\n");
   3.753 -               if (tokenizer.hasMoreTokens()) {
   3.754 -                  firstWord = tokenizer.nextToken();
   3.755 -               } else {
   3.756 -                  firstWord = plsqlText;
   3.757 -               }
   3.758 -               if (firstWord.equalsIgnoreCase("SELECT")) {
   3.759 -                  if (plsqlEditor != null) {
   3.760 -                     plsqlEditor.closeResultSetTabs();
   3.761 -                  }
   3.762 -                  //replace aliases since there are aliases in PROMPTS
   3.763 -                  if (!ignoreDefines) {
   3.764 -                     plsqlText = replaceAliases(plsqlText, definesMap, define, io);
   3.765 -                  }
   3.766 -                  moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
   3.767 -                  return null;
   3.768 -               } else if (firstWord.equalsIgnoreCase("DESC") || firstWord.equalsIgnoreCase("DESCRIBE")) {
   3.769 -                  describeObject(connection, doc, tokenizer, io);
   3.770 -                  return null;
   3.771 -               }
   3.772 -
   3.773 -            } catch (SQLException sqlEx) {
   3.774 -               try {
   3.775 -                  io = initializeIO(fileName, dataObj);
   3.776 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.777 -                  int outLine = executionObject.getStartLineNo() + errLine - 1;
   3.778 -                  String msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.779 -                  PlsqlOutputListener outList = new PlsqlOutputListener();
   3.780 -                  outList.setDocLinesArray(executionObject.getDocLinesArray());
   3.781 -                  outList.setOriginalFileName(executionObject.getOriginalFileName());
   3.782 -                  outList.setLineNo(outLine);
   3.783 -                  io.getErr().println((new StringBuilder()).append("!!!Error Executing Statement ").append(executionObject).toString());
   3.784 -                  io.getOut().println(plsqlText);
   3.785 -                  io.getErr().println(msg, outList);
   3.786 -                  io.getOut().close();
   3.787 -                  io.getErr().close();
   3.788 -                  return io;
   3.789 -               } catch (IOException ex) {
   3.790 -                  connectionProvider.setOnline(false);
   3.791 -                  return null;
   3.792 -               }
   3.793 -            }
   3.794 -         }
   3.795 -      }
   3.796 -      try {
   3.797 -         io = initializeIO(fileName, dataObj);
   3.798 -         con = debugConnection != null ? debugConnection : connection.getJDBCConnection();
   3.799 -         con.setAutoCommit(false);
   3.800 -         enableDbmsOut(con);
   3.801 -         firstSavepoint = con.setSavepoint();
   3.802 -         //savepointsCreated.put(new Integer(firstSavepoint.getSavepointId()),firstSavepoint);
   3.803 -
   3.804 -         stm = con.createStatement();
   3.805 -         stm.setEscapeProcessing(false);
   3.806 -         if (connectionProvider.isUsagesEnabled() && validator.isValidPackage(dataObj)) {//sadhlkd
   3.807 -            String plsqlText = "ALTER SYSTEM SET PLSCOPE_SETTINGS = 'IDENTIFIERS:ALL' \t\n";
   3.808 -            try {
   3.809 -               //io.getOut().println((new StringBuilder()).append("> Enabling Usages for ").append(fileName));
   3.810 -               stm.execute(plsqlText);
   3.811 -            } catch (SQLException sqlEx) {
   3.812 -               int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.813 -               int outLine = errLine - 1;
   3.814 -               String msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.815 -               // io.getErr().println((new StringBuilder()).append("!!!Error Creating View ").append(exeObjName).toString());
   3.816 -               io.getOut().println(plsqlText);
   3.817 -               deploymentOk = false;
   3.818 -            }
   3.819 -         }
   3.820 -         boolean firstSelectStatement = true;
   3.821 -         for (int i = 0; i < executableObjs.size(); i++) {
   3.822 -            if (cancel) {
   3.823 -               io.getErr().println("!!!Execution cancelled. Performing rollback");
   3.824 -               // con.rollback();
   3.825 -               con.rollback(firstSavepoint);
   3.826 -               return io;
   3.827 -            }
   3.828 -            PlsqlExecutableObject exeObj = (PlsqlExecutableObject) executableObjs.get(i);
   3.829 -            int lineNumber = exeObj.getStartLineNo();
   3.830 -            String plsqlText = exeObj.getPlsqlString();
   3.831 -
   3.832 -            String exeObjName = exeObj.getExecutableObjName().toUpperCase(Locale.ENGLISH);
   3.833 -            if ((exeObj.getType() != PlsqlExecutableObjectType.UNKNOWN) && (exeObj.getType() != PlsqlExecutableObjectType.COMMENT)) {
   3.834 -               //replace aliases since there are aliases in PROMPTS
   3.835 -               if (!ignoreDefines) {
   3.836 -                  plsqlText = replaceAliases(plsqlText, definesMap, define, io);
   3.837 -                  exeObjName = replaceAliases(exeObjName, definesMap, define, io);
   3.838 -               }
   3.839 -            }
   3.840 -            PlsqlOutputListener outList = new PlsqlOutputListener();
   3.841 -            outList.setDocLinesArray(exeObj.getDocLinesArray());
   3.842 -            outList.setOriginalFileName(exeObj.getOriginalFileName());
   3.843 -            String msg;
   3.844 -            if (exeObj.getType() == PlsqlExecutableObjectType.VIEW) {
   3.845 -               try {
   3.846 -                  stm.execute(plsqlText);
   3.847 -                  io.getOut().println((new StringBuilder()).append("> PL/SQL View ").append(exeObjName).append(" Created Successfully").toString());
   3.848 -                  continue;
   3.849 -               } catch (SQLException sqlEx) {
   3.850 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.851 -                  int outLine = errLine==-1 ? lineNumber : lineNumber + errLine - 1;
   3.852 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.853 -                  outList.setLineNo(outLine);
   3.854 -                  io.getErr().println((new StringBuilder()).append("!!!Error Creating View ").append(exeObjName).toString());
   3.855 -                  io.getOut().println(plsqlText);
   3.856 -                  io.getErr().println(msg, outList);
   3.857 -                  deploymentOk = false;
   3.858 -                  break;
   3.859 -               }
   3.860 -            }
   3.861 -            if (exeObj.getType() == PlsqlExecutableObjectType.STATEMENT) {
   3.862 -               try {
   3.863 -                  // String firstWord;
   3.864 -                  firstWord = null;
   3.865 -                  StringTokenizer tokenizer = new StringTokenizer(plsqlText, " \t\n;");
   3.866 -                  if (tokenizer.hasMoreTokens()) {
   3.867 -                     firstWord = tokenizer.nextToken();
   3.868 -                  } else {
   3.869 -                     firstWord = plsqlText;
   3.870 -                  }
   3.871 -
   3.872 -                  if (plsqlText.toUpperCase().contains("INSERT") || plsqlText.toUpperCase().contains("UPDATE") || plsqlText.toUpperCase().contains("DELETE")) {
   3.873 -                     commit = true;
   3.874 -                  }
   3.875 -
   3.876 -                  if (firstWord.equalsIgnoreCase("SELECT")) {
   3.877 -                     //this should really never happen... Unless there are multiple parts of a file and some sections are select statements
   3.878 -                     if (plsqlEditor != null && firstSelectStatement) {
   3.879 -                        plsqlEditor.closeResultSetTabs();
   3.880 -                        firstSelectStatement = false;
   3.881 -                     }
   3.882 -                     moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
   3.883 -                     continue;
   3.884 -                  } else {
   3.885 -                     io.select();
   3.886 -                     io.getOut().println((new StringBuilder()).append("> Executing Statement "));
   3.887 -                     io.getOut().println("   " + plsqlText.replaceAll("\n", "\n   "));
   3.888 -                     stm.execute(plsqlText);
   3.889 -                  }
   3.890 -                  continue;
   3.891 -               } catch (SQLException sqlEx) {
   3.892 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.893 -                  int outLine = lineNumber + errLine - 1;
   3.894 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.895 -                  outList.setLineNo(outLine);
   3.896 -                  io.getErr().println((new StringBuilder()).append("!!!Error Executing Statement ").append(exeObjName).toString());
   3.897 -                  io.getOut().println(plsqlText);
   3.898 -                  io.getErr().println(msg, outList);
   3.899 -                  deploymentOk = false;
   3.900 -                  break;
   3.901 -               }
   3.902 -            }
   3.903 -            if (exeObj.getType() == PlsqlExecutableObjectType.TRIGGER) {
   3.904 -               try {
   3.905 -                  stm.execute(plsqlText);
   3.906 -                  io.getOut().println((new StringBuilder()).append("> PL/SQL Trigger ").append(exeObjName).append(" Created Successfully").toString());
   3.907 -                  continue;
   3.908 -               } catch (SQLException sqlEx) {
   3.909 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.910 -                  int outLine = lineNumber + errLine - 1;
   3.911 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.912 -                  outList.setLineNo(outLine);
   3.913 -                  io.getErr().println((new StringBuilder()).append("!!!Error Creating Trigger ").append(exeObjName).toString());
   3.914 -                  io.getOut().println(plsqlText);
   3.915 -                  io.getErr().println(msg, outList);
   3.916 -                  deploymentOk = false;
   3.917 -                  break;
   3.918 -               }
   3.919 -            }
   3.920 -            if (exeObj.getType() == PlsqlExecutableObjectType.JAVASOURCE) {
   3.921 -               try {
   3.922 -                  stm.execute(plsqlText);
   3.923 -                  io.getOut().println((new StringBuilder()).append("> Java Source ").append(exeObjName).append(" Deployed Successfully").toString());
   3.924 -                  continue;
   3.925 -               } catch (SQLException sqlEx) {
   3.926 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.927 -                  int outLine = lineNumber + errLine - 1;
   3.928 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.929 -                  outList.setLineNo(outLine);
   3.930 -                  io.getErr().println((new StringBuilder()).append("!!!Error Deploying Java Source ").append(exeObjName).toString());
   3.931 -                  io.getOut().println(plsqlText);
   3.932 -                  io.getErr().println(msg, outList);
   3.933 -                  deploymentOk = false;
   3.934 -                  break;
   3.935 -               }
   3.936 -            }
   3.937 -            if (exeObj.getType() == PlsqlExecutableObjectType.TABLECOMMENT) {
   3.938 -               try {
   3.939 -                  stm.execute(plsqlText);
   3.940 -                  io.getOut().println((new StringBuilder()).append("> Table Comments On ").append(exeObjName).append(" Added Successfully").toString());
   3.941 -                  continue;
   3.942 -               } catch (SQLException sqlEx) {
   3.943 -                  io.getErr().println((new StringBuilder()).append("!!!Error Adding Table Comments On ").append(exeObjName).toString());
   3.944 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.945 -                  int outLine = lineNumber + errLine - 1;
   3.946 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.947 -                  outList.setLineNo(outLine);
   3.948 -                  io.getOut().println(plsqlText);
   3.949 -                  io.getErr().println(msg, outList);
   3.950 -                  deploymentOk = false;
   3.951 -                  break;
   3.952 -               }
   3.953 -            }
   3.954 -            if (exeObj.getType() == PlsqlExecutableObjectType.COLUMNCOMMENT) {
   3.955 -               try {
   3.956 -                  stm.execute(plsqlText);
   3.957 -                  io.getOut().println((new StringBuilder()).append("> Column Comments On ").append(exeObjName).append(" Added Successfully").toString());
   3.958 -                  continue;
   3.959 -               } catch (SQLException sqlEx) {
   3.960 -                  io.getErr().println((new StringBuilder()).append("!!!Error Adding Column Comments On ").append(exeObjName).toString());
   3.961 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.962 -                  int outLine = lineNumber + errLine - 1;
   3.963 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.964 -                  outList.setLineNo(outLine);
   3.965 -                  io.getOut().println(plsqlText);
   3.966 -                  io.getErr().println(msg, outList);
   3.967 -                  deploymentOk = false;
   3.968 -                  break;
   3.969 -               }
   3.970 -            }
   3.971 -            if (exeObj.getType() == PlsqlExecutableObjectType.DECLAREEND) {
   3.972 -               try {
   3.973 -                  stm.executeUpdate(plsqlText);
   3.974 -                  processDbmsOutputMessages(con, io.getOut());
   3.975 -                  io.getOut().println("> PL/SQL Block Executed Successfully");
   3.976 -                  continue;
   3.977 -               } catch (SQLException sqlEx) {
   3.978 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
   3.979 -                  int outLine = lineNumber + errLine - 1;
   3.980 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
   3.981 -                  outList.setLineNo(outLine);
   3.982 -                  io.getErr().println("!!!Error Occurred While Executing PL/SQL Block");
   3.983 -                  io.getOut().println(plsqlText);
   3.984 -                  io.getErr().println(msg, outList);
   3.985 -                  io.getOut().println("!!!Error detected. Performing Rollback");
   3.986 -                  deploymentOk = false;
   3.987 -                  try {
   3.988 -                     // con.rollback();
   3.989 -                     con.rollback(firstSavepoint);
   3.990 -                  } catch (SQLException ex) {
   3.991 -                  }
   3.992 -                  break;
   3.993 -               }
   3.994 -            }
   3.995 -            if (exeObj.getType() == PlsqlExecutableObjectType.BEGINEND) {
   3.996 -               if (plsqlText.toUpperCase().contains("INSERT") || plsqlText.toUpperCase().contains("UPDATE") || plsqlText.toUpperCase().contains("DELETE")) {
   3.997 -                  commit = true;
   3.998 -               }
   3.999 -               try {
  3.1000 -                  stm.executeUpdate(plsqlText);
  3.1001 -                  processDbmsOutputMessages(con, io.getOut());
  3.1002 -                  io.getOut().println("> PL/SQL Block Executed Successfully");
  3.1003 -                  continue;
  3.1004 -               } catch (SQLException sqlEx) {
  3.1005 -                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1006 -                  int outLine = lineNumber + errLine - 1;
  3.1007 -                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1008 -                  outList.setLineNo(outLine);
  3.1009 -                  io.getErr().println("!!!Error Occurred While Executing PL/SQL Block");
  3.1010 -                  io.getOut().println(plsqlText);
  3.1011 -                  io.getErr().println(msg, outList);
  3.1012 -                  deploymentOk = false;
  3.1013 -                  break;
  3.1014 -               }
  3.1015 -            }
  3.1016 -            if (exeObj.getType() == PlsqlExecutableObjectType.UNKNOWN) {
  3.1017 -               if (plsqlText.toUpperCase().contains("INSERT") || plsqlText.toUpperCase().contains("UPDATE") || plsqlText.toUpperCase().contains("DELETE")) {
  3.1018 -                  commit = true;
  3.1019 -               }
  3.1020 -               //Parse aliases
  3.1021 -               define = getAliases(definesMap, doc, exeObj.getStartOffset(), exeObj.getEndOffset(), define, io);
  3.1022 -               //Replace aliases
  3.1023 -               if (!ignoreDefines) {
  3.1024 -                  plsqlText = replaceAliases(plsqlText, definesMap, define, io);
  3.1025 -               }
  3.1026 -               plsqlText = plsqlText.trim();
  3.1027 -               // String firstWord;
  3.1028 -               firstWord = null;
  3.1029 -               StringTokenizer tokenizer = new StringTokenizer(plsqlText, " \t\n");
  3.1030 -               try {
  3.1031 -                  if (tokenizer.hasMoreTokens()) {
  3.1032 -                     firstWord = tokenizer.nextToken();
  3.1033 -                  } else {
  3.1034 -                     firstWord = plsqlText;
  3.1035 -                  }
  3.1036 -                  if (firstWord.equalsIgnoreCase("SELECT")) {
  3.1037 -                     //this should really never happen... Unless there are multiple parts of a file and some sections are select statements
  3.1038 -                     if (plsqlEditor != null) {
  3.1039 -                        plsqlEditor.closeResultSetTabs();
  3.1040 -                     }
  3.1041 -                     moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
  3.1042 -                     continue;
  3.1043 -                  } else {
  3.1044 -                     io.select();
  3.1045 -                     if (firstWord.equalsIgnoreCase("DESC") || firstWord.equalsIgnoreCase("DESCRIBE")) {
  3.1046 -                        describeObject(connection, doc, tokenizer, io);
  3.1047 +                }
  3.1048 +                PlsqlOutputListener outList = new PlsqlOutputListener();
  3.1049 +                outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1050 +                outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1051 +                String msg;
  3.1052 +                if (exeObj.getType() == PlsqlExecutableObjectType.VIEW) {
  3.1053 +                    try {
  3.1054 +                        stm.execute(plsqlText);
  3.1055 +                        io.getOut().println((new StringBuilder()).append("> PL/SQL View ").append(exeObjName).append(" Created Successfully").toString());
  3.1056                          continue;
  3.1057 -                     } else if (firstWord.equalsIgnoreCase("PROMPT")) {
  3.1058 -                        if (plsqlText.length() > 7) {
  3.1059 -                           io.getOut().println(plsqlText.substring(7));
  3.1060 +                    } catch (SQLException sqlEx) {
  3.1061 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1062 +                        int outLine = errLine == -1 ? lineNumber : lineNumber + errLine - 1;
  3.1063 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1064 +                        outList.setLineNo(outLine);
  3.1065 +                        io.getErr().println((new StringBuilder()).append("!!!Error Creating View ").append(exeObjName).toString());
  3.1066 +                        io.getOut().println(plsqlText);
  3.1067 +                        io.getErr().println(msg, outList);
  3.1068 +                        deploymentOk = false;
  3.1069 +                        break;
  3.1070 +                    }
  3.1071 +                }
  3.1072 +                if (exeObj.getType() == PlsqlExecutableObjectType.STATEMENT) {
  3.1073 +                    try {
  3.1074 +                        // String firstWord;
  3.1075 +                        firstWord = null;
  3.1076 +                        StringTokenizer tokenizer = new StringTokenizer(plsqlText, " \t\n;");
  3.1077 +                        if (tokenizer.hasMoreTokens()) {
  3.1078 +                            firstWord = tokenizer.nextToken();
  3.1079 +                        } else {
  3.1080 +                            firstWord = plsqlText;
  3.1081 +                        }
  3.1082 +                        
  3.1083 +                        if (plsqlText.toUpperCase().contains("INSERT") || plsqlText.toUpperCase().contains("UPDATE") || plsqlText.toUpperCase().contains("DELETE")) {
  3.1084 +                            commit = true;
  3.1085 +                        }
  3.1086 +                        
  3.1087 +                        if (firstWord.equalsIgnoreCase("SELECT")) {
  3.1088 +                            //this should really never happen... Unless there are multiple parts of a file and some sections are select statements
  3.1089 +                            if (plsqlEditor != null && firstSelectStatement) {
  3.1090 +                                plsqlEditor.closeResultSetTabs();
  3.1091 +                                firstSelectStatement = false;
  3.1092 +                            }
  3.1093 +                            moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
  3.1094 +                            continue;
  3.1095 +                        } else {
  3.1096 +                            io.select();
  3.1097 +                            io.getOut().println((new StringBuilder()).append("> Executing Statement "));
  3.1098 +                            io.getOut().println("   " + plsqlText.replaceAll("\n", "\n   "));
  3.1099 +                            stm.execute(plsqlText);
  3.1100                          }
  3.1101                          continue;
  3.1102 -                     } else if (firstWord.equalsIgnoreCase("SHOW")) {
  3.1103 +                    } catch (SQLException sqlEx) {
  3.1104 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1105 +                        int outLine = lineNumber + errLine - 1;
  3.1106 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1107 +                        outList.setLineNo(outLine);
  3.1108 +                        io.getErr().println((new StringBuilder()).append("!!!Error Executing Statement ").append(exeObjName).toString());
  3.1109 +                        io.getOut().println(plsqlText);
  3.1110 +                        io.getErr().println(msg, outList);
  3.1111 +                        deploymentOk = false;
  3.1112 +                        break;
  3.1113 +                    }
  3.1114 +                }
  3.1115 +                if (exeObj.getType() == PlsqlExecutableObjectType.TRIGGER) {
  3.1116 +                    try {
  3.1117 +                        stm.execute(plsqlText);
  3.1118 +                        io.getOut().println((new StringBuilder()).append("> PL/SQL Trigger ").append(exeObjName).append(" Created Successfully").toString());
  3.1119                          continue;
  3.1120 -                     } else if (firstWord.equalsIgnoreCase("SET")) {
  3.1121 +                    } catch (SQLException sqlEx) {
  3.1122 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1123 +                        int outLine = lineNumber + errLine - 1;
  3.1124 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1125 +                        outList.setLineNo(outLine);
  3.1126 +                        io.getErr().println((new StringBuilder()).append("!!!Error Creating Trigger ").append(exeObjName).toString());
  3.1127 +                        io.getOut().println(plsqlText);
  3.1128 +                        io.getErr().println(msg, outList);
  3.1129 +                        deploymentOk = false;
  3.1130 +                        break;
  3.1131 +                    }
  3.1132 +                }
  3.1133 +                if (exeObj.getType() == PlsqlExecutableObjectType.JAVASOURCE) {
  3.1134 +                    try {
  3.1135 +                        stm.execute(plsqlText);
  3.1136 +                        io.getOut().println((new StringBuilder()).append("> Java Source ").append(exeObjName).append(" Deployed Successfully").toString());
  3.1137 +                        continue;
  3.1138 +                    } catch (SQLException sqlEx) {
  3.1139 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1140 +                        int outLine = lineNumber + errLine - 1;
  3.1141 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1142 +                        outList.setLineNo(outLine);
  3.1143 +                        io.getErr().println((new StringBuilder()).append("!!!Error Deploying Java Source ").append(exeObjName).toString());
  3.1144 +                        io.getOut().println(plsqlText);
  3.1145 +                        io.getErr().println(msg, outList);
  3.1146 +                        deploymentOk = false;
  3.1147 +                        break;
  3.1148 +                    }
  3.1149 +                }
  3.1150 +                if (exeObj.getType() == PlsqlExecutableObjectType.TABLECOMMENT) {
  3.1151 +                    try {
  3.1152 +                        stm.execute(plsqlText);
  3.1153 +                        io.getOut().println((new StringBuilder()).append("> Table Comments On ").append(exeObjName).append(" Added Successfully").toString());
  3.1154 +                        continue;
  3.1155 +                    } catch (SQLException sqlEx) {
  3.1156 +                        io.getErr().println((new StringBuilder()).append("!!!Error Adding Table Comments On ").append(exeObjName).toString());
  3.1157 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1158 +                        int outLine = lineNumber + errLine - 1;
  3.1159 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1160 +                        outList.setLineNo(outLine);
  3.1161 +                        io.getOut().println(plsqlText);
  3.1162 +                        io.getErr().println(msg, outList);
  3.1163 +                        deploymentOk = false;
  3.1164 +                        break;
  3.1165 +                    }
  3.1166 +                }
  3.1167 +                if (exeObj.getType() == PlsqlExecutableObjectType.COLUMNCOMMENT) {
  3.1168 +                    try {
  3.1169 +                        stm.execute(plsqlText);
  3.1170 +                        io.getOut().println((new StringBuilder()).append("> Column Comments On ").append(exeObjName).append(" Added Successfully").toString());
  3.1171 +                        continue;
  3.1172 +                    } catch (SQLException sqlEx) {
  3.1173 +                        io.getErr().println((new StringBuilder()).append("!!!Error Adding Column Comments On ").append(exeObjName).toString());
  3.1174 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1175 +                        int outLine = lineNumber + errLine - 1;
  3.1176 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1177 +                        outList.setLineNo(outLine);
  3.1178 +                        io.getOut().println(plsqlText);
  3.1179 +                        io.getErr().println(msg, outList);
  3.1180 +                        deploymentOk = false;
  3.1181 +                        break;
  3.1182 +                    }
  3.1183 +                }
  3.1184 +                if (exeObj.getType() == PlsqlExecutableObjectType.DECLAREEND) {
  3.1185 +                    try {
  3.1186 +                        stm.executeUpdate(plsqlText);
  3.1187 +                        processDbmsOutputMessages(con, io.getOut());
  3.1188 +                        io.getOut().println("> PL/SQL Block Executed Successfully");
  3.1189 +                        continue;
  3.1190 +                    } catch (SQLException sqlEx) {
  3.1191 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1192 +                        int outLine = lineNumber + errLine - 1;
  3.1193 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1194 +                        outList.setLineNo(outLine);
  3.1195 +                        io.getErr().println("!!!Error Occurred While Executing PL/SQL Block");
  3.1196 +                        io.getOut().println(plsqlText);
  3.1197 +                        io.getErr().println(msg, outList);
  3.1198 +                        io.getOut().println("!!!Error detected. Performing Rollback");
  3.1199 +                        deploymentOk = false;
  3.1200 +                        try {
  3.1201 +                            // con.rollback();
  3.1202 +                            con.rollback(firstSavepoint);
  3.1203 +                        } catch (SQLException ex) {
  3.1204 +                        }
  3.1205 +                        break;
  3.1206 +                    }
  3.1207 +                }
  3.1208 +                if (exeObj.getType() == PlsqlExecutableObjectType.BEGINEND) {
  3.1209 +                    if (plsqlText.toUpperCase().contains("INSERT") || plsqlText.toUpperCase().contains("UPDATE") || plsqlText.toUpperCase().contains("DELETE")) {
  3.1210 +                        commit = true;
  3.1211 +                    }
  3.1212 +                    try {
  3.1213 +                        stm.executeUpdate(plsqlText);
  3.1214 +                        processDbmsOutputMessages(con, io.getOut());
  3.1215 +                        io.getOut().println("> PL/SQL Block Executed Successfully");
  3.1216 +                        continue;
  3.1217 +                    } catch (SQLException sqlEx) {
  3.1218 +                        int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1219 +                        int outLine = lineNumber + errLine - 1;
  3.1220 +                        msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1221 +                        outList.setLineNo(outLine);
  3.1222 +                        io.getErr().println("!!!Error Occurred While Executing PL/SQL Block");
  3.1223 +                        io.getOut().println(plsqlText);
  3.1224 +                        io.getErr().println(msg, outList);
  3.1225 +                        deploymentOk = false;
  3.1226 +                        break;
  3.1227 +                    }
  3.1228 +                }
  3.1229 +                if (exeObj.getType() == PlsqlExecutableObjectType.UNKNOWN) {
  3.1230 +                    if (plsqlText.toUpperCase().contains("INSERT") || plsqlText.toUpperCase().contains("UPDATE") || plsqlText.toUpperCase().contains("DELETE")) {
  3.1231 +                        commit = true;
  3.1232 +                    }
  3.1233 +                    //Parse aliases
  3.1234 +                    define = getAliases(definesMap, doc, exeObj.getStartOffset(), exeObj.getEndOffset(), define, io);
  3.1235 +                    //Replace aliases
  3.1236 +                    if (!ignoreDefines) {
  3.1237 +                        plsqlText = replaceAliases(plsqlText, definesMap, define, io);
  3.1238 +                    }
  3.1239 +                    plsqlText = plsqlText.trim();
  3.1240 +                    // String firstWord;
  3.1241 +                    firstWord = null;
  3.1242 +                    StringTokenizer tokenizer = new StringTokenizer(plsqlText, " \t\n");
  3.1243 +                    try {
  3.1244                          if (tokenizer.hasMoreTokens()) {
  3.1245 -                           String setting = tokenizer.nextToken();
  3.1246 -                           if ("DEFINE".equalsIgnoreCase(setting)) {
  3.1247 -                              if (tokenizer.hasMoreElements()) {
  3.1248 -                                 String token = tokenizer.nextToken();
  3.1249 -                                 ignoreDefines = "OFF".equalsIgnoreCase(token);
  3.1250 -                                 if (!ignoreDefines && token.length() == 1) {
  3.1251 -                                    define = token.charAt(0);
  3.1252 -                                 }
  3.1253 -                              }
  3.1254 -                           }
  3.1255 -
  3.1256 +                            firstWord = tokenizer.nextToken();
  3.1257 +                        } else {
  3.1258 +                            firstWord = plsqlText;
  3.1259                          }
  3.1260 -                        continue;
  3.1261 -                     } else if (firstWord.equalsIgnoreCase("DEFINE") || firstWord.equalsIgnoreCase("DEF") || firstWord.equalsIgnoreCase("DEFI") || firstWord.equalsIgnoreCase("DEFIN")) {
  3.1262 -                        continue;
  3.1263 -                        //sadhlkd
  3.1264 -                     } else if (firstWord.equalsIgnoreCase("UNDEFINE") || firstWord.equalsIgnoreCase("UNDEF")) {
  3.1265 -                        continue;
  3.1266 -                     } else if (firstWord.equalsIgnoreCase("EXECUTE") || firstWord.equalsIgnoreCase("EXEC")) {
  3.1267 -                        if (!plsqlText.trim().endsWith(";")) {
  3.1268 -                           plsqlText += ";";
  3.1269 +                        if (firstWord.equalsIgnoreCase("SELECT")) {
  3.1270 +                            //this should really never happen... Unless there are multiple parts of a file and some sections are select statements
  3.1271 +                            if (plsqlEditor != null) {
  3.1272 +                                plsqlEditor.closeResultSetTabs();
  3.1273 +                            }
  3.1274 +                            moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
  3.1275 +                            continue;
  3.1276 +                        } else {
  3.1277 +                            io.select();
  3.1278 +                            if (firstWord.equalsIgnoreCase("DESC") || firstWord.equalsIgnoreCase("DESCRIBE")) {
  3.1279 +                                describeObject(connection, doc, tokenizer, io);
  3.1280 +                                continue;
  3.1281 +                            } else if (firstWord.equalsIgnoreCase("PROMPT")) {
  3.1282 +                                if (plsqlText.length() > 7) {
  3.1283 +                                    io.getOut().println(plsqlText.substring(7));
  3.1284 +                                }
  3.1285 +                                continue;
  3.1286 +                            } else if (firstWord.equalsIgnoreCase("SHOW")) {
  3.1287 +                                continue;
  3.1288 +                            } else if (firstWord.equalsIgnoreCase("SET")) {
  3.1289 +                                if (tokenizer.hasMoreTokens()) {
  3.1290 +                                    String setting = tokenizer.nextToken();
  3.1291 +                                    if ("DEFINE".equalsIgnoreCase(setting)) {
  3.1292 +                                        if (tokenizer.hasMoreElements()) {
  3.1293 +                                            String token = tokenizer.nextToken();
  3.1294 +                                            ignoreDefines = "OFF".equalsIgnoreCase(token);
  3.1295 +                                            if (!ignoreDefines && token.length() == 1) {
  3.1296 +                                                define = token.charAt(0);
  3.1297 +                                            }
  3.1298 +                                        }
  3.1299 +                                    }
  3.1300 +                                    
  3.1301 +                                }
  3.1302 +                                continue;
  3.1303 +                            } else if (firstWord.equalsIgnoreCase("DEFINE") || firstWord.equalsIgnoreCase("DEF") || firstWord.equalsIgnoreCase("DEFI") || firstWord.equalsIgnoreCase("DEFIN")) {
  3.1304 +                                continue;
  3.1305 +                            } else if (firstWord.equalsIgnoreCase("UNDEFINE") || firstWord.equalsIgnoreCase("UNDEF")) {
  3.1306 +                                continue;
  3.1307 +                            } else if (firstWord.equalsIgnoreCase("EXECUTE") || firstWord.equalsIgnoreCase("EXEC")) {
  3.1308 +                                if (!plsqlText.trim().endsWith(";")) {
  3.1309 +                                    plsqlText += ";";
  3.1310 +                                }
  3.1311 +                                plsqlText = "BEGIN\n" + plsqlText.substring(firstWord.length()) + "\nEND;";
  3.1312 +                            } else if (plsqlText.equals(";") || plsqlText.equals("/")) {
  3.1313 +                                continue;
  3.1314 +                            }
  3.1315                          }
  3.1316 -                        plsqlText = "BEGIN\n" + plsqlText.substring(firstWord.length()) + "\nEND;";
  3.1317 -                     } else if (plsqlText.equals(";") || plsqlText.equals("/")) {
  3.1318 -                        continue;
  3.1319 -                     }
  3.1320 -                  }
  3.1321 -                  //Ingore ';' '/' which are added manually
  3.1322 -                  if ((plsqlText.equals(";")) || (plsqlText.equals("/")) || (plsqlText.equals(""))) {
  3.1323 -                     continue;
  3.1324 -                  }
  3.1325 -                  io.getOut().println("> Executing Statement:");
  3.1326 -                  io.getOut().println("   " + plsqlText.replaceAll("\n", "\n   "));
  3.1327 -                  stm.executeUpdate(plsqlText);
  3.1328 -                  SQLWarning warn = stm.getWarnings();
  3.1329 -                  processDbmsOutputMessages(con, io.getOut());
  3.1330 -                  if (warn == null) {
  3.1331 -                     stm.clearWarnings();
  3.1332 -                     continue;
  3.1333 -                  } else {
  3.1334 -                     int errLine = getLineNumberFromMsg(warn.getMessage());
  3.1335 -                     int outLine = lineNumber + errLine - 1;
  3.1336 -                     msg = getmodifiedErorrMsg(warn.getMessage(), outLine);
  3.1337 -                     outList.setLineNo(outLine);
  3.1338 -                     io.getErr().println("---Warning Occurred While Executing Statement ");
  3.1339 -                     io.getErr().println(msg, outList);
  3.1340 -                     break;
  3.1341 -                  }
  3.1342 -               } catch (SQLException sqlEx) {
  3.1343 -                  io.getErr().println("!!!Error Occurred While Executing Statement ");
  3.1344 -                  String completeMsg=sqlEx.getMessage();
  3.1345 -                  if(completeMsg!=null) {
  3.1346 -                     String[] lines = completeMsg.split("\n");
  3.1347 -                     for(String line : lines) {
  3.1348 -                        int errLine = getLineNumberFromMsg(line);
  3.1349 -                        if(errLine==-1) {
  3.1350 -                           io.getOut().println(line);
  3.1351 +                        //Ingore ';' '/' which are added manually
  3.1352 +                        if ((plsqlText.equals(";")) || (plsqlText.equals("/")) || (plsqlText.equals(""))) {
  3.1353 +                            continue;
  3.1354 +                        }
  3.1355 +                        io.getOut().println("> Executing Statement:");
  3.1356 +                        io.getOut().println("   " + plsqlText.replaceAll("\n", "\n   "));
  3.1357 +                        stm.executeUpdate(plsqlText);
  3.1358 +                        SQLWarning warn = stm.getWarnings();
  3.1359 +                        processDbmsOutputMessages(con, io.getOut());
  3.1360 +                        if (warn == null) {
  3.1361 +                            stm.clearWarnings();
  3.1362 +                            continue;
  3.1363                          } else {
  3.1364 -                           String[] nameCandidate = line.split("\"");
  3.1365 -                           PlsqlOutputListener listener = outList;
  3.1366 -                           if(nameCandidate.length==3) { //object name included
  3.1367 -                              String objectName = nameCandidate[1];
  3.1368 -                              if(objectName.contains(".")) {
  3.1369 -                                 objectName = objectName.substring(objectName.lastIndexOf(".")+1);
  3.1370 -                              }
  3.1371 -                              listener = new PlsqlOutputListener(project, objectName, errLine);
  3.1372 -                           } else {
  3.1373 -                              listener.setLineNo(lineNumber+errLine-1);
  3.1374 -                           }
  3.1375 -                           io.getErr().println(line, listener);
  3.1376 +                            int errLine = getLineNumberFromMsg(warn.getMessage());
  3.1377 +                            int outLine = lineNumber + errLine - 1;
  3.1378 +                            msg = getmodifiedErorrMsg(warn.getMessage(), outLine);
  3.1379 +                            outList.setLineNo(outLine);
  3.1380 +                            io.getErr().println("---Warning Occurred While Executing Statement ");
  3.1381 +                            io.getErr().println(msg, outList);
  3.1382 +                            break;
  3.1383                          }
  3.1384 -                     }
  3.1385 -                  }
  3.1386 +                    } catch (SQLException sqlEx) {
  3.1387 +                        io.getErr().println("!!!Error Occurred While Executing Statement ");
  3.1388 +                        String completeMsg = sqlEx.getMessage();
  3.1389 +                        if (completeMsg != null) {
  3.1390 +                            String[] lines = completeMsg.split("\n");
  3.1391 +                            for (String line : lines) {
  3.1392 +                                int errLine = getLineNumberFromMsg(line);
  3.1393 +                                if (errLine == -1) {
  3.1394 +                                    io.getOut().println(line);
  3.1395 +                                } else {
  3.1396 +                                    String[] nameCandidate = line.split("\"");
  3.1397 +                                    PlsqlOutputListener listener = outList;
  3.1398 +                                    if (nameCandidate.length == 3) { //object name included
  3.1399 +                                        String objectName = nameCandidate[1];
  3.1400 +                                        if (objectName.contains(".")) {
  3.1401 +                                            objectName = objectName.substring(objectName.lastIndexOf(".") + 1);
  3.1402 +                                        }
  3.1403 +                                        listener = new PlsqlOutputListener(project, objectName, errLine);
  3.1404 +                                    } else {
  3.1405 +                                        listener.setLineNo(lineNumber + errLine - 1);
  3.1406 +                                    }
  3.1407 +                                    io.getErr().println(line, listener);
  3.1408 +                                }
  3.1409 +                            }
  3.1410 +                        }
  3.1411  //                  int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  3.1412  //                  int outLine = lineNumber + errLine - 1;
  3.1413  //                  msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  3.1414 -                  if(!autoCommit) {
  3.1415 -                     try {
  3.1416 -                        io.getOut().println("!!!Error detected. Performing rollback");
  3.1417 -                        con.rollback(firstSavepoint);
  3.1418 -                     } catch (SQLException ex) {
  3.1419 -                     }
  3.1420 -                  }
  3.1421 -                  deploymentOk = false;
  3.1422 -                  break;
  3.1423 -               }
  3.1424 +                        if (!autoCommit) {
  3.1425 +                            try {
  3.1426 +                                io.getOut().println("!!!Error detected. Performing rollback");
  3.1427 +                                con.rollback(firstSavepoint);
  3.1428 +                            } catch (SQLException ex) {
  3.1429 +                            }
  3.1430 +                        }
  3.1431 +                        deploymentOk = false;
  3.1432 +                        break;
  3.1433 +                    }
  3.1434 +                }
  3.1435 +                List errLst;
  3.1436 +                boolean exception = false;
  3.1437 +                String excMessage = "";
  3.1438 +                if (exeObj.getType() == PlsqlExecutableObjectType.PROCEDURE) {
  3.1439 +                    try {
  3.1440 +                        stm.execute(plsqlText);
  3.1441 +                        io.getOut().println((new StringBuilder()).append("PL/SQL Procedure ").append(exeObjName).append(" Created Successfully").toString());
  3.1442 +                    } catch (SQLException sqlEx) {
  3.1443 +                        exception = true;
  3.1444 +                        excMessage = sqlEx.getMessage();
  3.1445 +                    }
  3.1446 +                    errLst = getPackageerrors(exeObjName, "PROCEDURE");
  3.1447 +                    if ((errLst.isEmpty()) && (!exception)) {
  3.1448 +                        continue;
  3.1449 +                    } else if ((errLst.isEmpty()) && (exception)) {
  3.1450 +                        io.getErr().println((new StringBuilder()).append("!!!Procedure ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1451 +                        int errLine = getLineNumberFromMsg(excMessage);
  3.1452 +                        int outLine = lineNumber + errLine - 1;
  3.1453 +                        msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1454 +                        outList.setLineNo(outLine);
  3.1455 +                        io.getOut().println(plsqlText);
  3.1456 +                        io.getErr().println(msg, outList);
  3.1457 +                        deploymentOk = false;
  3.1458 +                        break;
  3.1459 +                    } else {
  3.1460 +                        io.getErr().println((new StringBuilder()).append("!!!Procedure ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1461 +                        for (int a = 0; a < errLst.size(); a++) {
  3.1462 +                            PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.1463 +                            int stNo = exeObj.getStartLineNo();
  3.1464 +                            int errNo = errObj.getLineNumber();
  3.1465 +                            if (errNo <= 0) {
  3.1466 +                                errNo = 1;
  3.1467 +                            }
  3.1468 +                            int lineNo = stNo + errNo - 1;
  3.1469 +                            msg = errObj.getErrorMsg();
  3.1470 +                            msg = getmodifiedErorrMsg(msg, lineNo);
  3.1471 +                            outList = new PlsqlOutputListener();
  3.1472 +                            outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1473 +                            outList.setLineNo(lineNo);
  3.1474 +                            outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1475 +                            io.getErr().println(msg, outList);
  3.1476 +                        }
  3.1477 +                        deploymentOk = false;
  3.1478 +                        break;
  3.1479 +                    }
  3.1480 +                }
  3.1481 +                if (exeObj.getType() == PlsqlExecutableObjectType.FUNCTION) {
  3.1482 +                    try {
  3.1483 +                        stm.execute(plsqlText);
  3.1484 +                        io.getOut().println((new StringBuilder()).append("PL/SQL Function ").append(exeObjName).append(" Created Successfully").toString());
  3.1485 +                    } catch (SQLException sqlEx) {
  3.1486 +                        exception = true;
  3.1487 +                        excMessage = sqlEx.getMessage();
  3.1488 +                    }
  3.1489 +                    errLst = getPackageerrors(exeObjName, "FUNCTION");
  3.1490 +                    if ((errLst.isEmpty()) && (!exception)) {
  3.1491 +                        continue;
  3.1492 +                    } else if ((errLst.isEmpty()) && (exception)) {
  3.1493 +                        io.getErr().println((new StringBuilder()).append("!!!Function ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1494 +                        int errLine = getLineNumberFromMsg(excMessage);
  3.1495 +                        int outLine = lineNumber + errLine - 1;
  3.1496 +                        msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1497 +                        outList.setLineNo(outLine);
  3.1498 +                        io.getOut().println(plsqlText);
  3.1499 +                        io.getErr().println(msg, outList);
  3.1500 +                        deploymentOk = false;
  3.1501 +                        break;
  3.1502 +                    } else {
  3.1503 +                        io.getErr().println((new StringBuilder()).append("!!!Function ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1504 +                        for (int a = 0; a < errLst.size(); a++) {
  3.1505 +                            PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.1506 +                            int stNo = exeObj.getStartLineNo();
  3.1507 +                            int errNo = errObj.getLineNumber();
  3.1508 +                            if (errNo <= 0) {
  3.1509 +                                errNo = 1;
  3.1510 +                            }
  3.1511 +                            int lineNo = stNo + errNo - 1;
  3.1512 +                            msg = errObj.getErrorMsg();
  3.1513 +                            msg = getmodifiedErorrMsg(msg, lineNo);
  3.1514 +                            outList = new PlsqlOutputListener();
  3.1515 +                            outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1516 +                            outList.setLineNo(lineNo);
  3.1517 +                            outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1518 +                            io.getErr().println(msg, outList);
  3.1519 +                        }
  3.1520 +                        deploymentOk = false;
  3.1521 +                        break;
  3.1522 +                    }
  3.1523 +                }
  3.1524 +                if (exeObj.getType() == PlsqlExecutableObjectType.PACKAGE) {
  3.1525 +                    try {
  3.1526 +                        stm.execute(plsqlText);
  3.1527 +                        io.getOut().println((new StringBuilder()).append("PL/SQL Package ").append(exeObjName).append(" Created Successfully").toString());
  3.1528 +                    } catch (SQLException sqlEx) {
  3.1529 +                        exception = true;
  3.1530 +                        excMessage = sqlEx.getMessage();
  3.1531 +                    }
  3.1532 +                    errLst = getPackageerrors(exeObjName, "PACKAGE");
  3.1533 +                    if ((errLst.isEmpty()) && (!exception)) {
  3.1534 +                        continue;
  3.1535 +                    } else if ((errLst.isEmpty()) && (exception)) {
  3.1536 +                        io.getErr().println((new StringBuilder()).append("!!!Package ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1537 +                        int errLine = getLineNumberFromMsg(excMessage);
  3.1538 +                        int outLine = lineNumber + errLine - 1;
  3.1539 +                        msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1540 +                        outList.setLineNo(outLine);
  3.1541 +                        io.getErr().println(msg, outList);
  3.1542 +                        deploymentOk = false;
  3.1543 +                        break;
  3.1544 +                    } else {
  3.1545 +                        io.getErr().println((new StringBuilder()).append("!!!Package ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1546 +                        for (int a = 0; a < errLst.size(); a++) {
  3.1547 +                            PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.1548 +                            int stNo = exeObj.getStartLineNo();
  3.1549 +                            int errNo = errObj.getLineNumber();
  3.1550 +                            if (errNo <= 0) {
  3.1551 +                                errNo = 1;
  3.1552 +                            }
  3.1553 +                            int lineNo = stNo + errNo - 1;
  3.1554 +                            msg = errObj.getErrorMsg();
  3.1555 +                            msg = getmodifiedErorrMsg(msg, lineNo);
  3.1556 +                            outList = new PlsqlOutputListener();
  3.1557 +                            outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1558 +                            outList.setLineNo(lineNo);
  3.1559 +                            outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1560 +                            io.getErr().println(msg, outList);
  3.1561 +                        }
  3.1562 +                        deploymentOk = false;
  3.1563 +                        break;
  3.1564 +                    }
  3.1565 +                }
  3.1566 +                if (exeObj.getType() != PlsqlExecutableObjectType.PACKAGEBODY) {
  3.1567 +                    continue;
  3.1568 +                }
  3.1569 +                try {
  3.1570 +                    stm.execute(plsqlText);
  3.1571 +                    io.getOut().println((new StringBuilder()).append("PL/SQL Package Body ").append(exeObjName).append(" Created Successfully").toString());
  3.1572 +                } catch (SQLException sqlEx) {
  3.1573 +                    exception = true;
  3.1574 +                    excMessage = sqlEx.getMessage();
  3.1575 +                }
  3.1576 +                errLst = getPackageerrors(exeObjName, "PACKAGE BODY");
  3.1577 +                if ((errLst.isEmpty()) && (!exception)) {
  3.1578 +                    continue;
  3.1579 +                } else if ((errLst.isEmpty()) && (exception)) {
  3.1580 +                    io.getErr().println((new StringBuilder()).append("!!!Package Body ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1581 +                    int errLine = getLineNumberFromMsg(excMessage);
  3.1582 +                    int outLine = lineNumber + errLine - 1;
  3.1583 +                    msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1584 +                    outList.setLineNo(outLine);
  3.1585 +                    io.getErr().println(msg, outList, true);
  3.1586 +                    deploymentOk = false;
  3.1587 +                    break;
  3.1588 +                } else {
  3.1589 +                    io.getErr().println((new StringBuilder()).append("!!!Package Body ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1590 +                    for (int a = 0; a < errLst.size(); a++) {
  3.1591 +                        PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.1592 +                        int stNo = exeObj.getStartLineNo();
  3.1593 +                        int errNo = errObj.getLineNumber();
  3.1594 +                        if (errNo <= 0) {
  3.1595 +                            errNo = 1;
  3.1596 +                        }
  3.1597 +                        int lineNo = stNo + errNo - 1;
  3.1598 +                        msg = errObj.getErrorMsg();
  3.1599 +                        msg = getmodifiedErorrMsg(msg, lineNo);
  3.1600 +                        outList = new PlsqlOutputListener();
  3.1601 +                        outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1602 +                        outList.setLineNo(lineNo);
  3.1603 +                        outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1604 +                        io.getErr().println(msg, outList, true);
  3.1605 +                        a++;
  3.1606 +                    }
  3.1607 +                    deploymentOk = false;
  3.1608 +                    break;
  3.1609 +                }
  3.1610              }
  3.1611 -            List errLst;
  3.1612 -            boolean exception = false;
  3.1613 -            String excMessage = "";
  3.1614 -            if (exeObj.getType() == PlsqlExecutableObjectType.PROCEDURE) {
  3.1615 -               try {
  3.1616 -                  stm.execute(plsqlText);
  3.1617 -                  io.getOut().println((new StringBuilder()).append("PL/SQL Procedure ").append(exeObjName).append(" Created Successfully").toString());
  3.1618 -               } catch (SQLException sqlEx) {
  3.1619 -                  exception = true;
  3.1620 -                  excMessage = sqlEx.getMessage();
  3.1621 -               }
  3.1622 -               errLst = getPackageerrors(exeObjName, "PROCEDURE");
  3.1623 -               if ((errLst.isEmpty()) && (!exception)) {
  3.1624 -                  continue;
  3.1625 -               } else if ((errLst.isEmpty()) && (exception)) {
  3.1626 -                  io.getErr().println((new StringBuilder()).append("!!!Procedure ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1627 -                  int errLine = getLineNumberFromMsg(excMessage);
  3.1628 -                  int outLine = lineNumber + errLine - 1;
  3.1629 -                  msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1630 -                  outList.setLineNo(outLine);
  3.1631 -                  io.getOut().println(plsqlText);
  3.1632 -                  io.getErr().println(msg, outList);
  3.1633 -                  deploymentOk = false;
  3.1634 -                  break;
  3.1635 -               } else {
  3.1636 -                  io.getErr().println((new StringBuilder()).append("!!!Procedure ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1637 -                  for (int a = 0; a < errLst.size(); a++) {
  3.1638 -                     PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.1639 -                     int stNo = exeObj.getStartLineNo();
  3.1640 -                     int errNo = errObj.getLineNumber();
  3.1641 -                     if (errNo <= 0) {
  3.1642 -                        errNo = 1;
  3.1643 -                     }
  3.1644 -                     int lineNo = stNo + errNo - 1;
  3.1645 -                     msg = errObj.getErrorMsg();
  3.1646 -                     msg = getmodifiedErorrMsg(msg, lineNo);
  3.1647 -                     outList = new PlsqlOutputListener();
  3.1648 -                     outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1649 -                     outList.setLineNo(lineNo);
  3.1650 -                     outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1651 -                     io.getErr().println(msg, outList);
  3.1652 -                  }
  3.1653 -                  deploymentOk = false;
  3.1654 -                  break;
  3.1655 -               }
  3.1656 +            
  3.1657 +            if (fileName.endsWith(".tdb") && !autoCommit) {
  3.1658 +                if (!deploymentOk && !commit && !(firstWord != null
  3.1659 +                        && (firstWord.equalsIgnoreCase("INSERT") || firstWord.equalsIgnoreCase("UPDATE") || firstWord.equalsIgnoreCase("DELETE")))) {
  3.1660 +                    con.commit();
  3.1661 +                }
  3.1662 +            } else {
  3.1663 +                con.commit();
  3.1664              }
  3.1665 -            if (exeObj.getType() == PlsqlExecutableObjectType.FUNCTION) {
  3.1666 -               try {
  3.1667 -                  stm.execute(plsqlText);
  3.1668 -                  io.getOut().println((new StringBuilder()).append("PL/SQL Function ").append(exeObjName).append(" Created Successfully").toString());
  3.1669 -               } catch (SQLException sqlEx) {
  3.1670 -                  exception = true;
  3.1671 -                  excMessage = sqlEx.getMessage();
  3.1672 -               }
  3.1673 -               errLst = getPackageerrors(exeObjName, "FUNCTION");
  3.1674 -               if ((errLst.isEmpty()) && (!exception)) {
  3.1675 -                  continue;
  3.1676 -               } else if ((errLst.isEmpty()) && (exception)) {
  3.1677 -                  io.getErr().println((new StringBuilder()).append("!!!Function ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1678 -                  int errLine = getLineNumberFromMsg(excMessage);
  3.1679 -                  int outLine = lineNumber + errLine - 1;
  3.1680 -                  msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1681 -                  outList.setLineNo(outLine);
  3.1682 -                  io.getOut().println(plsqlText);
  3.1683 -                  io.getErr().println(msg, outList);
  3.1684 -                  deploymentOk = false;
  3.1685 -                  break;
  3.1686 -               } else {
  3.1687 -                  io.getErr().println((new StringBuilder()).append("!!!Function ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1688 -                  for (int a = 0; a < errLst.size(); a++) {
  3.1689 -                     PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.1690 -                     int stNo = exeObj.getStartLineNo();
  3.1691 -                     int errNo = errObj.getLineNumber();
  3.1692 -                     if (errNo <= 0) {
  3.1693 -                        errNo = 1;
  3.1694 -                     }
  3.1695 -                     int lineNo = stNo + errNo - 1;
  3.1696 -                     msg = errObj.getErrorMsg();
  3.1697 -                     msg = getmodifiedErorrMsg(msg, lineNo);
  3.1698 -                     outList = new PlsqlOutputListener();
  3.1699 -                     outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1700 -                     outList.setLineNo(lineNo);
  3.1701 -                     outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1702 -                     io.getErr().println(msg, outList);
  3.1703 -                  }
  3.1704 -                  deploymentOk = false;
  3.1705 -                  break;
  3.1706 -               }
  3.1707 +            
  3.1708 +            if (!moreRowsToBeFetched) {
  3.1709 +                long endTime = System.currentTimeMillis();
  3.1710 +                long duration = endTime - startTime;
  3.1711 +                String totalTime = Long.toString(duration / 1000);
  3.1712 +                if (duration < 10000) {
  3.1713 +                    totalTime += "." + Long.toString((duration % 1000) / 100);
  3.1714 +                }
  3.1715 +                if (preparedIO == null) {
  3.1716 +                    io.getOut().println("-------------------------------------------------------------");
  3.1717 +                    io.getOut().println(endMsg + " (Total times: " + totalTime + "s)");
  3.1718 +                    io.getOut().println(new Timestamp(endTime).toString());
  3.1719 +                }
  3.1720              }
  3.1721 -            if (exeObj.getType() == PlsqlExecutableObjectType.PACKAGE) {
  3.1722 -               try {
  3.1723 -                  stm.execute(plsqlText);
  3.1724 -                  io.getOut().println((new StringBuilder()).append("PL/SQL Package ").append(exeObjName).append(" Created Successfully").toString());
  3.1725 -               } catch (SQLException sqlEx) {
  3.1726 -                  exception = true;
  3.1727 -                  excMessage = sqlEx.getMessage();
  3.1728 -               }
  3.1729 -               errLst = getPackageerrors(exeObjName, "PACKAGE");
  3.1730 -               if ((errLst.isEmpty()) && (!exception)) {
  3.1731 -                  continue;
  3.1732 -               } else if ((errLst.isEmpty()) && (exception)) {
  3.1733 -                  io.getErr().println((new StringBuilder()).append("!!!Package ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1734 -                  int errLine = getLineNumberFromMsg(excMessage);
  3.1735 -                  int outLine = lineNumber + errLine - 1;
  3.1736 -                  msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1737 -                  outList.setLineNo(outLine);
  3.1738 -                  io.getErr().println(msg, outList);
  3.1739 -                  deploymentOk = false;
  3.1740 -                  break;
  3.1741 -               } else {
  3.1742 -                  io.getErr().println((new StringBuilder()).append("!!!Package ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1743 -                  for (int a = 0; a < errLst.size(); a++) {
  3.1744 -                     PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.1745 -                     int stNo = exeObj.getStartLineNo();
  3.1746 -                     int errNo = errObj.getLineNumber();
  3.1747 -                     if (errNo <= 0) {
  3.1748 -                        errNo = 1;
  3.1749 -                     }
  3.1750 -                     int lineNo = stNo + errNo - 1;
  3.1751 -                     msg = errObj.getErrorMsg();
  3.1752 -                     msg = getmodifiedErorrMsg(msg, lineNo);
  3.1753 -                     outList = new PlsqlOutputListener();
  3.1754 -                     outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.1755 -                     outList.setLineNo(lineNo);
  3.1756 -                     outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.1757 -                     io.getErr().println(msg, outList);
  3.1758 -                  }
  3.1759 -                  deploymentOk = false;
  3.1760 -                  break;
  3.1761 -               }
  3.1762 +        } catch (IOException e) {
  3.1763 +            JOptionPane.showMessageDialog(null, "CONNECTION CREATION PROBLEM");
  3.1764 +            deploymentOk = false;
  3.1765 +        } catch (SQLException ex) {
  3.1766 +            JOptionPane.showMessageDialog(null, "CONNECTION CREATION PROBLEM");
  3.1767 +            deploymentOk = false;
  3.1768 +        } finally {
  3.1769 +            if (stm != null) {
  3.1770 +                try {
  3.1771 +                    stm.close();
  3.1772 +                } catch (SQLException ex) {
  3.1773 +                    throw new RuntimeException(ex);
  3.1774 +                }
  3.1775              }
  3.1776 -            if (exeObj.getType() != PlsqlExecutableObjectType.PACKAGEBODY) {
  3.1777 -               continue;
  3.1778 +            if (io != null) {
  3.1779 +                io.getOut().close();
  3.1780 +                io.getErr().close();
  3.1781 +                // IOPosition.currentPosition(io).scrollTo();
  3.1782              }
  3.1783 +        }
  3.1784 +        return deploymentOk ? null : io;
  3.1785 +    }
  3.1786 +    
  3.1787 +    public String getmodifiedErorrMsg(String msg, int lineNumber) {
  3.1788 +        int index = msg.indexOf("\n");
  3.1789 +        if (index >= 0) {
  3.1790 +            msg = msg.replaceAll("\n", "");
  3.1791 +        }
  3.1792 +        msg = (new StringBuilder()).append(msg).append(" error at line no :").append(lineNumber).toString();
  3.1793 +        return msg;
  3.1794 +    }
  3.1795 +    
  3.1796 +    private List getPackageerrors(String packageName, String packageType) {
  3.1797 +        List<PlsqlErrorObject> lst = new ArrayList<PlsqlErrorObject>();
  3.1798 +        Connection con = debugConnection != null ? debugConnection : connection.getJDBCConnection();
  3.1799 +        if (con != null) {
  3.1800 +            Statement stm = null;
  3.1801              try {
  3.1802 -               stm.execute(plsqlText);
  3.1803 -               io.getOut().println((new StringBuilder()).append("PL/SQL Package Body ").append(exeObjName).append(" Created Successfully").toString());
  3.1804 -            } catch (SQLException sqlEx) {
  3.1805 -               exception = true;
  3.1806 -               excMessage = sqlEx.getMessage();
  3.1807 +                stm = con.createStatement();
  3.1808 +                String query = (new StringBuilder()).append("SELECT LINE, POSITION, TEXT FROM USER_ERRORS WHERE TYPE = '").append(packageType).append("' AND NAME = '").append(packageName).append("'").toString();
  3.1809 +                PlsqlErrorObject errObj;
  3.1810 +                for (ResultSet rs = stm.executeQuery(query); rs.next();) {
  3.1811 +                    int lineNo = rs.getInt("LINE");
  3.1812 +                    int pos = rs.getInt("POSITION");
  3.1813 +                    String msg = rs.getString("TEXT");
  3.1814 +                    errObj = new PlsqlErrorObject();
  3.1815 +                    errObj.setLineNumber(lineNo);
  3.1816 +                    errObj.setPosition(pos);
  3.1817 +                    errObj.setErrorMsg(msg);
  3.1818 +                    lst.add(errObj);
  3.1819 +                }
  3.1820 +            } catch (SQLException e) {
  3.1821 +            } finally {
  3.1822 +                try {
  3.1823 +                    if (stm != null) {
  3.1824 +                        stm.close();
  3.1825 +                    }
  3.1826 +                } catch (SQLException ex) {
  3.1827 +                    throw new RuntimeException(ex);
  3.1828 +                }
  3.1829              }
  3.1830 -            errLst = getPackageerrors(exeObjName, "PACKAGE BODY");
  3.1831 -            if ((errLst.isEmpty()) && (!exception)) {
  3.1832 -               continue;
  3.1833 -            } else if ((errLst.isEmpty()) && (exception)) {
  3.1834 -               io.getErr().println((new StringBuilder()).append("!!!Package Body ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.1835 -               int errLine = getLineNumberFromMsg(excMessage);
  3.1836 -               int outLine = lineNumber + errLine - 1;
  3.1837 -               msg = getmodifiedErorrMsg(excMessage, outLine);
  3.1838 -               outList.setLineNo(outLine);
  3.1839 -               io.getErr().println(msg, outList, true);
  3.1840 -               deploymentOk = false;
  3.1841 -               break;
  3.1842 +        } else {
  3.1843 +            throw new RuntimeException("Not Connected to Database to Get USER_ERRORS");
  3.1844 +        }
  3.1845 +        return lst;
  3.1846 +    }
  3.1847 +
  3.1848 +    /**
  3.1849 +     * Method that will return the error line number in the given SQL error message
  3.1850 +     * @param message
  3.1851 +     * @return
  3.1852 +     */
  3.1853 +    private int getLineNumberFromMsg(String message) {
  3.1854 +        int indexLine = message.lastIndexOf(" line ");
  3.1855 +        if (indexLine >= 0) {
  3.1856 +            try {
  3.1857 +                return Integer.parseInt(message.substring(indexLine + 6).trim());
  3.1858 +            } catch (NumberFormatException ex) {
  3.1859 +                return -1;
  3.1860 +            }
  3.1861 +        }
  3.1862 +        return -1;
  3.1863 +    }
  3.1864 +
  3.1865 +    /**
  3.1866 +     * Method that will parse the document and initialize the aliases
  3.1867 +     * @param definesMap
  3.1868 +     * @param doc
  3.1869 +     * @param start
  3.1870 +     * @param end
  3.1871 +     * @param define
  3.1872 +     * @param io
  3.1873 +     * @return
  3.1874 +     */
  3.1875 +    private char getAliases(HashMap<String, String> definesMap, Document doc, int start, int end, char define, InputOutput io) {
  3.1876 +        TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
  3.1877 +        @SuppressWarnings("unchecked")
  3.1878 +        TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
  3.1879 +        ts.move(start);
  3.1880 +        boolean moveNext = ts.moveNext();
  3.1881 +        
  3.1882 +        Token<PlsqlTokenId> token = ts.token();
  3.1883 +
  3.1884 +        //Get the difine by the name
  3.1885 +        while (moveNext) {
  3.1886 +            
  3.1887 +            if (token.offset(tokenHierarchy) >= end) {
  3.1888 +                break;         //Check whether this is DEFINE
  3.1889 +
  3.1890 +            }
  3.1891 +            //Check whether this is DEFINE
  3.1892 +            PlsqlTokenId tokenId = token.id();
  3.1893 +            if (tokenId == PlsqlTokenId.SQL_PLUS) {
  3.1894 +                String tokenTxt = FileExecutionUtil.readLine(ts, token);
  3.1895 +                if ((tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEF "))
  3.1896 +                        || (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEFI "))
  3.1897 +                        || (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEFIN "))
  3.1898 +                        || (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEFINE "))) {
  3.1899 +                    if (!tokenTxt.contains(" = ") && tokenTxt.contains("=")) {
  3.1900 +                        tokenTxt = tokenTxt.substring(0, tokenTxt.indexOf("=")) + " = " + tokenTxt.substring(tokenTxt.indexOf("=") + 1);
  3.1901 +                    }
  3.1902 +                    
  3.1903 +                    StringTokenizer tokenizer = new StringTokenizer(tokenTxt);
  3.1904 +                    tokenizer.nextToken();
  3.1905 +                    String alias;
  3.1906 +                    String value = "";
  3.1907 +                    boolean isNext = tokenizer.hasMoreTokens();
  3.1908 +
  3.1909 +                    //alias
  3.1910 +                    if (isNext) {
  3.1911 +                        alias = tokenizer.nextToken();
  3.1912 +                    } else {
  3.1913 +                        break;
  3.1914 +                    }
  3.1915 +                    
  3.1916 +                    isNext = tokenizer.hasMoreTokens();
  3.1917 +                    
  3.1918 +                    if ((isNext) && (tokenizer.nextToken().equals("="))) {
  3.1919 +                        boolean isComment = false;
  3.1920 +                        while (tokenizer.hasMoreTokens() && !isComment) {
  3.1921 +                            String temp = tokenizer.nextToken();
  3.1922 +                            if (temp.startsWith("--") || temp.startsWith("/*")) {
  3.1923 +                                isComment = true;
  3.1924 +                            } else {
  3.1925 +                                value = value + " " + temp;
  3.1926 +                            }
  3.1927 +                        }
  3.1928 +                        
  3.1929 +                        value = value.trim();
  3.1930 +                        
  3.1931 +                        if ((value.startsWith("\"") && value.endsWith("\""))
  3.1932 +                                || (value.startsWith("\'") && value.endsWith("\'"))) {
  3.1933 +                            value = value.substring(1, value.length() - 1);
  3.1934 +                        }
  3.1935 +                        
  3.1936 +                        if (value.indexOf(define) >= 0) {
  3.1937 +                            value = replaceAliases(value, definesMap, define, io);
  3.1938 +                        }
  3.1939 +                        definesMap.put(alias.toUpperCase(Locale.ENGLISH), value);
  3.1940 +                    }
  3.1941 +                } else if (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("SET ")) {
  3.1942 +                    StringTokenizer tokenizer = new StringTokenizer(tokenTxt);
  3.1943 +                    tokenizer.nextToken();
  3.1944 +                    String alias;
  3.1945 +                    boolean isNext = tokenizer.hasMoreTokens();
  3.1946 +                    tokenizer.nextToken();
  3.1947 +                    isNext = tokenizer.hasMoreTokens();
  3.1948 +                    //alias
  3.1949 +                    if (isNext) {
  3.1950 +                        alias = tokenizer.nextToken();
  3.1951 +                    } else {
  3.1952 +                        break;
  3.1953 +                    }
  3.1954 +                    
  3.1955 +                    if (alias.length() == 1) {
  3.1956 +                        define = alias.charAt(0); //If define changed we catch it here
  3.1957 +                    }
  3.1958 +                }
  3.1959 +            }
  3.1960 +            moveNext = ts.moveNext();
  3.1961 +            token = ts.token();
  3.1962 +        }
  3.1963 +        
  3.1964 +        return define;
  3.1965 +    }
  3.1966 +
  3.1967 +    /**
  3.1968 +     * Replace aliases in the given string
  3.1969 +     * @param plsqlString
  3.1970 +     * @param definesMap
  3.1971 +     * @param define
  3.1972 +     * @param io
  3.1973 +     * @return
  3.1974 +     */
  3.1975 +    public String replaceAliases(String plsqlString, HashMap<String, String> definesMap, char define, InputOutput io) {
  3.1976 +        if (plsqlString.indexOf(define) < 0) {
  3.1977 +            return plsqlString;
  3.1978 +        }
  3.1979 +        
  3.1980 +        StringBuilder newString = new StringBuilder();
  3.1981 +        for (int i = 0; i < plsqlString.length(); i++) {
  3.1982 +            char c = plsqlString.charAt(i);
  3.1983 +            if (c == define) {
  3.1984 +                for (int j = i + 1; j < plsqlString.length(); j++) {
  3.1985 +                    char nextChar = plsqlString.charAt(j);
  3.1986 +                    if (Character.isJavaIdentifierPart(nextChar) && j == plsqlString.length() - 1) { //we have reached the end of the text
  3.1987 +
  3.1988 +                        nextChar = '.'; //this will make sure that the correct sustitution is made below by emulating an additional character
  3.1989 +
  3.1990 +                        j = j + 1;
  3.1991 +                    }
  3.1992 +                    if (!Character.isJavaIdentifierPart(nextChar)) { //potential end of substitutionvariable
  3.1993 +
  3.1994 +                        if (j > i + 1) { //substituion variable found
  3.1995 +
  3.1996 +                            String name = plsqlString.substring(i + 1, j);
  3.1997 +                            String value = definesMap.get(name.toUpperCase(Locale.ENGLISH));
  3.1998 +                            if (value == null || value.startsWith(Character.toString(define))) {
  3.1999 +                                PromptDialog prompt = new PromptDialog(null, name, true);
  3.2000 +                                prompt.setVisible(true);
  3.2001 +                                value = prompt.getValue();
  3.2002 +                                definesMap.put(name.toUpperCase(Locale.ENGLISH), value);
  3.2003 +                                if (io != null) {
  3.2004 +                                    io.getOut().println((new StringBuilder()).append("> Variable ").append(name).append(" = \"").append(value).append("\"").toString());
  3.2005 +                                }
  3.2006 +                            }
  3.2007 +                            value = replaceAliases(value, definesMap, define, io);
  3.2008 +                            newString.append(value);
  3.2009 +                            if (nextChar == '.') {
  3.2010 +                                i = j;
  3.2011 +                            } else {
  3.2012 +                                i = j - 1;
  3.2013 +                            }
  3.2014 +                        } else {
  3.2015 +                            newString.append(c);
  3.2016 +                        }
  3.2017 +                        break;
  3.2018 +                    }
  3.2019 +                }
  3.2020              } else {
  3.2021 -               io.getErr().println((new StringBuilder()).append("!!!Package Body ").append(exeObjName).append(" Created With Compilation Errors").toString());
  3.2022 -               for (int a = 0; a < errLst.size(); a++) {
  3.2023 -                  PlsqlErrorObject errObj = (PlsqlErrorObject) errLst.get(a);
  3.2024 -                  int stNo = exeObj.getStartLineNo();
  3.2025 -                  int errNo = errObj.getLineNumber();
  3.2026 -                  if (errNo <= 0) {
  3.2027 -                     errNo = 1;
  3.2028 -                  }
  3.2029 -                  int lineNo = stNo + errNo - 1;
  3.2030 -                  msg = errObj.getErrorMsg();
  3.2031 -                  msg = getmodifiedErorrMsg(msg, lineNo);
  3.2032 -                  outList = new PlsqlOutputListener();
  3.2033 -                  outList.setDocLinesArray(exeObj.getDocLinesArray());
  3.2034 -                  outList.setLineNo(lineNo);
  3.2035 -                  outList.setOriginalFileName(exeObj.getOriginalFileName());
  3.2036 -                  io.getErr().println(msg, outList, true);
  3.2037 -                  a++;
  3.2038 -               }
  3.2039 -               deploymentOk = false;
  3.2040 -               break;
  3.2041 +                newString.append(c);
  3.2042              }
  3.2043 -         }
  3.2044 +        }
  3.2045 +        return newString.toString();
  3.2046 +    }
  3.2047 +    
  3.2048 +    private void setExecutionResults(SQLExecutionResults executionResults) {
  3.2049 +        this.executionResults = executionResults;
  3.2050 +    }
  3.2051 +    
  3.2052 +    private void setResultsToEditors(final SQLExecutionResults results, final DataObject obj, final String label) {
  3.2053 +        if (results != null) {
  3.2054 +            final List<Component> components = new ArrayList<Component>();
  3.2055 +            final List<String> toolTips = new ArrayList<String>();
  3.2056 +            
  3.2057 +            try {
  3.2058 +                SwingUtilities.invokeAndWait(new Runnable() {
  3.2059 +                    
  3.2060 +                    @Override
  3.2061 +                    public void run() {
  3.2062 +                        for (SQLExecutionResult result : results.getResults()) {
  3.2063 +                            for (Component component : result.getDataView().createComponents()) {
  3.2064 +                                if (label != null) {
  3.2065 +                                    component.setName(label);
  3.2066 +                                }
  3.2067 +                                components.add(component);
  3.2068 +                                toolTips.add("<html>" + result.getStatementInfo().getSQL().replaceAll("\n", "<br>"));
  3.2069 +                            }
  3.2070 +                        }
  3.2071 +                        
  3.2072 +                        if (plsqlEditor != null) {
  3.2073 +                            plsqlEditor.setResults(components, toolTips);
  3.2074 +                        }
  3.2075 +                    }
  3.2076 +                });
  3.2077 +            } catch (InterruptedException ex) {
  3.2078 +                Exceptions.printStackTrace(ex);
  3.2079 +            } catch (InvocationTargetException ex) {
  3.2080 +                Exceptions.printStackTrace(ex);
  3.2081 +            }
  3.2082 +            
  3.2083 +        }
  3.2084 +    }
  3.2085 +    
  3.2086 +    public PlsqlEditor getPlsqlEditor(DataObject dataObj) {
  3.2087 +        //Get all the data objects and save dataObjects that require auto Save
  3.2088 +        TopComponent.Registry registry = TopComponent.getRegistry();
  3.2089 +        Object[] topComponentSet = registry.getOpened().toArray();
  3.2090 +        for (int i = 0; i < topComponentSet.length; i++) {
  3.2091 +            TopComponent component = (TopComponent) topComponentSet[i];
  3.2092 +            if (component instanceof PlsqlEditor) {
  3.2093 +                PlsqlEditor editor = (PlsqlEditor) component;
  3.2094 +                DataObject obj = editor.getLookup().lookup(DataObject.class);
  3.2095 +                if (obj != null && dataObj != null && obj == dataObj) {
  3.2096 +                    return editor;
  3.2097 +                }
  3.2098 +            }
  3.2099 +        }
  3.2100 +        
  3.2101 +        return null;
  3.2102 +    }
  3.2103 +    
  3.2104 +    private void closeExecutionResult() {
  3.2105 +        if (executionResults != null) {
  3.2106 +            executionResults = null;
  3.2107 +        }
  3.2108 +    }
  3.2109 +    
  3.2110 +    private final class SQLExecutor implements Runnable, Cancellable {
  3.2111 +        
  3.2112 +        private static final int DEFAULT_PAGE_SIZE = 100;
  3.2113 +        private FileObject USERDIR = FileUtil.getConfigRoot();
  3.2114 +        private final DatabaseConnection dbconn;
  3.2115 +        private final String sqlStmt;
  3.2116 +        private String label;
  3.2117 +        private RequestProcessor.Task task;
  3.2118 +        private DataObject parent;
  3.2119 +        
  3.2120 +        public SQLExecutor(DataObject dataObj, DatabaseConnection dbconn, String sqlStmt, String label) {
  3.2121 +            this.dbconn = dbconn;
  3.2122 +            this.sqlStmt = sqlStmt + ";";
  3.2123 +            this.parent = dataObj;
  3.2124 +            this.label = label;
  3.2125 +        }
  3.2126 +        
  3.2127 +        public void setTask(RequestProcessor.Task task) {
  3.2128 +            this.task = task;
  3.2129 +        }
  3.2130 +        
  3.2131 +        @Override
  3.2132 +        public void run() {
  3.2133 +            assert task != null : "Should have called setTask()"; // NOI18N
  3.2134  
  3.2135 -         if (fileName.endsWith(".tdb") && !autoCommit) {
  3.2136 -            if (!deploymentOk && !commit && !(firstWord != null
  3.2137 -                    && (firstWord.equalsIgnoreCase("INSERT") || firstWord.equalsIgnoreCase("UPDATE") || firstWord.equalsIgnoreCase("DELETE")))) {
  3.2138 -               con.commit();
  3.2139 +            ProgressHandle handle = ProgressHandleFactory.createHandle("Executing Statements");
  3.2140 +            handle.start();
  3.2141 +            try {
  3.2142 +                handle.switchToIndeterminate();
  3.2143 +                //closeExecutionResult();
  3.2144 +                SQLExecutionResults executionResults = execute(sqlStmt, 0, sqlStmt.length() - 1, dbconn);
  3.2145 +                handleExecutionResults(executionResults);
  3.2146 +            } finally {
  3.2147 +                handle.finish();
  3.2148              }
  3.2149 -         } else {
  3.2150 -            con.commit();
  3.2151 -         }
  3.2152 +        }
  3.2153  
  3.2154 -         if (!moreRowsToBeFetched) {
  3.2155 -            long endTime = System.currentTimeMillis();
  3.2156 -            long duration = endTime - startTime;
  3.2157 -            String totalTime = Long.toString(duration / 1000);
  3.2158 -            if (duration < 10000) {
  3.2159 -               totalTime += "." + Long.toString((duration % 1000) / 100);
  3.2160 -            }
  3.2161 -            if (preparedIO == null) {
  3.2162 -               io.getOut().println("-------------------------------------------------------------");
  3.2163 -               io.getOut().println(endMsg + " (Total times: " + totalTime + "s)");
  3.2164 -               io.getOut().println(new Timestamp(endTime).toString());
  3.2165 -            }
  3.2166 -         }
  3.2167 -      } catch (IOException e) {
  3.2168 -         JOptionPane.showMessageDialog(null, "CONNECTION CREATION PROBLEM");
  3.2169 -         deploymentOk = false;
  3.2170 -      } catch (SQLException ex) {
  3.2171 -         JOptionPane.showMessageDialog(null, "CONNECTION CREATION PROBLEM");
  3.2172 -         deploymentOk = false;
  3.2173 -      } finally {
  3.2174 -         if (stm != null) {
  3.2175 -            try {
  3.2176 -               stm.close();
  3.2177 -            } catch (SQLException ex) {
  3.2178 -               throw new RuntimeException(ex);
  3.2179 -            }
  3.2180 -         }
  3.2181 -         if (io != null) {
  3.2182 -            io.getOut().close();
  3.2183 -            io.getErr().close();
  3.2184 -            // IOPosition.currentPosition(io).scrollTo();
  3.2185 -         }
  3.2186 -      }
  3.2187 -      return deploymentOk ? null : io;
  3.2188 -   }
  3.2189 +        /**
  3.2190 +         * Execute the sql
  3.2191 +         * @param sql
  3.2192 +         * @param i
  3.2193 +         * @param i0
  3.2194 +         * @param databaseConenction
  3.2195 +         * @return
  3.2196 +         */
  3.2197 +        private SQLExecutionResults execute(String sqlScript, int startOffset, int endOffset,
  3.2198 +                DatabaseConnection conn) {
  3.2199 +            boolean cancelled = false;
  3.2200 +            List<StatementInfo> statements = getStatements(sqlScript, startOffset, endOffset);
  3.2201 +            List<SQLExecutionResult> results = new ArrayList<SQLExecutionResult>();
  3.2202 +            String url = conn.getDatabaseURL();
  3.2203 +            
  3.2204 +            for (Iterator i = statements.iterator(); i.hasNext();) {
  3.2205 +                cancelled = Thread.currentThread().isInterrupted();
  3.2206 +                if (cancelled) {
  3.2207 +                    break;
  3.2208 +                }
  3.2209 +                
  3.2210 +                StatementInfo info = (StatementInfo) i.next();
  3.2211 +                String sql = info.getSQL();
  3.2212 +                
  3.2213 +                SQLExecutionResult result = null;
  3.2214 +                DataView view = DataView.create(conn, sql, DEFAULT_PAGE_SIZE);
  3.2215  
  3.2216 -   public String getmodifiedErorrMsg(String msg, int lineNumber) {
  3.2217 -      int index = msg.indexOf("\n");
  3.2218 -      if (index >= 0) {
  3.2219 -         msg = msg.replaceAll("\n", "");
  3.2220 -      }
  3.2221 -      msg = (new StringBuilder()).append(msg).append(" error at line no :").append(lineNumber).toString();
  3.2222 -      return msg;
  3.2223 -   }
  3.2224 -
  3.2225 -   private List getPackageerrors(String packageName, String packageType) {
  3.2226 -      List<PlsqlErrorObject> lst = new ArrayList<PlsqlErrorObject>();
  3.2227 -      Connection con = debugConnection != null ? debugConnection : connection.getJDBCConnection();
  3.2228 -      if (con != null) {
  3.2229 -         Statement stm = null;
  3.2230 -         try {
  3.2231 -            stm = con.createStatement();
  3.2232 -            String query = (new StringBuilder()).append("SELECT LINE, POSITION, TEXT FROM USER_ERRORS WHERE TYPE = '").append(packageType).append("' AND NAME = '").append(packageName).append("'").toString();
  3.2233 -            PlsqlErrorObject errObj;
  3.2234 -            for (ResultSet rs = stm.executeQuery(query); rs.next();) {
  3.2235 -               int lineNo = rs.getInt("LINE");
  3.2236 -               int pos = rs.getInt("POSITION");
  3.2237 -               String msg = rs.getString("TEXT");
  3.2238 -               errObj = new PlsqlErrorObject();
  3.2239 -               errObj.setLineNumber(lineNo);
  3.2240 -               errObj.setPosition(pos);
  3.2241 -               errObj.setErrorMsg(msg);
  3.2242 -               lst.add(errObj);
  3.2243 -            }
  3.2244 -         } catch (SQLException e) {
  3.2245 -         } finally {
  3.2246 -            try {
  3.2247 -               if (stm != null) {
  3.2248 -                  stm.close();
  3.2249 -               }
  3.2250 -            } catch (SQLException ex) {
  3.2251 -               throw new RuntimeException(ex);
  3.2252 -            }
  3.2253 -         }
  3.2254 -      } else {
  3.2255 -         throw new RuntimeException("Not Connected to Database to Get USER_ERRORS");
  3.2256 -      }
  3.2257 -      return lst;
  3.2258 -   }
  3.2259 -
  3.2260 -   /**
  3.2261 -    * Method that will return the error line number in the given SQL error message
  3.2262 -    * @param message
  3.2263 -    * @return
  3.2264 -    */
  3.2265 -   private int getLineNumberFromMsg(String message) {
  3.2266 -      int indexLine = message.lastIndexOf(" line ");
  3.2267 -      if (indexLine >= 0) {
  3.2268 -         try {
  3.2269 -            return Integer.parseInt(message.substring(indexLine + 6).trim());
  3.2270 -         } catch (NumberFormatException ex) {
  3.2271 -            return -1;
  3.2272 -         }
  3.2273 -      }
  3.2274 -      return -1;
  3.2275 -   }
  3.2276 -
  3.2277 -   /**
  3.2278 -    * Method that will parse the document and initialize the aliases
  3.2279 -    * @param definesMap
  3.2280 -    * @param doc
  3.2281 -    * @param start
  3.2282 -    * @param end
  3.2283 -    * @param define
  3.2284 -    * @param io
  3.2285 -    * @return
  3.2286 -    */
  3.2287 -   private char getAliases(HashMap<String, String> definesMap, Document doc, int start, int end, char define, InputOutput io) {
  3.2288 -      TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
  3.2289 -      @SuppressWarnings("unchecked")
  3.2290 -      TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
  3.2291 -      ts.move(start);
  3.2292 -      boolean moveNext = ts.moveNext();
  3.2293 -
  3.2294 -      Token<PlsqlTokenId> token = ts.token();
  3.2295 -
  3.2296 -      //Get the difine by the name
  3.2297 -      while (moveNext) {
  3.2298 -
  3.2299 -         if (token.offset(tokenHierarchy) >= end) {
  3.2300 -            break;         //Check whether this is DEFINE
  3.2301 -
  3.2302 -         }
  3.2303 -         //Check whether this is DEFINE
  3.2304 -         PlsqlTokenId tokenId = token.id();
  3.2305 -         if (tokenId == PlsqlTokenId.SQL_PLUS) {
  3.2306 -            String tokenTxt = FileExecutionUtil.readLine(ts, token);
  3.2307 -            if ((tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEF "))
  3.2308 -                    || (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEFI "))
  3.2309 -                    || (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEFIN "))
  3.2310 -                    || (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("DEFINE "))) {
  3.2311 -               if (!tokenTxt.contains(" = ") && tokenTxt.contains("=")) {
  3.2312 -                  tokenTxt = tokenTxt.substring(0, tokenTxt.indexOf("=")) + " = " + tokenTxt.substring(tokenTxt.indexOf("=") + 1);
  3.2313 -               }
  3.2314 -
  3.2315 -               StringTokenizer tokenizer = new StringTokenizer(tokenTxt);
  3.2316 -               tokenizer.nextToken();
  3.2317 -               String alias;
  3.2318 -               String value = "";
  3.2319 -               boolean isNext = tokenizer.hasMoreTokens();
  3.2320 -
  3.2321 -               //alias
  3.2322 -               if (isNext) {
  3.2323 -                  alias = tokenizer.nextToken();
  3.2324 -               } else {
  3.2325 -                  break;
  3.2326 -               }
  3.2327 -
  3.2328 -               isNext = tokenizer.hasMoreTokens();
  3.2329 -
  3.2330 -               if ((isNext) && (tokenizer.nextToken().equals("="))) {
  3.2331 -                  boolean isComment = false;
  3.2332 -                  while (tokenizer.hasMoreTokens() && !isComment) {
  3.2333 -                     String temp = tokenizer.nextToken();
  3.2334 -                     if (temp.startsWith("--") || temp.startsWith("/*")) {
  3.2335 -                        isComment = true;
  3.2336 -                     } else {
  3.2337 -                        value = value + " " + temp;
  3.2338 -                     }
  3.2339 -                  }
  3.2340 -
  3.2341 -                  value = value.trim();
  3.2342 -
  3.2343 -                  if ((value.startsWith("\"") && value.endsWith("\""))
  3.2344 -                          || (value.startsWith("\'") && value.endsWith("\'"))) {
  3.2345 -                     value = value.substring(1, value.length() - 1);
  3.2346 -                  }
  3.2347 -
  3.2348 -                  if (value.indexOf(define) >= 0) {
  3.2349 -                     value = replaceAliases(value, definesMap, define, io);
  3.2350 -                  }
  3.2351 -                  definesMap.put(alias.toUpperCase(Locale.ENGLISH), value);
  3.2352 -               }
  3.2353 -            } else if (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("SET ")) {
  3.2354 -               StringTokenizer tokenizer = new StringTokenizer(tokenTxt);
  3.2355 -               tokenizer.nextToken();
  3.2356 -               String alias;
  3.2357 -               boolean isNext = tokenizer.hasMoreTokens();
  3.2358 -               tokenizer.nextToken();
  3.2359 -               isNext = tokenizer.hasMoreTokens();
  3.2360 -               //alias
  3.2361 -               if (isNext) {
  3.2362 -                  alias = tokenizer.nextToken();
  3.2363 -               } else {
  3.2364 -                  break;
  3.2365 -               }
  3.2366 -
  3.2367 -               if (alias.length() == 1) {
  3.2368 -                  define = alias.charAt(0); //If define changed we catch it here
  3.2369 -               }
  3.2370 -            }
  3.2371 -         }
  3.2372 -         moveNext = ts.moveNext();
  3.2373 -         token = ts.token();
  3.2374 -      }
  3.2375 -
  3.2376 -      return define;
  3.2377 -   }
  3.2378 -
  3.2379 -   /**
  3.2380 -    * Replace aliases in the given string
  3.2381 -    * @param plsqlString
  3.2382 -    * @param definesMap
  3.2383 -    * @param define
  3.2384 -    * @param io
  3.2385 -    * @return
  3.2386 -    */
  3.2387 -   public String replaceAliases(String plsqlString, HashMap<String, String> definesMap, char define, InputOutput io) {
  3.2388 -      if (plsqlString.indexOf(define) < 0) {
  3.2389 -         return plsqlString;
  3.2390 -      }
  3.2391 -
  3.2392 -      StringBuilder newString = new StringBuilder();
  3.2393 -      for (int i = 0; i < plsqlString.length(); i++) {
  3.2394 -         char c = plsqlString.charAt(i);
  3.2395 -         if (c == define) {
  3.2396 -            for (int j = i + 1; j < plsqlString.length(); j++) {
  3.2397 -               char nextChar = plsqlString.charAt(j);
  3.2398 -               if (Character.isJavaIdentifierPart(nextChar) && j == plsqlString.length() - 1) { //we have reached the end of the text
  3.2399 -
  3.2400 -                  nextChar = '.'; //this will make sure that the correct sustitution is made below by emulating an additional character
  3.2401 -
  3.2402 -                  j = j + 1;
  3.2403 -               }
  3.2404 -               if (!Character.isJavaIdentifierPart(nextChar)) { //potential end of substitutionvariable
  3.2405 -
  3.2406 -                  if (j > i + 1) { //substituion variable found
  3.2407 -
  3.2408 -                     String name = plsqlString.substring(i + 1, j);
  3.2409 -                     String value = definesMap.get(name.toUpperCase(Locale.ENGLISH));
  3.2410 -                     if (value == null || value.startsWith(Character.toString(define))) {
  3.2411 -                        PromptDialog prompt = new PromptDialog(null, name, true);
  3.2412 -                        prompt.setVisible(true);
  3.2413 -                        value = prompt.getValue();
  3.2414 -                        definesMap.put(name.toUpperCase(Locale.ENGLISH), value);
  3.2415 -                        if (io != null) {
  3.2416 -                           io.getOut().println((new StringBuilder()).append("> Variable ").append(name).append(" = \"").append(value).append("\"").toString());
  3.2417 -                        }
  3.2418 -                     }
  3.2419 -                     value = replaceAliases(value, definesMap, define, io);
  3.2420 -                     newString.append(value);
  3.2421 -                     if (nextChar == '.') {
  3.2422 -                        i = j;
  3.2423 -                     } else {
  3.2424 -                        i = j - 1;
  3.2425 -                     }
  3.2426 -                  } else {
  3.2427 -                     newString.append(c);
  3.2428 -                  }
  3.2429 -                  break;
  3.2430 -               }
  3.2431 -            }
  3.2432 -         } else {
  3.2433 -            newString.append(c);
  3.2434 -         }
  3.2435 -      }
  3.2436 -      return newString.toString();
  3.2437 -   }
  3.2438 -
  3.2439 -   private void setExecutionResults(SQLExecutionResults executionResults) {
  3.2440 -      this.executionResults = executionResults;
  3.2441 -   }
  3.2442 -
  3.2443 -   private void setResultsToEditors(final SQLExecutionResults results, final DataObject obj, final String label) {
  3.2444 -      if (results != null) {
  3.2445 -         final List<Component> components = new ArrayList<Component>();
  3.2446 -         final List<String> toolTips = new ArrayList<String>();
  3.2447 -
  3.2448 -         try {
  3.2449 -            SwingUtilities.invokeAndWait(new Runnable() {
  3.2450 -
  3.2451 -               @Override
  3.2452 -               public void run() {
  3.2453 -                  for (SQLExecutionResult result : results.getResults()) {
  3.2454 -                     for (Component component : result.getDataView().createComponents()) {
  3.2455 -                        if (label != null) {
  3.2456 -                           component.setName(label);
  3.2457 -                        }
  3.2458 -                        components.add(component);
  3.2459 -                        toolTips.add("<html>" + result.getStatementInfo().getSQL().replaceAll("\n", "<br>"));
  3.2460 -                     }
  3.2461 -                  }
  3.2462 -
  3.2463 -                  if (plsqlEditor != null) {
  3.2464 -                     plsqlEditor.setResults(components, toolTips);
  3.2465 -                  }
  3.2466 -               }
  3.2467 -            });
  3.2468 -         } catch (InterruptedException ex) {
  3.2469 -            Exceptions.printStackTrace(ex);
  3.2470 -         } catch (InvocationTargetException ex) {
  3.2471 -            Exceptions.printStackTrace(ex);
  3.2472 -         }
  3.2473 -
  3.2474 -      }
  3.2475 -   }
  3.2476 -
  3.2477 -   public PlsqlEditor getPlsqlEditor(DataObject dataObj) {
  3.2478 -      //Get all the data objects and save dataObjects that require auto Save
  3.2479 -      TopComponent.Registry registry = TopComponent.getRegistry();
  3.2480 -      Object[] topComponentSet = registry.getOpened().toArray();
  3.2481 -      for (int i = 0; i < topComponentSet.length; i++) {
  3.2482 -         TopComponent component = (TopComponent) topComponentSet[i];
  3.2483 -         if (component instanceof PlsqlEditor) {
  3.2484 -            PlsqlEditor editor = (PlsqlEditor) component;
  3.2485 -            DataObject obj = editor.getLookup().lookup(DataObject.class);
  3.2486 -            if (obj != null && dataObj != null && obj == dataObj) {
  3.2487 -               return editor;
  3.2488 -            }
  3.2489 -         }
  3.2490 -      }
  3.2491 -
  3.2492 -      return null;
  3.2493 -   }
  3.2494 -
  3.2495 -   private void closeExecutionResult() {
  3.2496 -      if (executionResults != null) {
  3.2497 -         executionResults = null;
  3.2498 -      }
  3.2499 -   }
  3.2500 -
  3.2501 -   private final class SQLExecutor implements Runnable, Cancellable {
  3.2502 -
  3.2503 -      private static final int DEFAULT_PAGE_SIZE = 100;
  3.2504 -      private FileObject USERDIR = FileUtil.getConfigRoot();
  3.2505 -      private final DatabaseConnection dbconn;
  3.2506 -      private final String sqlStmt;
  3.2507 -      private String label;
  3.2508 -      private RequestProcessor.Task task;
  3.2509 -      private DataObject parent;
  3.2510 -
  3.2511 -      public SQLExecutor(DataObject dataObj, DatabaseConnection dbconn, String sqlStmt, String label) {
  3.2512 -         this.dbconn = dbconn;
  3.2513 -         this.sqlStmt = sqlStmt + ";";
  3.2514 -         this.parent = dataObj;
  3.2515 -         this.label = label;
  3.2516 -      }
  3.2517 -
  3.2518 -      public void setTask(RequestProcessor.Task task) {
  3.2519 -         this.task = task;
  3.2520 -      }
  3.2521 -
  3.2522 -      @Override
  3.2523 -      public void run() {
  3.2524 -         assert task != null : "Should have called setTask()"; // NOI18N
  3.2525 -
  3.2526 -         ProgressHandle handle = ProgressHandleFactory.createHandle("Executing Statements");
  3.2527 -         handle.start();
  3.2528 -         try {
  3.2529 -            handle.switchToIndeterminate();
  3.2530 -            //closeExecutionResult();
  3.2531 -            SQLExecutionResults executionResults = execute(sqlStmt, 0, sqlStmt.length() - 1, dbconn);
  3.2532 -            handleExecutionResults(executionResults);
  3.2533 -         } finally {
  3.2534 -            handle.finish();
  3.2535 -         }
  3.2536 -      }
  3.2537 -
  3.2538 -      /**
  3.2539 -       * Execute the sql
  3.2540 -       * @param sql
  3.2541 -       * @param i
  3.2542 -       * @param i0
  3.2543 -       * @param databaseConenction
  3.2544 -       * @return
  3.2545 -       */
  3.2546 -      private SQLExecutionResults execute(String sqlScript, int startOffset, int endOffset,
  3.2547 -              DatabaseConnection conn) {
  3.2548 -         boolean cancelled = false;
  3.2549 -         List<StatementInfo> statements = getStatements(sqlScript, startOffset, endOffset);
  3.2550 -         List<SQLExecutionResult> results = new ArrayList<SQLExecutionResult>();
  3.2551 -         String url = conn.getDatabaseURL();
  3.2552 -
  3.2553 -         for (Iterator i = statements.iterator(); i.hasNext();) {
  3.2554 -            cancelled = Thread.currentThread().isInterrupted();
  3.2555 -            if (cancelled) {
  3.2556 -               break;
  3.2557 +                // Save SQL statements executed for the SQLHistoryManager
  3.2558 +                SQLHistoryManager.getInstance().saveSQL(new SQLHistory(url, sql, new Date()));
  3.2559 +                result = new SQLExecutionResult(info, view);
  3.2560 +                results.add(result);
  3.2561              }
  3.2562  
  3.2563 -            StatementInfo info = (StatementInfo) i.next();
  3.2564 -            String sql = info.getSQL();
  3.2565 +            // Persist SQL executed
  3.2566 +            SQLHistoryManager.getInstance().save(USERDIR);
  3.2567 +            
  3.2568 +            if (!cancelled) {
  3.2569 +                return new SQLExecutionResults(results);
  3.2570 +            } else {
  3.2571 +                return null;
  3.2572 +            }
  3.2573 +        }
  3.2574 +        
  3.2575 +        private List<StatementInfo> getStatements(String script, int startOffset, int endOffset) {
  3.2576 +            List<StatementInfo> allStatements = new ArrayList<StatementInfo>();
  3.2577 +            if (script.endsWith(";")) {
  3.2578 +                script = script.substring(0, script.length() - 1);
  3.2579 +            }
  3.2580 +            allStatements.add(new StatementInfo(script, startOffset, startOffset, startOffset, startOffset, endOffset, script.length()));
  3.2581 +            return allStatements;
  3.2582 +        }
  3.2583 +        
  3.2584 +        private void handleExecutionResults(SQLExecutionResults executionResults) {
  3.2585 +            if (executionResults == null) {
  3.2586 +                // execution cancelled
  3.2587 +                return;
  3.2588 +            }
  3.2589 +            
  3.2590 +            setExecutionResults(executionResults);
  3.2591 +            
  3.2592 +            if (executionResults.size() <= 0) {
  3.2593 +                // no results, but successfull
  3.2594 +                return;
  3.2595 +            }
  3.2596 +            
  3.2597 +            if (executionResults.hasExceptions()) {
  3.2598 +                // there was at least one exception
  3.2599 +                displayErrors(executionResults);
  3.2600 +            } else {
  3.2601 +                setResultsToEditors(executionResults, parent, label);
  3.2602 +            }
  3.2603 +        }
  3.2604  
  3.2605 -            SQLExecutionResult result = null;
  3.2606 -            DataView view = DataView.create(conn, sql, DEFAULT_PAGE_SIZE);
  3.2607 +        /**
  3.2608 +         * Display the exceptions
  3.2609 +         * @param results
  3.2610 +         */
  3.2611 +        private void displayErrors(SQLExecutionResults results) {
  3.2612 +            if (results != null) {
  3.2613 +                for (SQLExecutionResult result : results.getResults()) {
  3.2614 +                    Collection<Throwable> collect = result.getExceptions();
  3.2615 +                    for (Iterator it = collect.iterator(); it.hasNext();) {
  3.2616 +                        Throwable excep = (Throwable) it.next();
  3.2617 +                        NotifyDescriptor descriptor = new NotifyDescriptor.Message(excep.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
  3.2618 +                        DialogDisplayer.getDefault().notifyLater(descriptor);
  3.2619 +                    }
  3.2620 +                }
  3.2621 +            }
  3.2622 +        }
  3.2623 +        
  3.2624 +        @Override
  3.2625 +        public boolean cancel() {
  3.2626 +            return task.cancel();
  3.2627 +        }
  3.2628 +    }
  3.2629  
  3.2630 -            // Save SQL statements executed for the SQLHistoryManager
  3.2631 -            SQLHistoryManager.getInstance().saveSQL(new SQLHistory(url, sql, new Date()));
  3.2632 -            result = new SQLExecutionResult(info, view);
  3.2633 -            results.add(result);
  3.2634 -         }
  3.2635 -
  3.2636 -         // Persist SQL executed
  3.2637 -         SQLHistoryManager.getInstance().save(USERDIR);
  3.2638 -
  3.2639 -         if (!cancelled) {
  3.2640 -            return new SQLExecutionResults(results);
  3.2641 -         } else {
  3.2642 -            return null;
  3.2643 -         }
  3.2644 -      }
  3.2645 -
  3.2646 -      private List<StatementInfo> getStatements(String script, int startOffset, int endOffset) {
  3.2647 -         List<StatementInfo> allStatements = new ArrayList<StatementInfo>();
  3.2648 -         if (script.endsWith(";")) {
  3.2649 -            script = script.substring(0, script.length() - 1);
  3.2650 -         }
  3.2651 -         allStatements.add(new StatementInfo(script, startOffset, startOffset, startOffset, startOffset, endOffset, script.length()));
  3.2652 -         return allStatements;
  3.2653 -      }
  3.2654 -
  3.2655 -      private void handleExecutionResults(SQLExecutionResults executionResults) {
  3.2656 -         if (executionResults == null) {
  3.2657 -            // execution cancelled
  3.2658 -            return;
  3.2659 -         }
  3.2660 -
  3.2661 -         setExecutionResults(executionResults);
  3.2662 -
  3.2663 -         if (executionResults.size() <= 0) {
  3.2664 -            // no results, but successfull
  3.2665 -            return;
  3.2666 -         }
  3.2667 -
  3.2668 -         if (executionResults.hasExceptions()) {
  3.2669 -            // there was at least one exception
  3.2670 -            displayErrors(executionResults);
  3.2671 -         } else {
  3.2672 -            setResultsToEditors(executionResults, parent, label);
  3.2673 -         }
  3.2674 -      }
  3.2675 -
  3.2676 -      /**
  3.2677 -       * Display the exceptions
  3.2678 -       * @param results
  3.2679 -       */
  3.2680 -      private void displayErrors(SQLExecutionResults results) {
  3.2681 -         if (results != null) {
  3.2682 -            for (SQLExecutionResult result : results.getResults()) {
  3.2683 -               Collection<Throwable> collect = result.getExceptions();
  3.2684 -               for (Iterator it = collect.iterator(); it.hasNext();) {
  3.2685 -                  Throwable excep = (Throwable) it.next();
  3.2686 -                  NotifyDescriptor descriptor = new NotifyDescriptor.Message(excep.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
  3.2687 -                  DialogDisplayer.getDefault().notifyLater(descriptor);
  3.2688 -               }
  3.2689 +    /*
  3.2690 +     * Get the suitable IO tab name, according to the content
  3.2691 +     * of the file.
  3.2692 +     */
  3.2693 +    private String getIOTabName(List executableObjs, String fileName, String displayName) {
  3.2694 +        PlsqlExecutableObject executionObject = (PlsqlExecutableObject) executableObjs.get(0);
  3.2695 +        if (fileName.equals(displayName)) {
  3.2696 +            if (executableObjs.size() > 0 && fileName.endsWith(".tdb")) {
  3.2697 +                String str = executionObject.getPlsqlString().replaceAll("\n", " ");
  3.2698 +                fileName = str.length() > 30 ? str.substring(0, 30) + "..." : str;
  3.2699              }
  3.2700 -         }
  3.2701 -      }
  3.2702 -
  3.2703 -      @Override
  3.2704 -      public boolean cancel() {
  3.2705 -         return task.cancel();
  3.2706 -      }
  3.2707 -   }
  3.2708 +        } else if (displayName != null) {
  3.2709 +            fileName = displayName;
  3.2710 +        }
  3.2711 +        return fileName;
  3.2712 +    }
  3.2713  }
     4.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/ViewDataAction.java	Mon Oct 17 15:09:02 2011 +0530
     4.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/ViewDataAction.java	Wed Oct 19 11:31:38 2011 +0530
     4.3 @@ -57,84 +57,89 @@
     4.4  
     4.5  public final class ViewDataAction extends CookieAction {
     4.6  
     4.7 -   /**
     4.8 -    * Create a sql execution window for the selected methoad
     4.9 -    * @param activatedNodes
    4.10 -    */
    4.11 -   protected void performAction(Node[] activatedNodes) {
    4.12 -      String selectStatement = "SELECT ${*} FROM " + getSelectedViewOrTable(activatedNodes) + ";\n${cursor}";
    4.13 -      SQLCommandWindow.createSQLCommandWindow(activatedNodes, selectStatement);
    4.14 -   }
    4.15 +    /**
    4.16 +     * Create a sql execution window for the selected methoad
    4.17 +     * @param activatedNodes
    4.18 +     */
    4.19 +    protected void performAction(Node[] activatedNodes) {
    4.20 +        String selectStatement = "SELECT ${*} FROM " + getSelectedViewOrTable(activatedNodes) + ";\n${cursor}";
    4.21 +        SQLCommandWindow.createSQLCommandWindow(activatedNodes, selectStatement, null);
    4.22 +    }
    4.23  
    4.24 -   protected int mode() {
    4.25 -      return CookieAction.MODE_EXACTLY_ONE;
    4.26 -   }
    4.27 +    protected int mode() {
    4.28 +        return CookieAction.MODE_EXACTLY_ONE;
    4.29 +    }
    4.30  
    4.31 -   public String getName() {
    4.32 -      return NbBundle.getMessage(ViewDataAction.class, "CTL_ViewDataAction");
    4.33 -   }
    4.34 +    public String getName() {
    4.35 +        return NbBundle.getMessage(ViewDataAction.class, "CTL_ViewDataAction");
    4.36 +    }
    4.37  
    4.38 -   protected Class[] cookieClasses() {
    4.39 -      return new Class[] {DataObject.class, EditorCookie.class};
    4.40 -   }
    4.41 +    protected Class[] cookieClasses() {
    4.42 +        return new Class[]{DataObject.class, EditorCookie.class};
    4.43 +    }
    4.44  
    4.45 -   @Override
    4.46 -   protected void initialize() {
    4.47 -      super.initialize();
    4.48 -      // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
    4.49 -      putValue("noIconInMenu", Boolean.TRUE);
    4.50 -   }
    4.51 +    @Override
    4.52 +    protected void initialize() {
    4.53 +        super.initialize();
    4.54 +        // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
    4.55 +        putValue("noIconInMenu", Boolean.TRUE);
    4.56 +    }
    4.57  
    4.58 -   public HelpCtx getHelpCtx() {
    4.59 -      return HelpCtx.DEFAULT_HELP;
    4.60 -   }
    4.61 +    public HelpCtx getHelpCtx() {
    4.62 +        return HelpCtx.DEFAULT_HELP;
    4.63 +    }
    4.64  
    4.65 -   @Override
    4.66 -   protected boolean asynchronous() {
    4.67 -      return false;
    4.68 -   }
    4.69 +    @Override
    4.70 +    protected boolean asynchronous() {
    4.71 +        return false;
    4.72 +    }
    4.73  
    4.74 -   /**
    4.75 -    * Enable this action when right clicked on views or tables
    4.76 -    * @param arg0
    4.77 -    * @return
    4.78 -    */
    4.79 -   @Override
    4.80 -   protected boolean enable(Node[] activatedNodes) {
    4.81 -      Project project = null;
    4.82 -      if (!super.enable(activatedNodes))
    4.83 -         return false;
    4.84 +    /**
    4.85 +     * Enable this action when right clicked on views or tables
    4.86 +     * @param arg0
    4.87 +     * @return
    4.88 +     */
    4.89 +    @Override
    4.90 +    protected boolean enable(Node[] activatedNodes) {
    4.91 +        Project project = null;
    4.92 +        if (!super.enable(activatedNodes)) {
    4.93 +            return false;
    4.94 +        }
    4.95  
    4.96 -      DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
    4.97 -      if(dataObject==null)
    4.98 -         return false;
    4.99 +        DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
   4.100 +        if (dataObject == null) {
   4.101 +            return false;
   4.102 +        }
   4.103  
   4.104 -      DatabaseConnectionManager connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
   4.105 -      if(connectionProvider==null)
   4.106 -         return false;
   4.107 +        DatabaseConnectionManager connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
   4.108 +        if (connectionProvider == null) {
   4.109 +            return false;
   4.110 +        }
   4.111  
   4.112 -      DatabaseConnection connection = connectionProvider.getDatabaseConnection(false);
   4.113 -      if(connection==null)
   4.114 -         return false;
   4.115 -      
   4.116 -      String viewName =  getSelectedViewOrTable(activatedNodes);
   4.117 -      if(viewName==null)
   4.118 -         return false;
   4.119 -      
   4.120 -      DatabaseContentManager dbCache = DatabaseContentManager.getInstance(connection);
   4.121 -      return dbCache.isView(viewName, connection) || dbCache.isTable(viewName, connection);
   4.122 -   }
   4.123 +        DatabaseConnection connection = connectionProvider.getDatabaseConnection(false);
   4.124 +        if (connection == null) {
   4.125 +            return false;
   4.126 +        }
   4.127  
   4.128 -   public static String getSelectedViewOrTable(Node[] activatedNodes) {
   4.129 -      EditorCookie editorCookie = activatedNodes[0].getLookup().lookup(EditorCookie.class);
   4.130 -      if(editorCookie==null)
   4.131 -         return null;
   4.132 +        String viewName = getSelectedViewOrTable(activatedNodes);
   4.133 +        if (viewName == null) {
   4.134 +            return false;
   4.135 +        }
   4.136  
   4.137 -      JEditorPane[] panes = editorCookie.getOpenedPanes();
   4.138 -      if ((panes != null) && (panes.length != 0)) {
   4.139 -         return panes[0].getSelectedText();
   4.140 -      }
   4.141 -      return null;
   4.142 -   }
   4.143 +        DatabaseContentManager dbCache = DatabaseContentManager.getInstance(connection);
   4.144 +        return dbCache.isView(viewName, connection) || dbCache.isTable(viewName, connection);
   4.145 +    }
   4.146 +
   4.147 +    public static String getSelectedViewOrTable(Node[] activatedNodes) {
   4.148 +        EditorCookie editorCookie = activatedNodes[0].getLookup().lookup(EditorCookie.class);
   4.149 +        if (editorCookie == null) {
   4.150 +            return null;
   4.151 +        }
   4.152 +
   4.153 +        JEditorPane[] panes = editorCookie.getOpenedPanes();
   4.154 +        if ((panes != null) && (panes.length != 0)) {
   4.155 +            return panes[0].getSelectedText();
   4.156 +        }
   4.157 +        return null;
   4.158 +    }
   4.159  }
   4.160 -
     5.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/ui/SQLCommandWindow.java	Mon Oct 17 15:09:02 2011 +0530
     5.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/ui/SQLCommandWindow.java	Wed Oct 19 11:31:38 2011 +0530
     5.3 @@ -67,86 +67,92 @@
     5.4  
     5.5  public class SQLCommandWindow {
     5.6  
     5.7 -   public static final String SQL_EXECUTION_FILE_PREFIX = "sqlexecutionwindow";
     5.8 +    public static final String SQL_EXECUTION_FILE_PREFIX = "sqlexecutionwindow";
     5.9  
    5.10 -   public static DataObject createSQLCommandWindow(Node[] activatedNodes, String codeTemplate) {
    5.11 -      Project project = activatedNodes[0].getLookup().lookup(Project.class);
    5.12 -      if(project==null) {
    5.13 -         DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
    5.14 -         if(dataObject==null)
    5.15 -            return null;
    5.16 -         project = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
    5.17 -         if (project == null)
    5.18 -            return null;
    5.19 -      }
    5.20 -      DataObject dataObj = null;
    5.21 -      try {
    5.22 -         File tmpFile;
    5.23 -         try {
    5.24 -            tmpFile = File.createTempFile(SQL_EXECUTION_FILE_PREFIX, ".tdb",
    5.25 -                  FileUtil.toFile(project.getLookup().lookup(CacheDirectoryProvider.class).getCacheDirectory()));
    5.26 -         } catch (IOException ex) {
    5.27 +    public static DataObject createSQLCommandWindow(Node[] activatedNodes, String codeTemplate, String displayName) {
    5.28 +        Project project = activatedNodes[0].getLookup().lookup(Project.class);
    5.29 +        if (project == null) {
    5.30 +            DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
    5.31 +            if (dataObject == null) {
    5.32 +                return null;
    5.33 +            }
    5.34 +            project = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
    5.35 +            if (project == null) {
    5.36 +                return null;
    5.37 +            }
    5.38 +        }
    5.39 +        DataObject dataObj = null;
    5.40 +        try {
    5.41 +            File tmpFile;
    5.42 +            try {
    5.43 +                tmpFile = File.createTempFile(SQL_EXECUTION_FILE_PREFIX, ".tdb",
    5.44 +                        FileUtil.toFile(project.getLookup().lookup(CacheDirectoryProvider.class).getCacheDirectory()));
    5.45 +            } catch (IOException ex) {
    5.46 +                Exceptions.printStackTrace(ex);
    5.47 +                return null;
    5.48 +            }
    5.49 +
    5.50 +            dataObj = DataFolder.find(FileUtil.toFileObject(tmpFile));
    5.51 +            if (dataObj != null) {
    5.52 +                if (displayName == null || displayName.equals("")) {
    5.53 +                    dataObj.getNodeDelegate().setDisplayName(NbBundle.getMessage(SQLCommandWindow.class, "LBL_SQLExecutionWindow"));
    5.54 +                } else {
    5.55 +                    dataObj.getNodeDelegate().setDisplayName(displayName);
    5.56 +                }
    5.57 +
    5.58 +                //Get open cookie from the data object and open that
    5.59 +                OpenCookie openCookie = dataObj.getCookie(OpenCookie.class);
    5.60 +                if (openCookie != null) {
    5.61 +                    openCookie.open();
    5.62 +                    //Get the new pane and paste the code template there
    5.63 +                    if (codeTemplate != null) {
    5.64 +                        EditorCookie editorCookie = dataObj.getCookie(EditorCookie.class);
    5.65 +                        JEditorPane[] panes = editorCookie.getOpenedPanes();
    5.66 +                        if ((panes != null) && (panes.length != 0)) {
    5.67 +                            JEditorPane component = panes[0];
    5.68 +                            if (component != null) {
    5.69 +                                //Ugly workaround for a bug in code templates.
    5.70 +                                //This bug makes it impossible to insert code templates at the first position in a file.
    5.71 +                                //By adding a comment line at the start of the file we avoid this problem for our test blocks...
    5.72 +                                Document doc = component.getDocument();
    5.73 +                                try {
    5.74 +                                    doc.insertString(0, "-- Enter values for your parameters. Use enter to move to the next parameter\n", null);
    5.75 +                                } catch (BadLocationException ex) {
    5.76 +                                    Exceptions.printStackTrace(ex);
    5.77 +                                }
    5.78 +                                CodeTemplate ct = CodeTemplateManager.get(component.getDocument()).createTemporary(codeTemplate);
    5.79 +                                ct.insert(component);
    5.80 +                            }
    5.81 +                        }
    5.82 +                    }
    5.83 +                }
    5.84 +            }
    5.85 +        } catch (DataObjectNotFoundException ex) {
    5.86              Exceptions.printStackTrace(ex);
    5.87              return null;
    5.88 -         }
    5.89 +        }
    5.90 +        return dataObj;
    5.91 +    }
    5.92  
    5.93 -         dataObj = DataFolder.find(FileUtil.toFileObject(tmpFile));
    5.94 -         if (dataObj != null) {
    5.95 -               dataObj.getNodeDelegate().setDisplayName(NbBundle.getMessage(SQLCommandWindow.class, "LBL_SQLExecutionWindow"));
    5.96 -
    5.97 -            //Get open cookie from the data object and open that
    5.98 -            OpenCookie openCookie = dataObj.getCookie(OpenCookie.class);
    5.99 -            if (openCookie != null) {
   5.100 -               openCookie.open();
   5.101 -               //Get the new pane and paste the code template there
   5.102 -               if(codeTemplate!=null) {
   5.103 -                  EditorCookie editorCookie = dataObj.getCookie(EditorCookie.class);
   5.104 -                  JEditorPane[] panes = editorCookie.getOpenedPanes();
   5.105 -                  if ((panes != null) && (panes.length != 0)) {
   5.106 -                     JEditorPane component = panes[0];
   5.107 -                     if (component != null) {
   5.108 -                        //Ugly workaround for a bug in code templates.
   5.109 -                        //This bug makes it impossible to insert code templates at the first position in a file.
   5.110 -                        //By adding a comment line at the start of the file we avoid this problem for our test blocks...
   5.111 -                        Document doc = component.getDocument();
   5.112 -                        try {
   5.113 -                           doc.insertString(0, "-- Enter values for your parameters. Use enter to move to the next parameter\n", null);
   5.114 -                        } catch (BadLocationException ex) {
   5.115 -                           Exceptions.printStackTrace(ex);
   5.116 -                        }
   5.117 -                        CodeTemplate ct = CodeTemplateManager.get(component.getDocument()).createTemporary(codeTemplate);
   5.118 -                        ct.insert(component);
   5.119 -                     }
   5.120 -                  }
   5.121 -               }
   5.122 +    private static String getCommandWindowSuffix() {
   5.123 +        int maxIndex = -1;
   5.124 +        String displayNamePrefix = NbBundle.getMessage(SQLCommandWindow.class, "LBL_SQLExecutionWindow");
   5.125 +        Registry registry = TopComponent.getRegistry();
   5.126 +        Set<TopComponent> topComponents = registry.getOpened();
   5.127 +        for (TopComponent component : topComponents) {
   5.128 +            if (component instanceof CloneableEditor && component.isVisible()) {
   5.129 +                String displayName = component.getDisplayName();
   5.130 +                if (displayName != null && displayName.startsWith(displayNamePrefix)) {
   5.131 +                    String suffix = displayName.substring(displayNamePrefix.length());
   5.132 +                    try {
   5.133 +                        int candidate = suffix.length() > 0 ? Integer.parseInt(suffix.trim()) : 0;
   5.134 +                        maxIndex = candidate > maxIndex ? candidate : maxIndex;
   5.135 +                    } catch (NumberFormatException ex) {
   5.136 +                        //do nothing - this isn't one of "our" windows.
   5.137 +                    }
   5.138 +                }
   5.139              }
   5.140 -         }
   5.141 -      } catch (DataObjectNotFoundException ex) {
   5.142 -         Exceptions.printStackTrace(ex);
   5.143 -         return null;
   5.144 -      }
   5.145 -      return dataObj;
   5.146 -   }
   5.147 -
   5.148 -   private static String getCommandWindowSuffix() {
   5.149 -      int maxIndex = -1;
   5.150 -      String displayNamePrefix = NbBundle.getMessage(SQLCommandWindow.class, "LBL_SQLExecutionWindow");
   5.151 -      Registry registry = TopComponent.getRegistry();
   5.152 -      Set<TopComponent> topComponents = registry.getOpened();
   5.153 -      for(TopComponent component : topComponents) {
   5.154 -         if(component instanceof CloneableEditor && component.isVisible()) {
   5.155 -            String displayName = component.getDisplayName();
   5.156 -            if(displayName!=null && displayName.startsWith(displayNamePrefix)) {
   5.157 -               String suffix = displayName.substring(displayNamePrefix.length());
   5.158 -               try {
   5.159 -                  int candidate = suffix.length()>0 ? Integer.parseInt(suffix.trim()) : 0;
   5.160 -                  maxIndex = candidate > maxIndex ? candidate : maxIndex;
   5.161 -               } catch(NumberFormatException ex) {
   5.162 -                  //do nothing - this isn't one of "our" windows.
   5.163 -               }
   5.164 -            }
   5.165 -         }
   5.166 -      }
   5.167 -      return maxIndex==-1 ? "" : " " + Integer.toString(maxIndex+1) + "";
   5.168 -   }
   5.169 +        }
   5.170 +        return maxIndex == -1 ? "" : " " + Integer.toString(maxIndex + 1) + "";
   5.171 +    }
   5.172  }
     6.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/ui/SQLExecutionAction.java	Mon Oct 17 15:09:02 2011 +0530
     6.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/ui/SQLExecutionAction.java	Wed Oct 19 11:31:38 2011 +0530
     6.3 @@ -50,46 +50,47 @@
     6.4  
     6.5  public final class SQLExecutionAction extends CookieAction {
     6.6  
     6.7 -   protected void performAction(Node[] activatedNodes) {
     6.8 -      SQLCommandWindow.createSQLCommandWindow(activatedNodes, null);
     6.9 -   }
    6.10 +    protected void performAction(Node[] activatedNodes) {
    6.11 +        SQLCommandWindow.createSQLCommandWindow(activatedNodes, null, null);
    6.12 +    }
    6.13  
    6.14 -   public String getName() {
    6.15 -      return NbBundle.getMessage(SQLExecutionAction.class, "CTL_SQLExecutionAction");
    6.16 -   }
    6.17 +    public String getName() {
    6.18 +        return NbBundle.getMessage(SQLExecutionAction.class, "CTL_SQLExecutionAction");
    6.19 +    }
    6.20  
    6.21 -   @Override
    6.22 -   protected void initialize() {
    6.23 -      super.initialize();
    6.24 -      // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
    6.25 -      putValue("noIconInMenu", Boolean.TRUE);
    6.26 -   }
    6.27 +    @Override
    6.28 +    protected void initialize() {
    6.29 +        super.initialize();
    6.30 +        // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
    6.31 +        putValue("noIconInMenu", Boolean.TRUE);
    6.32 +    }
    6.33  
    6.34 -   public HelpCtx getHelpCtx() {
    6.35 -      return HelpCtx.DEFAULT_HELP;
    6.36 -   }
    6.37 +    public HelpCtx getHelpCtx() {
    6.38 +        return HelpCtx.DEFAULT_HELP;
    6.39 +    }
    6.40  
    6.41 -   @Override
    6.42 -   protected boolean asynchronous() {
    6.43 -      return false;
    6.44 -   }
    6.45 +    @Override
    6.46 +    protected boolean asynchronous() {
    6.47 +        return false;
    6.48 +    }
    6.49  
    6.50 -   @Override
    6.51 -   protected int mode() {
    6.52 -      return CookieAction.MODE_EXACTLY_ONE;
    6.53 -   }
    6.54 +    @Override
    6.55 +    protected int mode() {
    6.56 +        return CookieAction.MODE_EXACTLY_ONE;
    6.57 +    }
    6.58  
    6.59 -   @Override
    6.60 -   protected Class<?>[] cookieClasses() {
    6.61 -      return new Class[] {Project.class};
    6.62 -   }
    6.63 +    @Override
    6.64 +    protected Class<?>[] cookieClasses() {
    6.65 +        return new Class[]{Project.class};
    6.66 +    }
    6.67  
    6.68 -   @Override
    6.69 -   protected boolean enable(Node[] activatedNodes) {
    6.70 -      if (!super.enable(activatedNodes))
    6.71 -         return false;
    6.72 -      Project project = activatedNodes[0].getLookup().lookup(Project.class);
    6.73 -      DatabaseConnectionManager provider = project.getLookup().lookup(DatabaseConnectionManager.class);
    6.74 -      return provider != null && provider.hasConnection() && provider.isOnline();
    6.75 -   }
    6.76 +    @Override
    6.77 +    protected boolean enable(Node[] activatedNodes) {
    6.78 +        if (!super.enable(activatedNodes)) {
    6.79 +            return false;
    6.80 +        }
    6.81 +        Project project = activatedNodes[0].getLookup().lookup(Project.class);
    6.82 +        DatabaseConnectionManager provider = project.getLookup().lookup(DatabaseConnectionManager.class);
    6.83 +        return provider != null && provider.hasConnection() && provider.isOnline();
    6.84 +    }
    6.85  }