@Override public void setMaxRows(int max) throws SQLException { rawStatement.setMaxRows(max); }
@Override public void setMaxRows(int max) throws SQLException { rawStatement.setMaxRows(max); }
/** {@inheritDoc} */ @Override public void setMaxRows(int max) throws SQLException { delegate.setMaxRows(max); }
@Override public void beforeExecution(final PreparedStatement stmt, final StatementContext ctx) throws SQLException { stmt.setMaxRows(maxRows); } };
@Override public String doInConnection(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement("some SQL"); ps.setFetchSize(10); ps.setMaxRows(20); ps.close(); return "test"; } });
public Long getMaxDirtyVectorClock(String machineName) { try (PreparedStatement preparedStatement = getStatement("databaseversion.select.dirty.getMaxDirtyVectorClock.sql")) { preparedStatement.setMaxRows(1); preparedStatement.setString(1, machineName); try (ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { return resultSet.getLong("logicaltime"); } } return null; } catch (SQLException e) { throw new RuntimeException(e); } }
public DatabaseVersionHeader getLastDatabaseVersionHeader() { try (PreparedStatement preparedStatement = getStatement("databaseversion.select.master.getLastDatabaseVersionHeader.sql")) { preparedStatement.setMaxRows(1); try (ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { DatabaseVersionHeader databaseVersionHeader = createDatabaseVersionHeaderFromRow(resultSet); return databaseVersionHeader; } } return null; } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException { if ( LimitHelper.hasMaxRows( selection ) ) { int maxRows = selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ); // Use Integer.MAX_VALUE on overflow if ( maxRows < 0 ) { statement.setMaxRows( Integer.MAX_VALUE ); } else { statement.setMaxRows( maxRows ); } } } }
/** * Note: Also selects versions marked as {@link DatabaseVersionStatus#DIRTY DIRTY} */ public Map<FileHistoryId, PartialFileHistory> getFileHistoriesWithFileVersions(VectorClock databaseVersionVectorClock, int maxCount) { try (PreparedStatement preparedStatement = getStatement("filehistory.select.all.getFileHistoriesWithFileVersionsByVectorClock.sql")) { preparedStatement.setString(1, databaseVersionVectorClock.toString()); if (maxCount > 0) { preparedStatement.setMaxRows(maxCount); } try (ResultSet resultSet = preparedStatement.executeQuery()) { return createFileHistoriesFromResult(resultSet); } } catch (SQLException e) { throw new RuntimeException(e); } }
ps.setMaxRows(maxCount);
/** * Prepare the given JDBC Statement (or PreparedStatement or * CallableStatement), applying statement settings such as fetch size, max * rows, and query timeout. @param stmt the JDBC Statement to prepare * * @param stmt {@link java.sql.PreparedStatement} to be configured * * @throws SQLException if interactions with provided stmt fail * * @see #setFetchSize * @see #setMaxRows * @see #setQueryTimeout */ protected void applyStatementSettings(PreparedStatement stmt) throws SQLException { if (fetchSize != VALUE_NOT_SET) { stmt.setFetchSize(fetchSize); stmt.setFetchDirection(ResultSet.FETCH_FORWARD); } if (maxRows != VALUE_NOT_SET) { stmt.setMaxRows(maxRows); } if (queryTimeout != VALUE_NOT_SET) { stmt.setQueryTimeout(queryTimeout); } }
public RowMetaInterface getQueryFieldsFromPreparedStatement( String sql ) throws Exception { PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement( databaseMeta.stripCR( sql ), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY ); preparedStatement.setMaxRows( 1 ); ResultSetMetaData rsmd = preparedStatement.getMetaData(); return getRowInfo( rsmd, false, false ); } catch ( Exception e ) { throw new Exception( e ); } finally { if ( preparedStatement != null ) { try { preparedStatement.close(); } catch ( SQLException e ) { throw new KettleDatabaseException( "Unable to close prepared statement after determining SQL layout", e ); } } } }
@Override public void doMessageIdScan(TransactionContext c, int limit, JDBCMessageIdScanListener listener) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindAllMessageIdsStatement()); s.setMaxRows(limit); rs = s.executeQuery(); // jdbc scrollable cursor requires jdbc ver > 1.0 and is often implemented locally so avoid LinkedList<MessageId> reverseOrderIds = new LinkedList<MessageId>(); while (rs.next()) { reverseOrderIds.addFirst(new MessageId(rs.getString(2), rs.getLong(3))); } if (LOG.isDebugEnabled()) { LOG.debug("messageIdScan with limit (" + limit + "), resulted in: " + reverseOrderIds.size() + " ids"); } for (MessageId id : reverseOrderIds) { listener.messageId(id); } } finally { close(rs); close(s); } }
try { s = c.getConnection().prepareStatement(this.statements.getFindDurableSubMessagesByPriorityStatement()); s.setMaxRows(Math.min(maxReturned * 2, maxRows)); s.setString(1, destination.getQualifiedName()); s.setString(2, clientId);
try { s = c.getConnection().prepareStatement(this.statements.getFindDurableSubMessagesStatement()); s.setMaxRows(Math.min(maxReturned * 2, maxRows)); s.setString(1, destination.getQualifiedName()); s.setString(2, clientId);
@Test public void testConnectionCallbackWithStatementSettings() throws Exception { String result = this.template.execute(new ConnectionCallback<String>() { @Override public String doInConnection(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement("some SQL"); ps.setFetchSize(10); ps.setMaxRows(20); ps.close(); return "test"; } }); assertEquals("test", result); verify(this.preparedStatement).setFetchSize(10); verify(this.preparedStatement).setMaxRows(20); verify(this.preparedStatement).close(); verify(this.connection).close(); }
/** * * The test inserts a few test snapshots. A query is issued to retrieve the two most recent snapshots */ @Test public void testKeepLast2Snapshots() throws Exception { insertSnapshot(new Path("/data/databases/Forum/Comments/1453743903767-PT-440505235")); insertSnapshot(new Path("/data/databases/Forum/Comments/1453830569999-PT-440746131")); insertSnapshot(new Path("/data/databases/Forum/Comments/1453860526464-PT-440847244")); insertSnapshot(new Path("/data/databases/Forum/Comments/1453889323804-PT-440936752")); // Derby does not support LIMIT keyword. The suggested workaround is to setMaxRows in the PreparedStatement PreparedStatement statement = connection.prepareStatement("SELECT name FROM Snapshots ORDER BY ts desc"); statement.setMaxRows(2); ResultSet rs = statement.executeQuery(); // Snapshots to be retained rs.next(); Assert.assertEquals(rs.getString(1), "1453889323804-PT-440936752"); rs.next(); Assert.assertEquals(rs.getString(1), "1453860526464-PT-440847244"); }
stmt.setMaxRows(defaultMaxRows); currentMaxRows = defaultMaxRows;
verify(this.preparedStatement).setMaxRows(maxRows.intValue());
ps.setMaxRows( rowlimit );