Search in sources :

Example 6 with LogTableInterface

use of org.pentaho.di.core.logging.LogTableInterface in project pentaho-kettle by pentaho.

the class JobDialog method showLogTypeOptions.

private void showLogTypeOptions(int index) {
    if (index != previousLogTableIndex) {
        getLogInfo(previousLogTableIndex);
        // 
        for (Control control : wLogOptionsComposite.getChildren()) {
            control.dispose();
        }
        previousLogTableIndex = index;
        LogTableInterface logTable = logTables.get(index);
        LogTableUserInterface logTableUserInterface = logTableUserInterfaces.get(index);
        if (logTableUserInterface != null) {
            logTableUserInterface.showLogTableOptions(wLogOptionsComposite, logTable);
        } else {
            if (logTable instanceof JobLogTable) {
                showJobLogTableOptions((JobLogTable) logTable);
            } else if (logTable instanceof ChannelLogTable) {
                showChannelLogTableOptions((ChannelLogTable) logTable);
            }
            if (logTable instanceof JobEntryLogTable) {
                showJobEntryLogTableOptions((JobEntryLogTable) logTable);
            }
        }
        wLogOptionsComposite.layout(true, true);
        wLogComp.layout(true, true);
    }
}
Also used : LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) Control(org.eclipse.swt.widgets.Control) JobLogTable(org.pentaho.di.core.logging.JobLogTable) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) JobEntryLogTable(org.pentaho.di.core.logging.JobEntryLogTable)

Example 7 with LogTableInterface

use of org.pentaho.di.core.logging.LogTableInterface in project pentaho-kettle by pentaho.

the class JobDialog method sql.

/**
 * Generates code for create table... Conversions done by Database
 */
private void sql() {
    if (previousLogTableIndex >= 0) {
        getLogInfo(previousLogTableIndex);
    }
    try {
        for (LogTableInterface logTable : logTables) {
            if (logTable.getDatabaseMeta() != null && !Utils.isEmpty(logTable.getTableName())) {
                // OK, we have something to work with!
                // 
                Database db = null;
                try {
                    db = new Database(jobMeta, logTable.getDatabaseMeta());
                    db.shareVariablesWith(jobMeta);
                    db.connect();
                    StringBuilder ddl = new StringBuilder();
                    RowMetaInterface fields = logTable.getLogRecord(LogStatus.START, null, null).getRowMeta();
                    String tableName = db.environmentSubstitute(logTable.getTableName());
                    String schemaTable = logTable.getDatabaseMeta().getQuotedSchemaTableCombination(db.environmentSubstitute(logTable.getSchemaName()), db.environmentSubstitute(logTable.getTableName()));
                    String createTable = db.getDDL(schemaTable, fields);
                    if (!Utils.isEmpty(createTable)) {
                        ddl.append("-- ").append(logTable.getLogTableType()).append(Const.CR);
                        ddl.append("--").append(Const.CR).append(Const.CR);
                        ddl.append(createTable).append(Const.CR);
                    }
                    java.util.List<RowMetaInterface> indexes = logTable.getRecommendedIndexes();
                    for (int i = 0; i < indexes.size(); i++) {
                        RowMetaInterface index = indexes.get(i);
                        if (!index.isEmpty()) {
                            String createIndex = db.getCreateIndexStatement(schemaTable, "IDX_" + tableName + "_" + (i + 1), index.getFieldNames(), false, false, false, true);
                            if (!Utils.isEmpty(createIndex)) {
                                ddl.append(createIndex);
                            }
                        }
                    }
                    if (ddl.length() > 0) {
                        SQLEditor sqledit = new SQLEditor(jobMeta, shell, SWT.NONE, logTable.getDatabaseMeta(), DBCache.getInstance(), ddl.toString());
                        sqledit.open();
                    } else {
                        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                        mb.setText(BaseMessages.getString(PKG, "JobDialog.NoSqlNedds.DialogTitle"));
                        mb.setMessage(logTable.getLogTableType() + Const.CR + Const.CR + BaseMessages.getString(PKG, "JobDialog.NoSqlNedds.DialogMessage"));
                        mb.open();
                    }
                } finally {
                    if (db != null) {
                        db.disconnect();
                    }
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "JobDialog.Dialog.ErrorCreatingSQL.Title"), BaseMessages.getString(PKG, "JobDialog.Dialog.ErrorCreatingSQL.Message"), e);
    }
}
Also used : LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) Database(org.pentaho.di.core.database.Database) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleException(org.pentaho.di.core.exception.KettleException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 8 with LogTableInterface

use of org.pentaho.di.core.logging.LogTableInterface in project pentaho-kettle by pentaho.

the class JobDialog method addLogTab.

private void addLogTab() {
    // ////////////////////////
    // START OF LOG TAB///
    // /
    wLogTab = new CTabItem(wTabFolder, SWT.NONE);
    wLogTab.setText(BaseMessages.getString(PKG, "JobDialog.LogTab.Label"));
    FormLayout LogLayout = new FormLayout();
    LogLayout.marginWidth = Const.MARGIN;
    LogLayout.marginHeight = Const.MARGIN;
    wLogComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wLogComp);
    wLogComp.setLayout(LogLayout);
    // Add a log type List on the left hand side...
    // 
    wLogTypeList = new List(wLogComp, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    props.setLook(wLogTypeList);
    for (LogTableInterface logTable : logTables) {
        wLogTypeList.add(logTable.getLogTableType());
    }
    FormData fdLogTypeList = new FormData();
    fdLogTypeList.left = new FormAttachment(0, 0);
    fdLogTypeList.top = new FormAttachment(0, 0);
    fdLogTypeList.right = new FormAttachment(middle / 2, 0);
    fdLogTypeList.bottom = new FormAttachment(100, 0);
    wLogTypeList.setLayoutData(fdLogTypeList);
    wLogTypeList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            showLogTypeOptions(wLogTypeList.getSelectionIndex());
        }
    });
    // On the right side we see a dynamic area : a composite...
    // 
    wLogOptionsComposite = new Composite(wLogComp, SWT.BORDER);
    FormLayout logOptionsLayout = new FormLayout();
    logOptionsLayout.marginWidth = Const.MARGIN;
    logOptionsLayout.marginHeight = Const.MARGIN;
    wLogOptionsComposite.setLayout(logOptionsLayout);
    props.setLook(wLogOptionsComposite);
    FormData fdLogOptionsComposite = new FormData();
    fdLogOptionsComposite.left = new FormAttachment(wLogTypeList, margin);
    fdLogOptionsComposite.top = new FormAttachment(0, 0);
    fdLogOptionsComposite.right = new FormAttachment(100, 0);
    fdLogOptionsComposite.bottom = new FormAttachment(100, 0);
    wLogOptionsComposite.setLayoutData(fdLogOptionsComposite);
    FormData fdLogComp = new FormData();
    fdLogComp.left = new FormAttachment(0, 0);
    fdLogComp.top = new FormAttachment(0, 0);
    fdLogComp.right = new FormAttachment(100, 0);
    fdLogComp.bottom = new FormAttachment(100, 0);
    wLogComp.setLayoutData(fdLogComp);
    wLogComp.layout();
    wLogTab.setControl(wLogComp);
// ///////////////////////////////////////////////////////////
// / END OF LOG TAB
// ///////////////////////////////////////////////////////////
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) CTabItem(org.eclipse.swt.custom.CTabItem) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 9 with LogTableInterface

use of org.pentaho.di.core.logging.LogTableInterface in project pentaho-kettle by pentaho.

the class JobDialog method open.

public JobMeta open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN | SWT.APPLICATION_MODAL);
    props.setLook(shell);
    shell.setImage(GUIResource.getInstance().getImageJobGraph());
    lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            changed = true;
        }
    };
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "JobDialog.JobProperties.ShellText"));
    middle = props.getMiddlePct();
    margin = Const.MARGIN;
    wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);
    // 
    for (LogTableInterface logTable : logTables) {
        // can be null
        logTableUserInterfaces.add(getLogTableUserInterface(logTable, jobMeta, lsMod));
    }
    addJobTab();
    addParamTab();
    addSettingsTab();
    addLogTab();
    // See if there are any other tabs to be added...
    extraTabs = new ArrayList<JobDialogPluginInterface>();
    java.util.List<PluginInterface> jobDialogPlugins = PluginRegistry.getInstance().getPlugins(JobDialogPluginType.class);
    for (PluginInterface jobDialogPlugin : jobDialogPlugins) {
        try {
            JobDialogPluginInterface extraTab = (JobDialogPluginInterface) PluginRegistry.getInstance().loadClass(jobDialogPlugin);
            extraTab.addTab(jobMeta, parent, wTabFolder);
            extraTabs.add(extraTab);
        } catch (Exception e) {
            KettleRepositoryLostException krle = KettleRepositoryLostException.lookupStackStrace(e);
            if (krle != null) {
                throw krle;
            }
            new ErrorDialog(shell, "Error", "Error loading job dialog plugin with id " + jobDialogPlugin.getIds()[0], e);
        }
    }
    fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(0, 0);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(100, -50);
    wTabFolder.setLayoutData(fdTabFolder);
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wSQL = new Button(shell, SWT.PUSH);
    wSQL.setText(BaseMessages.getString(PKG, "System.Button.SQL"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    // BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wSQL, wCancel }, margin, wSharedObjectsFile);
    BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wSQL, wCancel }, Const.MARGIN, null);
    // Add listeners
    lsOK = new Listener() {

        public void handleEvent(Event e) {
            ok();
        }
    };
    lsSQL = new Listener() {

        public void handleEvent(Event e) {
            sql();
        }
    };
    lsCancel = new Listener() {

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wSQL.addListener(SWT.Selection, lsSQL);
    wCancel.addListener(SWT.Selection, lsCancel);
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wJobname.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    wTabFolder.setSelection(0);
    getData();
    BaseStepDialog.setSize(shell);
    changed = false;
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobMeta;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) CTabFolder(org.eclipse.swt.custom.CTabFolder) FieldDisabledListener(org.pentaho.di.ui.core.widget.FieldDisabledListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) LogTablePluginInterface(org.pentaho.di.core.logging.LogTablePluginInterface) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ShellEvent(org.eclipse.swt.events.ShellEvent) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleException(org.pentaho.di.core.exception.KettleException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display)

Example 10 with LogTableInterface

use of org.pentaho.di.core.logging.LogTableInterface in project pentaho-kettle by pentaho.

the class TransMeta method getSQLStatements.

/**
 * Builds a list of all the SQL statements that this transformation needs in order to work properly.
 *
 * @param monitor
 *          a progress monitor listener to be updated as the SQL statements are generated
 * @return An ArrayList of SQLStatement objects.
 * @throws KettleStepException
 *           if any errors occur during SQL statement generation
 */
public List<SQLStatement> getSQLStatements(ProgressMonitorListener monitor) throws KettleStepException {
    if (monitor != null) {
        monitor.beginTask(BaseMessages.getString(PKG, "TransMeta.Monitor.GettingTheSQLForTransformationTask.Title"), nrSteps() + 1);
    }
    List<SQLStatement> stats = new ArrayList<>();
    for (int i = 0; i < nrSteps(); i++) {
        StepMeta stepMeta = getStep(i);
        if (monitor != null) {
            monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.GettingTheSQLForStepTask.Title", "" + stepMeta));
        }
        RowMetaInterface prev = getPrevStepFields(stepMeta);
        SQLStatement sqlCompat = compatibleStepMetaGetSQLStatements(stepMeta.getStepMetaInterface(), stepMeta, prev);
        if (sqlCompat.getSQL() != null || sqlCompat.hasError()) {
            stats.add(sqlCompat);
        }
        SQLStatement sql = stepMeta.getStepMetaInterface().getSQLStatements(this, stepMeta, prev, repository, metaStore);
        if (sql.getSQL() != null || sql.hasError()) {
            stats.add(sql);
        }
        if (monitor != null) {
            monitor.worked(1);
        }
    }
    // 
    if (monitor != null) {
        monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.GettingTheSQLForTransformationTask.Title2"));
    }
    if (transLogTable.getDatabaseMeta() != null && (!Utils.isEmpty(transLogTable.getTableName()) || !Utils.isEmpty(performanceLogTable.getTableName()))) {
        try {
            for (LogTableInterface logTable : new LogTableInterface[] { transLogTable, performanceLogTable, channelLogTable, stepLogTable }) {
                if (logTable.getDatabaseMeta() != null && !Utils.isEmpty(logTable.getTableName())) {
                    Database db = null;
                    try {
                        db = new Database(this, transLogTable.getDatabaseMeta());
                        db.shareVariablesWith(this);
                        db.connect();
                        RowMetaInterface fields = logTable.getLogRecord(LogStatus.START, null, null).getRowMeta();
                        String schemaTable = logTable.getDatabaseMeta().getQuotedSchemaTableCombination(logTable.getSchemaName(), logTable.getTableName());
                        String sql = db.getDDL(schemaTable, fields);
                        if (!Utils.isEmpty(sql)) {
                            SQLStatement stat = new SQLStatement("<this transformation>", transLogTable.getDatabaseMeta(), sql);
                            stats.add(stat);
                        }
                    } catch (Exception e) {
                        throw new KettleDatabaseException("Unable to connect to logging database [" + logTable.getDatabaseMeta() + "]", e);
                    } finally {
                        if (db != null) {
                            db.disconnect();
                        }
                    }
                }
            }
        } catch (KettleDatabaseException dbe) {
            SQLStatement stat = new SQLStatement("<this transformation>", transLogTable.getDatabaseMeta(), null);
            stat.setError(BaseMessages.getString(PKG, "TransMeta.SQLStatement.ErrorDesc.ErrorObtainingTransformationLogTableInfo") + dbe.getMessage());
            stats.add(stat);
        }
    }
    if (monitor != null) {
        monitor.worked(1);
    }
    if (monitor != null) {
        monitor.done();
    }
    return stats;
}
Also used : LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ArrayList(java.util.ArrayList) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SQLStatement(org.pentaho.di.core.SQLStatement) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IOException(java.io.IOException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Aggregations

LogTableInterface (org.pentaho.di.core.logging.LogTableInterface)28 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)11 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 Database (org.pentaho.di.core.database.Database)8 RepositoryAttributeInterface (org.pentaho.di.repository.RepositoryAttributeInterface)7 JobEntryLogTable (org.pentaho.di.core.logging.JobEntryLogTable)6 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)6 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)5 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)5 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)5 MessageBox (org.eclipse.swt.widgets.MessageBox)4 NotePadMeta (org.pentaho.di.core.NotePadMeta)4 KettleValueException (org.pentaho.di.core.exception.KettleValueException)4 ChannelLogTable (org.pentaho.di.core.logging.ChannelLogTable)4 JobLogTable (org.pentaho.di.core.logging.JobLogTable)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3