public class DbxRecord extends DbxFields
DbxTable
methods such as DbxTable.query()
or DbxTable.get(java.lang.String)
.
A DbxRecord
represents a direct view of the datastore. Changes to the DbxRecord
are immediately visible via access to the same DbxDatastore
, and a call to
DbxDatastore.sync()
that incorporates remote changes will change the state of any
outstanding DbxRecord
objects.
A DbxRecord
is an instance of DbxFields
, supporting all the same methods,
and can be used for methods such as DbxTable.query(DbxFields)
and
DbxRecord.setAll(DbxFields)
. Fields are identified by name, and have a value of one of
the types defined by DbxFields.ValueType
. Fields can never have a null
value.
Fields can be retrieved by name and type. Illegal field access will be
signaled by an exception: DbxFields.FieldNotFound
, DbxFields.IllegalFieldName
,
or DbxFields.WrongValueType
.
Modifier and Type | Class and Description |
---|---|
static class |
DbxRecord.IllegalRecordId
Thrown when an illegal record ID is given.
|
DbxFields.AtomType, DbxFields.FieldNotFound, DbxFields.IllegalFieldName, DbxFields.ValueType, DbxFields.WrongValueType
Modifier and Type | Method and Description |
---|---|
DbxRecord |
deleteField(java.lang.String name)
Removes the field with the given name.
|
void |
deleteRecord()
Deletes this record.
|
boolean |
equals(java.lang.Object other) |
java.util.Set |
fieldNames()
Returns a set containing the names of all of the fields that are set.
|
boolean |
getBoolean(java.lang.String name)
Returns the value of a
boolean field of the given name, which must
exist and be of the correct type. |
byte[] |
getBytes(java.lang.String name)
Returns the value of a byte field of the given name, which must
exist and be of the correct type.
|
java.util.Date |
getDate(java.lang.String name)
Returns the value of a
Date field of the given name, which must
exist and be of the correct type. |
double |
getDouble(java.lang.String name)
Returns the value of a
double field of the given name, which must
exist and be of a numerical type. |
DbxFields.ValueType |
getFieldType(java.lang.String name)
Returns the type of value in the field with the given name, or
null
if the field isn't set. |
java.lang.String |
getId()
Returns the ID of this record.
|
DbxList |
getList(java.lang.String name)
Returns a
DbxList object for reading and writing the contents of a
List field of the given name. |
long |
getLong(java.lang.String name)
Returns the value of a
long field of the given name, which must
exist and be of the correct type. |
DbxList |
getOrCreateList(java.lang.String name)
Returns a
DbxList object for reading and writing the contents of a
List field of the given name. |
java.lang.String |
getString(java.lang.String name)
Returns the value of a
String field of the given name, which must
exist and be of the correct type. |
DbxTable |
getTable()
Returns the table that contains this record.
|
boolean |
hasField(java.lang.String name)
Returns whether a field with the given name is set.
|
int |
hashCode() |
boolean |
isDeleted()
Returns whether this record has been deleted.
|
static boolean |
isValidId(java.lang.String id)
Returns true if
id is a valid ID for a DbxRecord . |
DbxRecord |
set(java.lang.String name,
boolean value)
Sets a field with the given name to the given
boolean value,
replacing any prior value. |
DbxRecord |
set(java.lang.String name,
byte[] value)
Sets a field with the given name to the given byte value,
replacing any prior value.
|
DbxRecord |
set(java.lang.String name,
java.util.Date value)
Sets a field with the given name to the given
Date value,
replacing any prior value. |
DbxRecord |
set(java.lang.String name,
DbxList value)
Sets a field with the given name to List value with a copy of
the contents of the given
DbxList , replacing any prior value. |
DbxRecord |
set(java.lang.String name,
double value)
Sets a field with the given name to the given
double value,
replacing any prior value. |
DbxRecord |
set(java.lang.String name,
long value)
Sets a field with the given name to the given
long value,
replacing any prior value. |
DbxRecord |
set(java.lang.String name,
java.lang.String value)
Sets a field with the given name to the given
String value,
replacing any prior value. |
DbxRecord |
setAll(DbxFields fields)
Copies all of the fields from the given object to this object,
replacing any prior values.
|
java.lang.String |
toString() |
isValidFieldName
public DbxTable getTable()
public java.lang.String getId()
public boolean isDeleted()
public void deleteRecord()
public boolean hasField(java.lang.String name)
public DbxFields.ValueType getFieldType(java.lang.String name)
null
if the field isn't set.getFieldType
in class DbxFields
public boolean getBoolean(java.lang.String name)
boolean
field of the given name, which must
exist and be of the correct type.getBoolean
in class DbxFields
public long getLong(java.lang.String name)
long
field of the given name, which must
exist and be of the correct type. This method won't convert a
double
or boolean
field to a long
.public double getDouble(java.lang.String name)
double
field of the given name, which must
exist and be of a numerical type. If the field value is a long
,
this method will silently convert it to a double
. No conversion
is performed on other field types.public java.lang.String getString(java.lang.String name)
String
field of the given name, which must
exist and be of the correct type.public byte[] getBytes(java.lang.String name)
public java.util.Date getDate(java.lang.String name)
Date
field of the given name, which must
exist and be of the correct type.public DbxList getList(java.lang.String name)
public DbxList getOrCreateList(java.lang.String name)
DbxList
object for reading and writing the contents of a
List field of the given name. The field must not be of an incompatible type
(or DbxFields.WrongValueType
will be thrown), but if it isn't set, an
empty DbxList
will be created.getOrCreateList
in class DbxFields
public DbxRecord set(java.lang.String name, boolean value)
boolean
value,
replacing any prior value.
Returns a reference to this object, to allow for call chaining.
public DbxRecord set(java.lang.String name, long value)
long
value,
replacing any prior value.
Returns a reference to this object, to allow for call chaining.
public DbxRecord set(java.lang.String name, double value)
double
value,
replacing any prior value.
Returns a reference to this object, to allow for call chaining.
public DbxRecord set(java.lang.String name, java.lang.String value)
String
value,
replacing any prior value. The value must not be null
.
Returns a reference to this object, to allow for call chaining.
public DbxRecord set(java.lang.String name, byte[] value)
null
.
Returns a reference to this object, to allow for call chaining.
public DbxRecord set(java.lang.String name, java.util.Date value)
Date
value,
replacing any prior value. The value must not be null
.
Returns a reference to this object, to allow for call chaining.
public DbxRecord set(java.lang.String name, DbxList value)
DbxList
, replacing any prior value.
The value must not be null
.
Setting a list in this way won't allow automatic conflict
resolution on items within the list. If you need that, you
should modify lists using a DbxList
obtained from DbxRecord.getList(java.lang.String)
or DbxRecord.getOrCreateList(java.lang.String)
.
Returns a reference to this object, to allow for call chaining.
public DbxRecord setAll(DbxFields fields)
Returns a reference to this object, to allow for call chaining.
public DbxRecord deleteField(java.lang.String name)
Returns a reference to this object, to allow for call chaining.
deleteField
in class DbxFields
public java.util.Set fieldNames()
fieldNames
in class DbxFields
public static boolean isValidId(java.lang.String id)
id
is a valid ID for a DbxRecord
.
IDs are case-sensitive, can be 1-32 characters long and may contain
alphanumeric characters plus these punctuation characters: . - _ + / =
IDs with a leading colon (:) are also valid, but reserved for internal use.