/projects/derby-10.9.1.0/db-derby-10.9.1.0-src/java/stubs/jdbc3/java/sql/SQLData.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 106 lines · 6 code · 5 blank · 95 comment · 0 complexity · afbb30a212634e2d4b994e9e9e4e27f1 MD5 · raw file

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package java.sql;
  18. /**
  19. * An interface for the custom mapping of an SQL User Defined Type (UDT) to a
  20. * Java Class. The Java Class object will be added to the Connection's type map
  21. * with the SQL Name of the UDT which it maps.
  22. * <p>
  23. * Usually within an implementation of SQLData, there is a corresponding field
  24. * for every attribute of an SQL type, or only one field if the type is SQL
  25. * DISTINCT. When the UDT is returned within a ResultSet, it is accessed with
  26. * the ResultSet.getObject method and is returned as an Object which is an
  27. * instance of the class defined by the SQLData mapping. The application can use
  28. * this object just like any other Java object and can store changes back into
  29. * the database using the PreparedStatement.setObject method which performs the
  30. * reverse mapping into the SQL UDT.
  31. * <p>
  32. * It is standard for an implementation for a custom mapping to be generated by
  33. * a tool. The tool usually requires the name of the SQL UDT, the name of the
  34. * class which it is going to be mapped to, and the field names to which the UDT
  35. * attributes will be mapped. The tool can then implement the SQLData readSQL
  36. * and writeSQL methods. readSQL reads attributes from an SQLInput object, and
  37. * writeSQL writes them. This is done via SQLInput and SQLOutput method calls
  38. * respectively
  39. * <p>
  40. * Ordinarily a programmer would not call SQLData methods directly. Similarly
  41. * SQLInput and SQLOutput methods are not usually called directly.
  42. */
  43. public interface SQLData {
  44. /**
  45. * Gets the SQL name of the User Defined Type (UDT) that this object
  46. * represents. This method, usually invoked by the JDBC driver, retrieves
  47. * the name of the UDT instance associated with this SQLData object.
  48. *
  49. * @return a string with UDT type name for this object mapping, passed to
  50. * readSQL when the object was created
  51. * @throws SQLException
  52. * if a database error occurs
  53. */
  54. public String getSQLTypeName() throws SQLException;
  55. /**
  56. * Reads data from the database into this object. This method follows these
  57. * steps:
  58. * <ul>
  59. * <li>Utilize the passed input stream to read the attributes or entries of
  60. * the SQL type</li>
  61. * <li>This is carried out by reading each entry from the input stream,
  62. * ordered as the are the SQL definition.</li>
  63. * <li>Assign the data to the appropriate fields or elements. This is done
  64. * by calling the relevant reader method for the type involved (eg.
  65. * SQLInput.readString, SQLInputreadBigDecimal). If the type is distinct,
  66. * then read its only data entry. For structured types, read every entry.</li>
  67. * </ul>
  68. * The supplied input stream is typically initialized by the calling JDBC
  69. * driver with the type map before readSQL is called.
  70. *
  71. * @param stream
  72. * the SQLInput stream from which the type map data is read for
  73. * the custom mapping
  74. * @param typeName
  75. * the SQL Type name for the type which is being mapped
  76. * @throws SQLException
  77. * if a database error occurs
  78. */
  79. public void readSQL(SQLInput stream, String typeName) throws SQLException;
  80. /**
  81. * Writes the object to a supplied SQLOutput data stream, writing it out as
  82. * an SQL value to the data source.
  83. * <p>
  84. * This method follows the following steps:
  85. * <ul>
  86. * <li>Write each attribute of the SQL type to the output stream.</li>
  87. * <li>Write each item by calling a method on the output stream, in the
  88. * order they appear in the SQL definition of the type. Use the appropriate
  89. * SQLOutput methods (eg. writeInt, writeString). Write a single data
  90. * element for a Distinct type. For a Structured type, write a value for
  91. * each attribute of the the SQL type.</li>
  92. * </ul>
  93. *
  94. * @param stream
  95. * the SQLOutput stream to use to write out the data for the
  96. * custom mapping
  97. * @throws SQLException
  98. * if a database error occurs
  99. */
  100. public void writeSQL(SQLOutput stream) throws SQLException;
  101. }