net.aditsu.depeche
public class Record extends AbstractMap<String,Serializable> implements Serializable
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
static Serializable |
UNSET
Special value for fields that have not been set
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
void |
clearKeys()
Clears the cached foreign and exported keys for this record
|
boolean |
containsKey(Object key) |
Record |
copy()
Returns a copy of this record, which can be modified independently
|
void |
delete()
Deletes this record from the database using a new connection
|
void |
delete(Conn conn)
Deletes this record from the database using the given connection
|
Set<Map.Entry<String,Serializable>> |
entrySet() |
boolean |
exists()
Returns true if this record exists in the database (checking by primary key, using a new connection)
|
boolean |
exists(Conn conn)
Returns true if this record exists in the database (checking by primary key, using the given connection)
|
Serializable |
get(Object key)
Returns a field's value given its name
|
Double |
getAsDouble(int x)
Returns a field's numeric value converted to Double, given its index
|
Double |
getAsDouble(String name)
Returns a field's numeric value converted to Double, given its name
|
Integer |
getAsInteger(int x)
Returns a field's numeric value converted to Integer, given its index
|
Integer |
getAsInteger(String name)
Returns a field's numeric value converted to Integer, given its name
|
Long |
getAsLong(int x)
Returns a field's numeric value converted to Long, given its index
|
Long |
getAsLong(String name)
Returns a field's numeric value converted to Long, given its name
|
BigDecimal |
getBigDecimal(int x)
Returns a field's BigDecimal value given its index
|
BigDecimal |
getBigDecimal(String name)
Returns a field's BigDecimal value given its name
|
Boolean |
getBoolean(int x)
Returns a field's Boolean value given its index
|
Boolean |
getBoolean(String name)
Returns a field's Boolean value given its name
|
byte[] |
getBytes(int x)
Returns a field's byte array value given its index
|
byte[] |
getBytes(String name)
Returns a field's byte array value given its name
|
Query |
getChildren(FKey expkey)
Returns a query for getting the child records linked from this one through an exported key
|
Query |
getChildren(String name)
Returns a query for getting the child records linked from this one through an exported key
|
Query |
getChildrenFrom(String table)
Returns a query for getting the child records from a given table (linked from this one through an exported key)
|
Column |
getColumn(int x)
Returns a column with a given index
|
Column |
getColumn(String name)
Returns a column with a given name
|
ColumnInfo |
getColumnInfo()
Returns the column information for this record
|
Date |
getDate(int x)
Returns a field's Date value given its index
|
Date |
getDate(String name)
Returns a field's Date value given its name
|
Double |
getDouble(int x)
Returns a field's Double value given its index
|
Double |
getDouble(String name)
Returns a field's Double value given its name
|
Field |
getField(int x)
Returns a field by its index
|
Field |
getField(String name)
Returns a field by its name
|
List<Field> |
getFields()
Returns a list of all the fields
|
Float |
getFloat(int x)
Returns a field's Float value given its index
|
Float |
getFloat(String name)
Returns a field's Float value given its name
|
int |
getInt(int x)
Returns a field's int value given its index
|
int |
getInt(String name)
Returns a field's int value given its name
|
Integer |
getInteger(int x)
Returns a field's Integer value given its index
|
Integer |
getInteger(String name)
Returns a field's Integer value given its name
|
Key |
getKey(KeyInfo kinfo)
Returns this record's field values for the given KeyInfo, in a Key object
|
Long |
getLong(int x)
Returns a field's Long value given its index
|
Long |
getLong(String name)
Returns a field's Long value given its name
|
Number |
getNumber(int x)
Returns a field's Number value given its index
|
Number |
getNumber(String name)
Returns a field's Number value given its name
|
Query |
getParent(FKey fkey)
Returns a query for getting the parent record linked from this one through a foreign key
|
Query |
getParent(String name)
Returns a query for getting the parent record linked from this one through a foreign key
|
Query |
getParentFrom(String table)
Returns a query for getting the parent record from a given table (linked from this one through a foreign key)
|
Query |
getParentThrough(String column)
Returns a query for getting the parent record linked from this one through a given column
|
Condition |
getPKCondition()
Returns a condition that matches this record's primary key (or null if there is no primary key)
|
Key |
getPKey()
Returns a Key object containing this record's primary key field value(s)
|
Provider |
getProvider()
Returns the provider used by this record
|
ProviderRef |
getProviderRef()
Returns the provider reference used by this record
|
String |
getString(int x)
Returns a field's String value given its index
|
String |
getString(String name)
Returns a field's String value given its name
|
Table |
getTable()
Returns the table that contains this record (if it was obtained from a table)
|
TableInfo |
getTableInfo()
Returns the table information for this record (if it was obtained from a table)
|
Timestamp |
getTimestamp(int x)
Returns a field's Timestamp value given its index
|
Timestamp |
getTimestamp(String name)
Returns a field's Timestamp value given its name
|
Serializable |
getValue(int x)
Returns a field's value given its index
|
Serializable |
getValue(String name)
Returns a field's value given its name
|
Serializable |
getValueOrNull(int x)
Returns a field's value given its index; if the value is UNSET then it returns null instead
|
Serializable |
getValueOrNull(String name)
Returns a field's value given its name; if the value is UNSET then it returns null instead
|
int |
insert()
Inserts this record into the database using a new connection,
and updates the autoincrement field (if any) with the generated value
|
int |
insert(Conn conn)
Inserts this record into the database using the given connection,
and updates the autoincrement field (if any) with the generated value
|
Serializable |
put(String key,
Serializable value)
Sets a field's value by its name
|
void |
refresh()
Refreshes this record (based on its primary key) with the values from the database,
using a new connection
|
void |
refresh(Conn conn)
Refreshes this record (based on its primary key) with the values from the database,
using the given connection
|
void |
refresh(Conn conn,
RowLock rowLock)
Refreshes this record (based on its primary key) with the values from the database,
using the given connection, and locks it with the given row lock
|
Serializable |
remove(Object key) |
int |
save()
Saves this record to the database using a new connection.
|
int |
save(Conn conn)
Saves this record to the database using the given connection.
|
void |
setKey(KeyInfo kinfo,
Key key)
Sets several field values into this record, using the field names from the
given KeyInfo object and the values from the given Key object
|
void |
setParent(FKey fkey,
Record rec)
Sets the parent record linked from this one through a foreign key
|
void |
setParent(String name,
Record rec)
Sets the parent record linked from this one through a foreign key
|
void |
setParentFrom(String table,
Record rec)
Sets the parent record from a given table, linked from this one through a foreign key
|
void |
setValue(int x,
Serializable value)
Sets a field's value by its index
|
void |
setValue(String name,
Serializable value)
Sets a field's value by its name
|
void |
setValues(List<Serializable> values)
Sets the values for all the fields in this record
|
void |
setValues(Serializable... values)
Sets the values for all the fields in this record
|
int |
size()
Returns the number of fields in this record
|
void |
update()
Updates this record in the database using a new connection
|
void |
update(Conn conn)
Updates this record in the database using the given connection
|
List<Serializable> |
values()
Returns a list with the values of all the fields in this record
|
containsValue, equals, hashCode, isEmpty, keySet, putAll, toString
public static final Serializable UNSET
public Record copy()
public ProviderRef getProviderRef()
public Provider getProvider()
public Serializable getValue(int x)
public void setValue(int x, Serializable value)
public Serializable getValue(String name)
public void setValue(String name, Serializable value)
public Serializable getValueOrNull(int x)
public Serializable getValueOrNull(String name)
public String getString(int x)
public Integer getInteger(int x)
public Integer getAsInteger(int x)
public Integer getAsInteger(String name)
public int getInt(int x)
public int getInt(String name)
public Long getLong(int x)
public Long getAsLong(int x)
public Long getAsLong(String name)
public Boolean getBoolean(int x)
public Date getDate(int x)
public Timestamp getTimestamp(int x)
public Timestamp getTimestamp(String name)
public Double getDouble(int x)
public Double getAsDouble(int x)
public Double getAsDouble(String name)
public Float getFloat(int x)
public BigDecimal getBigDecimal(int x)
public BigDecimal getBigDecimal(String name)
public Number getNumber(int x)
public byte[] getBytes(int x)
public byte[] getBytes(String name)
public Set<Map.Entry<String,Serializable>> entrySet()
entrySet
in interface Map<String,Serializable>
entrySet
in class AbstractMap<String,Serializable>
public Serializable get(Object key)
get
in interface Map<String,Serializable>
get
in class AbstractMap<String,Serializable>
getValue(String)
public Serializable put(String key, Serializable value)
put
in interface Map<String,Serializable>
put
in class AbstractMap<String,Serializable>
setValue(String, Serializable)
public ColumnInfo getColumnInfo()
public Column getColumn(int x)
public TableInfo getTableInfo()
public Table getTable()
public void clearKeys()
public Query getParent(String name)
name
- foreign key namepublic Query getParent(FKey fkey)
public void setParent(String name, Record rec)
name
- foreign key namerec
- parent recordpublic void setParent(FKey fkey, Record rec)
public Query getParentFrom(String table)
table
- primary key tablepublic void setParentFrom(String table, Record rec)
public Query getParentThrough(String column)
public Query getChildren(String name)
name
- exported key namepublic Query getChildren(FKey expkey)
public Query getChildrenFrom(String table)
table
- foreign key tablepublic int insert(Conn conn)
public int insert()
public void update(Conn conn)
public void update()
public void delete(Conn conn)
public void delete()
public int save(Conn conn)
update(Conn)
and returns -1,
otherwise it acts like insert(Conn)
. Note: not safe from race conditions.public int save()
public Field getField(int x)
public void setValues(Serializable... values)
public void setValues(List<Serializable> values)
public int size()
size
in interface Map<String,Serializable>
size
in class AbstractMap<String,Serializable>
public void clear()
clear
in interface Map<String,Serializable>
clear
in class AbstractMap<String,Serializable>
public boolean containsKey(Object key)
containsKey
in interface Map<String,Serializable>
containsKey
in class AbstractMap<String,Serializable>
public Serializable remove(Object key)
remove
in interface Map<String,Serializable>
remove
in class AbstractMap<String,Serializable>
public List<Serializable> values()
values
in interface Map<String,Serializable>
values
in class AbstractMap<String,Serializable>
public Key getKey(KeyInfo kinfo)
public void setKey(KeyInfo kinfo, Key key)
public Key getPKey()
public void refresh(Conn conn)
public void refresh(Conn conn, RowLock rowLock)
public void refresh()
public boolean exists(Conn conn)
public boolean exists()
public Condition getPKCondition()