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

Print this page


   1 /*
   2  * Copyright (c) 2003, 2011, 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
  23  * questions.
  24  */
  25 
  26 package javax.sql.rowset.serial;
  27 
  28 import java.sql.*;
  29 import java.io.*;
  30 import java.util.Map;
  31 import java.net.URL;
  32 
  33 
  34 /**
  35  * A serialized version of an <code>Array</code>
  36  * object, which is the mapping in the Java programming language of an SQL
  37  * <code>ARRAY</code> value.
  38  * <P>
  39  * The <code>SerialArray</code> class provides a constructor for creating
  40  * a <code>SerialArray</code> instance from an <code>Array</code> object,
  41  * methods for getting the base type and the SQL name for the base type, and
  42  * methods for copying all or part of a <code>SerialArray</code> object.
  43  * <P>
  44  * Note: In order for this class to function correctly, a connection to the
  45  * data source
  46  * must be available in order for the SQL <code>Array</code> object to be
  47  * materialized (have all of its elements brought to the client server)
  48  * if necessary. At this time, logical pointers to the data in the data source,
  49  * such as locators, are not currently supported.
  50  */
  51 public class SerialArray implements Array, Serializable, Cloneable {
  52 


 508      *              at the given index
 509      * @param map a <code>java.util.Map</code> object in which
 510      *        each entry consists of 1) a <code>String</code> object
 511      *        giving the fully qualified name of a UDT and 2) the
 512      *        <code>Class</code> object for the <code>SQLData</code> implementation
 513      *        that defines how the UDT is to be mapped
 514      * @return a <code>ResultSet</code> object containing the designated
 515      *         elements in this <code>SerialArray</code> object, with a
 516      *         separate row for each element
 517      * @throws SerialException if called, which in turn throws an
 518      *         <code>UnsupportedOperationException</code>
 519      */
 520     public ResultSet getResultSet(long index, int count,
 521                                   Map<String,Class<?>> map)
 522         throws SerialException
 523     {
 524         throw new UnsupportedOperationException();
 525     }
 526 
 527     /**



























































































 528      * The identifier that assists in the serialization of this <code>SerialArray</code>
 529      * object.
 530      */
 531     static final long serialVersionUID = -8466174297270688520L;
 532 }
   1 /*
   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.
   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
  23  * questions.
  24  */
  25 
  26 package javax.sql.rowset.serial;
  27 
  28 import java.sql.*;
  29 import java.io.*;
  30 import java.util.Map;
  31 import java.net.URL;
  32 import java.util.Arrays;
  33 
  34 /**
  35  * A serialized version of an <code>Array</code>
  36  * object, which is the mapping in the Java programming language of an SQL
  37  * <code>ARRAY</code> value.
  38  * <P>
  39  * The <code>SerialArray</code> class provides a constructor for creating
  40  * a <code>SerialArray</code> instance from an <code>Array</code> object,
  41  * methods for getting the base type and the SQL name for the base type, and
  42  * methods for copying all or part of a <code>SerialArray</code> object.
  43  * <P>
  44  * Note: In order for this class to function correctly, a connection to the
  45  * data source
  46  * must be available in order for the SQL <code>Array</code> object to be
  47  * materialized (have all of its elements brought to the client server)
  48  * if necessary. At this time, logical pointers to the data in the data source,
  49  * such as locators, are not currently supported.
  50  */
  51 public class SerialArray implements Array, Serializable, Cloneable {
  52 


 508      *              at the given index
 509      * @param map a <code>java.util.Map</code> object in which
 510      *        each entry consists of 1) a <code>String</code> object
 511      *        giving the fully qualified name of a UDT and 2) the
 512      *        <code>Class</code> object for the <code>SQLData</code> implementation
 513      *        that defines how the UDT is to be mapped
 514      * @return a <code>ResultSet</code> object containing the designated
 515      *         elements in this <code>SerialArray</code> object, with a
 516      *         separate row for each element
 517      * @throws SerialException if called, which in turn throws an
 518      *         <code>UnsupportedOperationException</code>
 519      */
 520     public ResultSet getResultSet(long index, int count,
 521                                   Map<String,Class<?>> map)
 522         throws SerialException
 523     {
 524         throw new UnsupportedOperationException();
 525     }
 526 
 527     /**
 528      * Compares this SerialArray to the specified object.  The result is {@code
 529      * true} if and only if the argument is not {@code null} and is a {@code
 530      * SerialArray} object whose elements are identical to this object's elements
 531      *
 532      * @param  obj The object to compare this {@code SerialArray} against
 533      *
 534      * @return  {@code true} if the given object represents a {@code SerialArray}
 535      *          equivalent to this SerialArray, {@code false} otherwise
 536      *
 537      */
 538     public boolean equals(Object obj) {
 539         if (this == obj) {
 540             return true;
 541         }
 542         
 543         if (obj instanceof SerialArray) {
 544             SerialArray sa = (SerialArray)obj;
 545             if(baseType == sa.baseType && baseTypeName.equals(sa.baseTypeName)) {
 546                 return Arrays.equals(elements, sa.elements);
 547             }
 548         }
 549         return false;
 550     }
 551 
 552     /**
 553      * Returns a hash code for this SerialArray. The hash code for a
 554      * {@code SerialArray} object is computed using the hash codes
 555      * of the elements of the  {@code SerialArray} object
 556      *
 557      * @return  a hash code value for this object.
 558      */
 559     public int hashCode() {
 560         return (((31 + Arrays.hashCode(elements)) * 31 + len)  * 31 + 
 561                 baseType) * 31 + baseTypeName.hashCode();
 562     }
 563    
 564     /**
 565      * Returns a clone of this {@code SerialArray}. The copy will contain a
 566      * reference to a clone of the underlying objects array, not a reference
 567      * to the original underlying object array of this {@code SerialArray} object.
 568      *  
 569      * @return  a clone of this SerialArray
 570      */ 
 571     public Object clone() {
 572         try {
 573             SerialArray sa = (SerialArray) super.clone();
 574             sa.elements = Arrays.copyOf(elements, len);         
 575             return sa;
 576         } catch (CloneNotSupportedException ex) {
 577             // this shouldn't happen, since we are Cloneable
 578             throw new InternalError();
 579         }
 580        
 581     }
 582     
 583     /**
 584      * readObject is called to restore the state of the {@code SerialArray} from
 585      * a stream.
 586      */
 587     private void readObject(ObjectInputStream s)
 588             throws IOException, ClassNotFoundException {
 589         
 590        ObjectInputStream.GetField fields = s.readFields();
 591        Object[] tmp = (Object[])fields.get("elements", null);
 592        if (tmp == null)
 593            throw new InvalidObjectException("elements is null and should not be!");
 594        elements = tmp.clone();
 595        len = fields.get("len", 0);
 596        if(elements.length != len)
 597            throw new InvalidObjectException("elements is not the expected size");
 598 
 599        baseType = fields.get("baseType", 0);
 600        baseTypeName = (String)fields.get("baseTypeName", null);
 601     }
 602     
 603     /**
 604      * writeObject is called to save the state of the {@code SerialArray}
 605      * to a stream.
 606      */
 607     private void writeObject(ObjectOutputStream s)
 608             throws IOException, ClassNotFoundException {
 609 
 610         ObjectOutputStream.PutField fields = s.putFields();
 611         fields.put("elements", elements);
 612         fields.put("len", len);
 613         fields.put("baseType", baseType);
 614         fields.put("baseTypeName", baseTypeName);
 615         s.writeFields();    
 616     }
 617 
 618     /**
 619      * The identifier that assists in the serialization of this <code>SerialArray</code>
 620      * object.
 621      */
 622     static final long serialVersionUID = -8466174297270688520L;
 623 }