1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
/* * @(#)SerialRef.java 1.8 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.sql.rowset.serial; import java.sql.*; import java.io.*; import java.util.*; /** * A serialized mapping of a <code>Ref</code> object, which is the mapping in the * Java programming language of an SQL <code>REF</code> value. * <p> * The <code>SerialRef</code> class provides a constructor for * creating a <code>SerialRef</code> instance from a <code>Ref</code> * object and provides methods for getting and setting the <code>Ref</code> object. */ public class SerialRef implements Ref, Serializable, Cloneable { /** * String containing the base type name. * @serial */ private String baseTypeName; /** * This will store the type <code>Ref</code> as an <code>Object</code>. */ private Object object; /** * Private copy of the Ref reference. */ private Ref reference; /** * Constructs a <code>SerialRef</code> object from the given <code>Ref</code> * object. * * @param ref a Ref object; cannot be <code>null</code> * @throws SQLException if a database access occurs; if <code>ref</code> * is <code>null</code>; or if the <code>Ref</code> object returns a * <code>null</code> value base type name. * @throws SerialException if an error occurs serializing the <code>Ref</code> * object */ public SerialRef(Ref ref) throws SerialException, SQLException { if (ref == null) { throw new SQLException("Cannot instantiate a SerialRef object " + "with a null Ref object"); } reference = ref; object = ref; if (ref.getBaseTypeName() == null) { throw new SQLException("Cannot instantiate a SerialRef object " + "that returns a null base type name"); } else { baseTypeName = new String(ref.getBaseTypeName()); } } /** * Returns a string describing the base type name of the <code>Ref</code>. * * @return a string of the base type name of the Ref * @throws SerialException in no Ref object has been set */ public String getBaseTypeName() throws SerialException { return baseTypeName; } /** * Returns an <code>Object</code> representing the SQL structured type * to which this <code>SerialRef</code> object refers. The attributes * of the structured type are mapped according to the given type map. * * @param map a <code>java.util.Map</code> object containing zero or * more entries, with each entry consisting of 1) a <code>String</code> * giving the fully qualified name of a UDT and 2) the * <code>Class</code> object for the <code>SQLData</code> implementation * that defines how the UDT is to be mapped * @return an object instance resolved from the Ref reference and mapped * according to the supplied type map * @throws SerialException if an error is encountered in the reference * resolution */ public Object getObject(java.util.Map<String,Class<?>> map) throws SerialException { map = new Hashtable(map); if (!object.equals(null)) { return map.get(object); } else { throw new SerialException("The object is not set"); } } /** * Returns an <code>Object</code> representing the SQL structured type * to which this <code>SerialRef</code> object refers. * * @return an object instance resolved from the Ref reference * @throws SerialException if an error is encountered in the reference * resolution */ public Object getObject() throws SerialException { if (reference != null) { try { return reference.getObject(); } catch (SQLException e) { throw new SerialException("SQLException: " + e.getMessage()); } } if (object != null) { return object; } throw new SerialException("The object is not set"); } /** * Sets the SQL structured type that this <code>SerialRef</code> object * references to the given <code>Object</code> object. * * @param obj an <code>Object</code> representing the SQL structured type * to be referenced * @throws SerialException if an error is encountered generating the * the structured type referenced by this <code>SerialRef</code> object */ public void setObject(Object obj) throws SerialException { try { reference.setObject(obj); } catch (SQLException e) { throw new SerialException("SQLException: " + e.getMessage()); } object = obj; } /** * The identifier that assists in the serialization of this <code>SerialRef</code> * object. */ static final long serialVersionUID = -4727123500609662274L; }