use of org.knime.core.data.blob.BinaryObjectCellFactory in project knime-core by knime.
the class DatabaseReaderConnection method createRowIteratorConnection.
/**
* Read data from database using a {@link RowIterator}.
* @param exec used for progress info
* @param cp {@link CredentialsProvider} providing user/password
* @param useDbRowId <code>true</code> if the row id returned by the database should be used to generate the
* KNIME row id
* @return an object that represents the open database connection. The individual entries are accessible by means of a {@link RowIterator}.
* @throws CanceledExecutionException if canceled in between
* @throws SQLException if the connection could not be opened
* @since 3.1
*/
public RowIteratorConnection createRowIteratorConnection(final ExecutionContext exec, final CredentialsProvider cp, final boolean useDbRowId) throws SQLException {
if (m_blobFactory == null) {
m_blobFactory = new BinaryObjectCellFactory(exec);
}
// synchronized (m_conn.syncConnection(conn)) {
return m_conn.execute(cp, conn -> {
exec.setMessage("Start reading rows from database...");
// remember auto-commit flag
final boolean autoCommit = conn.getAutoCommit();
final Statement stmt = initStatement(cp, conn);
int fetchsize = (DatabaseConnectionSettings.FETCH_SIZE != null) ? DatabaseConnectionSettings.FETCH_SIZE : -1;
m_conn.getUtility().getStatementManipulator().setFetchSize(stmt, fetchsize);
final String[] oQueries = m_conn.getQuery().split(SQL_QUERY_SEPARATOR);
// execute all except the last query
for (int i = 0; i < oQueries.length - 1; i++) {
LOGGER.debug("Executing SQL statement as execute: " + oQueries[i]);
stmt.execute(oQueries[i]);
}
final String selectQuery = oQueries[oQueries.length - 1];
LOGGER.debug("Executing SQL statement as executeQuery: " + selectQuery);
final ResultSet result = stmt.executeQuery(selectQuery);
LOGGER.debug("Reading meta data from database ResultSet...");
m_spec = createTableSpec(result.getMetaData());
LOGGER.debug("Parsing database ResultSet...");
return new RowIteratorConnection(conn, stmt, result, m_spec, autoCommit, useDbRowId);
});
}
Aggregations