Search in sources :

Example 1 with QueryParametersDialog

use of com.amalto.workbench.dialogs.QueryParametersDialog in project tmdm-studio-se by Talend.

the class StoredProcedureMainPage method executeProcedure.

protected void executeProcedure() {
    boolean checkMissingJar = MissingJarService.getInstance().checkMissingJar(true);
    if (!checkMissingJar) {
        return;
    }
    BusyIndicator.showWhile(this.getPartControl().getDisplay(), new Runnable() {

        public void run() {
            WSDataClusterPK dcpk = null;
            if (!"[ALL]".equals(dataClusterCombo.getText())) {
                dcpk = new WSDataClusterPK(dataClusterCombo.getText());
            }
            try {
                String proc = procedureViewer.getDocument().get();
                // read parameters
                int number = 0;
                while (true) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    Pattern p = Pattern.compile(".*[^\\\\]%" + number + "[^\\d]*.*", Pattern.DOTALL);
                    Matcher m = p.matcher(proc);
                    if (!m.matches()) {
                        break;
                    } else {
                        ++number;
                    }
                }
                String[] ps = null;
                if (number > 0) {
                    // transfer current parameters to new array
                    ps = new String[number];
                    for (int i = 0; i < number; i++) {
                        if (i < currentParameters.size()) {
                            ps[i] = currentParameters.get(i);
                        } else {
                            // $NON-NLS-1$
                            ps[i] = "";
                        }
                    }
                    // call parameters window
                    QueryParametersDialog dialog = new QueryParametersDialog(StoredProcedureMainPage.this.getSite().getShell(), ps);
                    dialog.setBlockOnOpen(true);
                    dialog.open();
                    if (dialog.getButtonPressed() == QueryParametersDialog.BUTTON_CANCEL) {
                        return;
                    }
                    ps = dialog.getParameters();
                    // Apply parameters
                    for (int i = 0; i < ps.length; i++) {
                        // transfer parameters back into current parameters
                        if (i < currentParameters.size()) {
                            currentParameters.set(i, ps[i]);
                        } else {
                            currentParameters.add(ps[i]);
                        }
                    }
                }
                // perform call
                TMDMService service = getMDMService();
                if (service != null) {
                    WSStoredProcedure wsStoredProcedure = (WSStoredProcedure) (getXObject().getWsObject());
                    service.putStoredProcedure(new WSPutStoredProcedure(wsStoredProcedure));
                    WSStringArray array = service.executeStoredProcedure(new WSExecuteStoredProcedure(currentParameters, dcpk, new WSStoredProcedurePK(wsStoredProcedure.getName())));
                    List<String> results = array.getStrings();
                    resultsLabel.setText(Messages.StoredProcedureMainPage_15 + results.size() + Messages.StoredProcedureMainPage_16);
                    resultsViewer.setInput(results);
                }
            } catch (Exception ex) {
                if (!Util.handleConnectionException(StoredProcedureMainPage.this.getSite().getShell(), ex, null)) {
                    String message = ex.getMessage();
                    Set<String> messages = getMessages(message);
                    StringBuilder builder = new StringBuilder();
                    for (String currentMessage : messages) {
                        builder.append(currentMessage + '\n');
                    }
                    MessageDialog.openError(StoredProcedureMainPage.this.getSite().getShell(), Messages._Error, builder.toString());
                }
            }
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) WSStoredProcedurePK(com.amalto.workbench.webservices.WSStoredProcedurePK) WSPutStoredProcedure(com.amalto.workbench.webservices.WSPutStoredProcedure) WSStringArray(com.amalto.workbench.webservices.WSStringArray) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) QueryParametersDialog(com.amalto.workbench.dialogs.QueryParametersDialog) TMDMService(com.amalto.workbench.webservices.TMDMService) WSExecuteStoredProcedure(com.amalto.workbench.webservices.WSExecuteStoredProcedure) List(java.util.List) LinkedList(java.util.LinkedList) WSStoredProcedure(com.amalto.workbench.webservices.WSStoredProcedure)

Aggregations

QueryParametersDialog (com.amalto.workbench.dialogs.QueryParametersDialog)1 TMDMService (com.amalto.workbench.webservices.TMDMService)1 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)1 WSExecuteStoredProcedure (com.amalto.workbench.webservices.WSExecuteStoredProcedure)1 WSPutStoredProcedure (com.amalto.workbench.webservices.WSPutStoredProcedure)1 WSStoredProcedure (com.amalto.workbench.webservices.WSStoredProcedure)1 WSStoredProcedurePK (com.amalto.workbench.webservices.WSStoredProcedurePK)1 WSStringArray (com.amalto.workbench.webservices.WSStringArray)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1