0N/A/*
2823N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.sql.rowset.serial;
0N/A
0N/Aimport java.sql.*;
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/A/**
0N/A * A serialized mapping of a <code>Ref</code> object, which is the mapping in the
0N/A * Java programming language of an SQL <code>REF</code> value.
0N/A * <p>
0N/A * The <code>SerialRef</code> class provides a constructor for
0N/A * creating a <code>SerialRef</code> instance from a <code>Ref</code>
0N/A * object and provides methods for getting and setting the <code>Ref</code> object.
0N/A */
0N/Apublic class SerialRef implements Ref, Serializable, Cloneable {
0N/A
0N/A /**
0N/A * String containing the base type name.
0N/A * @serial
0N/A */
0N/A private String baseTypeName;
0N/A
0N/A /**
0N/A * This will store the type <code>Ref</code> as an <code>Object</code>.
0N/A */
0N/A private Object object;
0N/A
0N/A /**
0N/A * Private copy of the Ref reference.
0N/A */
0N/A private Ref reference;
0N/A
0N/A /**
0N/A * Constructs a <code>SerialRef</code> object from the given <code>Ref</code>
0N/A * object.
0N/A *
0N/A * @param ref a Ref object; cannot be <code>null</code>
0N/A * @throws SQLException if a database access occurs; if <code>ref</code>
0N/A * is <code>null</code>; or if the <code>Ref</code> object returns a
0N/A * <code>null</code> value base type name.
0N/A * @throws SerialException if an error occurs serializing the <code>Ref</code>
0N/A * object
0N/A */
0N/A public SerialRef(Ref ref) throws SerialException, SQLException {
0N/A if (ref == null) {
0N/A throw new SQLException("Cannot instantiate a SerialRef object " +
0N/A "with a null Ref object");
0N/A }
0N/A reference = ref;
0N/A object = ref;
0N/A if (ref.getBaseTypeName() == null) {
0N/A throw new SQLException("Cannot instantiate a SerialRef object " +
0N/A "that returns a null base type name");
0N/A } else {
2823N/A baseTypeName = ref.getBaseTypeName();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a string describing the base type name of the <code>Ref</code>.
0N/A *
0N/A * @return a string of the base type name of the Ref
0N/A * @throws SerialException in no Ref object has been set
0N/A */
0N/A public String getBaseTypeName() throws SerialException {
0N/A return baseTypeName;
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Object</code> representing the SQL structured type
0N/A * to which this <code>SerialRef</code> object refers. The attributes
0N/A * of the structured type are mapped according to the given type map.
0N/A *
0N/A * @param map a <code>java.util.Map</code> object containing zero or
0N/A * more entries, with each entry consisting of 1) a <code>String</code>
0N/A * giving the fully qualified name of a UDT and 2) the
0N/A * <code>Class</code> object for the <code>SQLData</code> implementation
0N/A * that defines how the UDT is to be mapped
0N/A * @return an object instance resolved from the Ref reference and mapped
0N/A * according to the supplied type map
0N/A * @throws SerialException if an error is encountered in the reference
0N/A * resolution
0N/A */
0N/A public Object getObject(java.util.Map<String,Class<?>> map)
0N/A throws SerialException
0N/A {
0N/A map = new Hashtable(map);
2828N/A if (object != null) {
0N/A return map.get(object);
0N/A } else {
0N/A throw new SerialException("The object is not set");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Object</code> representing the SQL structured type
0N/A * to which this <code>SerialRef</code> object refers.
0N/A *
0N/A * @return an object instance resolved from the Ref reference
0N/A * @throws SerialException if an error is encountered in the reference
0N/A * resolution
0N/A */
0N/A public Object getObject() throws SerialException {
0N/A
0N/A if (reference != null) {
0N/A try {
0N/A return reference.getObject();
0N/A } catch (SQLException e) {
0N/A throw new SerialException("SQLException: " + e.getMessage());
0N/A }
0N/A }
0N/A
0N/A if (object != null) {
0N/A return object;
0N/A }
0N/A
0N/A
0N/A throw new SerialException("The object is not set");
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Sets the SQL structured type that this <code>SerialRef</code> object
0N/A * references to the given <code>Object</code> object.
0N/A *
0N/A * @param obj an <code>Object</code> representing the SQL structured type
0N/A * to be referenced
0N/A * @throws SerialException if an error is encountered generating the
0N/A * the structured type referenced by this <code>SerialRef</code> object
0N/A */
0N/A public void setObject(Object obj) throws SerialException {
0N/A try {
0N/A reference.setObject(obj);
0N/A } catch (SQLException e) {
0N/A throw new SerialException("SQLException: " + e.getMessage());
0N/A }
0N/A object = obj;
0N/A }
0N/A
0N/A /**
0N/A * The identifier that assists in the serialization of this <code>SerialRef</code>
0N/A * object.
0N/A */
0N/A static final long serialVersionUID = -4727123500609662274L;
0N/A
0N/A
0N/A}