/** * Assert that mandatory properties are set. * * @throws IllegalArgumentException if either data source or SQL properties * not set. */ @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(sql, "The SQL query must be provided"); Assert.notNull(rowMapper, "RowMapper must be provided"); }
protected void initializeConnection() { Assert.state(getDataSource() != null, "DataSource must not be null."); try { if (useSharedExtendedConnection) { if (!(getDataSource() instanceof ExtendedConnectionDataSourceProxy)) { throw new InvalidDataAccessApiUsageException( "You must use a ExtendedConnectionDataSourceProxy for the dataSource when " + "useSharedExtendedConnection is set to true."); } this.con = DataSourceUtils.getConnection(dataSource); ((ExtendedConnectionDataSourceProxy)dataSource).startCloseSuppression(this.con); } else { this.con = dataSource.getConnection(); } this.initialConnectionAutoCommit = this.con.getAutoCommit(); if (this.connectionAutoCommit != null && this.con.getAutoCommit() != this.connectionAutoCommit) { this.con.setAutoCommit(this.connectionAutoCommit); } } catch (SQLException se) { close(); throw getExceptionTranslator().translate("Executing query", getSql(), se); } }
/** * Read next row and map it to item, verify cursor position if * {@link #setVerifyCursorPosition(boolean)} is true. */ @Override protected T doRead() throws Exception { if (rs == null) { throw new ReaderNotOpenException("Reader must be open before it can be read."); } try { if (!rs.next()) { return null; } int currentRow = getCurrentItemCount(); T item = readCursor(rs, currentRow); verifyCursorPosition(currentRow); return item; } catch (SQLException se) { throw getExceptionTranslator().translate("Attempt to process next row failed", getSql(), se); } }
/** * Execute the statement to open the cursor. */ @Override protected void doOpen() throws Exception { Assert.state(!initialized, "Stream is already initialized. Close before re-opening."); Assert.isNull(rs, "ResultSet still open! Close before re-opening."); initializeConnection(); openCursor(con); initialized = true; }
/** * Moves the cursor in the ResultSet to the position specified by the row * parameter by traversing the ResultSet. * @param row The index of the row to move to */ private void moveCursorToRow(int row) { try { int count = 0; while (row != count && rs.next()) { count++; } } catch (SQLException se) { throw getExceptionTranslator().translate("Attempted to move ResultSet to last committed row", getSql(), se); } }
/** * Use {@link ResultSet#absolute(int)} if possible, otherwise scroll by * calling {@link ResultSet#next()}. */ @Override protected void jumpToItem(int itemIndex) throws Exception { if (driverSupportsAbsolute) { try { rs.absolute(itemIndex); } catch (SQLException e) { // Driver does not support rs.absolute(int) revert to // traversing ResultSet log.warn("The JDBC driver does not appear to support ResultSet.absolute(). Consider" + " reverting to the default behavior setting the driverSupportsAbsolute to false", e); moveCursorToRow(itemIndex); } } else { moveCursorToRow(itemIndex); } }
/** * Close the cursor and database connection. Make call to cleanupOnClose so sub classes can cleanup * any resources they have allocated. */ @Override protected void doClose() throws Exception { initialized = false; JdbcUtils.closeResultSet(this.rs); rs = null; cleanupOnClose(); if(this.con != null) { this.con.setAutoCommit(this.initialConnectionAutoCommit); } if (useSharedExtendedConnection && dataSource instanceof ExtendedConnectionDataSourceProxy) { ((ExtendedConnectionDataSourceProxy)dataSource).stopCloseSuppression(this.con); if (!TransactionSynchronizationManager.isActualTransactionActive()) { DataSourceUtils.releaseConnection(con, dataSource); } } else { JdbcUtils.closeConnection(this.con); } }
/** * Execute the statement to open the cursor. */ @Override protected void doOpen() throws Exception { Assert.state(!initialized, "Stream is already initialized. Close before re-opening."); Assert.isNull(rs, "ResultSet still open! Close before re-opening."); initializeConnection(); openCursor(con); initialized = true; }
/** * Moves the cursor in the ResultSet to the position specified by the row * parameter by traversing the ResultSet. * @param row The index of the row to move to */ private void moveCursorToRow(int row) { try { int count = 0; while (row != count && rs.next()) { count++; } } catch (SQLException se) { throw getExceptionTranslator().translate("Attempted to move ResultSet to last committed row", getSql(), se); } }
/** * Use {@link ResultSet#absolute(int)} if possible, otherwise scroll by * calling {@link ResultSet#next()}. */ @Override protected void jumpToItem(int itemIndex) throws Exception { if (driverSupportsAbsolute) { try { rs.absolute(itemIndex); } catch (SQLException e) { // Driver does not support rs.absolute(int) revert to // traversing ResultSet log.warn("The JDBC driver does not appear to support ResultSet.absolute(). Consider" + " reverting to the default behavior setting the driverSupportsAbsolute to false", e); moveCursorToRow(itemIndex); } } else { moveCursorToRow(itemIndex); } }
/** * Close the cursor and database connection. Make call to cleanupOnClose so sub classes can cleanup * any resources they have allocated. */ @Override protected void doClose() throws Exception { initialized = false; JdbcUtils.closeResultSet(this.rs); rs = null; cleanupOnClose(); if(this.con != null) { this.con.setAutoCommit(this.initialConnectionAutoCommit); } if (useSharedExtendedConnection && dataSource instanceof ExtendedConnectionDataSourceProxy) { ((ExtendedConnectionDataSourceProxy)dataSource).stopCloseSuppression(this.con); if (!TransactionSynchronizationManager.isActualTransactionActive()) { DataSourceUtils.releaseConnection(con, dataSource); } } else { JdbcUtils.closeConnection(this.con); } }
/** * Read next row and map it to item, verify cursor position if * {@link #setVerifyCursorPosition(boolean)} is true. */ @Override protected T doRead() throws Exception { if (rs == null) { throw new ReaderNotOpenException("Reader must be open before it can be read."); } try { if (!rs.next()) { return null; } int currentRow = getCurrentItemCount(); T item = readCursor(rs, currentRow); verifyCursorPosition(currentRow); return item; } catch (SQLException se) { throw getExceptionTranslator().translate("Attempt to process next row failed", getSql(), se); } }
protected void initializeConnection() { Assert.state(getDataSource() != null, "DataSource must not be null."); try { if (useSharedExtendedConnection) { if (!(getDataSource() instanceof ExtendedConnectionDataSourceProxy)) { throw new InvalidDataAccessApiUsageException( "You must use a ExtendedConnectionDataSourceProxy for the dataSource when " + "useSharedExtendedConnection is set to true."); } this.con = DataSourceUtils.getConnection(dataSource); ((ExtendedConnectionDataSourceProxy)dataSource).startCloseSuppression(this.con); } else { this.con = dataSource.getConnection(); } this.initialConnectionAutoCommit = this.con.getAutoCommit(); if (this.connectionAutoCommit != null && this.con.getAutoCommit() != this.connectionAutoCommit) { this.con.setAutoCommit(this.connectionAutoCommit); } } catch (SQLException se) { close(); throw getExceptionTranslator().translate("Executing query", getSql(), se); } }
/** * Assert that mandatory properties are set. * * @throws IllegalArgumentException if either data source or SQL properties * not set. */ @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(procedureName, "The name of the stored procedure must be provided"); Assert.notNull(rowMapper, "RowMapper must be provided"); }
/** * Assert that mandatory properties are set. * * @throws IllegalArgumentException if either data source or sql properties * not set. */ @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(sql, "The SQL query must be provided"); Assert.notNull(rowMapper, "RowMapper must be provided"); }
/** * Assert that mandatory properties are set. * * @throws IllegalArgumentException if either data source or SQL properties * not set. */ @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(procedureName, "The name of the stored procedure must be provided"); Assert.notNull(rowMapper, "RowMapper must be provided"); }
/** * Assert that mandatory properties are set. * * @throws IllegalArgumentException if either data source or SQL properties * not set. */ @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(sql, "The SQL query must be provided"); Assert.notNull(rowMapper, "RowMapper must be provided"); }