ewe.database
Class DatabaseEntryObject

java.lang.Object
  extended byewe.database.DatabaseEntryObject
All Implemented Interfaces:
DatabaseEntry, DatabaseTypes
Direct Known Subclasses:
ByteArrayDatabaseEntry

public abstract class DatabaseEntryObject
extends Object
implements DatabaseEntry


Field Summary
protected  DatabaseObject database
           
protected  boolean isDeleted
           
protected  Locale locale
           
protected  FoundEntries modifyingInside
           
protected  ByteArray myData
           
 
Fields inherited from interface ewe.database.DatabaseTypes
BOOLEAN, BYTE_ARRAY, CREATED_FIELD, DATE, DATE_TIME, DECIMAL, DOUBLE, FIRST_SPECIAL_FIELD, FLAG_SYNCHRONIZED, FLAGS_FIELD, INTEGER, JAVA_OBJECT, LONG, MAX_ID, MODIFIED_BY_FIELD, MODIFIED_FIELD, NAME_FIELD, OBJECT_BYTES_FIELD, OBJECT_TEXT_FIELD, OID_FIELD, reservedFieldHeaders, reservedFieldIDs, reservedFieldNames, reservedFieldTypes, SORT_DATE_ONLY, SORT_IGNORE_CASE, SORT_TIME_ONLY, SORT_UNKNOWN_IS_GREATER_THAN_KNOWN, SORT_UNKNOWN_IS_LESS_THAN_KNOWN, STRING, TIME, TIMESTAMP
 
Constructor Summary
protected DatabaseEntryObject(DatabaseObject database)
           
 
Method Summary
 boolean _getSetField(String fieldName, Wrapper value, boolean isGet)
          This is used as a mechanism for automatic data transfer between a DatabaseEntry and a user interface object.
 boolean _getSetValue(String fieldName, Wrapper value, boolean isGet)
          This is used as a mechanism for automatic data transfer between a DatabaseEntry and an object that has the same field names.
 int compareTo(DatabaseEntry other, int sortID)
          Compare this entry with another based on the sortID stored in the database (ignoring the SORT_DESCENDING option).
protected static Object convertStringToStaticObjectValue(Object value, int type)
          If the value is a String, convert it to an Object suitable for the specified type.
 boolean decode(byte[] source, int offset, int length)
           
 void delete()
          This will delete the entry from the database.
protected abstract  int discoverType(int field)
           
protected  String dump()
           
 void duplicateFrom(DatabaseEntry other)
          Duplicate all set fields in this DatabaseEntry with those from the other.
 byte[] encode()
           
 void erase()
          This will erase the entry from the database.
protected  int fieldToID(String fieldName)
           
protected  int fieldToType(int field)
           
 int[] getAssignedFields()
           
 Object getData()
          Get the data from the entry, creating a new data object.
 Object getData(Object destination)
          Get the data from the entry into a data object.
 Database getDatabase()
          Get the database associated with the FoundEntries.
 BigDecimal getField(int fieldID, BigDecimal defaultValue)
           
 boolean getField(int fieldID, boolean defaultValue)
           
 ByteArray getField(int fieldID, ByteArray dest)
           
 CharArray getField(int fieldID, CharArray dest)
           
 DayOfYear getField(int fieldID, DayOfYear dest)
           
 Decimal getField(int fieldID, Decimal dest)
           
 double getField(int fieldID, double defaultValue)
           
 int getField(int fieldID, int defaultValue)
           
 long getField(int fieldID, long defaultValue)
           
 String getField(int fieldID, String defaultValue)
           
 Time getField(int fieldID, Time dest)
           
 TimeOfDay getField(int fieldID, TimeOfDay dest)
           
 TimeStamp getField(int fieldID, TimeStamp dest)
           
 byte[] getFieldBytes(int fieldID)
           
protected  int getFieldInfo(String fieldName)
          Return the field info as the id|type.
protected  String getFieldName(int id)
           
abstract  Object getFieldValue(int fieldID, int type, Object data)
           
 Object getFieldValue(int fieldID, Object data)
           
 DatabaseEntry getNew()
           
 Object getObjectField(int fieldID, Object dest)
           
 boolean isADeletedEntry()
           
protected  void load()
           
protected  void markAsDeleted()
           
 void reset()
          Reset the entry to be an empty entry, as if it had just been returned by Database.getNewData()
 void revert()
          Reload the entries data.
 void save()
          This will save or add the entry into the database.
 void setData(Object data)
          Set the data in the entry from the data object.
 void setField(int fieldID, BigDecimal value)
           
 void setField(int fieldID, boolean value)
           
 void setField(int fieldID, byte[] bytes)
           
 void setField(int fieldID, ByteArray bytes)
           
 void setField(int fieldID, ByteEncodable value)
           
 void setField(int fieldID, CharArray chars)
           
 void setField(int fieldID, DayOfYear date)
           
 void setField(int fieldID, Decimal value)
           
 void setField(int fieldID, double value)
           
 void setField(int fieldID, int value)
           
 void setField(int fieldID, long value)
           
 void setField(int fieldID, String chars)
           
 void setField(int fieldID, SubString chars)
           
 void setField(int fieldID, Time time)
           
 void setField(int fieldID, TimeOfDay time)
           
 void setField(int fieldID, TimeStamp timestamp)
           
 void setFieldValue(int fieldID, Object data)
           
 void setObjectField(int fieldID, Object value)
           
 void store()
          This will store and add (if necessary) the entry into the database with no modifications.
 String toString()
          Return a String representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 
Methods inherited from interface ewe.database.DatabaseEntry
clearDataAndSpecialFields, clearField, clearFields, compareTo, countAssignedFields, decode, encode, getAssignedFields, hasField, isPointingTo, isSaved, pointTo, setFieldValue
 

Field Detail

myData

protected ByteArray myData

database

protected DatabaseObject database

isDeleted

protected boolean isDeleted

modifyingInside

protected FoundEntries modifyingInside

locale

protected Locale locale
Constructor Detail

DatabaseEntryObject

protected DatabaseEntryObject(DatabaseObject database)
Method Detail

convertStringToStaticObjectValue

protected static Object convertStringToStaticObjectValue(Object value,
                                                         int type)
If the value is a String, convert it to an Object suitable for the specified type.

Parameters:
value - the provided Object value, which may be a String.
type - the type of the field being set.
Returns:
a static (possibly shared) object value holding the appropriate data.

getFieldValue

public abstract Object getFieldValue(int fieldID,
                                     int type,
                                     Object data)
Specified by:
getFieldValue in interface DatabaseEntry

getDatabase

public Database getDatabase()
Get the database associated with the FoundEntries.

Specified by:
getDatabase in interface DatabaseEntry

isADeletedEntry

public boolean isADeletedEntry()
Specified by:
isADeletedEntry in interface DatabaseEntry

reset

public void reset()
Description copied from interface: DatabaseEntry
Reset the entry to be an empty entry, as if it had just been returned by Database.getNewData()

Specified by:
reset in interface DatabaseEntry

save

public void save()
          throws IllegalStateException,
                 IOException
Description copied from interface: DatabaseEntry
This will save or add the entry into the database. The database may decide to add or alter fields within the entry (e.g. the modified time field).

Specified by:
save in interface DatabaseEntry
Throws:
IllegalStateException - if the entry is a deleted entry or otherwise cannot be saved.
IOException - on error.

delete

public void delete()
            throws IOException
Description copied from interface: DatabaseEntry
This will delete the entry from the database. The database may decide to mark the entry as deleted, saving the object ID and delete time.

Specified by:
delete in interface DatabaseEntry
Throws:
IOException - on error.

markAsDeleted

protected void markAsDeleted()
                      throws IOException
Throws:
IOException

store

public void store()
           throws IllegalStateException,
                  IOException
Description copied from interface: DatabaseEntry
This will store and add (if necessary) the entry into the database with no modifications.

Specified by:
store in interface DatabaseEntry
Throws:
IllegalStateException - if the entry is a deleted entry or otherwise cannot be saved.
IOException - on error.

erase

public void erase()
           throws IOException
Description copied from interface: DatabaseEntry
This will erase the entry from the database. The database will not mark it as deleted.

Specified by:
erase in interface DatabaseEntry
Throws:
IOException

revert

public void revert()
            throws IllegalStateException,
                   IOException
Description copied from interface: DatabaseEntry
Reload the entries data.

Specified by:
revert in interface DatabaseEntry
Throws:
IOException
IllegalStateException - if the entry's data could not be reloaded, because it was deleted, erased or reset.

load

protected void load()
             throws IOException
Throws:
IOException

getData

public Object getData(Object destination)
               throws IllegalArgumentException,
                      IllegalStateException
Get the data from the entry into a data object.

Specified by:
getData in interface DatabaseEntry
Parameters:
destination - a destination object. If this is null a new one will be created if possible.
Returns:
the destination or new object.
Throws:
IllegalArgumentException - if the destination object is not the right type.
IllegalStateException - if a new object was requested but could not be created.

getData

public Object getData()
               throws IllegalStateException
Get the data from the entry, creating a new data object.

Specified by:
getData in interface DatabaseEntry
Returns:
the new data object.
Throws:
IllegalStateException - if a new object could not be created.

setData

public void setData(Object data)
             throws IllegalArgumentException
Set the data in the entry from the data object.

Specified by:
setData in interface DatabaseEntry
Parameters:
data - the data to set.
Throws:
IllegalArgumentException - if the data object is the wrong type.

getNew

public DatabaseEntry getNew()

compareTo

public int compareTo(DatabaseEntry other,
                     int sortID)
              throws IllegalArgumentException
Description copied from interface: DatabaseEntry
Compare this entry with another based on the sortID stored in the database (ignoring the SORT_DESCENDING option).

Specified by:
compareTo in interface DatabaseEntry
Throws:
IllegalArgumentException

_getSetField

public boolean _getSetField(String fieldName,
                            Wrapper value,
                            boolean isGet)
This is used as a mechanism for automatic data transfer between a DatabaseEntry and a user interface object.


_getSetValue

public boolean _getSetValue(String fieldName,
                            Wrapper value,
                            boolean isGet)
This is used as a mechanism for automatic data transfer between a DatabaseEntry and an object that has the same field names.


setFieldValue

public void setFieldValue(int fieldID,
                          Object data)
Specified by:
setFieldValue in interface DatabaseEntry

getFieldValue

public Object getFieldValue(int fieldID,
                            Object data)
Specified by:
getFieldValue in interface DatabaseEntry

setField

public void setField(int fieldID,
                     int value)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     long value)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     boolean value)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     double value)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     Time time)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     TimeOfDay time)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     DayOfYear date)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     TimeStamp timestamp)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     BigDecimal value)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     Decimal value)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     ByteArray bytes)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     byte[] bytes)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     SubString chars)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     CharArray chars)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     String chars)
Specified by:
setField in interface DatabaseEntry

setField

public void setField(int fieldID,
                     ByteEncodable value)

setObjectField

public void setObjectField(int fieldID,
                           Object value)
Specified by:
setObjectField in interface DatabaseEntry

getObjectField

public Object getObjectField(int fieldID,
                             Object dest)
Specified by:
getObjectField in interface DatabaseEntry

getField

public int getField(int fieldID,
                    int defaultValue)
Specified by:
getField in interface DatabaseEntry

getField

public long getField(int fieldID,
                     long defaultValue)
Specified by:
getField in interface DatabaseEntry

getField

public boolean getField(int fieldID,
                        boolean defaultValue)
Specified by:
getField in interface DatabaseEntry

getField

public double getField(int fieldID,
                       double defaultValue)
Specified by:
getField in interface DatabaseEntry

getField

public Time getField(int fieldID,
                     Time dest)
Specified by:
getField in interface DatabaseEntry

getField

public String getField(int fieldID,
                       String defaultValue)
Specified by:
getField in interface DatabaseEntry

getField

public CharArray getField(int fieldID,
                          CharArray dest)
Specified by:
getField in interface DatabaseEntry

getFieldBytes

public byte[] getFieldBytes(int fieldID)
Specified by:
getFieldBytes in interface DatabaseEntry

getField

public ByteArray getField(int fieldID,
                          ByteArray dest)
Specified by:
getField in interface DatabaseEntry

getField

public DayOfYear getField(int fieldID,
                          DayOfYear dest)
Specified by:
getField in interface DatabaseEntry

getField

public TimeOfDay getField(int fieldID,
                          TimeOfDay dest)
Specified by:
getField in interface DatabaseEntry

getField

public TimeStamp getField(int fieldID,
                          TimeStamp dest)
Specified by:
getField in interface DatabaseEntry

getField

public BigDecimal getField(int fieldID,
                           BigDecimal defaultValue)
Specified by:
getField in interface DatabaseEntry

getField

public Decimal getField(int fieldID,
                        Decimal dest)
Specified by:
getField in interface DatabaseEntry

getAssignedFields

public int[] getAssignedFields()
Specified by:
getAssignedFields in interface DatabaseEntry

getFieldInfo

protected int getFieldInfo(String fieldName)
Return the field info as the id|type.


fieldToID

protected int fieldToID(String fieldName)

discoverType

protected abstract int discoverType(int field)

getFieldName

protected String getFieldName(int id)

fieldToType

protected int fieldToType(int field)

dump

protected String dump()

toString

public String toString()
Description copied from class: Object
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
a String representing this object.

duplicateFrom

public void duplicateFrom(DatabaseEntry other)
Description copied from interface: DatabaseEntry
Duplicate all set fields in this DatabaseEntry with those from the other.

Specified by:
duplicateFrom in interface DatabaseEntry

encode

public byte[] encode()
Specified by:
encode in interface DatabaseEntry

decode

public boolean decode(byte[] source,
                      int offset,
                      int length)
Specified by:
decode in interface DatabaseEntry