SPT Object Database API

com.sptci.prevayler
Class PrevalentObject<K>

java.lang.Object
  extended by com.sptci.prevayler.PrevalentObject<K>
All Implemented Interfaces:
Serializable, Cloneable, Comparable<PrevalentObject<K>>

public abstract class PrevalentObject<K>
extends Object
implements Serializable, Cloneable, Comparable<PrevalentObject<K>>

Abstract base class whose instances are stored in the prevalent system. At present sptodb does not support persisting other types of classes. This restriction was introduced since we need a objectId field in the class that can be managed by the prevalent system. Making this an interface would not guarantee us the availability of such a field.

© Copyright 2008 Sans Pareil Technologies, Inc.

Version:
$Id: PrevalentObject.java 22 2008-11-24 19:04:25Z sptrakesh $
Author:
Rakesh Vidyadharan 2008-05-22
See Also:
Serialized Form

Field Summary
private  MetaData _sptodbMetaData
          The metadata for the persistent object.
private  K objectId
          The object id field for the instance.
private static long serialVersionUID
           
 
Constructor Summary
protected PrevalentObject()
          Default constructor.
protected PrevalentObject(K oid)
          Create a new instance of the prevalent object with the specified object id.
 
Method Summary
 Object clone()
          Over-ridden to make publicly accessible.
 int compareTo(PrevalentObject prevalentObject)
          Compare the specified prevalent object with this instance for ordering.
 boolean equals(Object object)
          Compare the specified object with this instance for equality.
(package private)  MetaData get_sptodbMetaData()
          Getter for property _sptodbMetaData.
 Date getCreationDate()
          Return the date at which this object was created.
 Date getModificationDate()
          Return the date at which this object was last updated in the prevalent system.
 K getObjectId()
          Return the object id for the business object.
abstract  K getObjectId(String oid)
          Return the objectId value that may be used to retrieve the prevalent instance from the specified string representation.
 int hashCode()
          Default implementation of Object.hashCode().
 boolean isPersistent()
          Return a flag indicating whether this instance represents a persistent instance or not.
(package private)  void set_sptodbMetaData(MetaData metadata)
          Setter for property _sptodbMetaData.
 String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

objectId

private K objectId
The object id field for the instance.


_sptodbMetaData

private MetaData _sptodbMetaData
The metadata for the persistent object. This field will be maintained by the PrevalentSystem when persistent operations on the object are performed.

Constructor Detail

PrevalentObject

protected PrevalentObject()
Default constructor. Note that a no-arg constructor is mandatory.


PrevalentObject

protected PrevalentObject(K oid)
Create a new instance of the prevalent object with the specified object id. Use this form only when you wish to control the object id (using custom object id such as String.

Parameters:
oid - The objectId value to use.
Method Detail

equals

public boolean equals(Object object)
Compare the specified object with this instance for equality. Two objects are considered equal if they have the same class and have the same value of objectId. Sub-classes are strongly discouraged from over-riding this method, since this method compares strictly based on objectId equality. In case you need to over-ride this method it is strongly recommended that you apply the additional rules after having invoked this implementation.

Overrides:
equals in class Object
Parameters:
object - The object to be compared for equality with this object.
Returns:
Return true if the specified object is equivalent to this object.

hashCode

public int hashCode()
Default implementation of Object.hashCode(). Over-ridden to return the hash code based upon objectId. Similar to equals(java.lang.Object), sub-classes are discouraged from over-riding this default implementation.

Overrides:
hashCode in class Object
Returns:
The hash code for this object.

compareTo

public int compareTo(PrevalentObject prevalentObject)
Compare the specified prevalent object with this instance for ordering. Returns a positive integer if the specified object is considered greater than this instance, 0 if equal and negative is less. Default implementation compares based upon objectId. Sub-classes may need to over-ride this method for special handling.

Specified by:
compareTo in interface Comparable<PrevalentObject<K>>
Parameters:
prevalentObject - The object to be compared with this instance.
Returns:
A positive, 0, or negative number.

toString

public String toString()
Return a string representation of this object. The default implementation just return the class name and objectId.

Overrides:
toString in class Object
Returns:
The string representation of this object.

clone

public Object clone()
             throws RuntimeException
Over-ridden to make publicly accessible.

Overrides:
clone in class Object
Returns:
The cloned instance of this object.
Throws:
RuntimeException - If the object cannot be cloned.

get_sptodbMetaData

final MetaData get_sptodbMetaData()
Getter for property _sptodbMetaData.

Returns:
Value for property _sptodbMetaData.

set_sptodbMetaData

final void set_sptodbMetaData(MetaData metadata)
Setter for property _sptodbMetaData.

Parameters:
metadata - Value to set for property _sptodbMetaData.
See Also:
get_sptodbMetaData()

getObjectId

public final K getObjectId()
Return the object id for the business object.

Returns:
The objectId value.

getCreationDate

public final Date getCreationDate()
Return the date at which this object was created. Note that the date will return different values until the object is initially persisted to the prevalent system.

Returns:
The date at which the object was persisted.

getModificationDate

public final Date getModificationDate()
Return the date at which this object was last updated in the prevalent system. Note that the date returned will return different values until the object has been persisted initially.

Returns:
The date at which the object was last updated.

isPersistent

public final boolean isPersistent()
Return a flag indicating whether this instance represents a persistent instance or not.

Returns:
Return true if the instance is perstent in the prevalent system.

getObjectId

public abstract K getObjectId(String oid)
Return the objectId value that may be used to retrieve the prevalent instance from the specified string representation. This is mandated by the necessity for storing the objectId values as String instances in the lucene index.

Note: The string value of objectId stored in the lucene index is the value returned by Object.toString(). Your primary key class must return a meaningful value to be able to reconstruct the primary key instance.

Parameters:
oid - The string value that is to be converted to the proper objectId value.
Returns:
The primary key instance.
Since:
Version 0.3

SPT Object Database API