org.jooq
Interface UpdatableRecord<R extends UpdatableRecord<R>>

Type Parameters:
R - The record type
All Superinterfaces:
Adapter, Attachable, FieldProvider, Record, Serializable, Store<Object>, TableRecord<R>, Updatable<R>
All Known Implementing Classes:
UpdatableRecordImpl

public interface UpdatableRecord<R extends UpdatableRecord<R>>
extends Updatable<R>, TableRecord<R>

A common interface for records that can be stored back to the database again.

Any Record can be Updatable, if

  1. it represents a record from a table or view - a TableRecord
  2. its underlying table or view has a "main unique key", i.e. a primary key or at least one unique key

The "main unique key" is used by jOOQ to perform the various operations that can be performed on an UpdatableRecord:

UpdatableRecords are Attachable, which means that they hold an underlying Configuration that they can be detached from. They can also be instanciated without any underlying Configuration, in case of which they have to be attached first, in order to be refreshed, stored, or deleted.

Author:
Lukas Eder

Method Summary
 R copy()
          Duplicate this record (in memory) and reset all fields from the primary key or main unique key, such that a subsequent call to store() will result in an INSERT statement.
 int delete()
          Deletes this record from the database, based on the value of the primary key or main unique key.
 UpdatableTable<R> getTable()
          The table from which this record was read
 void refresh()
          Refresh this record from the database, based on the value of the primary key or main unique key.
 int store()
          Store this record back to the database.
 
Methods inherited from interface org.jooq.TableRecord
deleteUsing, refreshUsing, storeUsing
 
Methods inherited from interface org.jooq.Record
from, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValueAsArray, getValueAsArray, getValueAsBigDecimal, getValueAsBigDecimal, getValueAsBigDecimal, getValueAsBigDecimal, getValueAsBigInteger, getValueAsBigInteger, getValueAsBigInteger, getValueAsBigInteger, getValueAsBoolean, getValueAsBoolean, getValueAsBoolean, getValueAsBoolean, getValueAsByte, getValueAsByte, getValueAsByte, getValueAsByte, getValueAsDate, getValueAsDate, getValueAsDate, getValueAsDate, getValueAsDouble, getValueAsDouble, getValueAsDouble, getValueAsDouble, getValueAsFloat, getValueAsFloat, getValueAsFloat, getValueAsFloat, getValueAsInteger, getValueAsInteger, getValueAsInteger, getValueAsInteger, getValueAsLong, getValueAsLong, getValueAsLong, getValueAsLong, getValueAsShort, getValueAsShort, getValueAsShort, getValueAsShort, getValueAsString, getValueAsString, getValueAsString, getValueAsString, getValueAsTime, getValueAsTime, getValueAsTime, getValueAsTime, getValueAsTimestamp, getValueAsTimestamp, getValueAsTimestamp, getValueAsTimestamp, into, into, into, intoArray, intoMap, setValue, setValue
 
Methods inherited from interface org.jooq.FieldProvider
getField, getField, getField, getFields, getIndex
 
Methods inherited from interface org.jooq.Store
getValue, getValue, getValue, getValue, getValueAsBigDecimal, getValueAsBigDecimal, getValueAsBigInteger, getValueAsBigInteger, getValueAsBoolean, getValueAsBoolean, getValueAsByte, getValueAsByte, getValueAsDate, getValueAsDate, getValueAsDouble, getValueAsDouble, getValueAsFloat, getValueAsFloat, getValueAsInteger, getValueAsInteger, getValueAsLong, getValueAsLong, getValueAsShort, getValueAsShort, getValueAsString, getValueAsString, getValueAsTime, getValueAsTime, getValueAsTimestamp, getValueAsTimestamp, size
 
Methods inherited from interface org.jooq.Attachable
attach
 
Methods inherited from interface org.jooq.Adapter
internalAPI
 

Method Detail

getTable

UpdatableTable<R> getTable()
The table from which this record was read

Specified by:
getTable in interface TableRecord<R extends UpdatableRecord<R>>

store

int store()
          throws DataAccessException,
                 DataChangedException
Store this record back to the database.

Depending on the state of the primary key's or main unique key's value, an INSERT or an UPDATE statement is executed.

Statement type

In either statement type, only those fields are inserted/updated, which had been explicitly set by client code, in order to allow for DEFAULT values to be applied by the underlying RDBMS. If no fields were modified, neither an UPDATE nor an INSERT will be executed.

Automatic value generation

Optimistic locking

If an UPDATE statement is executed and Settings.isExecuteWithOptimisticLocking() is set to true, then this record will first be compared with the latest state in the database. There are two modes of operation for optimistic locking:

Statement examples

Possible statements are

This is in fact the same as calling store(getTable().getMainKey().getFieldsArray())

Returns:
1 if the record was stored to the database. 0 if storing was not necessary.
Throws:
DataAccessException - if something went wrong executing the query
DataChangedException - If optimistic locking is enabled and the record has already been changed/deleted in the database

delete

int delete()
           throws DataAccessException,
                  DataChangedException
Deletes this record from the database, based on the value of the primary key or main unique key.

Optimistic locking

If a DELETE statement is executed and Settings.isExecuteWithOptimisticLocking() is set to true, then this record will first be compared with the latest state in the database. There are two modes of operation for optimistic locking:

Statement examples

The executed statement is

 DELETE FROM [table]
 WHERE [key fields = key values]
 AND [version/timestamp fields = version/timestamp values]

This is in fact the same as calling delete(getTable().getMainKey().getFieldsArray())

Returns:
1 if the record was deleted from the database. 0 if deletion was not necessary.
Throws:
DataAccessException - if something went wrong executing the query
DataChangedException - If optimistic locking is enabled and the record has already been changed/deleted in the database

refresh

void refresh()
             throws DataAccessException
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(getTable().getMainKey().getFieldsArray())

The executed statement is

 SELECT * FROM [table]
 WHERE [main key fields = main key values]

Throws:
DataAccessException - This exception is thrown if
  • something went wrong executing the query
  • the record does not exist anymore in the database

copy

R copy()
Duplicate this record (in memory) and reset all fields from the primary key or main unique key, such that a subsequent call to store() will result in an INSERT statement.

Returns:
A new record, distinct from this record.


Copyright © 2012. All Rights Reserved.