Ejemplo n.º 1
0
 @Override
 public boolean performFinish() {
   try {
     RuntimeUtils.run(
         getContainer(),
         true,
         true,
         new DBRRunnableWithProgress() {
           @Override
           public void run(DBRProgressMonitor monitor)
               throws InvocationTargetException, InterruptedException {
             try {
               createProject(monitor);
             } catch (Exception e) {
               throw new InvocationTargetException(e);
             }
           }
         });
   } catch (InterruptedException ex) {
     return false;
   } catch (InvocationTargetException ex) {
     UIUtils.showErrorDialog(
         getShell(),
         CoreMessages.dialog_project_create_wizard_error_cannot_create,
         CoreMessages.dialog_project_create_wizard_error_cannot_create_message,
         ex.getTargetException());
     return false;
   }
   return true;
 }
Ejemplo n.º 2
0
 @Override
 public void updateElement(UIElement element, Map parameters) {
   List<OracleSourceObject> objects = new ArrayList<>();
   IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
   if (partSite != null) {
     final ISelectionProvider selectionProvider = partSite.getSelectionProvider();
     if (selectionProvider != null) {
       ISelection selection = selectionProvider.getSelection();
       if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
         for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
           final Object item = iter.next();
           final OracleSourceObject sourceObject =
               RuntimeUtils.getObjectAdapter(item, OracleSourceObject.class);
           if (sourceObject != null) {
             objects.add(sourceObject);
           }
         }
       }
     }
     if (objects.isEmpty()) {
       final IWorkbenchPart activePart = partSite.getPart();
       final OracleSourceObject sourceObject =
           RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
       if (sourceObject != null) {
         objects.add(sourceObject);
       }
     }
   }
   if (!objects.isEmpty()) {
     if (objects.size() > 1) {
       element.setText("Compile " + objects.size() + " objects");
     } else {
       final OracleSourceObject sourceObject = objects.get(0);
       String objectType = TextUtils.formatWord(sourceObject.getSourceType().name());
       element.setText("Compile " + objectType /* + " '" + sourceObject.getName() + "'"*/);
     }
   }
 }
Ejemplo n.º 3
0
 private List<OracleSourceObject> getSelectedObjects(ExecutionEvent event) {
   List<OracleSourceObject> objects = new ArrayList<>();
   final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
   if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
     for (Iterator<?> iter = ((IStructuredSelection) currentSelection).iterator();
         iter.hasNext(); ) {
       final Object element = iter.next();
       final OracleSourceObject sourceObject =
           RuntimeUtils.getObjectAdapter(element, OracleSourceObject.class);
       if (sourceObject != null) {
         objects.add(sourceObject);
       }
     }
   }
   if (objects.isEmpty()) {
     final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
     final OracleSourceObject sourceObject =
         RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
     if (sourceObject != null) {
       objects.add(sourceObject);
     }
   }
   return objects;
 }
Ejemplo n.º 4
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final List<OracleSourceObject> objects = getSelectedObjects(event);
    if (!objects.isEmpty()) {
      final Shell activeShell = HandlerUtil.getActiveShell(event);
      if (objects.size() == 1) {
        final OracleSourceObject unit = objects.get(0);

        DBCSourceHost sourceHost = null;
        final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
        if (activePart != null) {
          sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
          if (sourceHost == null) {
            sourceHost = activePart.getAdapter(DBCSourceHost.class);
          }
        }
        if (sourceHost != null && sourceHost.getSourceObject() != unit) {
          sourceHost = null;
        }

        final DBCCompileLog compileLog =
            sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
        compileLog.clearLog();
        Throwable error = null;
        try {
          DBeaverUI.runInProgressService(
              new DBRRunnableWithProgress() {
                @Override
                public void run(DBRProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  try {
                    compileUnit(monitor, compileLog, unit);
                  } catch (DBCException e) {
                    throw new InvocationTargetException(e);
                  }
                }
              });
          if (compileLog.getError() != null) {
            error = compileLog.getError();
          }
        } catch (InvocationTargetException e) {
          error = e.getTargetException();
        } catch (InterruptedException e) {
          return null;
        }
        if (error != null) {
          UIUtils.showErrorDialog(activeShell, "Unexpected compilation error", null, error);
        } else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
          // Show compile errors
          int line = -1, position = -1;
          StringBuilder fullMessage = new StringBuilder();
          for (DBCCompileError oce : compileLog.getErrorStack()) {
            fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
            if (line < 0) {
              line = oce.getLine();
              position = oce.getPosition();
            }
          }

          // If compiled object is currently open in editor - try to position on error line
          if (sourceHost != null
              && sourceHost.getSourceObject() == unit
              && line > 0
              && position > 0) {
            sourceHost.positionSource(line, position);
            activePart.getSite().getPage().activate(activePart);
          }

          String errorTitle = unit.getName() + " compilation failed";
          if (sourceHost != null) {
            sourceHost.setCompileInfo(errorTitle, true);
            sourceHost.showCompileLog();
          }
          UIUtils.showErrorDialog(activeShell, errorTitle, fullMessage.toString());
        } else {
          String message = unit.getName() + " compiled successfully";
          if (sourceHost != null) {
            sourceHost.setCompileInfo(message, true);
          }
          UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
        }
      } else {
        OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
        dialog.open();
      }
    }
    return null;
  }
Ejemplo n.º 5
0
  @Override
  protected IStatus run(DBRProgressMonitor monitor) {
    RuntimeUtils.setThreadName("SQL script execution");
    statistics = new DBCStatistics();
    try {
      DBCExecutionContext context = getExecutionContext();
      DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
      DBCExecutionPurpose purpose =
          queries.size() > 1 ? DBCExecutionPurpose.USER_SCRIPT : DBCExecutionPurpose.USER;
      try (DBCSession session = context.openSession(monitor, purpose, "SQL Query")) {
        // Set transaction settings (only if autocommit is off)
        QMUtils.getDefaultHandler().handleScriptBegin(session);

        boolean oldAutoCommit = txnManager == null || txnManager.isAutoCommit();
        boolean newAutoCommit = (commitType == SQLScriptCommitType.AUTOCOMMIT);
        if (txnManager != null && !oldAutoCommit && newAutoCommit) {
          txnManager.setAutoCommit(monitor, true);
        }

        monitor.beginTask(this.getName(), queries.size());

        // Notify job start
        if (listener != null) {
          listener.onStartScript();
        }

        resultSetNumber = 0;
        for (int queryNum = 0; queryNum < queries.size(); ) {
          // Execute query
          SQLQuery query = queries.get(queryNum);

          fetchResultSetNumber = resultSetNumber;
          boolean runNext = executeSingleQuery(session, query, true);
          if (!runNext) {
            // Ask to continue
            if (lastError != null) {
              log.error(lastError);
            }
            boolean isQueue = queryNum < queries.size() - 1;
            ExecutionQueueErrorResponse response =
                ExecutionQueueErrorJob.showError(
                    isQueue ? "SQL script execution" : "SQL query execution", lastError, isQueue);

            boolean stopScript = false;
            switch (response) {
              case STOP:
                // just stop execution
                stopScript = true;
                break;
              case RETRY:
                // just make it again
                continue;
              case IGNORE:
                // Just do nothing
                break;
              case IGNORE_ALL:
                errorHandling = SQLScriptErrorHandling.IGNORE;
                break;
            }

            if (stopScript) {
              break;
            }
          }

          // Check monitor
          if (monitor.isCanceled()) {
            break;
          }
          monitor.worked(1);
          queryNum++;
        }
        showExecutionResult(session);
        monitor.done();

        // Commit data
        if (txnManager != null && !oldAutoCommit && commitType != SQLScriptCommitType.AUTOCOMMIT) {
          if (lastError == null || errorHandling == SQLScriptErrorHandling.STOP_COMMIT) {
            if (commitType != SQLScriptCommitType.NO_COMMIT) {
              monitor.beginTask("Commit data", 1);
              txnManager.commit(session);
              monitor.done();
            }
          } else {
            monitor.beginTask("Rollback data", 1);
            txnManager.rollback(session, null);
            monitor.done();
          }
        }

        // Restore transactions settings
        if (txnManager != null && !oldAutoCommit && newAutoCommit) {
          txnManager.setAutoCommit(monitor, false);
        }

        QMUtils.getDefaultHandler().handleScriptEnd(session);

        // Return success
        return new Status(Status.OK, DBeaverCore.getCorePluginID(), "SQL job completed");
      }
    } catch (Throwable ex) {
      return new Status(
          Status.ERROR,
          DBeaverCore.getCorePluginID(),
          "Error during SQL job execution: " + ex.getMessage());
    } finally {
      // Notify job end
      if (listener != null) {
        listener.onEndScript(statistics, lastError != null);
      }
    }
  }