1. /*
  2. * @(#)Array.java 1.23 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * The mapping in the Java programming language for the SQL type
  10. * <code>ARRAY</code>.
  11. * By default, an <code>Array</code> value is a transaction-duration
  12. * reference to an SQL <code>ARRAY</code> value. By default, an <code>Array</code>
  13. * object is implemented using an SQL LOCATOR(array) internally, which
  14. * means that an <code>Array</code> object contains a logical pointer
  15. * to the data in the SQL <code>ARRAY</code> value rather
  16. * than containing the <code>ARRAY</code> value's data.
  17. * <p>
  18. * The <code>Array</code> interface provides methods for bringing an SQL
  19. * <code>ARRAY</code> value's data to the client as either an array or a
  20. * <code>ResultSet</code> object.
  21. * If the elements of the SQL <code>ARRAY</code>
  22. * are a UDT, they may be custom mapped. To create a custom mapping,
  23. * a programmer must do two things:
  24. * <ul>
  25. * <li>create a class that implements the {@link SQLData}
  26. * interface for the UDT to be custom mapped.
  27. * <li>make an entry in a type map that contains
  28. * <ul>
  29. * <li>the fully-qualified SQL type name of the UDT
  30. * <li>the <code>Class</code> object for the class implementing
  31. * <code>SQLData</code>
  32. * </ul>
  33. * </ul>
  34. * <p>
  35. * When a type map with an entry for
  36. * the base type is supplied to the methods <code>getArray</code>
  37. * and <code>getResultSet</code>, the mapping
  38. * it contains will be used to map the elements of the <code>ARRAY</code> value.
  39. * If no type map is supplied, which would typically be the case,
  40. * the connection's type map is used by default.
  41. * If the connection's type map or a type map supplied to a method has no entry
  42. * for the base type, the elements are mapped according to the standard mapping.
  43. * <p>
  44. * @since 1.2
  45. */
  46. public interface Array {
  47. /**
  48. * Retrieves the SQL type name of the elements in
  49. * the array designated by this <code>Array</code> object.
  50. * If the elements are a built-in type, it returns
  51. * the database-specific type name of the elements.
  52. * If the elements are a user-defined type (UDT),
  53. * this method returns the fully-qualified SQL type name.
  54. *
  55. * @return a <code>String</code> that is the database-specific
  56. * name for a built-in base type; or the fully-qualified SQL type
  57. * name for a base type that is a UDT
  58. * @exception SQLException if an error occurs while attempting
  59. * to access the type name
  60. * @since 1.2
  61. */
  62. String getBaseTypeName() throws SQLException;
  63. /**
  64. * Retrieves the JDBC type of the elements in the array designated
  65. * by this <code>Array</code> object.
  66. *
  67. * @return a constant from the class {@link java.sql.Types} that is
  68. * the type code for the elements in the array designated by this
  69. * <code>Array</code> object
  70. * @exception SQLException if an error occurs while attempting
  71. * to access the base type
  72. * @since 1.2
  73. */
  74. int getBaseType() throws SQLException;
  75. /**
  76. * Retrieves the contents of the SQL <code>ARRAY</code> value designated
  77. * by this
  78. * <code>Array</code> object in the form of an array in the Java
  79. * programming language. This version of the method <code>getArray</code>
  80. * uses the type map associated with the connection for customizations of
  81. * the type mappings.
  82. *
  83. * @return an array in the Java programming language that contains
  84. * the ordered elements of the SQL <code>ARRAY</code> value
  85. * designated by this <code>Array</code> object
  86. * @exception SQLException if an error occurs while attempting to
  87. * access the array
  88. * @since 1.2
  89. */
  90. Object getArray() throws SQLException;
  91. /**
  92. * Retrieves the contents of the SQL <code>ARRAY</code> value designated by this
  93. * <code>Array</code> object.
  94. * This method uses
  95. * the specified <code>map</code> for type map customizations
  96. * unless the base type of the array does not match a user-defined
  97. * type in <code>map</code>, in which case it
  98. * uses the standard mapping. This version of the method
  99. * <code>getArray</code> uses either the given type map or the standard mapping;
  100. * it never uses the type map associated with the connection.
  101. *
  102. * @param map a <code>java.util.Map</code> object that contains mappings
  103. * of SQL type names to classes in the Java programming language
  104. * @return an array in the Java programming language that contains the ordered
  105. * elements of the SQL array designated by this object
  106. * @exception SQLException if an error occurs while attempting to
  107. * access the array
  108. * @since 1.2
  109. */
  110. Object getArray(java.util.Map<String,Class<?>> map) throws SQLException;
  111. /**
  112. * Retrieves a slice of the SQL <code>ARRAY</code>
  113. * value designated by this <code>Array</code> object, beginning with the
  114. * specified <code>index</code> and containing up to <code>count</code>
  115. * successive elements of the SQL array. This method uses the type map
  116. * associated with the connection for customizations of the type mappings.
  117. *
  118. * @param index the array index of the first element to retrieve;
  119. * the first element is at index 1
  120. * @param count the number of successive SQL array elements to retrieve
  121. * @return an array containing up to <code>count</code> consecutive elements
  122. * of the SQL array, beginning with element <code>index</code>
  123. * @exception SQLException if an error occurs while attempting to
  124. * access the array
  125. * @since 1.2
  126. */
  127. Object getArray(long index, int count) throws SQLException;
  128. /**
  129. * Retreives a slice of the SQL <code>ARRAY</code> value
  130. * designated by this <code>Array</code> object, beginning with the specified
  131. * <code>index</code> and containing up to <code>count</code>
  132. * successive elements of the SQL array.
  133. * <P>
  134. * This method uses
  135. * the specified <code>map</code> for type map customizations
  136. * unless the base type of the array does not match a user-defined
  137. * type in <code>map</code>, in which case it
  138. * uses the standard mapping. This version of the method
  139. * <code>getArray</code> uses either the given type map or the standard mapping;
  140. * it never uses the type map associated with the connection.
  141. *
  142. * @param index the array index of the first element to retrieve;
  143. * the first element is at index 1
  144. * @param count the number of successive SQL array elements to
  145. * retrieve
  146. * @param map a <code>java.util.Map</code> object
  147. * that contains SQL type names and the classes in
  148. * the Java programming language to which they are mapped
  149. * @return an array containing up to <code>count</code>
  150. * consecutive elements of the SQL <code>ARRAY</code> value designated by this
  151. * <code>Array</code> object, beginning with element
  152. * <code>index</code>
  153. * @exception SQLException if an error occurs while attempting to
  154. * access the array
  155. * @since 1.2
  156. */
  157. Object getArray(long index, int count, java.util.Map<String,Class<?>> map)
  158. throws SQLException;
  159. /**
  160. * Retrieves a result set that contains the elements of the SQL
  161. * <code>ARRAY</code> value
  162. * designated by this <code>Array</code> object. If appropriate,
  163. * the elements of the array are mapped using the connection's type
  164. * map; otherwise, the standard mapping is used.
  165. * <p>
  166. * The result set contains one row for each array element, with
  167. * two columns in each row. The second column stores the element
  168. * value; the first column stores the index into the array for
  169. * that element (with the first array element being at index 1).
  170. * The rows are in ascending order corresponding to
  171. * the order of the indices.
  172. *
  173. * @return a {@link ResultSet} object containing one row for each
  174. * of the elements in the array designated by this <code>Array</code>
  175. * object, with the rows in ascending order based on the indices.
  176. * @exception SQLException if an error occurs while attempting to
  177. * access the array
  178. * @since 1.2
  179. */
  180. ResultSet getResultSet () throws SQLException;
  181. /**
  182. * Retrieves a result set that contains the elements of the SQL
  183. * <code>ARRAY</code> value designated by this <code>Array</code> object.
  184. * This method uses
  185. * the specified <code>map</code> for type map customizations
  186. * unless the base type of the array does not match a user-defined
  187. * type in <code>map</code>, in which case it
  188. * uses the standard mapping. This version of the method
  189. * <code>getResultSet</code> uses either the given type map or the standard mapping;
  190. * it never uses the type map associated with the connection.
  191. * <p>
  192. * The result set contains one row for each array element, with
  193. * two columns in each row. The second column stores the element
  194. * value; the first column stores the index into the array for
  195. * that element (with the first array element being at index 1).
  196. * The rows are in ascending order corresponding to
  197. * the order of the indices.
  198. *
  199. * @param map contains the mapping of SQL user-defined types to
  200. * classes in the Java programming language
  201. * @return a <code>ResultSet</code> object containing one row for each
  202. * of the elements in the array designated by this <code>Array</code>
  203. * object, with the rows in ascending order based on the indices.
  204. * @exception SQLException if an error occurs while attempting to
  205. * access the array
  206. * @since 1.2
  207. */
  208. ResultSet getResultSet (java.util.Map<String,Class<?>> map) throws SQLException;
  209. /**
  210. * Retrieves a result set holding the elements of the subarray that
  211. * starts at index <code>index</code> and contains up to
  212. * <code>count</code> successive elements. This method uses
  213. * the connection's type map to map the elements of the array if
  214. * the map contains an entry for the base type. Otherwise, the
  215. * standard mapping is used.
  216. * <P>
  217. * The result set has one row for each element of the SQL array
  218. * designated by this object, with the first row containing the
  219. * element at index <code>index</code>. The result set has
  220. * up to <code>count</code> rows in ascending order based on the
  221. * indices. Each row has two columns: The second column stores
  222. * the element value; the first column stores the index into the
  223. * array for that element.
  224. *
  225. * @param index the array index of the first element to retrieve;
  226. * the first element is at index 1
  227. * @param count the number of successive SQL array elements to retrieve
  228. * @return a <code>ResultSet</code> object containing up to
  229. * <code>count</code> consecutive elements of the SQL array
  230. * designated by this <code>Array</code> object, starting at
  231. * index <code>index</code>.
  232. * @exception SQLException if an error occurs while attempting to
  233. * access the array
  234. * @since 1.2
  235. */
  236. ResultSet getResultSet(long index, int count) throws SQLException;
  237. /**
  238. * Retrieves a result set holding the elements of the subarray that
  239. * starts at index <code>index</code> and contains up to
  240. * <code>count</code> successive elements.
  241. * This method uses
  242. * the specified <code>map</code> for type map customizations
  243. * unless the base type of the array does not match a user-defined
  244. * type in <code>map</code>, in which case it
  245. * uses the standard mapping. This version of the method
  246. * <code>getResultSet</code> uses either the given type map or the standard mapping;
  247. * it never uses the type map associated with the connection.
  248. * <P>
  249. * The result set has one row for each element of the SQL array
  250. * designated by this object, with the first row containing the
  251. * element at index <code>index</code>. The result set has
  252. * up to <code>count</code> rows in ascending order based on the
  253. * indices. Each row has two columns: The second column stores
  254. * the element value; the first column stroes the index into the
  255. * array for that element.
  256. *
  257. * @param index the array index of the first element to retrieve;
  258. * the first element is at index 1
  259. * @param count the number of successive SQL array elements to retrieve
  260. * @param map the <code>Map</code> object that contains the mapping
  261. * of SQL type names to classes in the Java(tm) programming language
  262. * @return a <code>ResultSet</code> object containing up to
  263. * <code>count</code> consecutive elements of the SQL array
  264. * designated by this <code>Array</code> object, starting at
  265. * index <code>index</code>.
  266. * @exception SQLException if an error occurs while attempting to
  267. * access the array
  268. * @since 1.2
  269. */
  270. ResultSet getResultSet (long index, int count,
  271. java.util.Map<String,Class<?>> map)
  272. throws SQLException;
  273. }