1 7 8 package javax.sql.rowset.serial; 9 10 import java.sql.*; 11 import javax.sql.*; 12 import java.io.*; 13 import java.math.*; 14 import java.util.Map ; 15 import java.util.Vector ; 16 17 import javax.sql.rowset.*; 18 19 35 public class SerialStruct implements Struct, Serializable, Cloneable { 36 37 38 45 private String SQLTypeName; 46 47 56 private Object attribs[]; 57 58 72 public SerialStruct(Struct in, Map <String ,Class <?>> map) 73 throws SerialException 74 { 75 76 try { 77 78 SQLTypeName = new String (in.getSQLTypeName()); 80 System.out.println("SQLTypeName: " + SQLTypeName); 81 82 attribs = in.getAttributes(map); 84 85 90 mapToSerial(map); 91 92 } catch (SQLException e) { 93 throw new SerialException (e.getMessage()); 94 } 95 } 96 97 115 public SerialStruct(SQLData in, Map <String ,Class <?>> map) 116 throws SerialException 117 { 118 119 try { 120 121 SQLTypeName = new String (in.getSQLTypeName()); 123 124 Vector tmp = new Vector (); 125 in.writeSQL(new SQLOutputImpl (tmp, map)); 126 attribs = tmp.toArray(); 127 128 } catch (SQLException e) { 129 throw new SerialException (e.getMessage()); 130 } 131 } 132 133 134 144 public String getSQLTypeName() throws SerialException { 145 return SQLTypeName; 146 } 147 148 158 public Object [] getAttributes() throws SerialException { 159 return attribs; 160 } 161 162 179 public Object [] getAttributes(Map <String ,Class <?>> map) 180 throws SerialException 181 { 182 return attribs; 183 } 184 185 186 205 private void mapToSerial(Map map) throws SerialException { 206 207 try { 208 209 for (int i = 0; i < attribs.length; i++) { 210 if (attribs[i] instanceof Struct) { 211 attribs[i] = new SerialStruct ((Struct)attribs[i], map); 212 } else if (attribs[i] instanceof SQLData) { 213 attribs[i] = new SerialStruct ((SQLData)attribs[i], map); 214 } else if (attribs[i] instanceof Blob) { 215 attribs[i] = new SerialBlob ((Blob)attribs[i]); 216 } else if (attribs[i] instanceof Clob) { 217 attribs[i] = new SerialClob ((Clob)attribs[i]); 218 } else if (attribs[i] instanceof Ref) { 219 attribs[i] = new SerialRef ((Ref)attribs[i]); 220 } else if (attribs[i] instanceof java.sql.Array ) { 221 attribs[i] = new SerialArray ((java.sql.Array )attribs[i], map); 222 } 223 } 224 225 } catch (SQLException e) { 226 throw new SerialException (e.getMessage()); 227 } 228 return; 229 } 230 231 235 static final long serialVersionUID = -8322445504027483372L; 236 } 237 | Popular Tags |