Search in sources :

Example 21 with LogTableField

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

the class TransHistoryDelegate method getHistoryData.

private boolean getHistoryData(final int index, final Mode mode) {
    final int BATCH_SIZE = Props.getInstance().getLinesInHistoryFetchSize();
    boolean moreRows = false;
    TransHistoryLogTab model = models[index];
    LogTableInterface logTable = model.logTable;
    // 
    if (transMeta != null && !Utils.isEmpty(transMeta.getName()) && logTable.isDefined()) {
        Database database = null;
        try {
            DatabaseMeta logConnection = logTable.getDatabaseMeta();
            // open a connection
            database = new Database(loggingObject, logConnection);
            database.shareVariablesWith(transMeta);
            database.connect();
            int queryLimit = 0;
            switch(mode) {
                case ALL:
                    model.batchCount = 0;
                    queryLimit = Props.getInstance().getMaxNrLinesInHistory();
                    break;
                case NEXT_BATCH:
                    model.batchCount++;
                    queryLimit = BATCH_SIZE * model.batchCount;
                    break;
                case INITIAL:
                    model.batchCount = 1;
                    queryLimit = BATCH_SIZE;
                    break;
                default:
                    break;
            }
            database.setQueryLimit(queryLimit);
            // First, we get the information out of the database table...
            // 
            String schemaTable = logTable.getQuotedSchemaTableCombination();
            StringBuilder sql = new StringBuilder("SELECT ");
            boolean first = true;
            for (LogTableField field : logTable.getFields()) {
                if (field.isEnabled() && field.isVisible()) {
                    if (!first) {
                        sql.append(", ");
                    }
                    first = false;
                    sql.append(logConnection.quoteField(field.getFieldName()));
                }
            }
            sql.append(" FROM ").append(schemaTable);
            RowMetaAndData params = new RowMetaAndData();
            // Do we need to limit the amount of data?
            // 
            LogTableField nameField = logTable.getNameField();
            LogTableField keyField = logTable.getKeyField();
            // CHECKSTYLE:LineLength:OFF
            if (nameField != null) {
                if (transMeta.isUsingAClusterSchema()) {
                    sql.append(" WHERE ").append(logConnection.quoteField(nameField.getFieldName())).append(" LIKE ?");
                    params.addValue(new ValueMetaString("transname_literal"), transMeta.getName());
                    sql.append(" OR    ").append(logConnection.quoteField(nameField.getFieldName())).append(" LIKE ?");
                    params.addValue(new ValueMetaString("transname_cluster"), transMeta.getName() + " (%");
                } else {
                    sql.append(" WHERE ").append(logConnection.quoteField(nameField.getFieldName())).append(" = ?");
                    params.addValue(new ValueMetaString("transname_literal"), transMeta.getName());
                }
            }
            if (keyField != null && keyField.isEnabled()) {
                sql.append(" ORDER BY ").append(logConnection.quoteField(keyField.getFieldName())).append(" DESC");
            }
            ResultSet resultSet = database.openQuery(sql.toString(), params.getRowMeta(), params.getData());
            List<Object[]> rows = new ArrayList<Object[]>();
            Object[] rowData = database.getRow(resultSet);
            int rowsFetched = 1;
            while (rowData != null) {
                rows.add(rowData);
                rowData = database.getRow(resultSet);
                rowsFetched++;
            }
            if (rowsFetched >= queryLimit) {
                moreRows = true;
            }
            database.closeQuery(resultSet);
            model.rows = rows;
        } catch (Exception e) {
            LogChannel.GENERAL.logError("Unable to get rows of data from logging table " + model.logTable, e);
            model.rows = new ArrayList<Object[]>();
        } finally {
            if (database != null) {
                database.disconnect();
            }
        }
    } else {
        model.rows = new ArrayList<Object[]>();
    }
    return moreRows;
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleValueException(org.pentaho.di.core.exception.KettleValueException) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) Database(org.pentaho.di.core.database.Database) ResultSet(java.sql.ResultSet)

Example 22 with LogTableField

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

the class TransDialog method showPerformanceLogTableOptions.

private void showPerformanceLogTableOptions() {
    previousLogTableIndex = LOG_INDEX_PERFORMANCE;
    addDBSchemaTableLogOptions(performanceLogTable);
    // Log interval...
    // 
    Label wlLogInterval = new Label(wLogOptionsComposite, SWT.RIGHT);
    wlLogInterval.setText(BaseMessages.getString(PKG, "TransDialog.LogInterval.Label"));
    props.setLook(wlLogInterval);
    FormData fdlLogInterval = new FormData();
    fdlLogInterval.left = new FormAttachment(0, 0);
    fdlLogInterval.right = new FormAttachment(middle, -margin);
    fdlLogInterval.top = new FormAttachment(wLogTable, margin);
    wlLogInterval.setLayoutData(fdlLogInterval);
    wLogInterval = new TextVar(transMeta, wLogOptionsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wLogInterval);
    wLogInterval.addModifyListener(lsMod);
    FormData fdLogInterval = new FormData();
    fdLogInterval.left = new FormAttachment(middle, 0);
    fdLogInterval.top = new FormAttachment(wLogTable, margin);
    fdLogInterval.right = new FormAttachment(100, 0);
    wLogInterval.setLayoutData(fdLogInterval);
    wLogInterval.setText(Const.NVL(performanceLogTable.getLogInterval(), ""));
    // The log timeout in days
    // 
    Label wlLogTimeout = new Label(wLogOptionsComposite, SWT.RIGHT);
    wlLogTimeout.setText(BaseMessages.getString(PKG, "TransDialog.LogTimeout.Label"));
    wlLogTimeout.setToolTipText(BaseMessages.getString(PKG, "TransDialog.LogTimeout.Tooltip"));
    props.setLook(wlLogTimeout);
    FormData fdlLogTimeout = new FormData();
    fdlLogTimeout.left = new FormAttachment(0, 0);
    fdlLogTimeout.right = new FormAttachment(middle, -margin);
    fdlLogTimeout.top = new FormAttachment(wLogInterval, margin);
    wlLogTimeout.setLayoutData(fdlLogTimeout);
    wLogTimeout = new TextVar(transMeta, wLogOptionsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogTimeout.setToolTipText(BaseMessages.getString(PKG, "TransDialog.LogTimeout.Tooltip"));
    props.setLook(wLogTimeout);
    wLogTimeout.addModifyListener(lsMod);
    FormData fdLogTimeout = new FormData();
    fdLogTimeout.left = new FormAttachment(middle, 0);
    fdLogTimeout.top = new FormAttachment(wLogInterval, margin);
    fdLogTimeout.right = new FormAttachment(100, 0);
    wLogTimeout.setLayoutData(fdLogTimeout);
    wLogTimeout.setText(Const.NVL(performanceLogTable.getTimeoutInDays(), ""));
    // Add the fields grid...
    // 
    Label wlFields = new Label(wLogOptionsComposite, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.Label"));
    props.setLook(wlFields);
    FormData fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wLogTimeout, margin * 2);
    wlFields.setLayoutData(fdlFields);
    final java.util.List<LogTableField> fields = performanceLogTable.getFields();
    final int nrRows = fields.size();
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.FieldName"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.Description"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    FieldDisabledListener disabledListener = new FieldDisabledListener() {

        public boolean isFieldDisabled(int rowNr) {
            if (rowNr >= 0 && rowNr < fields.size()) {
                LogTableField field = fields.get(rowNr);
                return field.isSubjectAllowed();
            } else {
                return true;
            }
        }
    };
    colinf[1].setDisabledListener(disabledListener);
    wOptionFields = new TableView(transMeta, wLogOptionsComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK, colinf, nrRows, true, lsMod, props);
    wOptionFields.setSortable(false);
    for (int i = 0; i < fields.size(); i++) {
        LogTableField field = fields.get(i);
        TableItem item = wOptionFields.table.getItem(i);
        item.setChecked(field.isEnabled());
        item.setText(new String[] { "", Const.NVL(field.getFieldName(), ""), Const.NVL(field.getDescription(), "") });
    }
    wOptionFields.table.getColumn(0).setText(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.Enabled"));
    FormData fdOptionFields = new FormData();
    fdOptionFields.left = new FormAttachment(0, 0);
    fdOptionFields.top = new FormAttachment(wlFields, margin);
    fdOptionFields.right = new FormAttachment(100, 0);
    fdOptionFields.bottom = new FormAttachment(100, 0);
    wOptionFields.setLayoutData(fdOptionFields);
    wOptionFields.optWidth(true);
    wOptionFields.layout();
    wLogOptionsComposite.layout(true, true);
    wLogComp.layout(true, true);
}
Also used : FormData(org.eclipse.swt.layout.FormData) LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) FieldDisabledListener(org.pentaho.di.ui.core.widget.FieldDisabledListener) TextVar(org.pentaho.di.ui.core.widget.TextVar) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 23 with LogTableField

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

the class TransDialog method showMetricsLogTableOptions.

private void showMetricsLogTableOptions() {
    previousLogTableIndex = LOG_INDEX_METRICS;
    addDBSchemaTableLogOptions(metricsLogTable);
    // The log timeout in days
    // 
    Label wlLogTimeout = new Label(wLogOptionsComposite, SWT.RIGHT);
    wlLogTimeout.setText(BaseMessages.getString(PKG, "TransDialog.LogTimeout.Label"));
    wlLogTimeout.setToolTipText(BaseMessages.getString(PKG, "TransDialog.LogTimeout.Tooltip"));
    props.setLook(wlLogTimeout);
    FormData fdlLogTimeout = new FormData();
    fdlLogTimeout.left = new FormAttachment(0, 0);
    fdlLogTimeout.right = new FormAttachment(middle, -margin);
    fdlLogTimeout.top = new FormAttachment(wLogTable, margin);
    wlLogTimeout.setLayoutData(fdlLogTimeout);
    wLogTimeout = new TextVar(transMeta, wLogOptionsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogTimeout.setToolTipText(BaseMessages.getString(PKG, "TransDialog.LogTimeout.Tooltip"));
    props.setLook(wLogTimeout);
    wLogTimeout.addModifyListener(lsMod);
    FormData fdLogTimeout = new FormData();
    fdLogTimeout.left = new FormAttachment(middle, 0);
    fdLogTimeout.top = new FormAttachment(wLogTable, margin);
    fdLogTimeout.right = new FormAttachment(100, 0);
    wLogTimeout.setLayoutData(fdLogTimeout);
    wLogTimeout.setText(Const.NVL(metricsLogTable.getTimeoutInDays(), ""));
    // Add the fields grid...
    // 
    Label wlFields = new Label(wLogOptionsComposite, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.Label"));
    props.setLook(wlFields);
    FormData fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wLogTimeout, margin * 2);
    wlFields.setLayoutData(fdlFields);
    final java.util.List<LogTableField> fields = metricsLogTable.getFields();
    final int nrRows = fields.size();
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.FieldName"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.Description"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    FieldDisabledListener disabledListener = new FieldDisabledListener() {

        public boolean isFieldDisabled(int rowNr) {
            if (rowNr >= 0 && rowNr < fields.size()) {
                LogTableField field = fields.get(rowNr);
                return field.isSubjectAllowed();
            } else {
                return true;
            }
        }
    };
    colinf[1].setDisabledListener(disabledListener);
    wOptionFields = new TableView(transMeta, wLogOptionsComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK, colinf, nrRows, true, lsMod, props);
    wOptionFields.setSortable(false);
    for (int i = 0; i < fields.size(); i++) {
        LogTableField field = fields.get(i);
        TableItem item = wOptionFields.table.getItem(i);
        item.setChecked(field.isEnabled());
        item.setText(new String[] { "", Const.NVL(field.getFieldName(), ""), Const.NVL(field.getDescription(), "") });
    }
    wOptionFields.table.getColumn(0).setText(BaseMessages.getString(PKG, "TransDialog.TransLogTable.Fields.Enabled"));
    FormData fdOptionFields = new FormData();
    fdOptionFields.left = new FormAttachment(0, 0);
    fdOptionFields.top = new FormAttachment(wlFields, margin);
    fdOptionFields.right = new FormAttachment(100, 0);
    fdOptionFields.bottom = new FormAttachment(100, 0);
    wOptionFields.setLayoutData(fdOptionFields);
    wOptionFields.optWidth(true);
    wOptionFields.layout();
    wLogOptionsComposite.layout(true, true);
    wLogComp.layout(true, true);
}
Also used : FormData(org.eclipse.swt.layout.FormData) LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) FieldDisabledListener(org.pentaho.di.ui.core.widget.FieldDisabledListener) TextVar(org.pentaho.di.ui.core.widget.TextVar) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 24 with LogTableField

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

the class TransDialog method getChannelLogTableOptions.

private void getChannelLogTableOptions() {
    if (previousLogTableIndex == LOG_INDEX_CHANNEL) {
        // The connection...
        // 
        channelLogTable.setConnectionName(wLogconnection.getText());
        channelLogTable.setSchemaName(wLogSchema.getText());
        channelLogTable.setTableName(wLogTable.getText());
        channelLogTable.setTimeoutInDays(wLogTimeout.getText());
        for (int i = 0; i < channelLogTable.getFields().size(); i++) {
            TableItem item = wOptionFields.table.getItem(i);
            LogTableField field = channelLogTable.getFields().get(i);
            field.setEnabled(item.getChecked());
            field.setFieldName(item.getText(1));
        }
    }
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem)

Example 25 with LogTableField

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

the class JobHistoryDelegate method getHistoryData.

private boolean getHistoryData(final int index, final Mode mode) {
    final int BATCH_SIZE = Props.getInstance().getLinesInHistoryFetchSize();
    boolean moreRows = false;
    JobHistoryLogTab model = models[index];
    LogTableInterface logTable = model.logTable;
    // 
    if (jobMeta != null && !Utils.isEmpty(jobMeta.getName()) && logTable.isDefined()) {
        Database database = null;
        try {
            DatabaseMeta logConnection = logTable.getDatabaseMeta();
            // open a connection
            database = new Database(loggingObject, logConnection);
            database.shareVariablesWith(jobMeta);
            database.connect();
            int queryLimit = 0;
            switch(mode) {
                case ALL:
                    model.batchCount = 0;
                    queryLimit = Props.getInstance().getMaxNrLinesInHistory();
                    break;
                case NEXT_BATCH:
                    model.batchCount++;
                    queryLimit = BATCH_SIZE * model.batchCount;
                    break;
                case INITIAL:
                    model.batchCount = 1;
                    queryLimit = BATCH_SIZE;
                    break;
                default:
                    break;
            }
            database.setQueryLimit(queryLimit);
            // First, we get the information out of the database table...
            // 
            String schemaTable = logTable.getQuotedSchemaTableCombination();
            StringBuilder sql = new StringBuilder("SELECT ");
            boolean first = true;
            for (LogTableField field : logTable.getFields()) {
                if (field.isEnabled() && field.isVisible()) {
                    if (!first) {
                        sql.append(", ");
                    }
                    first = false;
                    sql.append(logConnection.quoteField(field.getFieldName()));
                }
            }
            sql.append(" FROM ").append(schemaTable);
            RowMetaAndData params = new RowMetaAndData();
            // Do we need to limit the amount of data?
            // 
            LogTableField nameField = logTable.getNameField();
            LogTableField keyField = logTable.getKeyField();
            if (nameField != null) {
                sql.append(" WHERE ").append(logConnection.quoteField(nameField.getFieldName())).append(" LIKE ?");
                params.addValue(new ValueMetaString("transname_literal"), jobMeta.getName());
            }
            if (keyField != null && keyField.isEnabled()) {
                sql.append(" ORDER BY ").append(logConnection.quoteField(keyField.getFieldName())).append(" DESC");
            }
            ResultSet resultSet = database.openQuery(sql.toString(), params.getRowMeta(), params.getData());
            List<Object[]> rows = new ArrayList<Object[]>();
            Object[] rowData = database.getRow(resultSet);
            int rowsFetched = 1;
            while (rowData != null) {
                rows.add(rowData);
                rowData = database.getRow(resultSet);
                rowsFetched++;
            }
            if (rowsFetched >= queryLimit) {
                moreRows = true;
            }
            database.closeQuery(resultSet);
            models[index].rows = rows;
        } catch (Exception e) {
            LogChannel.GENERAL.logError("Unable to get rows of data from logging table " + models[index].logTable, e);
            models[index].rows = new ArrayList<Object[]>();
        } finally {
            if (database != null) {
                database.disconnect();
            }
        }
    } else {
        models[index].rows = new ArrayList<Object[]>();
    }
    return moreRows;
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleValueException(org.pentaho.di.core.exception.KettleValueException) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) Database(org.pentaho.di.core.database.Database) ResultSet(java.sql.ResultSet)

Aggregations

LogTableField (org.pentaho.di.core.logging.LogTableField)25 TableItem (org.eclipse.swt.widgets.TableItem)18 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)8 FormData (org.eclipse.swt.layout.FormData)8 Label (org.eclipse.swt.widgets.Label)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 TextVar (org.pentaho.di.ui.core.widget.TextVar)8 FieldDisabledListener (org.pentaho.di.ui.core.widget.FieldDisabledListener)7 KettleValueException (org.pentaho.di.core.exception.KettleValueException)6 TableView (org.pentaho.di.ui.core.widget.TableView)5 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 Database (org.pentaho.di.core.database.Database)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Text (org.eclipse.swt.widgets.Text)2 KettleException (org.pentaho.di.core.exception.KettleException)2 LogStatus (org.pentaho.di.core.logging.LogStatus)2 LogTableInterface (org.pentaho.di.core.logging.LogTableInterface)2