org.rimudb
Class DataObject

java.lang.Object
  extended by org.rimudb.DataObject
All Implemented Interfaces:
java.io.Serializable

public abstract class DataObject
extends java.lang.Object
implements java.io.Serializable

Base class for DO classes.

Author:
Simon Ritchie
See Also:
Serialized Form

Field Summary
protected  Database database
           
static int DUPLICATE_EXCEPTION
           
static int DUPLICATE_FAIL_SILENT
           
static int DUPLICATE_REPLACE
           
protected  Record record
           
protected  Table table
           
 
Constructor Summary
DataObject()
           
DataObject(CompoundDatabase compoundDatabase)
           
DataObject(Database database)
           
DataObject(Database database, LockResult lockResult)
           
DataObject(Database database, Record record)
           
DataObject(DataObject dataObject)
           
 
Method Summary
protected  void add()
          Add the record referenced by this instance to the table.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener
 void commit()
           
 DataObject commit(Database database)
          Commit the data in this DataObject to the indicated database.
 void commit(int handleDuplicates)
          Commit changes made in this object to the database.
 void commit(Session session)
           
 void commit(Session session, int handleDuplicates)
           
 void copyTo(DataObject dataObject)
          Copy the values from this DataObject instance to another, including key values.
 void copyTo(DataObject dataObject, boolean includeKeyColumns)
          Copy the values from this DataObject instance to another, possibly including key columns.
protected  Record createRecord()
          Create a record for the data object.
 void delete()
          Delete this object from the database.
 void delete(Session session)
          Remove the record using a transactional connection.
 void deleteUsingTransaction(Session session)
          Deprecated. Use delete(Session) instead
 boolean exists()
          Return true if the underlying record exists in the database.
 java.lang.String[] getChangedProperties()
          Return an array of property names that have been changed and have not been committed to the database.
 Database getDatabase()
          Return the database.
protected  LockResult getLockResult()
          Return the LockResult.
 Record getOriginalRecord()
           
 KeyList getPrimaryKeyList()
          Deprecated. In some cases getPrimaryWhereList() can be used to replace this.
 WhereList getPrimaryWhereList()
          Return the primary WhereList from the underlying record.
 Record getRecord()
           
protected  java.lang.Object getRimuDBPropertyValue(java.lang.String propertyName)
          Return a property value.
 TableMetaData getTableMetaData()
           
 void init(Database database)
          Initialize the DO.
 boolean isAdding()
          Indicates if the record is going to be added.
 boolean isModified()
           
protected  boolean isNoArgsConstructorUsed()
          Return true if the no argument constructor was used.
protected  boolean isRecordConstructorUsed()
          Return true if the constructor that receives a record was used.
 boolean isVirtual()
           
protected  void newRecord()
          Create a new empty record
 void releaseLock()
          Release the lock.
 void reload()
          Reload the record from the database if it is not already loaded.
protected  java.lang.String rightJustify(java.lang.String s, int maxLength)
          Right justify the column value.
 void setDatabase(Database database)
          This method is designed primarily for use with Java object serialization.
 void setExists(boolean exists)
          Set to true if the underlying record exists in the database
protected  void setRimuDBPropertyValue(java.lang.String propertyName, java.lang.Object newValue)
           
 void setVirtual(boolean virtual)
           
 java.lang.String toString()
          Returns a string representation of the object.
 void undoChanges()
          Undo changes that have been made to the Data Object.
protected  void update()
          Update this object in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DUPLICATE_REPLACE

public static final int DUPLICATE_REPLACE
See Also:
Constant Field Values

DUPLICATE_FAIL_SILENT

public static final int DUPLICATE_FAIL_SILENT
See Also:
Constant Field Values

DUPLICATE_EXCEPTION

public static final int DUPLICATE_EXCEPTION
See Also:
Constant Field Values

database

protected transient Database database

table

protected transient Table table

record

protected Record record
Constructor Detail

DataObject

public DataObject()
           throws RimuDBException
Throws:
RimuDBException

DataObject

public DataObject(DataObject dataObject)
           throws RimuDBException
Throws:
RimuDBException

DataObject

public DataObject(Database database)
           throws RimuDBException
Throws:
RimuDBException

DataObject

public DataObject(Database database,
                  Record record)
           throws RimuDBException
Throws:
RimuDBException

DataObject

public DataObject(Database database,
                  LockResult lockResult)
           throws RimuDBException
Throws:
RimuDBException

DataObject

public DataObject(CompoundDatabase compoundDatabase)
           throws RimuDBException
Throws:
RimuDBException
Method Detail

getTableMetaData

public TableMetaData getTableMetaData()
                               throws RimuDBException
Throws:
RimuDBException

setRimuDBPropertyValue

protected void setRimuDBPropertyValue(java.lang.String propertyName,
                                      java.lang.Object newValue)
                               throws RimuDBException
Throws:
RimuDBException

getRecord

public Record getRecord()

getRimuDBPropertyValue

protected java.lang.Object getRimuDBPropertyValue(java.lang.String propertyName)
Return a property value.

Parameters:
propertyName - String
Returns:
Object

add

protected void add()
            throws RimuDBException
Add the record referenced by this instance to the table. WARNING: Do not call this method directly. Use commit() instead.

Throws:
RimuDBException

newRecord

protected void newRecord()
                  throws RimuDBException
Create a new empty record

Throws:
RimuDBException

update

protected void update()
               throws RimuDBException
Update this object in the database. WARNING: Do not call this method directly. Use commit() instead.

Throws:
RimuDBException

commit

public final void commit()
                  throws RimuDBException
Throws:
RimuDBException

commit

public final void commit(int handleDuplicates)
                  throws RimuDBException

Commit changes made in this object to the database.

The handleDuplicates parameter is used to control how a DuplicateKeyException is handled in the case of an add where the key already exists. The following values are valid:

DUPLICATE_REPLACE: Automatically try an update to replace the record.

DUPLICATE_FAIL_SILENT: Give up trying to add the record (fail silently)

DUPLICATE_EXCEPTION: Rethrow the DuplicateKeyException to th caller.

Throws:
RimuDBException

exists

public boolean exists()
               throws RimuDBException
Return true if the underlying record exists in the database.

Returns:
boolean
Throws:
RimuDBException

setExists

public void setExists(boolean exists)
               throws RimuDBException
Set to true if the underlying record exists in the database

Parameters:
exists - boolean
Throws:
RimuDBException

isAdding

public boolean isAdding()
Indicates if the record is going to be added. This will return true if the DataObject was created without a keylist, and the commit method has not already been called to add the record.


commit

public final DataObject commit(Database database)
                        throws RimuDBException
Commit the data in this DataObject to the indicated database. The purpose of this method is to allow a DataObject created with one Database (or even without a Database) to be committed to a different Database. This is useful when a DataObject is deserialized since the original Database is transient and cannot be serialized and deserialized as other member variables can.

Throws:
RimuDBException

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener

Parameters:
listener - PropertyChangeListener

getChangedProperties

public java.lang.String[] getChangedProperties()
Return an array of property names that have been changed and have not been committed to the database. Returns null if no properties have been changed.

Returns:
String[]

undoChanges

public void undoChanges()
Undo changes that have been made to the Data Object. Note this method does not undo changes that have been committed to the database.


reload

public void reload()
            throws RimuDBException
Reload the record from the database if it is not already loaded.

Throws:
RimuDBException

releaseLock

public void releaseLock()
                 throws RimuDBException
Release the lock. A lock on a record can be set by using the finder.find(..., Lock lock) or finder.find(KeyList primaryKeyList, Lock lock) method. If no lock exits, a RimuDBException will be thrown.

Throws:
RimuDBException

rightJustify

protected java.lang.String rightJustify(java.lang.String s,
                                        int maxLength)
Right justify the column value. This is particularly useful for some legacy iSeries tables where CHAR columns must enforce right justification of data.

Parameters:
s - String
maxLength - int
Returns:
String

delete

public void delete()
            throws RimuDBException
Delete this object from the database.

Throws:
RimuDBException

delete

public void delete(Session session)
            throws RimuDBException
Remove the record using a transactional connection.

Parameters:
session -
Throws:
RimuDBException

deleteUsingTransaction

@Deprecated
public void deleteUsingTransaction(Session session)
                            throws RimuDBException
Deprecated. Use delete(Session) instead

Remove the record using a transactional connection.

Parameters:
session -
Throws:
RimuDBException

getPrimaryKeyList

@Deprecated
public KeyList getPrimaryKeyList()
Deprecated. In some cases getPrimaryWhereList() can be used to replace this.

Return the primary keylist from the underlying record.

Returns:
KeyList

getPrimaryWhereList

public WhereList getPrimaryWhereList()
Return the primary WhereList from the underlying record.

Returns:
WhereList

getOriginalRecord

public Record getOriginalRecord()

getDatabase

public Database getDatabase()
Return the database.


setDatabase

public void setDatabase(Database database)
This method is designed primarily for use with Java object serialization.

Parameters:
database - Database

init

public void init(Database database)
          throws RimuDBException
Initialize the DO. When a DO is created with the no-args constructor, the record TableMetaData cannot be accessed to create a record. In order to cause the record to be created, this method must be called before any other method is used.

Parameters:
database - Database
Throws:
RimuDBException

createRecord

protected Record createRecord()
                       throws RimuDBException
Create a record for the data object.

Throws:
RimuDBException

copyTo

public void copyTo(DataObject dataObject)
            throws RimuDBException
Copy the values from this DataObject instance to another, including key values.

Parameters:
dataObject - DataObject
Throws:
RimuDBException

isModified

public boolean isModified()

setVirtual

public void setVirtual(boolean virtual)
Parameters:
virtual - the virtual to set

isVirtual

public boolean isVirtual()
Returns:
the virtual

commit

public void commit(Session session)
            throws RimuDBException
Throws:
RimuDBException

commit

public void commit(Session session,
                   int handleDuplicates)
            throws RimuDBException
Throws:
RimuDBException

getLockResult

protected LockResult getLockResult()
Return the LockResult.

Returns:
LockResult

isNoArgsConstructorUsed

protected boolean isNoArgsConstructorUsed()
Return true if the no argument constructor was used.

Returns:
boolean

isRecordConstructorUsed

protected boolean isRecordConstructorUsed()
Return true if the constructor that receives a record was used.

Returns:
boolean

toString

public java.lang.String toString()
Returns a string representation of the object. If the DataObject has had it's key properties loaded, then the String returned will be DataObjectName[key1=value1|key2=value2]. i.e. OrderLineDO[orderNumber=1000|lineNumber=5]

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.

copyTo

public void copyTo(DataObject dataObject,
                   boolean includeKeyColumns)
            throws RimuDBException
Copy the values from this DataObject instance to another, possibly including key columns.

Parameters:
dataObject - DataObject
includeKeyColumns - boolean
Throws:
RimuDBException


Copyright © 2008-2011 Simon Ritchie. All Rights Reserved.