@Override public Clob createSerial(Clob clob) throws SQLException { return new SerialClob(clob); } }
/** * Truncates the <code>CLOB</code> value that this <code>SerialClob</code> * object represents so that it has a length of <code>len</code> * characters. * <p> * Truncating a <code>SerialClob</code> object to length 0 has the effect of * clearing its contents. * * @param length the length, in bytes, to which the <code>CLOB</code> * value should be truncated * @throws SerialException if there is an error accessing the * <code>CLOB</code> value; * if the {@code free} method had been previously called on this object */ public void truncate(long length) throws SerialException { isValid(); if (length > len) { throw new SerialException ("Length more than what can be truncated"); } else { len = length; // re-size the buffer if (len == 0) { buf = new char[] {}; } else { buf = (this.getSubString(1, (int)len)).toCharArray(); } } }
/** * Returns the position in this <code>SerialClob</code> object * where the given <code>Clob</code> signature begins, starting * the search at the specified position. This method returns * <code>-1</code> if the pattern is not found. * * @param searchStr the <code>Clob</code> object for which to search * @param start the position in this <code>SerialClob</code> object * at which to begin the search; the first position is * <code>1</code>; must not be less than <code>1</code> nor * greater than the length of this <code>SerialClob</code> object * @return the position at which the given <code>Clob</code> * object begins in this <code>SerialClob</code> object, * at or after the specified starting position * @throws SerialException if an error occurs locating the Clob signature; * if the {@code free} method had been previously called on this object * @throws SQLException if there is an error accessing the Clob value * from the database */ public long position(Clob searchStr, long start) throws SerialException, SQLException { isValid(); return position(searchStr.getSubString(1,(int)searchStr.length()), start); }
@Test public void testClobHashError() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); clob.free(); ClobType ct = new ClobType(clob); assertEquals(0, ct.hashCode()); }
/** * Retrieves the number of characters in this <code>SerialClob</code> * object's array of characters. * * @return a <code>long</code> indicating the length in characters of this * <code>SerialClob</code> object's array of character * @throws SerialException if an error occurs; * if {@code free} had previously been called on this object */ public long length() throws SerialException { isValid(); return len; }
/** * Returns this <code>SerialClob</code> object's data as a stream * of Unicode characters. Unlike the related method, <code>getAsciiStream</code>, * a stream is produced regardless of whether the <code>SerialClob</code> object * was created with a <code>Clob</code> object or a <code>char</code> array. * * @return a <code>java.io.Reader</code> object containing this * <code>SerialClob</code> object's data * @throws SerialException if an error occurs; * if {@code free} had previously been called on this object */ public java.io.Reader getCharacterStream() throws SerialException { isValid(); return (java.io.Reader) new CharArrayReader(buf); }
/** * Create a new Clob. * @param text The null value is supported. */ public static final SerialClob createClob(char[] text) { try { return text!=null ? new SerialClob(text) : null; } catch (Exception e) { throw new IllegalStateException(e); } }
isValid(); if (start < 1 || start > len) { return -1;
/********************************************************************************************* * From String to CLOB * @return CLOB representation of string *********************************************************************************************/ private java.sql.Clob stringToClob(String source) { try { return new javax.sql.rowset.serial.SerialClob(source.toCharArray()); } catch (Exception e) { log.error("Could not convert string to a CLOB",e); return null; } }
/** * Retrieves the <code>CLOB</code> value designated by this <code>SerialClob</code> * object as an ascii stream. This method forwards the <code>getAsciiStream</code> * call to the underlying <code>Clob</code> object in the event that this * <code>SerialClob</code> object is instantiated with a <code>Clob</code> * object. If this <code>SerialClob</code> object is instantiated with * a <code>char</code> array, a <code>SerialException</code> object is thrown. * * @return a <code>java.io.InputStream</code> object containing * this <code>SerialClob</code> object's data * @throws SerialException if this {@code SerialClob} object was not * instantiated with a <code>Clob</code> object; * if {@code free} had previously been called on this object * @throws SQLException if there is an error accessing the * <code>CLOB</code> value represented by the <code>Clob</code> object * that was used to create this <code>SerialClob</code> object */ public java.io.InputStream getAsciiStream() throws SerialException, SQLException { isValid(); if (this.clob != null) { return this.clob.getAsciiStream(); } else { throw new SerialException("Unsupported operation. SerialClob cannot " + "return a the CLOB value as an ascii stream, unless instantiated " + "with a fully implemented Clob object."); } }
@Override public void executeSetPreparedStatement(Object pstmt, int index, Object data) throws Exception { if (data == null || ((String) data).length() == 0) { ((PreparedStatement) pstmt).setNull(index, Types.CLOB); } else { ((PreparedStatement) pstmt).setClob(index, new SerialClob(((String) data).toCharArray())); } }
/** * Retrieves a stream to be used to write Ascii characters to the * <code>CLOB</code> value that this <code>SerialClob</code> object represents, * starting at position <code>pos</code>. This method forwards the * <code>setAsciiStream()</code> call to the underlying <code>Clob</code> object in * the event that this <code>SerialClob</code> object is instantiated with a * <code>Clob</code> object. If this <code>SerialClob</code> object is instantiated * with a <code>char</code> array, a <code>SerialException</code> object is thrown. * * @param pos the position at which to start writing to the * <code>CLOB</code> object * @return the stream to which ASCII encoded characters can be written * @throws SerialException if SerialClob is not instantiated with a * Clob object; * if the {@code free} method had been previously called on this object * @throws SQLException if there is an error accessing the * <code>CLOB</code> value * @see #getAsciiStream */ public java.io.OutputStream setAsciiStream(long pos) throws SerialException, SQLException { isValid(); if (this.clob != null) { return this.clob.setAsciiStream(pos); } else { throw new SerialException("Unsupported operation. SerialClob cannot " + "return a writable ascii stream\n unless instantiated with a Clob object " + "that has a setAsciiStream() implementation"); } }
/** * {@inheritDoc} */ public Object convert( String value, TypeLiteral<?> toType ) { try { return new SerialClob( value.toCharArray() ); } catch ( SQLException e ) { throw new IllegalArgumentException( "String value '" + value + "' is not a valid SerialClob", e ); } }
isValid(); if (this.clob != null) { return this.clob.setCharacterStream(pos);
/** * Writes a <code>Clob</code> object in the Java programming language * to this <code>SQLOutputImpl</code> object. The driver converts * it to a serializable <code>SerialClob</code> SQL <code>CLOB</code> value * before returning it to the database. * * @param x an object representing an SQL <code>CLOB</code> value * @throws SQLException if the <code>SQLOutputImpl</code> object is in * use by a <code>SQLData</code> object attempting to write the attribute * values of a UDT to the database. */ @SuppressWarnings("unchecked") public void writeClob(Clob x) throws SQLException { if (x == null) { attribs.add(null); } else { attribs.add(new SerialClob(x)); } }
/** * Returns a {@code Reader} object that contains a partial * {@code SerialClob} value, starting * with the character specified by pos, which is length characters in length. * * @param pos the offset to the first character of the partial value to * be retrieved. The first character in the {@code SerialClob} is at position 1. * @param length the length in characters of the partial value to be retrieved. * @return {@code Reader} through which the partial {@code SerialClob} * value can be read. * @throws SQLException if pos is less than 1 or if pos is greater than the * number of characters in the {@code SerialClob} or if pos + length * is greater than the number of characters in the {@code SerialClob}; * @throws SerialException if the {@code free} method had been previously * called on this object * @since 1.6 */ public Reader getCharacterStream(long pos, long length) throws SQLException { isValid(); if (pos < 1 || pos > len) { throw new SerialException("Invalid position in Clob object set"); } if ((pos-1) + length > len) { throw new SerialException("Invalid position and substring length"); } if (length <= 0) { throw new SerialException("Invalid length specified"); } return new CharArrayReader(buf, (int)pos, (int)length); }
@Override public Clob getClob(final int columnIndex) throws SQLException { final String s = getString(columnIndex); if (s == null) { return null; } return new SerialClob(s.toCharArray()); }
public Clob convert(String obj) throws ConversionException { try { return new javax.sql.rowset.serial.SerialClob(obj.toCharArray()); } catch (Exception e) { throw new ConversionException(e); } } }