net.sourceforge.pain.db
Class DbObject

java.lang.Object
  extended bynet.sourceforge.pain.db.DbObject
Direct Known Subclasses:
Administrator, AffectData, CodebaseData, CodebasePulse, Role, Root, TimedAffectsQueue, TriggerData, TriggersDataSet

public abstract class DbObject
extends java.lang.Object

Superclass for any persistent PAiNDb object.
Subclass should implement provideSchema method.


Constructor Summary
protected DbObject()
          This constuctor used for database startup time objects instantiation
Subclasses should also provide default empty constructor
(and not use any get/set methods in it)
protected DbObject(PainDB db)
          this contructor used by user in runtime to create new objects
if no class instance for this object exists provideSchema method
will be invoked and DbClass instance created.
 
Method Summary
 void delete()
          Removes object from database.
 DbArrayList getArrayList(int fid)
          Note: there is only getter method for Lists.
 boolean getBoolean(int fid)
           
 byte getByte(int fid)
           
 byte[] getByteArray(int fid)
          NOTE: PainDB is not able to track any changes in arrays,
user should use getXArrayForRead to avoid copying.
 byte[] getByteArrayForRead(int fid)
          NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)
 char getChar(int fid)
           
 char[] getCharArray(int fid)
          NOTE: PainDB is not able to track any changes in arrays,
user should use getXArrayForRead to avoid copying.
 char[] getCharArrayForRead(int fid)
          NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)
 PainDB getDB()
           
 DbClass getDbClass()
           
 double getDouble(int fid)
           
 float getFloat(int fid)
           
 int getInt(int fid)
           
 int[] getIntArray(int fid)
          NOTE: PainDB is not able to track any changes in arrays,
user should use getXArrayForRead to avoid copying.
 int[] getIntArrayForRead(int fid)
          NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)
 DbIntKeyMap getIntKeyMap(int fid)
          Note: there is only getter method for Maps.
 DbLinkedList getLinkedList(int fid)
          Note: there is only getter method for Lists.
 java.util.List getList(int fid)
           
 long getLong(int fid)
           
 java.io.Serializable getOid()
           
 DbObject getReference(int fid)
           
 DbReferenceSet getRefSet(int fid)
          Note: there is only getter method for Sets.
 short getShort(int fid)
           
 java.lang.String getString(int fid)
           
 java.lang.String[] getStringArray(int fid)
          NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)
 java.lang.String[] getStringArrayForRead(int fid)
          NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)
 DbStringKeyMap getStringKeyMap(int fid)
          Note: there is only getter method for Maps.
 DbStringMap getStringMap(int fid)
           
 DbStringSet getStringSet(int fid)
           
 boolean isClean()
           
 boolean isDeleted()
           
 boolean isDetached()
           
 boolean isDirty()
           
 boolean isNew()
           
protected abstract  DbClassSchema provideSchema()
          Every time we add new DbObject of the unknown class to database this method is called.
 void setBoolean(int fid, boolean value)
           
 void setByte(int fid, byte value)
           
 void setByteArray(int fid, byte[] value)
           
 void setChar(int fid, char value)
           
 void setCharArray(int fid, char[] value)
           
 void setDouble(int fid, double value)
           
 void setFloat(int fid, float value)
           
 void setInt(int fid, int value)
           
 void setIntArray(int fid, int[] value)
           
 void setLong(int fid, long value)
           
 void setReference(int fid, DbObject value)
           
 void setShort(int fid, short value)
           
 void setString(int fid, java.lang.String value)
           
 void setStringArray(int fid, java.lang.String[] value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbObject

protected DbObject()
This constuctor used for database startup time objects instantiation
Subclasses should also provide default empty constructor
(and not use any get/set methods in it)


DbObject

protected DbObject(PainDB db)
            throws java.lang.RuntimeException
this contructor used by user in runtime to create new objects
if no class instance for this object exists provideSchema method
will be invoked and DbClass instance created. Object is NEW after creation inside transaction or DIRTY in plain write mode.

Parameters:
db -
Throws:
java.lang.RuntimeException - (TODO: will be changed to some PAIN RuntimeExceptionImpl)
Method Detail

provideSchema

protected abstract DbClassSchema provideSchema()
Every time we add new DbObject of the unknown class to database this method is called. DbClass instance will be automatically created. It's called only once for every new class.


getBoolean

public final boolean getBoolean(int fid)

getByte

public final byte getByte(int fid)

getChar

public final char getChar(int fid)

getDouble

public final double getDouble(int fid)

getFloat

public final float getFloat(int fid)

getInt

public final int getInt(int fid)

getLong

public final long getLong(int fid)

getShort

public final short getShort(int fid)

getReference

public final DbObject getReference(int fid)

getString

public final java.lang.String getString(int fid)

getByteArray

public final byte[] getByteArray(int fid)
NOTE: PainDB is not able to track any changes in arrays,
user should use getXArrayForRead to avoid copying.

Parameters:
fid -
Returns:
copy of the field value

getByteArrayForRead

public final byte[] getByteArrayForRead(int fid)
NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)

Parameters:
fid -
Returns:
original field value(array, do not make copy)

getCharArray

public final char[] getCharArray(int fid)
NOTE: PainDB is not able to track any changes in arrays,
user should use getXArrayForRead to avoid copying.

Parameters:
fid -
Returns:
copy of the field value

getCharArrayForRead

public final char[] getCharArrayForRead(int fid)
NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)

Parameters:
fid -
Returns:
original field value(array, do not make copy)

getIntArray

public final int[] getIntArray(int fid)
NOTE: PainDB is not able to track any changes in arrays,
user should use getXArrayForRead to avoid copying.

Parameters:
fid -
Returns:
copy of the field value

getIntArrayForRead

public final int[] getIntArrayForRead(int fid)
NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)

Parameters:
fid -
Returns:
original field value(array, do not make copy)

getStringArray

public final java.lang.String[] getStringArray(int fid)
NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)

Parameters:
fid -
Returns:
original field value(array, do not make copy)

getStringArrayForRead

public final java.lang.String[] getStringArrayForRead(int fid)
NOTE: PainDB is not able to track any changes in arrays, this method provides direct access to arrays user should not modify array instance obtained with this method (rollback info could be lost)

Parameters:
fid -
Returns:
original field value(array, do not make copy)

getList

public final java.util.List getList(int fid)

getLinkedList

public final DbLinkedList getLinkedList(int fid)
Note: there is only getter method for Lists. List could be empty but not null!

Parameters:
fid - number of field
Returns:
list

getArrayList

public final DbArrayList getArrayList(int fid)
Note: there is only getter method for Lists. List could be empty but not null!

Parameters:
fid - number of field
Returns:
list

getIntKeyMap

public final DbIntKeyMap getIntKeyMap(int fid)
Note: there is only getter method for Maps. Map could be empty but never null!

Parameters:
fid - number of field
Returns:
map

getStringKeyMap

public final DbStringKeyMap getStringKeyMap(int fid)
Note: there is only getter method for Maps. Map could be empty but never null!

Parameters:
fid - number of field
Returns:
map

getRefSet

public final DbReferenceSet getRefSet(int fid)
Note: there is only getter method for Sets. Set could be empty but never null!

Parameters:
fid -
Returns:
set

getStringSet

public final DbStringSet getStringSet(int fid)

getStringMap

public final DbStringMap getStringMap(int fid)

setBoolean

public final void setBoolean(int fid,
                             boolean value)

setByte

public final void setByte(int fid,
                          byte value)

setChar

public final void setChar(int fid,
                          char value)

setDouble

public final void setDouble(int fid,
                            double value)

setFloat

public final void setFloat(int fid,
                           float value)

setInt

public final void setInt(int fid,
                         int value)

setLong

public final void setLong(int fid,
                          long value)

setShort

public final void setShort(int fid,
                           short value)

setString

public final void setString(int fid,
                            java.lang.String value)

setReference

public final void setReference(int fid,
                               DbObject value)

setByteArray

public final void setByteArray(int fid,
                               byte[] value)

setCharArray

public final void setCharArray(int fid,
                               char[] value)

setStringArray

public final void setStringArray(int fid,
                                 java.lang.String[] value)

setIntArray

public final void setIntArray(int fid,
                              int[] value)

delete

public void delete()
Removes object from database. Object could be restored if rollback called on current or upper level transaction


getDB

public final PainDB getDB()

getDbClass

public final DbClass getDbClass()

getOid

public final java.io.Serializable getOid()
Returns:
serializable object id. This id is unique for object and will never be reused

isDeleted

public final boolean isDeleted()
Returns:
true if obj was deleted in current transaction, commit still is not called

isDirty

public final boolean isDirty()
Returns:
true if obj was modified (or created in plainwrite mode) and still not flushed

isNew

public final boolean isNew()
Returns:
true if obj was created in current transaction

isClean

public final boolean isClean()

isDetached

public final boolean isDetached()
Returns:
true if object is not registered in db, was deleted and commited or deleted in plainwrite mode or database was closed