org.nakedobjects.plugins.hibernate.objectstore.persistence.oidgenerator
Class HibernateOid

java.lang.Object
  extended by org.nakedobjects.plugins.hibernate.objectstore.persistence.oidgenerator.HibernateOid
All Implemented Interfaces:
Oid, Encodable

public final class HibernateOid
extends java.lang.Object
implements Oid


Constructor Summary
HibernateOid(DataInputExtended input)
           
 
Method Summary
 void clearPrevious()
           
 void copyFrom(Oid oid)
           
static HibernateOid createPersistent(java.lang.Class<?> clazz, java.io.Serializable primaryKey)
          Creates a new persistent instance, using the specified primaryKey.
static HibernateOid createPersistent(java.lang.String className, java.io.Serializable primaryKey)
          Creates a new persistent instance, using the specified primaryKey.
static HibernateOid createPersistent(java.lang.String className, java.io.Serializable primaryKey, java.io.Serializable hibernateId)
          Creates a new persistent instance, using the specified primaryKey and (possibly different) hibernateId.
static HibernateOid createTransient(java.lang.Class<?> clazz, long id)
          Create a new transient instance, creating a primaryKey from the provided id.
static HibernateOid createTransient(java.lang.Class<?> clazz, java.io.Serializable primaryKey)
          Create a new transient instance, using the specified primaryKey.
static HibernateOid createTransient(java.lang.String className, long id)
          Create a new transient instance, creating a primaryKey from the provided id.
static HibernateOid createTransient(java.lang.String className, java.io.Serializable primaryKey)
          Create a new transient id.
 void encode(DataOutputExtended output)
           
 boolean equals(java.lang.Object obj)
           
 java.lang.String getClassName()
          Used in equals(Object).
 java.io.Serializable getHibernateId()
          The id to return to hibernate.
 Oid getPrevious()
          The previous Oid, if any.
 java.io.Serializable getPrimaryKey()
          Used in equals(Object).
 int hashCode()
           
 boolean hasPrevious()
           
 boolean isTransient()
           
 void makePersistent()
          Use the hibernate Id as the primary key, in the process marking the Oid as persistent, and storing the previous value.
 void setHibernateId(java.io.Serializable hibernateId)
          Update the Id, and recache state.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HibernateOid

public HibernateOid(DataInputExtended input)
             throws java.io.IOException
Throws:
java.io.IOException
Method Detail

createTransient

public static HibernateOid createTransient(java.lang.Class<?> clazz,
                                           long id)
Create a new transient instance, creating a primaryKey from the provided id.

See Also:
for postconditions.

createTransient

public static HibernateOid createTransient(java.lang.String className,
                                           long id)
Create a new transient instance, creating a primaryKey from the provided id.

See Also:
for postconditions.

createTransient

public static HibernateOid createTransient(java.lang.Class<?> clazz,
                                           java.io.Serializable primaryKey)
Create a new transient instance, using the specified primaryKey.

See Also:
for postconditions.

createTransient

public static HibernateOid createTransient(java.lang.String className,
                                           java.io.Serializable primaryKey)
Create a new transient id.

The getHibernateId() will initially be null.


createPersistent

public static HibernateOid createPersistent(java.lang.Class<?> clazz,
                                            java.io.Serializable primaryKey)
Creates a new persistent instance, using the specified primaryKey.

See Also:
for postconditions.

createPersistent

public static HibernateOid createPersistent(java.lang.String className,
                                            java.io.Serializable primaryKey)
Creates a new persistent instance, using the specified primaryKey.

The getHibernateId() will be the same as the primaryKey.


createPersistent

public static HibernateOid createPersistent(java.lang.String className,
                                            java.io.Serializable primaryKey,
                                            java.io.Serializable hibernateId)
Creates a new persistent instance, using the specified primaryKey and (possibly different) hibernateId.


encode

public void encode(DataOutputExtended output)
            throws java.io.IOException
Specified by:
encode in interface Encodable
Throws:
java.io.IOException

copyFrom

public void copyFrom(Oid oid)
Specified by:
copyFrom in interface Oid

getClassName

public java.lang.String getClassName()
Used in equals(Object).


getPrimaryKey

public java.io.Serializable getPrimaryKey()
Used in equals(Object).

Will be the same as the getHibernateId() once the Oid has been made persistent.

Returns:

makePersistent

public void makePersistent()
Use the hibernate Id as the primary key, in the process marking the Oid as persistent, and storing the previous value.

Note 1: should be preceded by a call to setHibernateId(Serializable) to set the hibernate Id.

Note 2: if called then the hashCode() may change; it is the caller's responsibility to manage any Maps that the Oid might be using.

TODO: should probably combine with setHibernateId(Serializable) ??

Specified by:
makePersistent in interface Oid

getHibernateId

public java.io.Serializable getHibernateId()
The id to return to hibernate.

Will return null if the HibernateOid has not been made persistent.


setHibernateId

public void setHibernateId(java.io.Serializable hibernateId)
Update the Id, and recache state.

Note: if called then the hashCode() may change; it is the caller's responsibility to manage any Maps that the Oid might be using.


getPrevious

public Oid getPrevious()
The previous Oid, if any.

Will hold this Oid in its transient form once makePersistent() has been called. This allows client-side code to maintain its Oid->Object maps.

Specified by:
getPrevious in interface Oid

hasPrevious

public boolean hasPrevious()
Specified by:
hasPrevious in interface Oid

clearPrevious

public void clearPrevious()
Specified by:
clearPrevious in interface Oid

isTransient

public boolean isTransient()
Specified by:
isTransient in interface Oid

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2001-2009 Naked Objects Group Ltd.. All Rights Reserved.