use of org.knime.core.node.workflow.CredentialsProvider in project knime-core by knime.
the class DBReaderNodeModel method getResultTable.
/**
* @param exec {@link ExecutionContext} to create the table
* @param inData
* @param load
* @return the result table for the
* @throws CanceledExecutionException
* @throws SQLException
* @throws InvalidSettingsException
*/
protected BufferedDataTable getResultTable(final ExecutionContext exec, final PortObject[] inData, final DBReader load) throws CanceledExecutionException, SQLException, InvalidSettingsException {
CredentialsProvider cp = getCredentialsProvider();
final BufferedDataTable result = load.createTable(exec, cp);
return result;
}
use of org.knime.core.node.workflow.CredentialsProvider 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;
}
use of org.knime.core.node.workflow.CredentialsProvider 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.workflow.CredentialsProvider 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.workflow.CredentialsProvider 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