001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jdbc.support.xml;
018
019import java.sql.ResultSet;
020import java.sql.SQLException;
021
022/**
023 * Abstraction for handling XML object mapping to fields in a database.
024 *
025 * <p>Provides accessor methods for XML fields unmarshalled to an Object,
026 * and acts as factory for {@link SqlXmlValue} instances for marshalling
027 * purposes.
028 *
029 * @author Thomas Risberg
030 * @since 2.5.5
031 * @see java.sql.ResultSet#getSQLXML
032 * @see java.sql.SQLXML
033 */
034public interface SqlXmlObjectMappingHandler extends SqlXmlHandler {
035
036        /**
037         * Retrieve the given column as an object marshalled from the XML data retrieved
038         * from the given ResultSet.
039         * <p>Works with an internal Object to XML Mapping implementation.
040         * @param rs the ResultSet to retrieve the content from
041         * @param columnName the column name to use
042         * @return the content as an Object, or {@code null} in case of SQL NULL
043         * @throws java.sql.SQLException if thrown by JDBC methods
044         * @see java.sql.ResultSet#getSQLXML
045         */
046        Object getXmlAsObject(ResultSet rs, String columnName) throws SQLException;
047
048        /**
049         * Retrieve the given column as an object marshalled from the XML data retrieved
050         * from the given ResultSet.
051         * <p>Works with an internal Object to XML Mapping implementation.
052         * @param rs the ResultSet to retrieve the content from
053         * @param columnIndex the column index to use
054         * @return the content as an Object, or {@code null} in case of SQL NULL
055         * @throws java.sql.SQLException if thrown by JDBC methods
056         * @see java.sql.ResultSet#getSQLXML
057         */
058        Object getXmlAsObject(ResultSet rs, int columnIndex) throws SQLException;
059
060        /**
061         * Get an instance of an {@code SqlXmlValue} implementation to be used together
062         * with the database specific implementation of this {@code SqlXmlObjectMappingHandler}.
063         * @param value the Object to be marshalled to XML
064         * @return the implementation specific instance
065         * @see SqlXmlValue
066         */
067        SqlXmlValue newMarshallingSqlXmlValue(Object value);
068
069}