KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > sql > SQLData


1 /*
2  * @(#)SQLData.java 1.20 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.sql;
9
10 /**
11  * The interface used for the custom mapping of an SQL user-defined type (UDT) to
12  * a class in the Java programming language. The class object for a class
13  * implementing the <code>SQLData</code> interface will be entered in the
14  * appropriate <code>Connection</code> object's type map along with the SQL
15  * name of the UDT for which it is a custom mapping.
16  * <P>
17  * Typically, a <code>SQLData</code> implementation
18  * will define a field for each attribute of an SQL structured type or a
19  * single field for an SQL <code>DISTINCT</code> type. When the UDT is
20  * retrieved from a data source with the <code>ResultSet.getObject</code>
21  * method, it will be mapped as an instance of this class. A programmer
22  * can operate on this class instance just as on any other object in the
23  * Java programming language and then store any changes made to it by
24  * calling the <code>PreparedStatement.setObject</code> method,
25  * which will map it back to the SQL type.
26  * <p>
27  * It is expected that the implementation of the class for a custom
28  * mapping will be done by a tool. In a typical implementation, the
29  * programmer would simply supply the name of the SQL UDT, the name of
30  * the class to which it is being mapped, and the names of the fields to
31  * which each of the attributes of the UDT is to be mapped. The tool will use
32  * this information to implement the <code>SQLData.readSQL</code> and
33  * <code>SQLData.writeSQL</code> methods. The <code>readSQL</code> method
34  * calls the appropriate <code>SQLInput</code> methods to read
35  * each attribute from an <code>SQLInput</code> object, and the
36  * <code>writeSQL</code> method calls <code>SQLOutput</code> methods
37  * to write each attribute back to the data source via an
38  * <code>SQLOutput</code> object.
39  * <P>
40  * An application programmer will not normally call <code>SQLData</code> methods
41  * directly, and the <code>SQLInput</code> and <code>SQLOutput</code> methods
42  * are called internally by <code>SQLData</code> methods, not by application code.
43  *
44  * @since 1.2
45  */

46 public interface SQLData {
47
48  /**
49   * Returns the fully-qualified
50   * name of the SQL user-defined type that this object represents.
51   * This method is called by the JDBC driver to get the name of the
52   * UDT instance that is being mapped to this instance of
53   * <code>SQLData</code>.
54   *
55   * @return the type name that was passed to the method <code>readSql</code>
56   * when this object was constructed and populated
57   * @exception SQLException if there is a database access error
58   * @since 1.2
59   */

60   String JavaDoc getSQLTypeName() throws SQLException JavaDoc;
61
62  /**
63   * Populates this object with data read from the database.
64   * The implementation of the method must follow this protocol:
65   * <UL>
66   * <LI>It must read each of the attributes or elements of the SQL
67   * type from the given input stream. This is done
68   * by calling a method of the input stream to read each
69   * item, in the order that they appear in the SQL definition
70   * of the type.
71   * <LI>The method <code>readSQL</code> then
72   * assigns the data to appropriate fields or
73   * elements (of this or other objects).
74   * Specifically, it must call the appropriate <i>reader</i> method
75   * (<code>SQLInput.readString</code>, <code>SQLInput.readBigDecimal</code>,
76   * and so on) method(s) to do the following:
77   * for a distinct type, read its single data element;
78   * for a structured type, read a value for each attribute of the SQL type.
79   * </UL>
80   * The JDBC driver initializes the input stream with a type map
81   * before calling this method, which is used by the appropriate
82   * <code>SQLInput</code> reader method on the stream.
83   *
84   * @param stream the <code>SQLInput</code> object from which to read the data for
85   * the value that is being custom mapped
86   * @param typeName the SQL type name of the value on the data stream
87   * @exception SQLException if there is a database access error
88   * @see SQLInput
89   */

90   void readSQL (SQLInput JavaDoc stream, String JavaDoc typeName) throws SQLException JavaDoc;
91
92   /**
93   * Writes this object to the given SQL data stream, converting it back to
94   * its SQL value in the data source.
95   * The implementation of the method must follow this protocol:<BR>
96   * It must write each of the attributes of the SQL type
97   * to the given output stream. This is done by calling a
98   * method of the output stream to write each item, in the order that
99   * they appear in the SQL definition of the type.
100   * Specifically, it must call the appropriate <code>SQLOutput</code> writer
101   * method(s) (<code>writeInt</code>, <code>writeString</code>, and so on)
102   * to do the following: for a Distinct Type, write its single data element;
103   * for a Structured Type, write a value for each attribute of the SQL type.
104   *
105   * @param stream the <code>SQLOutput</code> object to which to write the data for
106   * the value that was custom mapped
107   * @exception SQLException if there is a database access error
108   * @see SQLOutput
109   * @since 1.2
110   */

111   void writeSQL (SQLOutput JavaDoc stream) throws SQLException JavaDoc;
112 }
113
114
Popular Tags