src/java.sql/share/classes/java/sql/SQLData.java
author alanb
Tue, 15 May 2018 09:33:02 +0100
changeset 50109 ea54197f4fe4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203059: (so) Closing a socket channel registered with Selector and with SO_LINGER set to 0 does not reset connection Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The interface used for the custom mapping of an SQL user-defined type (UDT) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * a class in the Java programming language. The class object for a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * implementing the <code>SQLData</code> interface will be entered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * appropriate <code>Connection</code> object's type map along with the SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * name of the UDT for which it is a custom mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Typically, a <code>SQLData</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * will define a field for each attribute of an SQL structured type or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * single field for an SQL <code>DISTINCT</code> type. When the UDT is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * retrieved from a data source with the <code>ResultSet.getObject</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * method, it will be mapped as an instance of this class.  A programmer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * can operate on this class instance just as on any other object in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Java programming language and then store any changes made to it by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * calling the <code>PreparedStatement.setObject</code> method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * which will map it back to the SQL type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * It is expected that the implementation of the class for a custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * mapping will be done by a tool.  In a typical implementation, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * programmer would simply supply the name of the SQL UDT, the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the class to which it is being mapped, and the names of the fields to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * which each of the attributes of the UDT is to be mapped.  The tool will use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * this information to implement the <code>SQLData.readSQL</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>SQLData.writeSQL</code> methods.  The <code>readSQL</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * calls the appropriate <code>SQLInput</code> methods to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * each attribute from an <code>SQLInput</code> object, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <code>writeSQL</code> method calls <code>SQLOutput</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * to write each attribute back to the data source via an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>SQLOutput</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * An application programmer will not normally call <code>SQLData</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * directly, and the <code>SQLInput</code> and <code>SQLOutput</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * are called internally by <code>SQLData</code> methods, not by application code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
public interface SQLData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  * Returns the fully-qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  * name of the SQL user-defined type that this object represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  * This method is called by the JDBC driver to get the name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  * UDT instance that is being mapped to this instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  * <code>SQLData</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  * @return the type name that was passed to the method <code>readSQL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  *            when this object was constructed and populated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  * @exception SQLException if there is a database access error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  * this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  String getSQLTypeName() throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  * Populates this object with data read from the database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  * The implementation of the method must follow this protocol:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  * <LI>It must read each of the attributes or elements of the SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  * type  from the given input stream.  This is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  * by calling a method of the input stream to read each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  * item, in the order that they appear in the SQL definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  * of the type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  * <LI>The method <code>readSQL</code> then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  * assigns the data to appropriate fields or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  * elements (of this or other objects).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  * Specifically, it must call the appropriate <i>reader</i> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  * (<code>SQLInput.readString</code>, <code>SQLInput.readBigDecimal</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  * and so on) method(s) to do the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  * for a distinct type, read its single data element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  * for a structured type, read a value for each attribute of the SQL type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  * The JDBC driver initializes the input stream with a type map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  * before calling this method, which is used by the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  * <code>SQLInput</code> reader method on the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  * @param stream the <code>SQLInput</code> object from which to read the data for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  * the value that is being custom mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  * @param typeName the SQL type name of the value on the data stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  * @exception SQLException if there is a database access error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  * this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  * @see SQLInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  void readSQL (SQLInput stream, String typeName) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  * Writes this object to the given SQL data stream, converting it back to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
  * its SQL value in the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  * The implementation of the method must follow this protocol:<BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  * It must write each of the attributes of the SQL type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  * to the given output stream.  This is done by calling a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  * method of the output stream to write each item, in the order that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  * they appear in the SQL definition of the type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  * Specifically, it must call the appropriate <code>SQLOutput</code> writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  * method(s) (<code>writeInt</code>, <code>writeString</code>, and so on)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  * to do the following: for a Distinct Type, write its single data element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  * for a Structured Type, write a value for each attribute of the SQL type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  * @param stream the <code>SQLOutput</code> object to which to write the data for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  * the value that was custom mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  * @exception SQLException if there is a database access error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  * this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  * @see SQLOutput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  void writeSQL (SQLOutput stream) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}