use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec 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.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBTableCreatorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (inSpecs[0] == null && !(inSpecs[0] instanceof DatabaseConnectionPortObjectSpec)) {
throw new InvalidSettingsException("No valid database connection available.");
}
final DatabaseConnectionPortObjectSpec dbSpec = (DatabaseConnectionPortObjectSpec) inSpecs[0];
m_config.setTableSpec((DataTableSpec) inSpecs[1]);
final boolean isColumnsEmpty = m_config.getColumns().isEmpty();
if (m_config.getTableSpec() != null && (m_config.useDynamicSettings() || isColumnsEmpty)) {
m_config.loadColumnSettingsFromTableSpec(m_config.getTableSpec());
m_config.updateKeysWithDynamicSettings();
}
if (m_config.getTableSpec() == null && m_config.useDynamicSettings()) {
throw new InvalidSettingsException("Dynamic settings enabled but no input table available.");
}
if (isColumnsEmpty) {
throw new InvalidSettingsException("At least one column must be defined.");
}
final DatabaseConnectionSettings conn = dbSpec.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();
try {
tableCreator.validateSettings(m_config.ifNotExists(), columns.toArray(new DBColumn[columns.size()]), keys.toArray(new DBKey[keys.size()]), m_config.getAdditionalOptions());
} catch (Exception e) {
throw new InvalidSettingsException(e.getMessage());
}
pushFlowVariables(tableCreator.getSchema(), tableCreator.getTableName());
return new PortObjectSpec[] { dbSpec };
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBReaderDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
if (m_showConnectionPanel) {
m_connectionPane.loadSettingsFrom(settings, specs, getCredentialsProvider());
}
DatabaseQueryConnectionSettings s = new DatabaseQueryConnectionSettings();
try {
s.loadValidatedConnection(settings, getCredentialsProvider());
} catch (InvalidSettingsException ex) {
// use settings as they are
}
// statement
String statement = s.getQuery();
m_statmnt.setText(statement == null ? "SELECT * FROM " + DatabaseQueryConnectionSettings.TABLE_PLACEHOLDER : statement);
// select the table placeholder statement for easier replacements
selectPlaceHolder(m_statmnt, DatabaseQueryConnectionSettings.TABLE_PLACEHOLDER);
// update list of flow/workflow variables
m_listModelVars.removeAllElements();
for (Map.Entry<String, FlowVariable> e : getAvailableFlowVariables().entrySet()) {
m_listModelVars.addElement(e.getValue());
}
// read execute without configure checkbox
if (runWithoutConfigure()) {
m_configureBox.setSelected(!s.getValidateQuery());
}
m_upstreamConnectionSettings = null;
for (PortObjectSpec pos : specs) {
if (pos instanceof DatabaseConnectionPortObjectSpec) {
try {
m_upstreamConnectionSettings = ((DatabaseConnectionPortObjectSpec) pos).getConnectionSettings(getCredentialsProvider());
} catch (InvalidSettingsException ex) {
LOGGER.warn("Could not load database connection from upstream node: " + ex.getMessage(), ex);
}
}
}
if (m_upstreamConnectionSettings != null || !m_showConnectionPanel) {
m_connectionPane.setVisible(false);
} else {
m_connectionPane.setVisible(true);
}
}
Aggregations