org.garret.consus
Class ConsusRef

java.lang.Object
  extended by org.garret.consus.ConsusRef
All Implemented Interfaces:
java.lang.Comparable, java.sql.Ref, java.io.Serializable

public class ConsusRef
extends java.lang.Object
implements java.sql.Ref, java.lang.Comparable, java.io.Serializable

JDBC 2.0 A reference to an SQL structured type value in the database. A Ref can be saved to a persistent storage. A Ref is dereferenced by passing it as a parameter to an SQL statement and executing the statement.

See Also:
Serialized Form

Constructor Summary
ConsusRef(long oid)
          Construct a reference to the object with the specified OID
ConsusRef(PersistentObjectStorage db, long oid)
          Construct a reference to the object with the specified OID
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compare two OID as longs
 boolean equals(java.lang.Object ref)
          Compare two references for equality
 java.lang.String getBaseTypeName()
          Gets the fully-qualified SQL structured type name of the referenced item.
 java.lang.Object getObject()
          Retrieves the SQL structured type instance referenced by this Ref object.
 java.lang.Object getObject(java.util.Map map)
          Retrieves the referenced object and maps it to a Java type using the given type map.
 long getOid()
          Get the OID.
 int hashCode()
          Rerference the hash code.
 void setObject(java.lang.Object value)
          Sets the structured type value that this Ref object references to the given instance of Object.
 java.lang.String toString()
          Convert reference to a String.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConsusRef

public ConsusRef(long oid)
Construct a reference to the object with the specified OID

Parameters:
oid - OID of the object or 0

ConsusRef

public ConsusRef(PersistentObjectStorage db,
                 long oid)
Construct a reference to the object with the specified OID

Parameters:
oid - OID of the object or 0
Method Detail

compareTo

public int compareTo(java.lang.Object obj)
Compare two OID as longs

Specified by:
compareTo in interface java.lang.Comparable
Returns:
-1 if less than, 0 if equal, and 1 if greater

equals

public boolean equals(java.lang.Object ref)
Compare two references for equality

Overrides:
equals in class java.lang.Object
Returns:
true if there are references to the same object or null references, false otherwise.

getBaseTypeName

public java.lang.String getBaseTypeName()
                                 throws java.sql.SQLException
Gets the fully-qualified SQL structured type name of the referenced item.

Specified by:
getBaseTypeName in interface java.sql.Ref
Returns:
fully-qualified SQL structured type name of the referenced item.
Throws:
java.sql.SQLException - if a database access error occurs

getObject

public java.lang.Object getObject()
                           throws java.sql.SQLException
Retrieves the SQL structured type instance referenced by this Ref object. If the connection's type map has an entry for the structured type, the instance will be custom mapped to the Java class indicated in the type map. Otherwise, the structured type instance will be mapped to a Struct object.

Specified by:
getObject in interface java.sql.Ref
Returns:
a Java Object that is the mapping for the SQL structured type to which this Ref object refers
Throws:
java.sql.SQLException - if a database access error occurs
Since:
1.4
See Also:
setObject(java.lang.Object)

getObject

public java.lang.Object getObject(java.util.Map map)
                           throws java.sql.SQLException
Retrieves the referenced object and maps it to a Java type using the given type map.

Specified by:
getObject in interface java.sql.Ref
Parameters:
map - a java.util.Map object that contains the mapping to use (the fully-qualified name of the SQL structured type being referenced and the class object for SQLData implementation to which the SQL structured type will be mapped)
Returns:
a Java Object that is the custom mapping for the SQL structured type to which this Ref object refers
Throws:
java.sql.SQLException - if a database access error occurs
Since:
1.4
See Also:
setObject(java.lang.Object)

getOid

public final long getOid()
Get the OID.

Returns:
object identifier

hashCode

public int hashCode()
Rerference the hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
OID

setObject

public void setObject(java.lang.Object value)
               throws java.sql.SQLException
Sets the structured type value that this Ref object references to the given instance of Object. The driver converts this to an SQL structured type when it sends it to the database.

Specified by:
setObject in interface java.sql.Ref
Parameters:
value - an Object representing the SQL structured type instance that this Ref object will reference
Throws:
java.sql.SQLException - if a database access error occurs
Since:
1.4
See Also:
getObject(), getObject(Map), PreparedStatement.setObject(int, Object)

toString

public java.lang.String toString()
Convert reference to a String.

Overrides:
toString in class java.lang.Object
Returns:
integer representing OID with prepended '@' symbol