File: PGobject.java

package info (click to toggle)
libpgjava 8.4-701-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,532 kB
  • ctags: 4,162
  • sloc: java: 33,948; xml: 3,158; makefile: 14; sh: 10
file content (102 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*-------------------------------------------------------------------------
*
* Copyright (c) 2003-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
*   $PostgreSQL: pgjdbc/org/postgresql/util/PGobject.java,v 1.11 2008/01/08 06:56:31 jurka Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.util;

import java.io.Serializable;
import java.sql.SQLException;

/**
 *     PGobject is a class used to describe unknown types
 *     An unknown type is any type that is unknown by JDBC Standards
 */
public class PGobject implements Serializable, Cloneable
{
    protected String type;
    protected String value;

    /**
     * This is called by org.postgresql.Connection.getObject() to create the
     * object.
     */
    public PGobject()
    {
    }

    /**
     * This method sets the type of this object.
     *
     * <p>It should not be extended by subclasses, hence its final
     *
     * @param type a string describing the type of the object
     */
    public final void setType(String type)
    {
        this.type = type;
    }

    /**
     * This method sets the value of this object. It must be overidden.
     *
     * @param value a string representation of the value of the object
     * @exception SQLException thrown if value is invalid for this type
     */
    public void setValue(String value) throws SQLException
    {
        this.value = value;
    }

    /**
     * As this cannot change during the life of the object, it's final.
     * @return the type name of this object
     */
    public final String getType()
    {
        return type;
    }

    /**
     * This must be overidden, to return the value of the object, in the
     * form required by org.postgresql.
     * @return the value of this object
     */
    public String getValue()
    {
        return value;
    }

    /**
     * This must be overidden to allow comparisons of objects
     * @param obj Object to compare with
     * @return true if the two boxes are identical
     */
    public boolean equals(Object obj)
    {
        if (obj instanceof PGobject)
            return ((PGobject)obj).getValue().equals(getValue());
        return false;
    }

    /**
     * This must be overidden to allow the object to be cloned
     */
    public Object clone() throws CloneNotSupportedException
    {
        return super.clone();
    }

    /**
     * This is defined here, so user code need not overide it.
     * @return the value of this object, in the syntax expected by org.postgresql
     */
    public String toString()
    {
        return getValue();
    }
}