Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: postgresql/util/PGobject.java


1   package postgresql.util;
2   
3   import java.io.*;
4   import java.lang.*;
5   import java.sql.*;
6   import java.util.*;
7   
8   /**
9    * postgresql.PG_Object is a class used to describe unknown types 
10   * An unknown type is any type that is unknown by JDBC Standards
11   *
12   * <p>As of PostgreSQL 6.3, this allows user code to add their own
13   * handlers via a call to postgresql.Connection. These handlers
14   * must extend this class.
15   */
16  public class PGobject implements Serializable,Cloneable
17  {
18    protected String  type;
19    protected String  value;
20    
21    /**
22     * This is called by postgresql.Connection.getObject() to create the
23     * object.
24     */
25    public PGobject()
26    {
27    }
28    
29    /**
30     * This method sets the type of this object.
31     *
32     * <p>It should not be extended by subclasses, hence its final
33     *
34     * @param type a string describing the type of the object
35     */
36    public final void setType(String type)
37    {
38      this.type = type;
39    }
40    
41    /**
42     * This method sets the value of this object. It must be overidden.
43     *
44     * @param value a string representation of the value of the object
45     * @exception SQLException thrown if value is invalid for this type
46     */
47    public void setValue(String value) throws SQLException
48    {
49      this.value = value;
50    }
51    
52    /**
53     * As this cannot change during the life of the object, it's final.
54     * @return the type name of this object
55     */
56    public final String getType()
57    {
58      return type;
59    }
60    
61    /**
62     * This must be overidden, to return the value of the object, in the
63     * form required by postgresql.
64     * @return the value of this object
65     */
66    public String getValue()
67    {
68      return value;
69    }
70    
71    /**
72     * This must be overidden to allow comparisons of objects
73     * @param obj Object to compare with
74     * @return true if the two boxes are identical
75     */
76    public boolean equals(Object obj)
77    {
78      if(obj instanceof PGobject)
79        return ((PGobject)obj).getValue().equals(getValue());
80      return false;
81    }
82    
83    /**
84     * This must be overidden to allow the object to be cloned
85     */
86    public Object clone()
87    {
88      PGobject obj = new PGobject();
89      obj.type=type;
90      obj.value=value;
91      return obj;
92    }
93    
94    /**
95     * This is defined here, so user code need not overide it.
96     * @return the value of this object, in the syntax expected by postgresql
97     */
98    public String toString()
99    {
100     return getValue();
101   }
102 }