use of org.knime.core.node.port.database.DatabaseConnectionPortObject in project knime-core by knime.
the class JDBCConnectorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
DatabaseConnectionSettings s = new DatabaseConnectionSettings(m_settings);
// new behavior since 2.10
s.setRowIdsStartWithZero(true);
DatabaseConnectionPortObject dbPort = new DatabaseConnectionPortObject(new DatabaseConnectionPortObjectSpec(s));
try {
dbPort.getConnectionSettings(getCredentialsProvider()).execute(getCredentialsProvider(), conn -> {
return conn != null;
});
} catch (SQLException ex) {
Throwable cause = ExceptionUtils.getRootCause(ex);
if (cause == null) {
cause = ex;
}
if (cause instanceof ClassNotFoundException) {
cause = new Exception("Could not find driver class: " + cause.getMessage());
}
throw new SQLException("Could not create connection to database: " + cause.getMessage(), ex);
}
return new PortObject[] { dbPort };
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObject in project knime-core by knime.
the class DBTableCreatorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
exec.setMessage("Creating table");
final DatabaseConnectionPortObject dbConn = (DatabaseConnectionPortObject) inData[0];
final DatabaseConnectionSettings conn = dbConn.getConnectionSettings(getCredentialsProvider());
final DBTableCreator tableCreator = conn.getUtility().getTableCreator(m_config.getSchema(), getTableName(), m_config.isTempTable());
final List<DBColumn> columns = m_config.getColumns();
final List<DBKey> keys = m_config.getKeys();
tableCreator.createTable(conn, getCredentialsProvider(), m_config.ifNotExists(), columns.toArray(new DBColumn[columns.size()]), keys.toArray(new DBKey[keys.size()]), m_config.getAdditionalOptions());
pushFlowVariables(tableCreator.getSchema(), tableCreator.getTableName());
final String warning = tableCreator.getWarning();
if (!StringUtils.isBlank(warning)) {
setWarningMessage(warning);
}
return new PortObject[] { dbConn };
}
Aggregations