diff --git a/jOOQ-test/src/org/jooq/test/_/testcases/KeepResultSetTests.java b/jOOQ-test/src/org/jooq/test/_/testcases/KeepResultSetTests.java index a21450d71b..7265675f44 100644 --- a/jOOQ-test/src/org/jooq/test/_/testcases/KeepResultSetTests.java +++ b/jOOQ-test/src/org/jooq/test/_/testcases/KeepResultSetTests.java @@ -101,6 +101,14 @@ extends BaseTest b1 = create().selectFrom(TBook()).fetch(); @@ -143,19 +151,31 @@ extends BaseTest c1 = create().select().from(TBook().getName()).keepResultSet(KEEP_AFTER_FETCH).fetchLazy(); assertFalse(c1.closesAfterFetch()); @@ -298,7 +318,6 @@ extends BaseTest { */ void refresh() throws DataAccessException; -// /** -// * Refresh this record from the database, based on the value of the primary -// * key or main unique key. -// *

-// * The executed statement is

-//     * SELECT [fields] FROM [table]
-//     * WHERE [primary key fields = primary key values]
-// * -// * @throws DataAccessException This exception is thrown if -// *
    -// *
  • something went wrong executing the query
  • the -// * record does not exist anymore in the database
  • -// *
-// */ -// void refresh(Field... fields) throws DataAccessException; + /** + * Refresh parts of this record from the database. + *

+ * A successful refresh results in the following: + *

    + *
  • {@link #valuesRow()} will have been restored to the respective values + * from the database
  • + *
  • {@link #original()} will match this record
  • + *
  • {@link #changed()} will be false
  • + *
+ *

+ * Refreshing can trigger any of the following actions: + *

    + *
  • Re-reading the underlying {@link #resultSet()}, if that + * ResultSet is available.
  • + *
  • Executing a new SELECT statement, if this is an + * {@link UpdatableRecord}.
  • + *
  • Failing, otherwise
  • + *
+ *

+ * This is the same as calling record.refresh(record.fields()) + * + * @throws DataAccessException This exception is thrown if + *

    + *
  • something went wrong executing the query
  • the + * {@link #resultSet()} is not available, or is in + * {@link ResultSet#TYPE_FORWARD_ONLY} mode, such that + * refreshing is not possible.
  • the record does not exist + * anymore in the database
  • + *
+ * @see UpdatableRecord#refresh() + * @see ResultQuery#keepResultSet(KeepResultSetMode) + */ + void refresh(Field... fields) throws DataAccessException; /** * Close the underlying JDBC {@link ResultSet}, if applicable. diff --git a/jOOQ/src/main/java/org/jooq/UpdatableRecord.java b/jOOQ/src/main/java/org/jooq/UpdatableRecord.java index 32a802d0b3..a23ab7600a 100644 --- a/jOOQ/src/main/java/org/jooq/UpdatableRecord.java +++ b/jOOQ/src/main/java/org/jooq/UpdatableRecord.java @@ -301,39 +301,15 @@ public interface UpdatableRecord> extends TableReco int delete() throws DataAccessException, DataChangedException; /** - * Refresh this record from the database, based on the value of the primary - * key or main unique key. - *

- * This is in fact the same as calling - * refresh(getFields().toArray(new Field[0])) - *

- * The executed statement is

-     * SELECT * FROM [table]
-     * WHERE [primary key fields = primary key values]
- * - * @throws DataAccessException This exception is thrown if - *
    - *
  • something went wrong executing the query
  • the - * record does not exist anymore in the database
  • - *
+ * {@inheritDoc} */ @Override void refresh() throws DataAccessException; /** - * Refresh this record from the database, based on the value of the primary - * key or main unique key. - *

- * The executed statement is

-     * SELECT [fields] FROM [table]
-     * WHERE [primary key fields = primary key values]
- * - * @throws DataAccessException This exception is thrown if - *
    - *
  • something went wrong executing the query
  • the - * record does not exist anymore in the database
  • - *
+ * {@inheritDoc} */ + @Override void refresh(Field... fields) throws DataAccessException; /** diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java b/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java index 90217ba11b..0550411c91 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java @@ -694,17 +694,27 @@ abstract class AbstractRecord extends AbstractStore implements Record { // ------------------------------------------------------------------------- @Override - public void refresh() { + public final void refresh() { + refresh(fields.fields.fields); + } + + /** + * {@inheritDoc} + *

+ * Subclasses may override this + */ + @Override + public void refresh(Field... f) throws DataAccessException { if (rs != null) { try { // [#2265] TODO: This code is prototypical. fetchLazy() is not // the best way to fetch a record rs.absolute(rsIndex - 1); - Record record = create().fetchLazy(rs).fetchOne(); + AbstractRecord record = (AbstractRecord) create().fetchLazy(rs).fetchOne(); - for (int i = 0; i < record.size(); i++) { - setValue(i, new Value(record.getValue(i))); + for (Field field : f) { + setValue(field, record.getValue0(field)); } } catch (SQLException e) { diff --git a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java index e4b61a4257..afde70bf59 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java @@ -338,11 +338,6 @@ public class UpdatableRecordImpl> extends TableReco } } - @Override - public final void refresh() { - refresh(fields.fields.fields()); - } - @Override public final void refresh(Field... f) { SelectQuery select = create().selectQuery();