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) };
}
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 };
}
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) };
}
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 };
}
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;
}
Aggregations