src/share/classes/javax/sql/rowset/serial/SerialJavaObject.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 25,34 ****
--- 25,36 ----
package javax.sql.rowset.serial;
import java.io.*;
import java.lang.reflect.*;
+ import java.util.Arrays;
+ import java.util.Vector;
import javax.sql.rowset.RowSetWarning;
/**
* A serializable mapping in the Java programming language of an SQL
* <code>JAVA_OBJECT</code> value. Assuming the Java object
*** 47,57 ****
public class SerialJavaObject implements Serializable, Cloneable {
/**
* Placeholder for object to be serialized.
*/
! private final Object obj;
/**
* Placeholder for all fields in the <code>JavaObject</code> being serialized.
*/
--- 49,59 ----
public class SerialJavaObject implements Serializable, Cloneable {
/**
* Placeholder for object to be serialized.
*/
! private Object obj;
/**
* Placeholder for all fields in the <code>JavaObject</code> being serialized.
*/
*** 140,156 ****
/**
* A container for the warnings issued on this <code>SerialJavaObject</code>
* object. When there are multiple warnings, each warning is chained to the
* previous warning.
*/
! java.util.Vector<RowSetWarning> chain;
/**
* Registers the given warning.
*/
private void setWarning(RowSetWarning e) {
if (chain == null) {
! chain = new java.util.Vector<>();
}
chain.add(e);
}
}
--- 142,239 ----
/**
* A container for the warnings issued on this <code>SerialJavaObject</code>
* object. When there are multiple warnings, each warning is chained to the
* previous warning.
*/
! Vector<RowSetWarning> chain;
!
! /**
! * Compares this SerialJavaObject to the specified object.
! * The result is {@code true} if and only if the argument
! * is not {@code null} and is a {@code SerialJavaObject}
! * object that is identical to this object
! *
! * @param o The object to compare this {@code SerialJavaObject} against
! *
! * @return {@code true} if the given object represents a {@code SerialJavaObject}
! * equivalent to this SerialJavaObject, {@code false} otherwise
! *
! */
! public boolean equals(Object o) {
! if (this == o) {
! return true;
! }
! if (o instanceof SerialJavaObject) {
! if(this.obj.equals( ((SerialJavaObject)o).obj))
! return true;
! }
! return false;
! }
!
! /**
! * Returns a hash code for this SerialJavaObject. The hash code for a
! * {@code SerialJavaObject} object is taken as the hash code of
! * the {@code Object} it stores
! *
! * @return a hash code value for this object.
! */
! public int hashCode() {
! return 31 + obj.hashCode();
! }
!
! /**
! * Returns a clone of this {@code SerialJavaObject}.
! *
! * @return a clone of this SerialJavaObject
! */
!
! public Object clone() {
! try {
! SerialJavaObject sjo = (SerialJavaObject) super.clone();
! sjo.fields = Arrays.copyOf(fields, fields.length);
! if (chain != null)
! sjo.chain = new Vector<RowSetWarning>(chain);
! return sjo;
! } catch (CloneNotSupportedException ex) {
! // this shouldn't happen, since we are Cloneable
! throw new InternalError();
! }
! }
/**
* Registers the given warning.
*/
private void setWarning(RowSetWarning e) {
if (chain == null) {
! chain = new Vector<RowSetWarning>();
}
chain.add(e);
}
+
+ /**
+ * readObject is called to restore the state of the {@code SerialJavaObject}
+ * from a stream.
+ */
+ private void readObject(ObjectInputStream s)
+ throws IOException, ClassNotFoundException {
+
+ ObjectInputStream.GetField fields1 = s.readFields();
+ @SuppressWarnings("unchecked")
+ Vector<RowSetWarning> tmp = (Vector<RowSetWarning>)fields1.get("chain", null);
+ if (tmp != null)
+ chain = new Vector<RowSetWarning>(tmp);
+ obj = fields1.get("obj", null);
+ fields = obj.getClass().getFields();
+ }
+
+ /**
+ * writeObject is called to save the state of the {@code SerialJavaObject}
+ * to a stream.
+ */
+ private void writeObject(ObjectOutputStream s)
+ throws IOException {
+ ObjectOutputStream.PutField fields = s.putFields();
+ fields.put("obj", obj);
+ fields.put("chain", chain);
+ s.writeFields();
+ }
}