jdk/src/share/classes/javax/sql/rowset/serial/SerialRef.java
changeset 14409 d879c92507ec
parent 14342 8435a30053c1
child 14781 701d0765f75f
equal deleted inserted replaced
14408:db08012d1d6f 14409:d879c92507ec
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   161         }
   161         }
   162         object = obj;
   162         object = obj;
   163     }
   163     }
   164 
   164 
   165     /**
   165     /**
   166          * The identifier that assists in the serialization of this <code>SerialRef</code>
   166      * Compares this SerialRef to the specified object.  The result is {@code
       
   167      * true} if and only if the argument is not {@code null} and is a {@code
       
   168      * SerialRef} object that represents the same object as this
   167      * object.
   169      * object.
       
   170      *
       
   171      * @param  obj The object to compare this {@code SerialRef} against
       
   172      *
       
   173      * @return  {@code true} if the given object represents a {@code SerialRef}
       
   174      *          equivalent to this SerialRef, {@code false} otherwise
       
   175      *
       
   176      */
       
   177     public boolean equals(Object obj) {
       
   178         if (this == obj) {
       
   179             return true;
       
   180         }
       
   181         if(obj instanceof SerialRef) {
       
   182             SerialRef ref = (SerialRef)obj;
       
   183             return baseTypeName.equals(ref.baseTypeName) &&
       
   184                     object.equals(ref.object);
       
   185         }
       
   186         return false;
       
   187     }
       
   188 
       
   189     /**
       
   190      * Returns a hash code for this {@code SerialRef}.
       
   191      * @return  a hash code value for this object.
       
   192      */
       
   193     public int hashCode() {
       
   194         return (31 + object.hashCode()) * 31 + baseTypeName.hashCode();
       
   195     }
       
   196 
       
   197     /**
       
   198      * Returns a clone of this {@code SerialRef}. .
       
   199      * The underlying {@code Ref} object will be set to null.
       
   200      *
       
   201      * @return  a clone of this SerialRef
       
   202      */
       
   203     public Object clone() {
       
   204         try {
       
   205             SerialRef ref = (SerialRef) super.clone();
       
   206             ref.reference = null;
       
   207             return ref;
       
   208         } catch (CloneNotSupportedException ex) {
       
   209             // this shouldn't happen, since we are Cloneable
       
   210             throw new InternalError();
       
   211         }
       
   212 
       
   213     }
       
   214 
       
   215     /**
       
   216      * readObject is called to restore the state of the SerialRef from
       
   217      * a stream.
       
   218      */
       
   219     private void readObject(ObjectInputStream s)
       
   220             throws IOException, ClassNotFoundException {
       
   221         ObjectInputStream.GetField fields = s.readFields();
       
   222         object = fields.get("object", null);
       
   223         baseTypeName = (String) fields.get("baseTypeName", null);
       
   224         reference = (Ref) fields.get("reference", null);
       
   225     }
       
   226 
       
   227     /**
       
   228      * writeObject is called to save the state of the SerialRef
       
   229      * to a stream.
       
   230      */
       
   231     private void writeObject(ObjectOutputStream s)
       
   232             throws IOException, ClassNotFoundException {
       
   233 
       
   234         ObjectOutputStream.PutField fields = s.putFields();
       
   235         fields.put("baseTypeName", baseTypeName);
       
   236         fields.put("object", object);
       
   237         // Note: this check to see if it is an instance of Serializable
       
   238         // is for backwards compatibiity
       
   239         fields.put("reference", reference instanceof Serializable ? reference : null);
       
   240         s.writeFields();
       
   241     }
       
   242 
       
   243     /**
       
   244      * The identifier that assists in the serialization of this <code>SerialRef</code>
       
   245      * object.
   168      */
   246      */
   169     static final long serialVersionUID = -4727123500609662274L;
   247     static final long serialVersionUID = -4727123500609662274L;
   170 
   248 
   171 
   249 
   172 }
   250 }