@Override public void updateString(int columnIndex, String x) throws SQLException { rs.updateString(columnIndex, x); }
@Override public void updateString(String columnLabel, String x) throws SQLException { rs.updateString(columnLabel, x); }
@Override public void updateString(int columnIndex, String x) throws SQLException { delegate.updateString(columnIndex, x); }
@Override public void updateString(String columnLabel, String x) throws SQLException { delegate.updateString(columnLabel, x); }
@Override public void updateString(int columnIndex, String x) throws SQLException { try { rs.updateString(columnIndex, x); } catch (Throwable t) { throw checkException(t); } }
@Override public void updateString(String columnLabel, String x) throws SQLException { try { rs.updateString(columnLabel, x); } catch (Throwable t) { throw checkException(t); } }
@NoWarning("SQL") public void test3(ResultSet rs) throws SQLException { String s = rs.getString("foo"); s = s.substring(1); rs.updateString("foo", s); }
@ExpectWarning("SQL") public void test2(ResultSet rs) throws SQLException { String s = rs.getString(0); s = s.substring(1); rs.updateString(0, s); }
@Override public void run() throws Exception { rs.updateString("id", ""); } });
@Override public void run() throws Exception { rs.updateString(1, ""); } });
@Override public void resultSet_updateString(ResultSetProxy resultSet, String columnLabel, String x) throws SQLException { if (this.pos < filterSize) { nextFilter().resultSet_updateString(this, resultSet, columnLabel, x); return; } resultSet.getResultSetRaw().updateString(columnLabel, x); }
@Override public void resultSet_updateString(ResultSetProxy resultSet, int columnIndex, String x) throws SQLException { if (this.pos < filterSize) { nextFilter().resultSet_updateString(this, resultSet, columnIndex, x); return; } resultSet.getResultSetRaw().updateString(columnIndex, x); }
switch (type) { case Types.TIME: rs.updateString(columnIndex, "12:00:00"); break; case Types.TIMESTAMP: case Types.DATE: rs.updateString(columnIndex, "2001-01-01"); break; default: rs.updateString(columnIndex, "1"); break; int type = meta.getColumnType(columnIndex); if (session.getContents().isH2()) { rs.updateString(columnIndex, x); return; break; default: rs.updateString(columnIndex, x);
/** * Tries to claim the given token {@code entry}. If the claim fails an {@link UnableToClaimTokenException} should be * thrown. Otherwise the given {@code resultSet} should be updated to reflect the claim. * * @param resultSet the updatable query result of an executed {@link PreparedStatement} * @param entry the entry extracted from the given result set * @return the claimed tracking token * * @throws UnableToClaimTokenException if the token cannot be claimed because another node currently owns the token * @throws SQLException when an exception occurs while claiming the token entry */ protected TrackingToken claimToken(ResultSet resultSet, AbstractTokenEntry<?> entry) throws SQLException { if (!entry.claim(nodeId, claimTimeout)) { throw new UnableToClaimTokenException( format("Unable to claim token '%s[%s]'. It is owned by '%s'", entry.getProcessorName(), entry.getSegment(), entry.getOwner())); } resultSet.updateString(schema.ownerColum(), entry.getOwner()); resultSet.updateString(schema.timestampColumn(), entry.timestampAsString()); resultSet.updateRow(); return entry.getToken(serializer); }
values.put(2, "Thomas"); query.execute(2, values); verify(resultSet).updateString(2, "Rod"); verify(resultSet).updateString(2, "Thomas"); verify(resultSet, times(2)).updateRow(); verify(preparedStatement).setObject(1, 2, Types.NUMERIC);
/** * Inserts a new token entry via the given updatable {@code resultSet}. * * @param resultSet the updatable result set to add the entry to * @param token the token of the entry to insert * @param processorName the name of the processor to insert a token for * @param segment the segment of the processor to insert a token for * @return the tracking token of the inserted entry * * @throws SQLException when an exception occurs while inserting a token entry */ protected TrackingToken insertTokenEntry(ResultSet resultSet, TrackingToken token, String processorName, int segment) throws SQLException { AbstractTokenEntry<?> entry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment); entry.claim(nodeId, claimTimeout); resultSet.moveToInsertRow(); resultSet.updateObject(schema.tokenColumn(), token == null ? null : entry.getSerializedToken().getData()); resultSet.updateString(schema.tokenTypeColumn(), token == null ? null : entry.getSerializedToken().getType().getName()); resultSet.updateString(schema.timestampColumn(), entry.timestampAsString()); resultSet.updateString(schema.ownerColum(), entry.getOwner()); resultSet.updateString(schema.processorNameColumn(), processorName); resultSet.updateInt(schema.segmentColumn(), segment); resultSet.insertRow(); return token; }
/** * If the given {@code resultSet} has no items this method should insert a new token entry. If a token already * exists it should be attempted to replace the token in the entry with the given {@code token} and claim ownership. * * @param resultSet the updatable query result set of an executed {@link PreparedStatement} * @param token the token for the new or updated entry * @param processorName the name of the processor owning the token * @param segment the segment of the processor owning the token * @throws UnableToClaimTokenException if the token cannot be claimed because another node currently owns the token * @throws SQLException when an exception occurs while updating the result set */ protected void insertOrUpdateToken(ResultSet resultSet, TrackingToken token, String processorName, int segment) throws SQLException { if (resultSet.next()) { AbstractTokenEntry<?> entry = readTokenEntry(resultSet); entry.updateToken(token, serializer); resultSet.updateObject(schema.tokenColumn(), entry.getSerializedToken().getData()); resultSet.updateString(schema.tokenTypeColumn(), entry.getSerializedToken().getType().getName()); resultSet.updateString(schema.timestampColumn(), entry.timestampAsString()); claimToken(resultSet, entry); } else { insertTokenEntry(resultSet, token, processorName, segment); } }
@Test public void testConcurrentUpdateableResultSet() { handle.execute("create table something (id identity primary key, name varchar(50))"); handle.execute("insert into something (id, name) values (7, 'Tim')"); handle.createQuery("select id, name from something where id = :id") .bind("id", 7) .concurrentUpdatable() .map((r, ctx) -> { r.updateString("name", "Tom"); r.updateRow(); return null; }).list(); final String name = handle.createQuery("select name from something where id = :id") .bind("id", 7) .mapTo(String.class) .findOnly(); assertThat(name).isEqualTo("Tom"); } }
@Override public void updateString(String columnLabel, String x) throws SQLException { try { rs.updateString(columnLabel, x); } catch (Throwable t) { throw checkException(t); } }
@Override public void updateString(int columnIndex, String x) throws SQLException { try { rs.updateString(columnIndex, x); } catch (Throwable t) { throw checkException(t); } }