Search in sources :

Example 76 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class SQLInjectNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    exec.setMessage("Retrieving metadata from database");
    final String varName = m_flowVariableName.getStringValue();
    if (varName == null) {
        throw new InvalidSettingsException("No flow variable for the SQL statement selected");
    }
    final String sql = peekFlowVariableString(varName);
    if (sql == null) {
        throw new InvalidSettingsException("The selected flow variable is not assigned");
    }
    DatabaseConnectionPortObject dbIn = (DatabaseConnectionPortObject) inData[0];
    DatabaseConnectionSettings inSettings = dbIn.getConnectionSettings(getCredentialsProvider());
    // Attach the SQL query
    DatabaseQueryConnectionSettings outSettings = new DatabaseQueryConnectionSettings(inSettings, sql);
    // Probe the database to see how the result table looks like
    DBReader load = outSettings.getUtility().getReader(outSettings);
    DataTableSpec tableSpec = load.getDataTableSpec(getCredentialsProvider());
    DatabasePortObjectSpec outSpec = new DatabasePortObjectSpec(tableSpec, outSettings.createConnectionModel());
    return new PortObject[] { new DatabasePortObject(outSpec) };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) DBReader(org.knime.core.node.port.database.reader.DBReader) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 77 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class DBAutoBinnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setMessage("Retrieving metadata from database");
    final DatabasePortObject dbObject = (DatabasePortObject) inData[0];
    final DatabasePortObjectSpec inSpec = dbObject.getSpec();
    DatabaseQueryConnectionSettings connectionSettings = inSpec.getConnectionSettings(getCredentialsProvider());
    PMMLPortObject pmmlPortObject = createPMMLPortObject(inSpec, connectionSettings, exec);
    DatabasePortObject databasePortObject = createDatabasePortObject(inSpec, connectionSettings, pmmlPortObject);
    return new PortObject[] { databasePortObject, pmmlPortObject };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 78 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class DBApplyBinnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    PMMLPortObject pmmlPortObject = (PMMLPortObject) inData[0];
    DatabasePortObject databasePortObject = (DatabasePortObject) inData[1];
    DatabaseQueryConnectionSettings connectionSettings = databasePortObject.getConnectionSettings(getCredentialsProvider());
    return new PortObject[] { createDatabasePortObject(databasePortObject.getSpec(), connectionSettings, pmmlPortObject) };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 79 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class DBNumericBinnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setMessage("Retrieving metadata from database");
    checkDuplicateBinNames();
    final DatabasePortObject inDatabasePortObject = (DatabasePortObject) inData[0];
    final DatabasePortObjectSpec inDatabasePortObjectSpec = inDatabasePortObject.getSpec();
    DatabaseQueryConnectionSettings connectionSettings = inDatabasePortObject.getConnectionSettings(getCredentialsProvider());
    DataTableSpec outDataTableSpec = DBAutoBinner.createNewDataTableSpec(inDatabasePortObjectSpec.getDataTableSpec(), m_columnToAppended);
    PMMLPortObject outPMMLPortObject = createPMMLPortObject(inDatabasePortObjectSpec.getDataTableSpec(), outDataTableSpec);
    DBBinnerMaps binnerMaps = DBAutoBinner.intoBinnerMaps(outPMMLPortObject, inDatabasePortObjectSpec.getDataTableSpec());
    DatabasePortObjectSpec outDatabasePortObjectSpec = createDatabasePortObjectSpec(connectionSettings, inDatabasePortObjectSpec, binnerMaps);
    return new PortObject[] { new DatabasePortObject(outDatabasePortObjectSpec), outPMMLPortObject };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DBBinnerMaps(org.knime.base.node.io.database.binning.DBBinnerMaps) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 80 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class DBDropTableNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    exec.setMessage("Droping table");
    final DatabaseConnectionPortObject incomingConnection = (DatabaseConnectionPortObject) inObjects[0];
    final CredentialsProvider cp = getCredentialsProvider();
    final DatabaseConnectionSettings connSettings = incomingConnection.getConnectionSettings(cp);
    final DatabaseUtility dbUtility = connSettings.getUtility();
    final StatementManipulator manipulator = dbUtility.getStatementManipulator();
    final String table2Drop = m_tableName.getStringValue();
    try {
        if (m_failIfNotExists.getBooleanValue() || connSettings.execute(cp, conn -> {
            return dbUtility.tableExists(conn, table2Drop);
        })) {
            connSettings.execute(manipulator.dropTable(table2Drop, m_cascade.getBooleanValue()), cp);
            exec.setMessage("Table " + table2Drop + " sucessful droped");
        } else {
            exec.setMessage("Table " + table2Drop + " does not exist in db");
        }
    } catch (SQLException ex) {
        Throwable cause = ExceptionUtils.getRootCause(ex);
        if (cause == null) {
            cause = ex;
        }
        throw new InvalidSettingsException("Error while validating drop statement: " + cause.getMessage(), ex);
    }
    return inObjects;
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) NodeModel(org.knime.core.node.NodeModel) File(java.io.File) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) ExecutionContext(org.knime.core.node.ExecutionContext) SQLException(java.sql.SQLException) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) CredentialsProvider(org.knime.core.node.workflow.CredentialsProvider) StatementManipulator(org.knime.core.node.port.database.StatementManipulator) PortObject(org.knime.core.node.port.PortObject) PortType(org.knime.core.node.port.PortType) DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) SQLException(java.sql.SQLException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CredentialsProvider(org.knime.core.node.workflow.CredentialsProvider) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) StatementManipulator(org.knime.core.node.port.database.StatementManipulator)

Aggregations

PortObject (org.knime.core.node.port.PortObject)173 BufferedDataTable (org.knime.core.node.BufferedDataTable)97 DataTableSpec (org.knime.core.data.DataTableSpec)68 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)59 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)39 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)37 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)35 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)34 IOException (java.io.IOException)33 DataRow (org.knime.core.data.DataRow)25 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)24 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)23 DataCell (org.knime.core.data.DataCell)20 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)19 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)19 DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)18 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)16 ExecutionContext (org.knime.core.node.ExecutionContext)15 DataColumnSpec (org.knime.core.data.DataColumnSpec)14 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)13