use of org.knime.core.node.port.database.writer.DBWriter in project knime-core by knime.
the class DBDeleteRowsNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable inTable = (BufferedDataTable) inData[0];
final DataTableSpec inSpec = inTable.getSpec();
final String[] whereIncludes = m_configWHERE.applyTo(inSpec).getIncludes();
DatabaseConnectionSettings connSettings;
if ((inData.length > 1) && (inData[1] instanceof DatabaseConnectionPortObject)) {
connSettings = ((DatabaseConnectionPortObject) inData[1]).getConnectionSettings(getCredentialsProvider());
} else {
connSettings = m_loginConfig;
}
// DELETE rows
final int[] deleteStatus = new int[inTable.getRowCount()];
final DBWriter dbWriter = connSettings.getUtility().getWriter(connSettings);
final String errMsg = dbWriter.deleteRows(null, m_tableName, inTable, whereIncludes, deleteStatus, exec, getCredentialsProvider(), m_batchSize);
// set warning message generated during deleting rows
if (errMsg != null) {
setWarningMessage(errMsg);
}
// create out table with update column
final ColumnRearranger colre = createColumnRearranger(inTable.getSpec(), deleteStatus);
final BufferedDataTable outTable = exec.createColumnRearrangeTable(inTable, colre, exec.createSubProgress(1.0));
return new BufferedDataTable[] { outTable };
}
use of org.knime.core.node.port.database.writer.DBWriter in project knime-core by knime.
the class DBWriterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
exec.setProgress("Opening database connection to write data...");
DatabaseConnectionSettings connSettings;
if ((inData.length > 1) && (inData[1] instanceof DatabaseConnectionPortObject)) {
connSettings = ((DatabaseConnectionPortObject) inData[1]).getConnectionSettings(getCredentialsProvider());
} else {
connSettings = m_conn;
}
DBWriter writer = connSettings.getUtility().getWriter(connSettings);
BufferedDataTable inputTable = (BufferedDataTable) inData[0];
DataTableRowInput rowInput = new DataTableRowInput(inputTable);
// write entire data
final String error = writer.writeData(m_tableName, rowInput, inputTable.size(), m_append, exec, m_types, getCredentialsProvider(), m_batchSize, m_insertNullForMissingCols, m_failOnError);
// set error message generated during writing rows
if (error != null) {
super.setWarningMessage(error);
}
return new BufferedDataTable[0];
}
use of org.knime.core.node.port.database.writer.DBWriter in project knime-core by knime.
the class DBWriterNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
exec.setProgress("Opening database connection to write data...");
DatabaseConnectionSettings connSettings;
PortObject portObj = ((PortObjectInput) inputs[1]).getPortObject();
if (portObj != null && (portObj instanceof DatabaseConnectionPortObject)) {
connSettings = ((DatabaseConnectionPortObject) portObj).getConnectionSettings(getCredentialsProvider());
} else {
connSettings = m_conn;
}
DBWriter writer = connSettings.getUtility().getWriter(connSettings);
// write entire data
m_errorMessage = writer.writeData(m_tableName, (RowInput) inputs[0], -1, m_append, exec, m_types, getCredentialsProvider(), m_batchSize, m_insertNullForMissingCols);
}
};
}
use of org.knime.core.node.port.database.writer.DBWriter in project knime-core by knime.
the class DBUpdateNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable inTable = (BufferedDataTable) inData[0];
final DataTableSpec inSpec = inTable.getSpec();
final String[] setIncludes = m_configSET.applyTo(inSpec).getIncludes();
final String[] whereIncludes = m_configWHERE.applyTo(inSpec).getIncludes();
DatabaseConnectionSettings connSettings;
if ((inData.length > 1) && (inData[1] instanceof DatabaseConnectionPortObject)) {
connSettings = ((DatabaseConnectionPortObject) inData[1]).getConnectionSettings(getCredentialsProvider());
} else {
connSettings = m_loginConfig;
}
// UPDATE table
final int[] updateStatus = new int[inTable.getRowCount()];
final DBWriter dbWriter = connSettings.getUtility().getWriter(connSettings);
final String errMsg = dbWriter.updateTable(null, m_tableName, inTable, setIncludes, whereIncludes, updateStatus, exec, getCredentialsProvider(), m_batchSize);
// set warning message generated during updating rows
if (errMsg != null) {
setWarningMessage(errMsg);
}
// create out table with update column
final ColumnRearranger colre = createColumnRearranger(inTable.getSpec(), updateStatus);
final BufferedDataTable outTable = exec.createColumnRearrangeTable(inTable, colre, exec.createSubProgress(1.0));
return new BufferedDataTable[] { outTable };
}
Aggregations