SerialStructpublic class SerialStruct extends Object implements Serializable, Cloneable, StructA serialized mapping in the Java programming language of an SQL
structured type. Each attribute that is not already serialized
is mapped to a serialized form, and if an attribute is itself
a structured type, each of its attributes that is not already
serialized is mapped to a serialized form.
In addition, the structured type is custom mapped to a class in the
Java programming language if there is such a mapping, as are
its attributes, if appropriate.
The SerialStruct class provides a constructor for creating
an instance from a Struct object, a method for retrieving
the SQL type name of the SQL structured type in the database, and methods
for retrieving its attribute values. |
Fields Summary |
---|
private String | SQLTypeNameThe SQL type name for the structured type that this
SerialStruct object represents. This is the name
used in the SQL definition of the SQL structured type. | private Object[] | attribsAn array of Object instances in which each
element is an attribute of the SQL structured type that this
SerialStruct object represents. The attributes are
ordered according to their order in the definition of the
SQL structured type. | static final long | serialVersionUIDThe identifier that assists in the serialization of this
SerialStruct object. |
Constructors Summary |
---|
public SerialStruct(Struct in, Map map)Constructs a SerialStruct object from the given
Struct object, using the given java.util.Map
object for custom mapping the SQL structured type or any of its
attributes that are SQL structured types.
try {
// get the type name
SQLTypeName = new String(in.getSQLTypeName());
System.out.println("SQLTypeName: " + SQLTypeName);
// get the attributes of the struct
attribs = in.getAttributes(map);
/*
* the array may contain further Structs
* and/or classes that have been mapped,
* other types that we have to serialize
*/
mapToSerial(map);
} catch (SQLException e) {
throw new SerialException(e.getMessage());
}
| public SerialStruct(SQLData in, Map map)Constructs a SerialStruct object from the
given SQLData object, using the given type
map to custom map it to a class in the Java programming
language. The type map gives the SQL type and the class
to which it is mapped. The SQLData object
defines the class to which the SQL type will be mapped.
try {
//set the type name
SQLTypeName = new String(in.getSQLTypeName());
Vector tmp = new Vector();
in.writeSQL(new SQLOutputImpl(tmp, map));
attribs = tmp.toArray();
} catch (SQLException e) {
throw new SerialException(e.getMessage());
}
|
Methods Summary |
---|
public java.lang.Object[] | getAttributes()Retrieves an array of Object values containing the
attributes of the SQL structured type that this
SerialStruct object represents.
return attribs;
| public java.lang.Object[] | getAttributes(java.util.Map map)Retrieves the attributes for the SQL structured type that
this SerialStruct represents as an array of
Object values, using the given type map for
custom mapping if appropriate.
return attribs;
| public java.lang.String | getSQLTypeName()Retrieves the SQL type name for this SerialStruct
object. This is the name used in the SQL definition of the
structured type
return SQLTypeName;
| private void | mapToSerial(java.util.Map map)Maps attributes of an SQL structured type that are not
serialized to a serialized form, using the given type map
for custom mapping when appropriate. The following types
in the Java programming language are mapped to their
serialized forms: Struct , SQLData ,
Ref , Blob , Clob , and
Array .
This method is called internally and is not used by an
application programmer.
try {
for (int i = 0; i < attribs.length; i++) {
if (attribs[i] instanceof Struct) {
attribs[i] = new SerialStruct((Struct)attribs[i], map);
} else if (attribs[i] instanceof SQLData) {
attribs[i] = new SerialStruct((SQLData)attribs[i], map);
} else if (attribs[i] instanceof Blob) {
attribs[i] = new SerialBlob((Blob)attribs[i]);
} else if (attribs[i] instanceof Clob) {
attribs[i] = new SerialClob((Clob)attribs[i]);
} else if (attribs[i] instanceof Ref) {
attribs[i] = new SerialRef((Ref)attribs[i]);
} else if (attribs[i] instanceof java.sql.Array) {
attribs[i] = new SerialArray((java.sql.Array)attribs[i], map);
}
}
} catch (SQLException e) {
throw new SerialException(e.getMessage());
}
return;
|
|