com.sun.sgs.impl.service.data
Class ManagedReferenceImpl<T>

java.lang.Object
  extended by com.sun.sgs.impl.service.data.ManagedReferenceImpl<T>
All Implemented Interfaces:
ManagedReference<T>, Serializable

final class ManagedReferenceImpl<T>
extends Object
implements ManagedReference<T>, Serializable

Provides an implementation of ManagedReference. Instances of this class are associated with a single transaction. Within a transaction, instances are canonicalized: only a single instance appears for a given object ID or object.


Field Summary
(package private)  long oid
          The object ID.
 
Method Summary
(package private) static void checkAllState(Context context)
          Checks the consistency of the managed references table, throwing an exception if a problem is found.
(package private)  void checkState()
          Checks the fields of this object to make sure they have valid values, throwing an assertion error if a problem is found.
 boolean equals(Object object)
          Compares the specified object with this reference.
(package private) static
<T> ManagedReferenceImpl<T>
findReference(Context context, T object)
          Returns the reference associated with a context and object, or null if the reference is not found.
(package private)  byte[] flush()
          Returns any modifications that need to be stored to the data store, or null if there are none, and changes the state to FLUSHED.
(package private) static void flushAll(Context context)
          Saves all object modifications to the data store.
 T get()
          Obtains the object associated with this reference.
(package private)  T get(boolean checkContext)
          Like get, but with optional checking of the context.
 T getForUpdate()
          Obtains the managed object associated with this reference, and notifies the system that the object is going to be modified.
(package private)  T getForUpdate(boolean checkContext)
          Like getForUpdate, but with optional checking of the context.
 BigInteger getId()
          Returns a unique identifier for the object associated with this reference.
(package private)  ManagedObject getObject()
          Returns the object currently associated with this reference or null.
(package private) static ManagedReferenceImpl<?> getReference(Context context, long oid)
          Returns the reference associated with a context and object ID, creating an EMPTY reference if none is found.
(package private) static
<T> ManagedReferenceImpl<T>
getReference(Context context, T object)
          Returns the reference associated with a context and object, creating a NEW reference if none is found.
 int hashCode()
          Returns an appropriate hash code value for the object.
(package private)  boolean isNew()
          Checks if the object has been created in the current transaction and not removed.
(package private)  boolean isRemoved()
          Checks if the object has been marked removed.
(package private)  void markForUpdate()
           
(package private) static long nextObjectId(Context context, long oid)
          Returns the next object ID, or -1 if there are no more objects.
(package private)  void removeObject()
           
(package private) static
<T> ManagedReferenceImpl<T>
safeFindReference(Context context, T object)
          Returns the reference associated with a context and object, or null if the reference is not found or the object has been removed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

oid

final long oid
The object ID.

Method Detail

findReference

static <T> ManagedReferenceImpl<T> findReference(Context context,
                                                 T object)
Returns the reference associated with a context and object, or null if the reference is not found. Throws ObjectNotFoundException if the object has been removed.


safeFindReference

static <T> ManagedReferenceImpl<T> safeFindReference(Context context,
                                                     T object)
Returns the reference associated with a context and object, or null if the reference is not found or the object has been removed.


getReference

static <T> ManagedReferenceImpl<T> getReference(Context context,
                                                T object)
Returns the reference associated with a context and object, creating a NEW reference if none is found.


getReference

static ManagedReferenceImpl<?> getReference(Context context,
                                            long oid)
Returns the reference associated with a context and object ID, creating an EMPTY reference if none is found.


removeObject

void removeObject()

markForUpdate

void markForUpdate()

get

public T get()
Obtains the object associated with this reference. The object returned will implement ManagedObject and Serializable. For implementations that need to be notified of object modifications, applications should call getForUpdate or DataManager.markForUpdate before modifying the returned object or any of the non-managed objects it refers to.

Specified by:
get in interface ManagedReference<T>
Returns:
the associated object
See Also:
getForUpdate, DataManager.markForUpdate

get

T get(boolean checkContext)
Like get, but with optional checking of the context. Checking the context should only be suppressed if the reference was just obtained from the context.


getForUpdate

public T getForUpdate()
Obtains the managed object associated with this reference, and notifies the system that the object is going to be modified. The object returned will implement ManagedObject and Serializable.

Specified by:
getForUpdate in interface ManagedReference<T>
Returns:
the associated object
See Also:
DataManager.markForUpdate

getForUpdate

T getForUpdate(boolean checkContext)
Like getForUpdate, but with optional checking of the context. Checking the context should only be suppressed if the reference was just obtained from the context.


getId

public BigInteger getId()
Returns a unique identifier for the object associated with this reference. Two references have equal identifiers if and only if they refer to the same object.

Specified by:
getId in interface ManagedReference<T>
Returns:
a unique identifier for this reference

equals

public boolean equals(Object object)
Compares the specified object with this reference. Returns true if the argument is a ManagedReference that refers to the same object as this reference, otherwise false.

Specified by:
equals in interface ManagedReference<T>
Overrides:
equals in class Object
Parameters:
object - the object to be compared with
Returns:
if object refers to the same object

hashCode

public int hashCode()
Returns an appropriate hash code value for the object.

Specified by:
hashCode in interface ManagedReference<T>
Overrides:
hashCode in class Object
Returns:
the hash code for this object

toString

public String toString()
Overrides:
toString in class Object

checkAllState

static void checkAllState(Context context)
Checks the consistency of the managed references table, throwing an exception if a problem is found.


checkState

void checkState()
Checks the fields of this object to make sure they have valid values, throwing an assertion error if a problem is found.


flushAll

static void flushAll(Context context)
Saves all object modifications to the data store.


nextObjectId

static long nextObjectId(Context context,
                         long oid)
Returns the next object ID, or -1 if there are no more objects. Does not return IDs for removed objects. Specifying -1 requests the first ID.


flush

byte[] flush()
Returns any modifications that need to be stored to the data store, or null if there are none, and changes the state to FLUSHED.


isRemoved

boolean isRemoved()
Checks if the object has been marked removed. This method will return false if the object was not removed in this transaction.


isNew

boolean isNew()
Checks if the object has been created in the current transaction and not removed.


getObject

ManagedObject getObject()
Returns the object currently associated with this reference or null.


RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved