com.arsdigita.persistence
Class OID

java.lang.Object
  extended bycom.arsdigita.persistence.OID

public class OID
extends Object

An OID represents a unique object ID. An OID is composed of an object type and 1 or more values.

The OID class encapsulates the details of the primary key of an object. You use instances of OID for retrieving an object from the database and you would set the OID to a known value. You can also get an OID object from a DataObject.

Note that when the object type is a subtype of ACS Object, we know that the object_id uniquely identifies the object. The OID class is meant to handle both this special case and the more general case where there does not exist a single, unique integer.

Version:
$Revision: #15 $ $Date: 2004/04/07 $
Author:
rhs@mit.edu

Field Summary
static String versionId
           
 
Constructor Summary
OID(ObjectType type)
          Creates an OID for the Object type.
OID(ObjectType type, int value)
          Creates an OID with a single attribute for the key.
OID(ObjectType type, Object value)
          Creates an OID with a single attribute for the key.
OID(String typeName)
          Creates an OID for the named ObjectType.
OID(String typeName, int value)
          Creates an OID with a single attribute for the key.
OID(String typeName, Object value)
          Creates an OID with a single attribute for the key.
 
Method Summary
 boolean arePropertiesNull()
          Indicates if an OID contains no non-null information.
 boolean equals(Object obj)
          Indicates if two OIDs have the same base type and contain the same values.
 Object get(String propertyName)
          Obtains a property associated with the OID.
 ObjectType getDataObjectType()
          Deprecated.  
 int getNumberOfProperties()
           
 ObjectType getObjectType()
           
 int hashCode()
          Simple hashcode method to calculate hashcode based on the information used in the equals method.
 boolean hasProperty(String name)
           
 boolean isInitialized()
           
 void set(String propertyName, Object value)
          Adds a property to the OID.
 String toString()
          Serializes the OID.
static OID valueOf(String s)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

OID

public OID(ObjectType type)
Creates an OID for the Object type. An example of an object type would be "com.arsdigita.kernel.ACSObject." Using this constructor alone does not create a full OID. Rather, the code must also call the set(String propertyName, Object value) method to set the value that corresponds with the OID (this value must be part of the object key for the passed in object type). For instance, if the code passes in the ACSObject ObjectType then the code should also call oid.set("id", valueOfID);. The list of potential parameters that can be set can be retrieved by calling type.getObjectMap().getObjectKey().

This constructor is typically used when the ObjectType has multiple keys ( type.getObjectMap().getObjectKey().getCount() > 1) but it can be used when there is only a single key however it would probably be easier to use one of the other convenience constructors when there is only a single key.

Parameters:
type - The ObjectType

OID

public OID(ObjectType type,
           Object value)
Creates an OID with a single attribute for the key. To create a multi-valued OID, use a single arg OID constructor, and add individual properties with the set method. This constructor should be used when the object type being instantiated has a single primary key. For instance, if the object type is com.arsdigita.kernel.ACSObject then the value should be the object_id. So, if developers wanted to create the OID for ID zero, they would call new OID(acsObjectType, new BigDecimal(0)). A BigDecimal is passed in because the "id" attribute for the ACSObject type is declared as BigDecimal in the PDL file.

Parameters:
type - The ObjectType of the ID
value - The value of the ID
Throws:
PersistenceException - will be thrown if the given object type does not have exactly a single key (if type.getObjectMap().getObjectKey().getCount() != 1).

OID

public OID(String typeName)
Creates an OID for the named ObjectType. The typename of the ObjectType must be defined in the MetadataRoot. An example of how this would be used is whithin the default constructor of a DomainObject. For instance, ACSObject may have a default constructor that looks like
  
  public ACSObject() {
     super("com.arsdigita.kernel.ACSObject");
  }
  
  
and the call to super contains "new OID(typeName)"

Parameters:
typeName - The name of the ObjectType.

OID

public OID(String typeName,
           Object value)
Creates an OID with a single attribute for the key. To create a multi-valued OID, use a single arg OID constructor, and add individual properties with the set method. This constructor should be used when the object type being instantiated has a single primary key. For instance, if the object type is com.arsdigita.kernel.ACSObject then the value should be the object_id. So, if developers wanted to create the OID for ID zero, they would call new OID("com.arsdigita.kernel.ACSObject", new BigDecimal(0)). A BigDecimal is passed in because the "id" attribute for the ACSObject type is declared as BigDecimal in the PDL file. This is analogous to OID(ObjectType type, Object value) except that a string is used to lookup the correct object type.

The typename of the ObjectType must be defined in the MetadataRoot.

Parameters:
value - The value of the ID
Throws:
PersistenceException - will be thrown if the given object type does not have exactly a single key (if type.getObjectMap().getObjectKey().getCount() != 1).

OID

public OID(String typeName,
           int value)
Creates an OID with a single attribute for the key. To create a multi-valued OID, use a single arg OID constructor, and add individual properties with the set method. This constructor should be used when the object type being instantiated has a single primary key. For instance, if the object type is com.arsdigita.kernel.ACSObject then the value should be the object_id. So, if developers wanted to create the OID for ID zero, they would call new OID("com.arsdigita.kernel.ACSObject", 0). This is analogous to OID(ObjectType type, Object value) except that a string is used to lookup the correct object type and the passed in int is converted to a BigDecimal object.

The typename of the ObjectType must be defined in the MetadataRoot.

Parameters:
value - The integer value of the ID
Throws:
PersistenceException - will be thrown if the given object type does not have exactly a single key (if type.getObjectMap().getObjectKey().getCount() != 1).

OID

public OID(ObjectType type,
           int value)
Creates an OID with a single attribute for the key. To create a multi-valued OID, use a single arg OID constructor, and add individual properties with the set method. This constructor should be used when the object type being instantiated has a single primary key. For instance, if the object type is com.arsdigita.kernel.ACSObject then the value should be the object_id. So, if developers wanted to create the OID for ID zero, they would call new OID(acsObjectType, 0). This is analogous to OID(ObjectType type, Object value) except that the passed in int is converted to a BigDecimal object.

Parameters:
type - The ObjectType of the ID
value - The value of the property
Throws:
PersistenceException - will be thrown if the given object type does not have exactly a single key (if type.getObjectMap().getObjectKey().getCount() != 1).
Method Detail

set

public void set(String propertyName,
                Object value)
Adds a property to the OID. Is used as part of the key for the Object ID.

Parameters:
propertyName - Name of the property
value - The property

get

public Object get(String propertyName)
Obtains a property associated with the OID.

Parameters:
propertyName - Name of the property
Returns:
The property, or null if there is no property with this name.

hasProperty

public boolean hasProperty(String name)
Parameters:
name - The name of the property
Returns:
true if there is a property mapped to name, false if not.

isInitialized

public boolean isInitialized()

getNumberOfProperties

public int getNumberOfProperties()
Returns:
The number of properties

arePropertiesNull

public boolean arePropertiesNull()
Indicates if an OID contains no non-null information.

Returns:
true if no values have been set or if all values have been set to null.

getDataObjectType

public ObjectType getDataObjectType()
Deprecated.  

Returns:
The ObjectType.

getObjectType

public ObjectType getObjectType()
Returns:
The ObjectType.

toString

public String toString()
Serializes the OID.


valueOf

public static OID valueOf(String s)
                   throws IllegalArgumentException
Throws:
IllegalArgumentException

equals

public boolean equals(Object obj)
Indicates if two OIDs have the same base type and contain the same values. Note that if values are null this isn't an ideal distinction; it's best to check "arePropertiesNull" before relying on this equals method (see DomainObject's equals method for an example).


hashCode

public int hashCode()
Simple hashcode method to calculate hashcode based on the information used in the equals method. Needed because we overrode equals; two equivalent objects must hash to the same value.



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC