Search in sources :

Example 1 with PartitionDatabaseMeta

use of org.pentaho.di.core.database.PartitionDatabaseMeta in project pentaho-kettle by pentaho.

the class DataHandler method loadAccessData.

// On Database type change
public void loadAccessData() {
    getControls();
    pushCache();
    Object key = connectionBox.getSelectedItem();
    // Nothing selected yet...
    if (key == null) {
        key = connectionMap.firstKey();
        connectionBox.setSelectedItem(key);
        return;
    }
    DatabaseInterface database = connectionMap.get(key);
    int[] acc = database.getAccessTypeList();
    Object accessKey = accessBox.getSelectedItem();
    accessBox.removeItems();
    for (int value : acc) {
        accessBox.addItem(DatabaseMeta.getAccessTypeDescLong(value));
    }
    // HACK: Need to force height of list control, as it does not behave
    // well when using relative layouting
    accessBox.setRows(accessBox.getRows());
    // May not exist for this connection type.
    if (accessKey != null) {
        // This check keeps the SwtListbox from complaining about a null value
        accessBox.setSelectedItem(accessKey);
    }
    // Last resort, set first as default
    if (accessBox.getSelectedItem() == null) {
        accessBox.setSelectedItem(DatabaseMeta.getAccessTypeDescLong(acc[0]));
    }
    Map<String, String> options = null;
    if (this.databaseMeta != null) {
        // Apply defaults to meta if set (only current db type will be displayed)
        this.databaseMeta.applyDefaultOptions(database);
        options = this.databaseMeta.getExtraOptions();
    } else {
        // Otherwise clear and display defaults directly
        clearOptionsData();
        options = database.getDefaultOptions();
    }
    setOptionsData(options);
    PartitionDatabaseMeta[] clusterInfo = null;
    if (this.databaseMeta != null) {
        clusterInfo = this.databaseMeta.getPartitioningInformation();
    }
    setClusterData(clusterInfo);
    popCache();
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta)

Example 2 with PartitionDatabaseMeta

use of org.pentaho.di.core.database.PartitionDatabaseMeta in project pentaho-kettle by pentaho.

the class DataHandler method setClusterData.

private void setClusterData(PartitionDatabaseMeta[] clusterInformation) {
    if (clusterParameterTree == null) {
        // there's nothing to do
        return;
    }
    clusterParameterTree.getRootChildren().removeAll();
    if ((clusterInformation != null) && (clusterParameterTree != null)) {
        for (int i = 0; i < clusterInformation.length; i++) {
            PartitionDatabaseMeta meta = clusterInformation[i];
            XulTreeRow row = clusterParameterTree.getRootChildren().addNewRow();
            row.addCellText(0, Const.NVL(meta.getPartitionId(), ""));
            row.addCellText(1, Const.NVL(meta.getHostname(), ""));
            row.addCellText(2, Const.NVL(meta.getPort(), ""));
            row.addCellText(3, Const.NVL(meta.getDatabaseName(), ""));
            row.addCellText(4, Const.NVL(meta.getUsername(), ""));
            row.addCellText(5, Const.NVL(meta.getPassword(), ""));
        }
    }
    // Add 5 blank rows if none are already there, otherwise, just add one.
    int numToAdd = 5;
    /*
     * if(clusterInformation != null && clusterInformation.length > 0){ numToAdd = 1; }
     */
    while (numToAdd-- > 0) {
        XulTreeRow row = clusterParameterTree.getRootChildren().addNewRow();
        // easy way of putting new cells in the row
        row.addCellText(0, "");
        row.addCellText(1, "");
        row.addCellText(2, "");
        row.addCellText(3, "");
        row.addCellText(4, "");
        row.addCellText(5, "");
    }
}
Also used : PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta) XulTreeRow(org.pentaho.ui.xul.containers.XulTreeRow)

Example 3 with PartitionDatabaseMeta

use of org.pentaho.di.core.database.PartitionDatabaseMeta in project pentaho-kettle by pentaho.

the class DataHandler method getInfo.

protected void getInfo(DatabaseMeta meta) {
    getControls();
    if (this.databaseMeta != null && this.databaseMeta != meta) {
        meta.initializeVariablesFrom(this.databaseMeta);
    }
    // Let's not remove any (default) options or attributes
    // We just need to display the correct ones for the database type below...
    // 
    // In fact, let's just clear the database port...
    // 
    // TODO: what about the port number?
    // Name:
    meta.setName(connectionNameBox.getValue());
    // Display Name: (PDI-12292)
    meta.setDisplayName(connectionNameBox.getValue());
    // Connection type:
    Object connection = connectionBox.getSelectedItem();
    if (connection != null) {
        meta.setDatabaseType((String) connection);
    }
    // Access type:
    Object access = accessBox.getSelectedItem();
    if (access != null) {
        meta.setAccessType(DatabaseMeta.getAccessType((String) access));
    }
    getConnectionSpecificInfo(meta);
    // Port number:
    if (portNumberBox != null) {
        meta.setDBPort(portNumberBox.getValue());
    }
    if (optionsParameterTree != null) {
        Object[][] values = optionsParameterTree.getValues();
        for (int i = 0; i < values.length; i++) {
            String parameter = (String) values[i][0];
            String value = (String) values[i][1];
            if (value == null) {
                value = "";
            }
            String dbType = meta.getPluginId();
            // Only if parameter are supplied, we will add to the map...
            if ((parameter != null) && (parameter.trim().length() > 0)) {
                if (value.trim().length() <= 0) {
                    value = DatabaseMeta.EMPTY_OPTIONS_STRING;
                }
                meta.addExtraOption(dbType, parameter, value);
            }
        }
    }
    if (supportBooleanDataType != null) {
        meta.setSupportsBooleanDataType(supportBooleanDataType.isChecked());
    }
    if (supportTimestampDataType != null) {
        meta.setSupportsTimestampDataType(supportTimestampDataType.isChecked());
    }
    if (quoteIdentifiersCheck != null) {
        meta.setQuoteAllFields(quoteIdentifiersCheck.isChecked());
    }
    if (lowerCaseIdentifiersCheck != null) {
        meta.setForcingIdentifiersToLowerCase(lowerCaseIdentifiersCheck.isChecked());
    }
    if (upperCaseIdentifiersCheck != null) {
        meta.setForcingIdentifiersToUpperCase(upperCaseIdentifiersCheck.isChecked());
    }
    if (preserveReservedCaseCheck != null) {
        meta.setPreserveReservedCase(preserveReservedCaseCheck.isChecked());
    }
    if (strictBigNumberInterpretaion != null && meta.getDatabaseInterface() instanceof OracleDatabaseMeta) {
        ((OracleDatabaseMeta) meta.getDatabaseInterface()).setStrictBigNumberInterpretation(strictBigNumberInterpretaion.isChecked());
    }
    if (preferredSchemaName != null) {
        meta.setPreferredSchemaName(preferredSchemaName.getValue());
    }
    if (sqlBox != null) {
        meta.setConnectSQL(sqlBox.getValue());
    }
    // Cluster panel settings
    if (clusteringCheck != null) {
        meta.setPartitioned(clusteringCheck.isChecked());
    }
    if ((clusterParameterTree != null) && (meta.isPartitioned())) {
        Object[][] values = clusterParameterTree.getValues();
        List<PartitionDatabaseMeta> pdms = new ArrayList<PartitionDatabaseMeta>();
        for (int i = 0; i < values.length; i++) {
            String partitionId = (String) values[i][0];
            if ((partitionId == null) || (partitionId.trim().length() <= 0)) {
                continue;
            }
            String hostname = (String) values[i][1];
            String port = (String) values[i][2];
            String dbName = (String) values[i][3];
            String username = (String) values[i][4];
            String password = (String) values[i][5];
            PartitionDatabaseMeta pdm = new PartitionDatabaseMeta(partitionId, hostname, port, dbName);
            pdm.setUsername(username);
            pdm.setPassword(password);
            pdms.add(pdm);
        }
        PartitionDatabaseMeta[] pdmArray = new PartitionDatabaseMeta[pdms.size()];
        meta.setPartitioningInformation(pdms.toArray(pdmArray));
    }
    if (poolingCheck != null) {
        meta.setUsingConnectionPool(poolingCheck.isChecked());
    }
    if (meta.isUsingConnectionPool()) {
        if (poolSizeBox != null) {
            try {
                int initialPoolSize = Integer.parseInt(poolSizeBox.getValue());
                meta.setInitialPoolSize(initialPoolSize);
            } catch (NumberFormatException e) {
            // TODO log exception and move on ...
            }
        }
        if (maxPoolSizeBox != null) {
            try {
                int maxPoolSize = Integer.parseInt(maxPoolSizeBox.getValue());
                meta.setMaximumPoolSize(maxPoolSize);
            } catch (NumberFormatException e) {
            // TODO log exception and move on ...
            }
        }
        if (poolParameterTree != null) {
            Object[][] values = poolParameterTree.getValues();
            Properties properties = new Properties();
            for (int i = 0; i < values.length; i++) {
                boolean isChecked = false;
                if (values[i][0] instanceof Boolean) {
                    isChecked = ((Boolean) values[i][0]).booleanValue();
                } else {
                    isChecked = Boolean.valueOf((String) values[i][0]);
                }
                if (!isChecked) {
                    continue;
                }
                String parameter = (String) values[i][1];
                String value = (String) values[i][2];
                if ((parameter != null) && (parameter.trim().length() > 0) && (value != null) && (value.trim().length() > 0)) {
                    properties.setProperty(parameter, value);
                }
            }
            meta.setConnectionPoolingProperties(properties);
        }
    }
}
Also used : OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) ArrayList(java.util.ArrayList) PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta) Properties(java.util.Properties)

Example 4 with PartitionDatabaseMeta

use of org.pentaho.di.core.database.PartitionDatabaseMeta in project pentaho-kettle by pentaho.

the class PartitionSchemaDialog method importPartitions.

protected void importPartitions() {
    List<String> partitionedDatabaseNames = new ArrayList<String>();
    for (int i = 0; i < databases.size(); i++) {
        DatabaseMeta databaseMeta = databases.get(i);
        if (databaseMeta.isPartitioned()) {
            partitionedDatabaseNames.add(databaseMeta.getName());
        }
    }
    String[] dbNames = partitionedDatabaseNames.toArray(new String[partitionedDatabaseNames.size()]);
    if (dbNames.length > 0) {
        EnterSelectionDialog dialog = new EnterSelectionDialog(shell, dbNames, BaseMessages.getString(PKG, "PartitionSchema.SelectDatabase"), BaseMessages.getString(PKG, "PartitionSchema.SelectPartitionnedDatabase"));
        String dbName = dialog.open();
        if (dbName != null) {
            DatabaseMeta databaseMeta = DatabaseMeta.findDatabase(databases, dbName);
            PartitionDatabaseMeta[] partitioningInformation = databaseMeta.getPartitioningInformation();
            if (partitioningInformation != null) {
                // Here we are...
                wPartitions.clearAll(false);
                for (int i = 0; i < partitioningInformation.length; i++) {
                    PartitionDatabaseMeta meta = partitioningInformation[i];
                    wPartitions.add(new String[] { meta.getPartitionId() });
                }
                wPartitions.removeEmptyRows();
                wPartitions.setRowNums();
                wPartitions.optWidth(true);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog)

Example 5 with PartitionDatabaseMeta

use of org.pentaho.di.core.database.PartitionDatabaseMeta in project pentaho-kettle by pentaho.

the class SQLEditor method exec.

private void exec() {
    DatabaseMeta ci = connection;
    if (ci == null) {
        return;
    }
    StringBuilder message = new StringBuilder();
    Database db = new Database(loggingObject, ci);
    boolean first = true;
    PartitionDatabaseMeta[] partitioningInformation = ci.getPartitioningInformation();
    for (int partitionNr = 0; first || (partitioningInformation != null && partitionNr < partitioningInformation.length); partitionNr++) {
        first = false;
        String partitionId = null;
        if (partitioningInformation != null && partitioningInformation.length > 0) {
            partitionId = partitioningInformation[partitionNr].getPartitionId();
        }
        try {
            db.connect(partitionId);
            String sqlScript = Utils.isEmpty(wScript.getSelectionText()) ? wScript.getText() : wScript.getSelectionText();
            // Multiple statements in the script need to be split into individual
            // executable statements
            statements = ci.getDatabaseInterface().getSqlScriptStatements(sqlScript + Const.CR);
            int nrstats = 0;
            for (SqlScriptStatement sql : statements) {
                if (sql.isQuery()) {
                    // A Query
                    log.logDetailed("launch SELECT statement: " + Const.CR + sql);
                    nrstats++;
                    try {
                        List<Object[]> rows = db.getRows(sql.getStatement(), 1000);
                        RowMetaInterface rowMeta = db.getReturnRowMeta();
                        if (rows.size() > 0) {
                            PreviewRowsDialog prd = new PreviewRowsDialog(shell, ci, SWT.NONE, BaseMessages.getString(PKG, "SQLEditor.ResultRows.Title", Integer.toString(nrstats)), rowMeta, rows);
                            prd.open();
                        } else {
                            MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                            mb.setMessage(BaseMessages.getString(PKG, "SQLEditor.NoRows.Message", sql));
                            mb.setText(BaseMessages.getString(PKG, "SQLEditor.NoRows.Title"));
                            mb.open();
                        }
                    } catch (KettleDatabaseException dbe) {
                        new ErrorDialog(shell, BaseMessages.getString(PKG, "SQLEditor.ErrorExecSQL.Title"), BaseMessages.getString(PKG, "SQLEditor.ErrorExecSQL.Message", sql), dbe);
                    }
                } else {
                    log.logDetailed("launch DDL statement: " + Const.CR + sql);
                    // A DDL statement
                    nrstats++;
                    int startLogLine = KettleLogStore.getLastBufferLineNr();
                    try {
                        log.logDetailed("Executing SQL: " + Const.CR + sql);
                        db.execStatement(sql.getStatement());
                        message.append(BaseMessages.getString(PKG, "SQLEditor.Log.SQLExecuted", sql));
                        message.append(Const.CR);
                        // Clear the database cache, in case we're using one...
                        if (dbcache != null) {
                            dbcache.clear(ci.getName());
                        }
                        // mark the statement in green in the dialog...
                        // 
                        sql.setOk(true);
                    } catch (Exception dbe) {
                        sql.setOk(false);
                        String error = BaseMessages.getString(PKG, "SQLEditor.Log.SQLExecError", sql, dbe.toString());
                        message.append(error).append(Const.CR);
                        ErrorDialog dialog = new ErrorDialog(shell, BaseMessages.getString(PKG, "SQLEditor.ErrorExecSQL.Title"), error, dbe, true);
                        if (dialog.isCancelled()) {
                            break;
                        }
                    } finally {
                        int endLogLine = KettleLogStore.getLastBufferLineNr();
                        sql.setLoggingText(KettleLogStore.getAppender().getLogBufferFromTo(db.getLogChannelId(), true, startLogLine, endLogLine).toString());
                        sql.setComplete(true);
                        refreshExecutionResults();
                    }
                }
            }
            message.append(BaseMessages.getString(PKG, "SQLEditor.Log.StatsExecuted", Integer.toString(nrstats)));
            if (partitionId != null) {
                message.append(BaseMessages.getString(PKG, "SQLEditor.Log.OnPartition", partitionId));
            }
            message.append(Const.CR);
        } catch (KettleDatabaseException dbe) {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            String error = BaseMessages.getString(PKG, "SQLEditor.Error.CouldNotConnect.Message", (connection == null ? "" : connection.getName()), dbe.getMessage());
            message.append(error).append(Const.CR);
            mb.setMessage(error);
            mb.setText(BaseMessages.getString(PKG, "SQLEditor.Error.CouldNotConnect.Title"));
            mb.open();
        } finally {
            db.disconnect();
            refreshExecutionResults();
        }
    }
    EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SQLEditor.Result.Title"), BaseMessages.getString(PKG, "SQLEditor.Result.Message"), message.toString(), true);
    dialog.open();
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) MessageBox(org.eclipse.swt.widgets.MessageBox) Database(org.pentaho.di.core.database.Database) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) SqlScriptStatement(org.pentaho.di.core.database.SqlScriptStatement)

Aggregations

PartitionDatabaseMeta (org.pentaho.di.core.database.PartitionDatabaseMeta)6 ArrayList (java.util.ArrayList)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 Properties (java.util.Properties)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Database (org.pentaho.di.core.database.Database)1 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)1 OracleDatabaseMeta (org.pentaho.di.core.database.OracleDatabaseMeta)1 SqlScriptStatement (org.pentaho.di.core.database.SqlScriptStatement)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)1 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)1 XulException (org.pentaho.ui.xul.XulException)1 XulTreeRow (org.pentaho.ui.xul.containers.XulTreeRow)1