1 /*
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
157 * </pre>
158 * To create a DOMSource from a DOMResult:
159 * <pre>
160 * DOMSource domSource = new DOMSource(domResult.getNode());
161 * </pre>
162 * <p>
163 * Incomplete or invalid XML values may cause an SQLException when
164 * set or the exception may occur when execute() occurs. All streams
165 * must be closed before execute() occurs or an SQLException will be thrown.
166 * <p>
167 * Reading and writing XML values to or from an SQLXML object can happen at most once.
168 * The conceptual states of readable and not readable determine if one
169 * of the reading APIs will return a value or throw an exception.
170 * The conceptual states of writable and not writable determine if one
171 * of the writing APIs will set a value or throw an exception.
172 * <p>
173 * The state moves from readable to not readable once free() or any of the
174 * reading APIs are called: getBinaryStream(), getCharacterStream(), getSource(), and getString().
175 * Implementations may also change the state to not writable when this occurs.
176 * <p>
177 * The state moves from writable to not writeable once free() or any of the
178 * writing APIs are called: setBinaryStream(), setCharacterStream(), setResult(), and setString().
179 * Implementations may also change the state to not readable when this occurs.
180 *
181 * <p>
182 * All methods on the <code>SQLXML</code> interface must be fully implemented if the
183 * JDBC driver supports the data type.
184 *
185 * @see javax.xml.parsers
186 * @see javax.xml.stream
187 * @see javax.xml.transform
188 * @see javax.xml.xpath
189 * @since 1.6
190 */
191 public interface SQLXML
192 {
193 /**
194 * This method closes this object and releases the resources that it held.
195 * The SQL XML object becomes invalid and neither readable or writeable
196 * when this method is called.
197 *
198 * After <code>free</code> has been called, any attempt to invoke a
199 * method other than <code>free</code> will result in a <code>SQLException</code>
200 * being thrown. If <code>free</code> is called multiple times, the subsequent
201 * calls to <code>free</code> are treated as a no-op.
202 * @throws SQLException if there is an error freeing the XML value.
203 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
204 * this method
205 * @since 1.6
206 */
207 void free() throws SQLException;
208
209 /**
210 * Retrieves the XML value designated by this SQLXML instance as a stream.
211 * The bytes of the input stream are interpreted according to appendix F of the XML 1.0 specification.
212 * The behavior of this method is the same as ResultSet.getBinaryStream()
213 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
214 * <p>
215 * The SQL XML object becomes not readable when this method is called and
216 * may also become not writable depending on implementation.
217 *
218 * @return a stream containing the XML data.
219 * @throws SQLException if there is an error processing the XML value.
220 * An exception is thrown if the state is not readable.
221 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
222 * this method
223 * @since 1.6
224 */
225 InputStream getBinaryStream() throws SQLException;
226
227 /**
228 * Retrieves a stream that can be used to write the XML value that this SQLXML instance represents.
229 * The stream begins at position 0.
230 * The bytes of the stream are interpreted according to appendix F of the XML 1.0 specification
231 * The behavior of this method is the same as ResultSet.updateBinaryStream()
232 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
233 * <p>
234 * The SQL XML object becomes not writeable when this method is called and
235 * may also become not readable depending on implementation.
236 *
237 * @return a stream to which data can be written.
238 * @throws SQLException if there is an error processing the XML value.
239 * An exception is thrown if the state is not writable.
240 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
241 * this method
242 * @since 1.6
243 */
244 OutputStream setBinaryStream() throws SQLException;
245
246 /**
247 * Retrieves the XML value designated by this SQLXML instance as a java.io.Reader object.
248 * The format of this stream is defined by org.xml.sax.InputSource,
249 * where the characters in the stream represent the unicode code points for
250 * XML according to section 2 and appendix B of the XML 1.0 specification.
251 * Although an encoding declaration other than unicode may be present,
252 * the encoding of the stream is unicode.
253 * The behavior of this method is the same as ResultSet.getCharacterStream()
254 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
260 * @throws SQLException if there is an error processing the XML value.
261 * The getCause() method of the exception may provide a more detailed exception, for example,
262 * if the stream does not contain valid characters.
263 * An exception is thrown if the state is not readable.
264 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
265 * this method
266 * @since 1.6
267 */
268 Reader getCharacterStream() throws SQLException;
269
270 /**
271 * Retrieves a stream to be used to write the XML value that this SQLXML instance represents.
272 * The format of this stream is defined by org.xml.sax.InputSource,
273 * where the characters in the stream represent the unicode code points for
274 * XML according to section 2 and appendix B of the XML 1.0 specification.
275 * Although an encoding declaration other than unicode may be present,
276 * the encoding of the stream is unicode.
277 * The behavior of this method is the same as ResultSet.updateCharacterStream()
278 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
279 * <p>
280 * The SQL XML object becomes not writeable when this method is called and
281 * may also become not readable depending on implementation.
282 *
283 * @return a stream to which data can be written.
284 * @throws SQLException if there is an error processing the XML value.
285 * The getCause() method of the exception may provide a more detailed exception, for example,
286 * if the stream does not contain valid characters.
287 * An exception is thrown if the state is not writable.
288 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
289 * this method
290 * @since 1.6
291 */
292 Writer setCharacterStream() throws SQLException;
293
294 /**
295 * Returns a string representation of the XML value designated by this SQLXML instance.
296 * The format of this String is defined by org.xml.sax.InputSource,
297 * where the characters in the stream represent the unicode code points for
298 * XML according to section 2 and appendix B of the XML 1.0 specification.
299 * Although an encoding declaration other than unicode may be present,
300 * the encoding of the String is unicode.
308 * @throws SQLException if there is an error processing the XML value.
309 * The getCause() method of the exception may provide a more detailed exception, for example,
310 * if the stream does not contain valid characters.
311 * An exception is thrown if the state is not readable.
312 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
313 * this method
314 * @since 1.6
315 */
316 String getString() throws SQLException;
317
318 /**
319 * Sets the XML value designated by this SQLXML instance to the given String representation.
320 * The format of this String is defined by org.xml.sax.InputSource,
321 * where the characters in the stream represent the unicode code points for
322 * XML according to section 2 and appendix B of the XML 1.0 specification.
323 * Although an encoding declaration other than unicode may be present,
324 * the encoding of the String is unicode.
325 * The behavior of this method is the same as ResultSet.updateString()
326 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
327 * <p>
328 * The SQL XML object becomes not writeable when this method is called and
329 * may also become not readable depending on implementation.
330 *
331 * @param value the XML value
332 * @throws SQLException if there is an error processing the XML value.
333 * The getCause() method of the exception may provide a more detailed exception, for example,
334 * if the stream does not contain valid characters.
335 * An exception is thrown if the state is not writable.
336 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
337 * this method
338 * @since 1.6
339 */
340 void setString(String value) throws SQLException;
341
342 /**
343 * Returns a Source for reading the XML value designated by this SQLXML instance.
344 * Sources are used as inputs to XML parsers and XSLT transformers.
345 * <p>
346 * Sources for XML parsers will have namespace processing on by default.
347 * The systemID of the Source is implementation dependent.
348 * <p>
370 * javax.xml.transform.stax.StAXSource - returns a StAXSource
371 * javax.xml.transform.stream.StreamSource - returns a StreamSource
372 * </pre>
373 * @return a Source for reading the XML value.
374 * @throws SQLException if there is an error processing the XML value
375 * or if this feature is not supported.
376 * The getCause() method of the exception may provide a more detailed exception, for example,
377 * if an XML parser exception occurs.
378 * An exception is thrown if the state is not readable.
379 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
380 * this method
381 * @since 1.6
382 */
383 <T extends Source> T getSource(Class<T> sourceClass) throws SQLException;
384
385 /**
386 * Returns a Result for setting the XML value designated by this SQLXML instance.
387 * <p>
388 * The systemID of the Result is implementation dependent.
389 * <p>
390 * The SQL XML object becomes not writeable when this method is called and
391 * may also become not readable depending on implementation.
392 * <p>
393 * Note that SAX is a callback architecture and the returned
394 * SAXResult has a content handler assigned that will receive the
395 * SAX events based on the contents of the XML. Call the content
396 * handler with the contents of the XML document to assign the values.
397 * <pre>
398 * SAXResult saxResult = sqlxml.setResult(SAXResult.class);
399 * ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
400 * contentHandler.startDocument();
401 * // set the XML elements and attributes into the result
402 * contentHandler.endDocument();
403 * </pre>
404 *
405 * @param <T> the type of the class modeled by this Class object
406 * @param resultClass The class of the result, or null.
407 * If resultClass is null, a vendor specific Result implementation will be returned.
408 * The following classes are supported at a minimum:
409 * <pre>
410 * javax.xml.transform.dom.DOMResult - returns a DOMResult
|
1 /*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
157 * </pre>
158 * To create a DOMSource from a DOMResult:
159 * <pre>
160 * DOMSource domSource = new DOMSource(domResult.getNode());
161 * </pre>
162 * <p>
163 * Incomplete or invalid XML values may cause an SQLException when
164 * set or the exception may occur when execute() occurs. All streams
165 * must be closed before execute() occurs or an SQLException will be thrown.
166 * <p>
167 * Reading and writing XML values to or from an SQLXML object can happen at most once.
168 * The conceptual states of readable and not readable determine if one
169 * of the reading APIs will return a value or throw an exception.
170 * The conceptual states of writable and not writable determine if one
171 * of the writing APIs will set a value or throw an exception.
172 * <p>
173 * The state moves from readable to not readable once free() or any of the
174 * reading APIs are called: getBinaryStream(), getCharacterStream(), getSource(), and getString().
175 * Implementations may also change the state to not writable when this occurs.
176 * <p>
177 * The state moves from writable to not writable once free() or any of the
178 * writing APIs are called: setBinaryStream(), setCharacterStream(), setResult(), and setString().
179 * Implementations may also change the state to not readable when this occurs.
180 *
181 * <p>
182 * All methods on the <code>SQLXML</code> interface must be fully implemented if the
183 * JDBC driver supports the data type.
184 *
185 * @see javax.xml.parsers
186 * @see javax.xml.stream
187 * @see javax.xml.transform
188 * @see javax.xml.xpath
189 * @since 1.6
190 */
191 public interface SQLXML
192 {
193 /**
194 * This method closes this object and releases the resources that it held.
195 * The SQL XML object becomes invalid and neither readable or writable
196 * when this method is called.
197 *
198 * After <code>free</code> has been called, any attempt to invoke a
199 * method other than <code>free</code> will result in a <code>SQLException</code>
200 * being thrown. If <code>free</code> is called multiple times, the subsequent
201 * calls to <code>free</code> are treated as a no-op.
202 * @throws SQLException if there is an error freeing the XML value.
203 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
204 * this method
205 * @since 1.6
206 */
207 void free() throws SQLException;
208
209 /**
210 * Retrieves the XML value designated by this SQLXML instance as a stream.
211 * The bytes of the input stream are interpreted according to appendix F of the XML 1.0 specification.
212 * The behavior of this method is the same as ResultSet.getBinaryStream()
213 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
214 * <p>
215 * The SQL XML object becomes not readable when this method is called and
216 * may also become not writable depending on implementation.
217 *
218 * @return a stream containing the XML data.
219 * @throws SQLException if there is an error processing the XML value.
220 * An exception is thrown if the state is not readable.
221 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
222 * this method
223 * @since 1.6
224 */
225 InputStream getBinaryStream() throws SQLException;
226
227 /**
228 * Retrieves a stream that can be used to write the XML value that this SQLXML instance represents.
229 * The stream begins at position 0.
230 * The bytes of the stream are interpreted according to appendix F of the XML 1.0 specification
231 * The behavior of this method is the same as ResultSet.updateBinaryStream()
232 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
233 * <p>
234 * The SQL XML object becomes not writable when this method is called and
235 * may also become not readable depending on implementation.
236 *
237 * @return a stream to which data can be written.
238 * @throws SQLException if there is an error processing the XML value.
239 * An exception is thrown if the state is not writable.
240 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
241 * this method
242 * @since 1.6
243 */
244 OutputStream setBinaryStream() throws SQLException;
245
246 /**
247 * Retrieves the XML value designated by this SQLXML instance as a java.io.Reader object.
248 * The format of this stream is defined by org.xml.sax.InputSource,
249 * where the characters in the stream represent the unicode code points for
250 * XML according to section 2 and appendix B of the XML 1.0 specification.
251 * Although an encoding declaration other than unicode may be present,
252 * the encoding of the stream is unicode.
253 * The behavior of this method is the same as ResultSet.getCharacterStream()
254 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
260 * @throws SQLException if there is an error processing the XML value.
261 * The getCause() method of the exception may provide a more detailed exception, for example,
262 * if the stream does not contain valid characters.
263 * An exception is thrown if the state is not readable.
264 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
265 * this method
266 * @since 1.6
267 */
268 Reader getCharacterStream() throws SQLException;
269
270 /**
271 * Retrieves a stream to be used to write the XML value that this SQLXML instance represents.
272 * The format of this stream is defined by org.xml.sax.InputSource,
273 * where the characters in the stream represent the unicode code points for
274 * XML according to section 2 and appendix B of the XML 1.0 specification.
275 * Although an encoding declaration other than unicode may be present,
276 * the encoding of the stream is unicode.
277 * The behavior of this method is the same as ResultSet.updateCharacterStream()
278 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
279 * <p>
280 * The SQL XML object becomes not writable when this method is called and
281 * may also become not readable depending on implementation.
282 *
283 * @return a stream to which data can be written.
284 * @throws SQLException if there is an error processing the XML value.
285 * The getCause() method of the exception may provide a more detailed exception, for example,
286 * if the stream does not contain valid characters.
287 * An exception is thrown if the state is not writable.
288 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
289 * this method
290 * @since 1.6
291 */
292 Writer setCharacterStream() throws SQLException;
293
294 /**
295 * Returns a string representation of the XML value designated by this SQLXML instance.
296 * The format of this String is defined by org.xml.sax.InputSource,
297 * where the characters in the stream represent the unicode code points for
298 * XML according to section 2 and appendix B of the XML 1.0 specification.
299 * Although an encoding declaration other than unicode may be present,
300 * the encoding of the String is unicode.
308 * @throws SQLException if there is an error processing the XML value.
309 * The getCause() method of the exception may provide a more detailed exception, for example,
310 * if the stream does not contain valid characters.
311 * An exception is thrown if the state is not readable.
312 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
313 * this method
314 * @since 1.6
315 */
316 String getString() throws SQLException;
317
318 /**
319 * Sets the XML value designated by this SQLXML instance to the given String representation.
320 * The format of this String is defined by org.xml.sax.InputSource,
321 * where the characters in the stream represent the unicode code points for
322 * XML according to section 2 and appendix B of the XML 1.0 specification.
323 * Although an encoding declaration other than unicode may be present,
324 * the encoding of the String is unicode.
325 * The behavior of this method is the same as ResultSet.updateString()
326 * when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
327 * <p>
328 * The SQL XML object becomes not writable when this method is called and
329 * may also become not readable depending on implementation.
330 *
331 * @param value the XML value
332 * @throws SQLException if there is an error processing the XML value.
333 * The getCause() method of the exception may provide a more detailed exception, for example,
334 * if the stream does not contain valid characters.
335 * An exception is thrown if the state is not writable.
336 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
337 * this method
338 * @since 1.6
339 */
340 void setString(String value) throws SQLException;
341
342 /**
343 * Returns a Source for reading the XML value designated by this SQLXML instance.
344 * Sources are used as inputs to XML parsers and XSLT transformers.
345 * <p>
346 * Sources for XML parsers will have namespace processing on by default.
347 * The systemID of the Source is implementation dependent.
348 * <p>
370 * javax.xml.transform.stax.StAXSource - returns a StAXSource
371 * javax.xml.transform.stream.StreamSource - returns a StreamSource
372 * </pre>
373 * @return a Source for reading the XML value.
374 * @throws SQLException if there is an error processing the XML value
375 * or if this feature is not supported.
376 * The getCause() method of the exception may provide a more detailed exception, for example,
377 * if an XML parser exception occurs.
378 * An exception is thrown if the state is not readable.
379 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
380 * this method
381 * @since 1.6
382 */
383 <T extends Source> T getSource(Class<T> sourceClass) throws SQLException;
384
385 /**
386 * Returns a Result for setting the XML value designated by this SQLXML instance.
387 * <p>
388 * The systemID of the Result is implementation dependent.
389 * <p>
390 * The SQL XML object becomes not writable when this method is called and
391 * may also become not readable depending on implementation.
392 * <p>
393 * Note that SAX is a callback architecture and the returned
394 * SAXResult has a content handler assigned that will receive the
395 * SAX events based on the contents of the XML. Call the content
396 * handler with the contents of the XML document to assign the values.
397 * <pre>
398 * SAXResult saxResult = sqlxml.setResult(SAXResult.class);
399 * ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
400 * contentHandler.startDocument();
401 * // set the XML elements and attributes into the result
402 * contentHandler.endDocument();
403 * </pre>
404 *
405 * @param <T> the type of the class modeled by this Class object
406 * @param resultClass The class of the result, or null.
407 * If resultClass is null, a vendor specific Result implementation will be returned.
408 * The following classes are supported at a minimum:
409 * <pre>
410 * javax.xml.transform.dom.DOMResult - returns a DOMResult
|