use of org.knime.core.node.port.database.DatabasePortObject in project knime-core by knime.
the class DBQueryNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
DatabasePortObject dbObj = (DatabasePortObject) inData[0];
CredentialsProvider cp = getCredentialsProvider();
DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(cp);
String newQuery = createQuery(conn.getQuery());
conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
DBReader load = conn.getUtility().getReader(conn);
DataTableSpec outSpec = load.getDataTableSpec(cp);
DatabasePortObjectSpec dbSpec = new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
DatabasePortObject outObj = new DatabasePortObject(dbSpec);
return new PortObject[] { outObj };
}
use of org.knime.core.node.port.database.DatabasePortObject in project knime-core by knime.
the class DBQueryNodeModel2 method execute.
/**
* {@inheritDoc}
*/
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
DatabasePortObject dbObj = (DatabasePortObject) inData[0];
DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
String newQuery = parseQuery(conn.getQuery());
conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
DBReader load = conn.getUtility().getReader(conn);
DataTableSpec outSpec = load.getDataTableSpec(getCredentialsProvider());
DatabasePortObjectSpec dbSpec = new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
DatabasePortObject outObj = new DatabasePortObject(dbSpec);
return new PortObject[] { outObj };
}
use of org.knime.core.node.port.database.DatabasePortObject in project knime-core by knime.
the class DBColumnFilterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
DatabasePortObject dbObj = (DatabasePortObject) inData[0];
DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
ColumnRearranger colre = new ColumnRearranger(dbObj.getSpec().getDataTableSpec());
colre.keepOnly(m_filter.getIncludeList().toArray(new String[0]));
final DataTableSpec resultSpec = colre.createSpec();
final String newQuery = createQuery(conn, resultSpec);
conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
DatabasePortObjectSpec outSpec = new DatabasePortObjectSpec(resultSpec, conn.createConnectionModel());
DatabasePortObject outObj = new DatabasePortObject(outSpec);
return new PortObject[] { outObj };
}
use of org.knime.core.node.port.database.DatabasePortObject in project knime-core by knime.
the class DBConnectionWriterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
DatabasePortObject dbObj = (DatabasePortObject) inData[0];
exec.setProgress("Opening database connection...");
String tableName = m_tableName.getStringValue();
DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
CredentialsProvider cp = getCredentialsProvider();
final StatementManipulator statementManipulator = conn.getUtility().getStatementManipulator();
try {
// use the statement manipulator to create the drop table statement
conn.execute(statementManipulator.dropTable(tableName, false), cp);
} catch (Exception e) {
// suppress exception thrown when table does not exist in database
}
String[] stmts = statementManipulator.createTableAsSelect(tableName, conn.getQuery());
for (final String stmt : stmts) {
conn.execute(stmt, cp);
}
return new BufferedDataTable[0];
}
use of org.knime.core.node.port.database.DatabasePortObject in project knime-core by knime.
the class DBConnectionNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
exec.setProgress("Opening database connection...");
DatabasePortObject dbObj = (DatabasePortObject) inData[0];
DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
final DBReader reader = conn.getUtility().getReader(conn);
// final DatabaseReaderConnection load = new DatabaseReaderConnection(conn);
exec.setProgress("Reading data from database...");
CredentialsProvider cp = getCredentialsProvider();
return new BufferedDataTable[] { reader.createTable(exec, cp, m_useDbRowId.getBooleanValue()) };
}
Aggregations