📄 jdbcclob.java
字号:
if (searchstr == null || start > Integer.MAX_VALUE) { return -1; } final String ldata = data; final int pos = ldata.indexOf(searchstr, (int) --start); return (pos < 0) ? -1 : pos + 1; } /** * Retrieves the character position at which the specified * <code>Clob</code> object <code>searchstr</code> appears in this * <code>Clob</code> object. The search begins at position * <code>start</code>. * * @param searchstr the <code>Clob</code> object for which to search * @param start the position at which to begin searching; the first * position is 1 * @return the position at which the <code>Clob</code> object appears * or -1 if it is not present; the first position is 1 * @exception SQLException if there is an error accessing the * <code>CLOB</code> value * * @since JDK 1.2, HSQLDB 1.7.2 */ public long position(final Clob searchstr, long start) throws SQLException { if (searchstr == null) { return -1; } final String ldata = data; final long dlen = ldata.length(); final long sslen = searchstr.length(); start--; //***** FOIRGOT THIS *******// This is potentially much less expensive than materializing a large// substring from some other vendor's CLOB. Indeed, we should probably// do the comparison piecewise, using an in-memory buffer (or temp-files// when available), if it is detected that the input CLOB is very long. if (start > dlen - sslen) { return -1; } // by now, we know sslen and start are both < Integer.MAX_VALUE String s; if (searchstr instanceof jdbcClob) { s = ((jdbcClob) searchstr).data; } else { s = searchstr.getSubString(1L, (int) sslen); } final int pos = ldata.indexOf(s, (int) start); return (pos < 0) ? -1 : pos + 1; } //---------------------------- jdbc 3.0 ----------------------------------- /** * Writes the given Java <code>String</code> to the <code>CLOB</code> * value that this <code>Clob</code> object designates at the position * <code>pos</code>. <p> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSLQDB 1.7.2 does not support this feature. <p> * * Calling this method always throws an <code>SQLException</code>. * </div> * <!-- end release-specific documentation --> * * @param pos the position at which to start writing to the * <code>CLOB</code> value that this <code>Clob</code> object * represents * @param str the string to be written to the <code>CLOB</code> * value that this <code>Clob</code> designates * @return the number of characters written * @exception SQLException if there is an error accessing the * <code>CLOB</code> value * * @since JDK 1.4, HSQLDB 1.7.2 */ public int setString(long pos, String str) throws SQLException { throw Util.notSupported(); } /** * Writes <code>len</code> characters of <code>str</code>, starting * at character <code>offset</code>, to the <code>CLOB</code> value * that this <code>Clob</code> represents. <p> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSLQDB 1.7.2 does not support this feature. <p> * * Calling this method always throws an <code>SQLException</code>. * </div> * <!-- end release-specific documentation --> * * @param pos the position at which to start writing to this * <code>CLOB</code> object * @param str the string to be written to the <code>CLOB</code> * value that this <code>Clob</code> object represents * @param offset the offset into <code>str</code> to start reading * the characters to be written * @param len the number of characters to be written * @return the number of characters written * @exception SQLException if there is an error accessing the * <code>CLOB</code> value * * @since JDK 1.4, HSQLDB 1.7.2 */ public int setString(long pos, String str, int offset, int len) throws SQLException { throw Util.notSupported(); } /** * Retrieves a stream to be used to write Ascii characters to the * <code>CLOB</code> value that this <code>Clob</code> object represents, * starting at position <code>pos</code>. <p> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSLQDB 1.7.2 does not support this feature. <p> * * Calling this method always throws an <code>SQLException</code>. * </div> * <!-- end release-specific documentation --> * * @param pos the position at which to start writing to this * <code>CLOB</code> object * @return the stream to which ASCII encoded characters can be written * @exception SQLException if there is an error accessing the * <code>CLOB</code> value * @see #getAsciiStream * * @since JDK 1.4, HSQLDB 1.7.2 */ public java.io.OutputStream setAsciiStream(long pos) throws SQLException { throw Util.notSupported(); } /** * Retrieves a stream to be used to write a stream of Unicode characters * to the <code>CLOB</code> value that this <code>Clob</code> object * represents, at position <code>pos</code>. <p> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSLQDB 1.7.2 does not support this feature. <p> * * Calling this method always throws an <code>SQLException</code>. * </div> * <!-- end release-specific documentation --> * * @param pos the position at which to start writing to the * <code>CLOB</code> value * * @return a stream to which Unicode encoded characters can be written * @exception SQLException if there is an error accessing the * <code>CLOB</code> value * @see #getCharacterStream * * @since JDK 1.4, HSQLDB 1.7.2 */ public java.io.Writer setCharacterStream(long pos) throws SQLException { throw Util.notSupported(); } /** * Truncates the <code>CLOB</code> value that this <code>Clob</code> * designates to have a length of <code>len</code> * characters. <p> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * This operation affects only the client-side value; it has no effect upon * the value as it is stored in the database. * </div> * <!-- end release-specific documentation --> * * @param len the length, in bytes, to which the <code>CLOB</code> value * should be truncated * @exception SQLException if there is an error accessing the * <code>CLOB</code> value * * @since JDK 1.4, HSQLDB 1.7.2 */ public void truncate(final long len) throws SQLException { final String ldata = data; final long dlen = ldata.length(); final long chars = len >> 1; if (chars == dlen) { // nothing has changed, so there's nothing to be done } else if (len < 0 || chars > dlen) { throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT, Long.toString(len)); } else { // use new String() to ensure we get rid of slack data = new String(ldata.substring(0, (int) chars)); } }//#ifdef JAVA6/* public void free() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public Reader getCharacterStream(long pos, long length) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); }*///#endif JAVA6}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -