org.opensubsystems.core.data
Class DataObject

java.lang.Object
  extended by org.opensubsystems.core.data.DataObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BasicDataObject

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

Base class for all data objects regardless of how they are persisted. Data object is here to implement Transfer Object pattern as described in http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html The main goal is to encapsulate set of related attributes as one object so they can be easily passed between different modules and tiers.

Version:
$Id: DataObject.java,v 1.9 2007/01/07 06:14:17 bastafidli Exp $
Author:
Miro Halas
See Also:
Serialized Form
Code reviewer:
Miro Halas
Code reviewed:
1.6 2005/09/07 16:32:31 alkalimero

Field Summary
static int NEW_ID
          ID used when creating new object for which the real ID wasn't generated yet.
static java.lang.Integer NEW_ID_OBJ
          Object representation for easy reuse.
static java.lang.String NEW_ID_STR
          String representation for easy reuse.
 
Constructor Summary
DataObject()
           
 
Method Summary
abstract  int getId()
          Get the id uniquely identifying the object.
abstract  java.lang.Integer getIdAsObject()
          Get the id as object uniquely identifying the object.
 boolean isFromPersistenceStore()
          Check if this record was loaded from some persistence store and therefore it is existing data object which was already created in the persistence store or it came from somewhere else (was created in memory).
abstract  boolean isSame(java.lang.Object oObject)
          Method to compare all data attributes of two objects to figure out, if their attributes are the same.
 void setFromPersistenceStore()
          Set flag that this record was loaded from some persistance store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_ID

public static final int NEW_ID
ID used when creating new object for which the real ID wasn't generated yet. HSQLDB at some time autogenerated first entry as 0 and it wasn't possible to change it. Therefore we used -1 as value which won't be generated by DB. Then HSQLDB made it configurable but I was afraid that -1 was already used at some places as hardcoded value and not at constant that it is too risky to change it to 0 (which is what would it be if the value it not initialized)

See Also:
Constant Field Values

NEW_ID_OBJ

public static final java.lang.Integer NEW_ID_OBJ
Object representation for easy reuse.


NEW_ID_STR

public static final java.lang.String NEW_ID_STR
String representation for easy reuse.

Constructor Detail

DataObject

public DataObject()
Method Detail

isFromPersistenceStore

public boolean isFromPersistenceStore()
Check if this record was loaded from some persistence store and therefore it is existing data object which was already created in the persistence store or it came from somewhere else (was created in memory).

Returns:
boolean

setFromPersistenceStore

public void setFromPersistenceStore()
Set flag that this record was loaded from some persistance store.


getId

public abstract int getId()
Get the id uniquely identifying the object.

Returns:
int

getIdAsObject

public abstract java.lang.Integer getIdAsObject()
Get the id as object uniquely identifying the object. This method allows to the implementing class to cache this object if desired to improve performance.

Returns:
Integer

isSame

public abstract boolean isSame(java.lang.Object oObject)
Method to compare all data attributes of two objects to figure out, if their attributes are the same. The objects can for example differ by database generated id and creation or modification timestamp but if other properties which represents the real data are the same then the objects are considered to be the same. This is weaker constraint that equals since not all attributes has to be the same, only the one which really represents the business data should match.

Parameters:
oObject - - Object to compare
Returns:
boolean - true if same, false otherwise


Copyright © 2003 - 2006 OpenSubsystems s.r.o.