src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialClob.java
author lancea
Wed, 13 Mar 2019 14:10:18 -0400
changeset 54106 9a90236ab64c
parent 51310 a694574b2def
child 58338 faf791c5a710
permissions -rw-r--r--
8220253: Fix Headings in java.sql.rowset Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 51310
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sql.rowset.serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
14337
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
    30
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A serialized mapping in the Java programming language of an SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <code>CLOB</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The <code>SerialClob</code> class provides a constructor for creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * an instance from a <code>Clob</code> object.  Note that the <code>Clob</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * object should have brought the SQL <code>CLOB</code> value's data over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * to the client before a <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * is constructed from it.  The data of an SQL <code>CLOB</code> value can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * be materialized on the client as a stream of Unicode characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>SerialClob</code> methods make it possible to get a substring
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * from a <code>SerialClob</code> object or to locate the start of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * a pattern of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 51310
diff changeset
    47
 * <h2> Thread safety </h2>
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
    48
 *
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
    49
 * <p> A SerialClob is not safe for use by multiple concurrent threads.  If a
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
    50
 * SerialClob is to be used by more than one thread then access to the SerialClob
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
    51
 * should be controlled by appropriate synchronization.
24968
3308660aa3f2 8046389: Add missing @since tag under javax.sql.**
henryjen
parents: 18564
diff changeset
    52
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Jonathan Bruce
24968
3308660aa3f2 8046389: Add missing @since tag under javax.sql.**
henryjen
parents: 18564
diff changeset
    54
 * @since 1.5
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class SerialClob implements Clob, Serializable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * A serialized array of characters containing the data of the SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * <code>CLOB</code> value that this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private char buf[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
    68
     * Internal Clob representation if SerialClob is initialized with a
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
    69
     * Clob. Null if SerialClob is initialized with a char[].
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
14337
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
    71
    private Clob clob;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * The length in characters of this <code>SerialClob</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * internal array of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private long len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
    82
     * The original length in characters of this <code>SerialClob</code>
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
    83
     * object's internal array of characters.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
14337
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
    87
    private long origLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Constructs a <code>SerialClob</code> object that is a serialized version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * the given <code>char</code> array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * The new <code>SerialClob</code> object is initialized with the data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <code>char</code> array, thus allowing disconnected <code>RowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * objects to establish a serialized <code>Clob</code> object without touching
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param ch the char array representing the <code>Clob</code> object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *         serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @throws SerialException if an error occurs during serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @throws SQLException if a SQL error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public SerialClob(char ch[]) throws SerialException, SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // %%% JMB. Agreed. Add code here to throw a SQLException if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // support is available for locatorsUpdateCopy=false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // Serializing locators is not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        len = ch.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        buf = new char[(int)len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        for (int i = 0; i < len ; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
           buf[i] = ch[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        origLen = len;
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   115
        clob = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Constructs a <code>SerialClob</code> object that is a serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * version of the given <code>Clob</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * The new <code>SerialClob</code> object is initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * data from the <code>Clob</code> object; therefore, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>Clob</code> object should have previously brought the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * SQL <code>CLOB</code> value's data over to the client from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * the database. Otherwise, the new <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * object will contain no data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <p>
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   129
     * Note: The <code>Clob</code> object supplied to this constructor must
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   130
     * return non-null for both the <code>Clob.getCharacterStream()</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * and <code>Clob.getAsciiStream</code> methods. This <code>SerialClob</code>
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   132
     * constructor cannot serialize a <code>Clob</code> object in this instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * and will throw an <code>SQLException</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param  clob the <code>Clob</code> object from which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *     <code>SerialClob</code> object is to be constructed; cannot be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @throws SerialException if an error occurs during serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws SQLException if a SQL error occurs in capturing the CLOB;
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   139
     *     if the <code>Clob</code> object is a null; or if either of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *     <code>Clob.getCharacterStream()</code> and <code>Clob.getAsciiStream()</code>
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   141
     *     methods on the <code>Clob</code> returns a null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see java.sql.Clob
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public SerialClob(Clob clob) throws SerialException, SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (clob == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            throw new SQLException("Cannot instantiate a SerialClob " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                "object with a null Clob object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        len = clob.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.clob = clob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        buf = new char[(int)len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        int read = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        int offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   156
        try (Reader charStream = clob.getCharacterStream()) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   157
            if (charStream == null) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   158
                throw new SQLException("Invalid Clob object. The call to getCharacterStream " +
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   159
                    "returned null which cannot be serialized.");
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   160
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   162
            // Note: get an ASCII stream in order to null-check it,
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   163
            // even though we don't do anything with it.
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   164
            try (InputStream asciiStream = clob.getAsciiStream()) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   165
                if (asciiStream == null) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   166
                    throw new SQLException("Invalid Clob object. The call to getAsciiStream " +
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   167
                        "returned null which cannot be serialized.");
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   168
                }
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   169
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   171
            try (Reader reader = new BufferedReader(charStream)) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   172
                do {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   173
                    read = reader.read(buf, offset, (int)(len - offset));
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   174
                    offset += read;
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   175
                } while (read > 0);
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   176
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } catch (java.io.IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            throw new SerialException("SerialClob: " + ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        origLen = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Retrieves the number of characters in this <code>SerialClob</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * object's array of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @return a <code>long</code> indicating the length in characters of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *         <code>SerialClob</code> object's array of character
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   190
     * @throws SerialException if an error occurs;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   191
     * if {@code free} had previously been called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public long length() throws SerialException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   194
        isValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns this <code>SerialClob</code> object's data as a stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * of Unicode characters. Unlike the related method, <code>getAsciiStream</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * a stream is produced regardless of whether the <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * was created with a <code>Clob</code> object or a <code>char</code> array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return a <code>java.io.Reader</code> object containing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *         <code>SerialClob</code> object's data
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   206
     * @throws SerialException if an error occurs;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   207
     * if {@code free} had previously been called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public java.io.Reader getCharacterStream() throws SerialException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   210
        isValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return (java.io.Reader) new CharArrayReader(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Retrieves the <code>CLOB</code> value designated by this <code>SerialClob</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * object as an ascii stream. This method forwards the <code>getAsciiStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * call to the underlying <code>Clob</code> object in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <code>SerialClob</code> object is instantiated with a <code>Clob</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * object. If this <code>SerialClob</code> object is instantiated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * a <code>char</code> array, a <code>SerialException</code> object is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return a <code>java.io.InputStream</code> object containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *     this <code>SerialClob</code> object's data
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   224
     * @throws SerialException if this {@code SerialClob} object was not
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   225
     * instantiated with a <code>Clob</code> object;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   226
     * if {@code free} had previously been called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @throws SQLException if there is an error accessing the
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   228
     *     <code>CLOB</code> value represented by the <code>Clob</code> object
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   229
     * that was used to create this <code>SerialClob</code> object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public java.io.InputStream getAsciiStream() throws SerialException, SQLException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   232
        isValid();
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   233
        if (this.clob != null) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   234
            return this.clob.getAsciiStream();
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   235
        } else {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   236
            throw new SerialException("Unsupported operation. SerialClob cannot " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                "return a the CLOB value as an ascii stream, unless instantiated " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                "with a fully implemented Clob object.");
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 5506
diff changeset
   239
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Returns a copy of the substring contained in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <code>SerialClob</code> object, starting at the given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * and continuing for the specified number or characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param pos the position of the first character in the substring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *            to be copied; the first character of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *            <code>SerialClob</code> object is at position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *            <code>1</code>; must not be less than <code>1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *            and the sum of the starting position and the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *            of the substring must be less than the length of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *            <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param length the number of characters in the substring to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *               returned; must not be greater than the length of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *               this <code>SerialClob</code> object, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *               sum of the starting position and the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *               of the substring must be less than the length of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *               <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return a <code>String</code> object containing a substring of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *         this <code>SerialClob</code> object beginning at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *         given position and containing the specified number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *         consecutive characters
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   264
     * @throws SerialException if either of the arguments is out of bounds;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   265
     * if {@code free} had previously been called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public String getSubString(long pos, int length) throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   269
        isValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (pos < 1 || pos > this.length()) {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   271
            throw new SerialException("Invalid position in SerialClob object set");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if ((pos-1) + length > this.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            throw new SerialException("Invalid position and substring length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return new String(buf, (int)pos - 1, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        } catch (StringIndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            throw new SerialException("StringIndexOutOfBoundsException: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Returns the position in this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * where the given <code>String</code> object begins, starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * the search at the specified position. This method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <code>-1</code> if the pattern is not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param searchStr the <code>String</code> object for which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *                  search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param start the position in this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *         at which to start the search; the first position is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *         <code>1</code>; must not be less than <code>1</code> nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *         greater than the length of this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @return the position at which the given <code>String</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *         begins, starting the search at the specified position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *         <code>-1</code> if the given <code>String</code> object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *         not found or the starting position is out of bounds; position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *         numbering for the return value starts at <code>1</code>
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   305
     * @throws SerialException  if the {@code free} method had been
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   306
     * previously called on this object
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   307
     * @throws SQLException if there is an error accessing the Clob value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *         from the database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public long position(String searchStr, long start)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        throws SerialException, SQLException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   312
        isValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (start < 1 || start > len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        char pattern[] = searchStr.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int pos = (int)start-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        long patlen = pattern.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        while (pos < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            if (pattern[i] == buf[pos]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                if (i + 1 == patlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    return (pos + 1) - (patlen - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                i++; pos++; // increment pos, and i
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            } else if (pattern[i] != buf[pos]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                pos++; // increment pos only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return -1; // not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * Returns the position in this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * where the given <code>Clob</code> signature begins, starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * the search at the specified position. This method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * <code>-1</code> if the pattern is not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @param searchStr the <code>Clob</code> object for which to search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @param start the position in this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *        at which to begin the search; the first position is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *         <code>1</code>; must not be less than <code>1</code> nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *         greater than the length of this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @return the position at which the given <code>Clob</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *         object begins in this <code>SerialClob</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *         at or after the specified starting position
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   351
     * @throws SerialException if an error occurs locating the Clob signature;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   352
     * if the {@code free} method had been previously called on this object
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   353
     * @throws SQLException if there is an error accessing the Clob value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *         from the database
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public long position(Clob searchStr, long start)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        throws SerialException, SQLException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   358
        isValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return position(searchStr.getSubString(1,(int)searchStr.length()), start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Writes the given Java <code>String</code> to the <code>CLOB</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * value that this <code>SerialClob</code> object represents, at the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <code>pos</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param pos the position at which to start writing to the <code>CLOB</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *         value that this <code>SerialClob</code> object represents; the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *         position is <code>1</code>; must not be less than <code>1</code> nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *         greater than the length of this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @param str the string to be written to the <code>CLOB</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *        value that this <code>SerialClob</code> object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @return the number of characters written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @throws SerialException if there is an error accessing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *     <code>CLOB</code> value; if an invalid position is set; if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *     invalid offset value is set; if number of bytes to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *     is greater than the <code>SerialClob</code> length; or the combined
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   378
     *     values of the length and offset is greater than the Clob buffer;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   379
     * if the {@code free} method had been previously called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public int setString(long pos, String str) throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return (setString(pos, str, 0, str.length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Writes <code>len</code> characters of <code>str</code>, starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * at character <code>offset</code>, to the <code>CLOB</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * that this <code>Clob</code> represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param pos the position at which to start writing to the <code>CLOB</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *         value that this <code>SerialClob</code> object represents; the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *         position is <code>1</code>; must not be less than <code>1</code> nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *         greater than the length of this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param str the string to be written to the <code>CLOB</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *        value that this <code>Clob</code> object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param offset the offset into <code>str</code> to start reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *        the characters to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @param length the number of characters to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @return the number of characters written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @throws SerialException if there is an error accessing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *     <code>CLOB</code> value; if an invalid position is set; if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *     invalid offset value is set; if number of bytes to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *     is greater than the <code>SerialClob</code> length; or the combined
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   404
     *     values of the length and offset is greater than the Clob buffer;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   405
     * if the {@code free} method had been previously called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public int setString(long pos, String str, int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        throws SerialException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   409
        isValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        String temp = str.substring(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        char cPattern[] = temp.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (offset < 0 || offset > str.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            throw new SerialException("Invalid offset in byte array set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (pos < 1 || pos > this.length()) {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   418
            throw new SerialException("Invalid position in Clob object set");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if ((long)(length) > origLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            throw new SerialException("Buffer is not sufficient to hold the value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if ((length + offset) > str.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            // need check to ensure length + offset !> bytes.length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            throw new SerialException("Invalid OffSet. Cannot have combined offset " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                " and length that is greater that the Blob buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        pos--;  //values in the array are at position one less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        while ( i < length || (offset + i +1) < (str.length() - offset ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            this.buf[(int)pos + i ] = cPattern[offset + i ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Retrieves a stream to be used to write Ascii characters to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * <code>CLOB</code> value that this <code>SerialClob</code> object represents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * starting at position <code>pos</code>. This method forwards the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * <code>setAsciiStream()</code> call to the underlying <code>Clob</code> object in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * the event that this <code>SerialClob</code> object is instantiated with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * <code>Clob</code> object. If this <code>SerialClob</code> object is instantiated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *  with a <code>char</code> array, a <code>SerialException</code> object is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @param pos the position at which to start writing to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *        <code>CLOB</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @return the stream to which ASCII encoded characters can be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @throws SerialException if SerialClob is not instantiated with a
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   453
     *     Clob object;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   454
     * if the {@code free} method had been previously called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @throws SQLException if there is an error accessing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *     <code>CLOB</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @see #getAsciiStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public java.io.OutputStream setAsciiStream(long pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        throws SerialException, SQLException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   461
        isValid();
10323
48d695d1e966 7077451: SerialLob, SerialClob have the wrong checks for setStream methods
lancea
parents: 9035
diff changeset
   462
         if (this.clob != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
             return this.clob.setAsciiStream(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
             throw new SerialException("Unsupported operation. SerialClob cannot " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                "return a writable ascii stream\n unless instantiated with a Clob object " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                "that has a setAsciiStream() implementation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Retrieves a stream to be used to write a stream of Unicode characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * to the <code>CLOB</code> value that this <code>SerialClob</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * represents, at position <code>pos</code>. This method forwards the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <code>setCharacterStream()</code> call to the underlying <code>Clob</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * object in the event that this <code>SerialClob</code> object is instantiated with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * <code>Clob</code> object. If this <code>SerialClob</code> object is instantiated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * a <code>char</code> array, a <code>SerialException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @param  pos the position at which to start writing to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *        <code>CLOB</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @return a stream to which Unicode encoded characters can be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @throws SerialException if the SerialClob is not instantiated with
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   485
     *     a Clob object;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   486
     * if the {@code free} method had been previously called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @throws SQLException if there is an error accessing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *            <code>CLOB</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @see #getCharacterStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    public java.io.Writer setCharacterStream(long pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        throws SerialException, SQLException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   493
        isValid();
10323
48d695d1e966 7077451: SerialLob, SerialClob have the wrong checks for setStream methods
lancea
parents: 9035
diff changeset
   494
        if (this.clob != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return this.clob.setCharacterStream(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            throw new SerialException("Unsupported operation. SerialClob cannot " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                "return a writable character stream\n unless instantiated with a Clob object " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                "that has a setCharacterStream implementation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Truncates the <code>CLOB</code> value that this <code>SerialClob</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * object represents so that it has a length of <code>len</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Truncating a <code>SerialClob</code> object to length 0 has the effect of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * clearing its contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @param length the length, in bytes, to which the <code>CLOB</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *        value should be truncated
16732
c96397eeca72 8011393: Typo in javadoc for SerialClob.truncate
lancea
parents: 14781
diff changeset
   513
     * @throws SerialException if there is an error accessing the
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   514
     *        <code>CLOB</code> value;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   515
     * if the {@code free} method had been previously called on this object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public void truncate(long length) throws SerialException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   518
        isValid();
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   519
        if (length > len) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   520
           throw new SerialException
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   521
              ("Length more than what can be truncated");
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   522
        } else {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   523
             len = length;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   524
             // re-size the buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   526
             if (len == 0) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   527
                buf = new char[] {};
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   528
             } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                buf = (this.getSubString(1, (int)len)).toCharArray();
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   530
             }
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   531
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   535
    /**
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   536
     * Returns a {@code Reader} object that contains a partial
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   537
     * {@code SerialClob} value, starting
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   538
     * with the character specified by pos, which is length characters in length.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   539
     *
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   540
     * @param pos the offset to the first character of the partial value to
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   541
     * be retrieved.  The first character in the {@code SerialClob} is at position 1.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   542
     * @param length the length in characters of the partial value to be retrieved.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   543
     * @return {@code Reader} through which the partial {@code SerialClob}
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   544
     * value can be read.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   545
     * @throws SQLException if pos is less than 1 or if pos is greater than the
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   546
     * number of characters in the {@code SerialClob} or if pos + length
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   547
     * is greater than the number of characters in the {@code SerialClob};
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   548
     * @throws SerialException if the {@code free} method had been previously
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   549
     * called on this object
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   550
     * @since 1.6
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   551
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    public Reader getCharacterStream(long pos, long length) throws SQLException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   553
        isValid();
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   554
        if (pos < 1 || pos > len) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   555
            throw new SerialException("Invalid position in Clob object set");
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   556
        }
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   557
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   558
        if ((pos-1) + length > len) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   559
            throw new SerialException("Invalid position and substring length");
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   560
        }
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   561
        if (length <= 0) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   562
            throw new SerialException("Invalid length specified");
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   563
        }
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   564
        return new CharArrayReader(buf, (int)pos, (int)length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   567
    /**
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 24968
diff changeset
   568
     * This method frees the {@code SerialClob} object and releases the
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   569
     * resources that it holds.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   570
     * The object is invalid once the {@code free} method is called.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   571
     * <p>
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   572
     * If {@code free} is called multiple times, the subsequent
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   573
     * calls to {@code free} are treated as a no-op.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   574
     * </P>
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   575
     * @throws SQLException if an error occurs releasing
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   576
     * the Clob's resources
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   577
     * @since 1.6
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   578
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    public void free() throws SQLException {
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   580
        if (buf != null) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   581
            buf = null;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   582
            if (clob != null) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   583
                clob.free();
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   584
            }
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   585
            clob = null;
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   586
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
14337
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   590
     * Compares this SerialClob to the specified object.  The result is {@code
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   591
     * true} if and only if the argument is not {@code null} and is a {@code
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   592
     * SerialClob} object that represents the same sequence of characters as this
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   593
     * object.
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   594
     *
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   595
     * @param  obj The object to compare this {@code SerialClob} against
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   596
     *
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   597
     * @return  {@code true} if the given object represents a {@code SerialClob}
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   598
     *          equivalent to this SerialClob, {@code false} otherwise
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   599
     *
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   600
     */
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   601
    public boolean equals(Object obj) {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   602
        if (this == obj) {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   603
            return true;
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   604
        }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   605
        if (obj instanceof SerialClob) {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   606
            SerialClob sc = (SerialClob)obj;
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   607
            if (this.len == sc.len) {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   608
                return Arrays.equals(buf, sc.buf);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   609
            }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   610
        }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   611
        return false;
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   612
    }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   613
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   614
    /**
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   615
     * Returns a hash code for this {@code SerialClob}.
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   616
     * @return  a hash code value for this object.
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   617
     */
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   618
    public int hashCode() {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   619
       return ((31 + Arrays.hashCode(buf)) * 31 + (int)len) * 31 + (int)origLen;
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   620
    }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   621
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   622
    /**
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   623
     * Returns a clone of this {@code SerialClob}. The copy will contain a
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   624
     * reference to a clone of the internal character array, not a reference
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   625
     * to the original internal character array of this {@code SerialClob} object.
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   626
     * The underlying {@code Clob} object will be set to null.
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   627
     *
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   628
     * @return  a clone of this SerialClob
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   629
     */
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   630
    public Object clone() {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   631
        try {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   632
            SerialClob sc = (SerialClob) super.clone();
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   633
            sc.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
14337
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   634
            sc.clob = null;
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   635
            return sc;
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   636
        } catch (CloneNotSupportedException ex) {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   637
            // this shouldn't happen, since we are Cloneable
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   638
            throw new InternalError();
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   639
        }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   640
    }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   641
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   642
    /**
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   643
     * readObject is called to restore the state of the SerialClob from
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   644
     * a stream.
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   645
     */
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   646
    private void readObject(ObjectInputStream s)
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   647
            throws IOException, ClassNotFoundException {
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   648
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   649
        ObjectInputStream.GetField fields = s.readFields();
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   650
       char[] tmp = (char[])fields.get("buf", null);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   651
       if (tmp == null)
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   652
           throw new InvalidObjectException("buf is null and should not be!");
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   653
       buf = tmp.clone();
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   654
       len = fields.get("len", 0L);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   655
       if (buf.length != len)
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   656
           throw new InvalidObjectException("buf is not the expected size");
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   657
       origLen = fields.get("origLen", 0L);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   658
       clob = (Clob) fields.get("clob", null);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   659
    }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   660
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   661
    /**
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   662
     * writeObject is called to save the state of the SerialClob
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   663
     * to a stream.
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   664
     */
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   665
    private void writeObject(ObjectOutputStream s)
51310
a694574b2def 8208782: Remove extra type in throws clause of SerialClob.writeObject
darcy
parents: 47216
diff changeset
   666
            throws IOException {
14337
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   667
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   668
        ObjectOutputStream.PutField fields = s.putFields();
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   669
        fields.put("buf", buf);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   670
        fields.put("len", len);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   671
        fields.put("origLen", origLen);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   672
        // Note: this check to see if it is an instance of Serializable
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 24968
diff changeset
   673
        // is for backwards compatibility
14337
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   674
        fields.put("clob", clob instanceof Serializable ? clob : null);
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   675
        s.writeFields();
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   676
    }
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   677
a003c6a54cb6 8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents: 10323
diff changeset
   678
    /**
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   679
     * Check to see if this object had previously had its {@code free} method
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   680
     * called
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   681
     *
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   682
     * @throws SerialException
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   683
     */
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   684
    private void isValid() throws SerialException {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   685
        if (buf == null) {
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   686
            throw new SerialException("Error: You cannot call a method on a "
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   687
                    + "SerialClob instance once free() has been called.");
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   688
        }
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   689
    }
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   690
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   691
    /**
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14337
diff changeset
   692
     * The identifier that assists in the serialization of this {@code SerialClob}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    static final long serialVersionUID = -1662519690087375313L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
}