org.apache.ojb.broker
Class Identity

java.lang.Object
  extended byorg.apache.ojb.broker.Identity
All Implemented Interfaces:
java.io.Serializable

public class Identity
extends java.lang.Object
implements java.io.Serializable

represents the identity of an object. identity (it's primary keys) must be unique accross extents !

Version:
$Id: Identity.java,v 1.32 2004/02/17 16:39:34 arminw Exp $
Author:
Thomas Mahler
See Also:
Serialized Form

Field Summary
(package private) static long serialVersionUID
           
 
Constructor Summary
Identity(java.lang.Class realClass, java.lang.Class topLevel, java.lang.Object[] pkValues)
          creates an Identity from a class and the objects primary key values.
Identity(java.lang.Object objectToIdentitify, PersistenceBroker targetBroker)
           
Identity(java.lang.Object objectToIdentitify, PersistenceBroker targetBroker, ClassDescriptor cld)
           
 
Method Summary
protected  void checkForPrimaryKeys()
          OJB can handle only classes that declare at least one primary key attribute, this method checks this condition.
 boolean equals(java.lang.Object obj)
          Compare this Identity object to any other object.
static Identity fromByteArray(byte[] anArray)
          Factory method that returns an Identity object from the given byte array - see serialize().
 java.lang.Class getObjectsRealClass()
          Return the "real" Class of the real subject
 java.lang.Class getObjectsTopLevelClass()
          Return the top-level class of the real subject (means class name of a base class, base interface denoted in the repository or objects real class name if none top-level was found)
 java.lang.Object[] getPrimaryKeyValues()
          return the list of Primary Key Values of the real subject
 int hashCode()
          Calculate a hashcode for this Identity.
 byte[] serialize()
          Return a serialized Identity as byte[].
 void setObjectsRealClass(java.lang.Class objectsRealClass)
          Set the objects real class
 java.lang.String toString()
          return a String representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

Identity

public Identity(java.lang.Class realClass,
                java.lang.Class topLevel,
                java.lang.Object[] pkValues)
creates an Identity from a class and the objects primary key values. used for the definition of proxies.

Parameters:
realClass - the concrete class of the object, or null if not known.
topLevel - the highest persistence-capable class or interface (in the inheritance hierarchy) that the identified object is an instance of
pkValues - (unique across the extents !)

Identity

public Identity(java.lang.Object objectToIdentitify,
                PersistenceBroker targetBroker)

Identity

public Identity(java.lang.Object objectToIdentitify,
                PersistenceBroker targetBroker,
                ClassDescriptor cld)
Method Detail

fromByteArray

public static Identity fromByteArray(byte[] anArray)
                              throws PersistenceBrokerException
Factory method that returns an Identity object from the given byte array - see serialize().

Throws:
PersistenceBrokerException

getObjectsTopLevelClass

public java.lang.Class getObjectsTopLevelClass()
Return the top-level class of the real subject (means class name of a base class, base interface denoted in the repository or objects real class name if none top-level was found)


getObjectsRealClass

public java.lang.Class getObjectsRealClass()
Return the "real" Class of the real subject


setObjectsRealClass

public void setObjectsRealClass(java.lang.Class objectsRealClass)
Set the objects real class


serialize

public byte[] serialize()
                 throws PersistenceBrokerException
Return a serialized Identity as byte[].

Throws:
PersistenceBrokerException
See Also:
fromByteArray(byte[])

toString

public java.lang.String toString()
return a String representation.

Returns:
java.lang.String

checkForPrimaryKeys

protected void checkForPrimaryKeys()
                            throws ClassNotPersistenceCapableException
OJB can handle only classes that declare at least one primary key attribute, this method checks this condition.

Throws:
ClassNotPersistenceCapableException - thrown if no primary key is specified for the objects class

getPrimaryKeyValues

public java.lang.Object[] getPrimaryKeyValues()
return the list of Primary Key Values of the real subject

Returns:
Object[]

equals

public boolean equals(java.lang.Object obj)
Compare this Identity object to any other object. This comparison is delegated to the super-class.


hashCode

public int hashCode()
Calculate a hashcode for this Identity. The Hashcode should be equal for Identities where Identity.equals() returns true. Therefore all primary key values that return a hashcode depending on its content (this is assumed for String and Number) are taken into account. Additionally the hashCode() of the Class this Identity is representing is taken into account.



Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14