< prev index next >

src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialRef.java

Print this page

  1 /*
  2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

208      * Returns a clone of this {@code SerialRef}.
209      * The underlying {@code Ref} object will be set to null.
210      *
211      * @return  a clone of this SerialRef
212      */
213     public Object clone() {
214         try {
215             SerialRef ref = (SerialRef) super.clone();
216             ref.reference = null;
217             return ref;
218         } catch (CloneNotSupportedException ex) {
219             // this shouldn't happen, since we are Cloneable
220             throw new InternalError();
221         }
222 
223     }
224 
225     /**
226      * readObject is called to restore the state of the SerialRef from
227      * a stream.





228      */
229     private void readObject(ObjectInputStream s)
230             throws IOException, ClassNotFoundException {
231         ObjectInputStream.GetField fields = s.readFields();
232         object = fields.get("object", null);
233         baseTypeName = (String) fields.get("baseTypeName", null);
234         reference = (Ref) fields.get("reference", null);
235     }
236 
237     /**
238      * writeObject is called to save the state of the SerialRef
239      * to a stream.


240      */
241     private void writeObject(ObjectOutputStream s)
242             throws IOException {
243 
244         ObjectOutputStream.PutField fields = s.putFields();
245         fields.put("baseTypeName", baseTypeName);
246         fields.put("object", object);
247         // Note: this check to see if it is an instance of Serializable
248         // is for backwards compatibility
249         fields.put("reference", reference instanceof Serializable ? reference : null);
250         s.writeFields();
251     }
252 
253     /**
254      * The identifier that assists in the serialization of this <code>SerialRef</code>
255      * object.
256      */
257     static final long serialVersionUID = -4727123500609662274L;
258 
259 

  1 /*
  2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

208      * Returns a clone of this {@code SerialRef}.
209      * The underlying {@code Ref} object will be set to null.
210      *
211      * @return  a clone of this SerialRef
212      */
213     public Object clone() {
214         try {
215             SerialRef ref = (SerialRef) super.clone();
216             ref.reference = null;
217             return ref;
218         } catch (CloneNotSupportedException ex) {
219             // this shouldn't happen, since we are Cloneable
220             throw new InternalError();
221         }
222 
223     }
224 
225     /**
226      * readObject is called to restore the state of the SerialRef from
227      * a stream.
228      * @param s the {@code ObjectInputStream} to read from.
229      *
230      * @throws  ClassNotFoundException if the class of a serialized object
231      *          could not be found.
232      * @throws  IOException if an I/O error occurs.
233      */
234     private void readObject(ObjectInputStream s)
235             throws IOException, ClassNotFoundException {
236         ObjectInputStream.GetField fields = s.readFields();
237         object = fields.get("object", null);
238         baseTypeName = (String) fields.get("baseTypeName", null);
239         reference = (Ref) fields.get("reference", null);
240     }
241 
242     /**
243      * writeObject is called to save the state of the SerialRef
244      * to a stream.
245      * @param s the {@code ObjectOutputStream} to write to.
246      + @throws  IOException if I/O errors occur.
247      */
248     private void writeObject(ObjectOutputStream s)
249             throws IOException {
250 
251         ObjectOutputStream.PutField fields = s.putFields();
252         fields.put("baseTypeName", baseTypeName);
253         fields.put("object", object);
254         // Note: this check to see if it is an instance of Serializable
255         // is for backwards compatibility
256         fields.put("reference", reference instanceof Serializable ? reference : null);
257         s.writeFields();
258     }
259 
260     /**
261      * The identifier that assists in the serialization of this <code>SerialRef</code>
262      * object.
263      */
264     static final long serialVersionUID = -4727123500609662274L;
265 
266 
< prev index next >