136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe/*
236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * Licensed to the Apache Software Foundation (ASF) under one or more
336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * contributor license agreements.  See the NOTICE file distributed with
436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * this work for additional information regarding copyright ownership.
536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * The ASF licenses this file to You under the Apache License, Version 2.0
636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * (the "License"); you may not use this file except in compliance with
736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * the License.  You may obtain a copy of the License at
836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe *
936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe *     http://www.apache.org/licenses/LICENSE-2.0
1036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe *
1136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * Unless required by applicable law or agreed to in writing, software
1236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * distributed under the License is distributed on an "AS IS" BASIS,
1336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * See the License for the specific language governing permissions and
1536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * limitations under the License.
1636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe */
1736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
1836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpepackage java.sql;
1936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
2036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpeimport java.io.InputStream;
2136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpeimport java.io.OutputStream;
2236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpeimport java.io.Reader;
2336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpeimport java.io.Writer;
2436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpeimport javax.xml.transform.Result;
2536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpeimport javax.xml.transform.Source;
2636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
2736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe/**
28f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes * Maps SQL's XML type into Java.
2936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe */
3036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpepublic interface SQLXML {
31f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
32f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Frees any resources held by this object. After {@code free} is called, calling
33f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * method other than {@code free} will throw {@code SQLException} (calling {@code free}
34f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * repeatedly will do nothing).
35f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException
36f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
3736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    void free() throws SQLException;
3836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
39f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
40f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Returns a stream that can be used to read binary data from this SQL {@code XML} object.
41f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
42f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
4336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    InputStream getBinaryStream() throws SQLException;
4436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
45f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
46f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Returns a stream that can be used to write binary data to this SQL {@code XML} object.
47f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
48f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
4936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    OutputStream setBinaryStream() throws SQLException;
5036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
51f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
52f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Returns a reader that can be used to read character data from this SQL {@code XML} object.
53f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
54f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
5536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    Reader getCharacterStream() throws SQLException;
5636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
57f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
58f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Returns a writer that can be used to write character data to this SQL {@code XML} object.
59f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
60f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
6136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    Writer setCharacterStream() throws SQLException;
6236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
63f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
64f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Returns this object's data as an XML string.
65f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
66f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
6736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    String getString() throws SQLException;
6836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
69f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
70f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Sets this object's data to the given XML string.
71f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
72f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
7336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    void setString(String value) throws SQLException;
7436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
75f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
76f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Returns a {@link Source} for reading this object's data.
77f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
78f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
7936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    <T extends Source> T getSource(Class<T> sourceClass) throws SQLException;
8036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
81f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes    /**
82f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * Returns a {@link Result} for writing this object's data.
83f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     * @throws SQLException if an error occurs accessing the data
84f3cc41ede7af1dd683e1a55eabc8f36963aec8abElliott Hughes     */
8536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    <T extends Result> T setResult(Class<T> resultClass) throws SQLException;
8636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe}
87