clob.java
来自「derby database source code.good for you.」· Java 代码 · 共 502 行 · 第 1/2 页
JAVA
502 行
} private long positionX(String searchstr, long start) throws SqlException { checkForClosedConnection(); if (start <= 0) { throw new SqlException(agent_.logWriter_, "Clob.position(): start must be >= 1."); } int index = string_.indexOf(searchstr, (int) start - 1); if (index != -1) { index++; // api index starts at 1 } return (long) index; } public long position(java.sql.Clob searchstr, long start) throws SqlException { synchronized (agent_.connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "position(Clob, long)", searchstr, start); } if (searchstr == null) { throw new SqlException(agent_.logWriter_, "Search string cannot be null."); } long pos = positionX(searchstr, start); if (agent_.loggingEnabled()) { agent_.logWriter_.traceExit(this, "position(Clob, long)", pos); } return pos; } } private long positionX(java.sql.Clob searchstr, long start) throws SqlException { checkForClosedConnection(); if (start <= 0) { throw new SqlException(agent_.logWriter_, "Clob.position(): start must be >= 1."); } // if the searchstr is longer than the source, no match int index; try { if (searchstr.length() > length()) { return -1; } index = string_.indexOf(searchstr.getSubString(1L, (int) searchstr.length()), (int) start - 1); } catch (java.sql.SQLException e) { throw new SqlException(agent_.logWriter_, e.getMessage()); } if (index != -1) { index++; // api index starts at 1 } return (long) index; } //---------------------------- jdbc 3.0 ----------------------------------- public int setString(long pos, String str) throws SqlException { synchronized (agent_.connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "setString", (int) pos, str); } int length = setStringX(pos, str, 0, str.length()); if (agent_.loggingEnabled()) { agent_.logWriter_.traceExit(this, "setString", length); } return length; } } public int setString(long pos, String str, int offset, int len) throws SqlException { synchronized (agent_.connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "setString", (int) pos, str, offset, len); } int length = setStringX(pos, str, offset, len); if (agent_.loggingEnabled()) { agent_.logWriter_.traceExit(this, "setString", length); } return length; } } public int setStringX(long pos, String str, int offset, int len) throws SqlException { if ((int) pos <= 0 || pos - 1 > sqlLength_) { throw new SqlException(agent_.logWriter_, "Invalid position " + pos + " , offset " + offset + " or length " + len); } if ((offset < 0) || offset > str.length() || len < 0) { throw new SqlException(agent_.logWriter_, "Invalid position " + pos + " , offset " + offset + " or length " + len); } if (len == 0) { return 0; } int length = 0; length = Math.min((str.length() - offset), len); String newString = string_.substring(0, (int) pos - 1); string_ = newString.concat(str.substring(offset, offset + length)); asciiStream_ = new java.io.StringBufferInputStream(string_); unicodeStream_ = new java.io.StringBufferInputStream(string_); characterStream_ = new java.io.StringReader(string_); sqlLength_ = string_.length(); return length; } public java.io.OutputStream setAsciiStream(long pos) throws SqlException { synchronized (agent_.connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "setAsciiStream", (int) pos); } ClobOutputStream outStream = new ClobOutputStream(this, pos); if (agent_.loggingEnabled()) { agent_.logWriter_.traceExit(this, "setAsciiStream", outStream); } return outStream; } } public java.io.Writer setCharacterStream(long pos) throws SqlException { synchronized (agent_.connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "setCharacterStream", (int) pos); } ClobWriter writer = new ClobWriter(this, pos); if (agent_.loggingEnabled()) { agent_.logWriter_.traceExit(this, "setCharacterStream", writer); } return writer; } } public void truncate(long len) throws SqlException { synchronized (agent_.connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, " truncate", (int) len); } if (len < 0 || len > this.length()) { throw new SqlException(agent_.logWriter_, "Invalid length " + len); } if (len == this.length()) { return; } String newstr = string_.substring(0, (int) len); string_ = newstr; asciiStream_ = new java.io.StringBufferInputStream(string_); unicodeStream_ = new java.io.StringBufferInputStream(string_); characterStream_ = new java.io.StringReader(string_); sqlLength_ = string_.length(); } } //----------------------------helper methods---------------------------------- public boolean isString() { return ((dataType_ & STRING) == STRING); } public boolean isAsciiStream() { return ((dataType_ & ASCII_STREAM) == ASCII_STREAM); } public boolean isCharacterStream() { return ((dataType_ & CHARACTER_STREAM) == CHARACTER_STREAM); } public boolean isUnicodeStream() { return ((dataType_ & UNICODE_STREAM) == UNICODE_STREAM); } public java.io.InputStream getUnicodeStream() { return unicodeStream_; } public String getString() { return string_; } public byte[] getUtf8String() { return utf8String_; } // Return the length of the equivalent UTF-8 string // precondition: string_ is not null and dataType_ includes STRING public int getUTF8Length() throws SqlException { if (utf8String_ != null) { return utf8String_.length; } try { utf8String_ = string_.getBytes("UTF-8"); return utf8String_.length; } catch (java.io.UnsupportedEncodingException e) { throw new SqlException(agent_.logWriter_, e.getMessage()); } } // auxiliary method for position (Clob, long) protected Clob createClobWrapper(java.sql.Clob clob) throws SqlException { long length; java.io.Reader rdr; try { length = clob.length(); } catch (java.sql.SQLException e) { throw new SqlException(agent_.logWriter_, e.getMessage()); } if (length > java.lang.Integer.MAX_VALUE) { throw new SqlException(agent_.logWriter_, "searchstr Clob object is too large"); } try { rdr = clob.getCharacterStream(); } catch (java.sql.SQLException e) { throw new SqlException(agent_.logWriter_, e.getMessage()); } return new Clob(this.agent_, rdr, (int) length); } public void convertFromAsciiToCharacterStream() throws SqlException { try { characterStream_ = new java.io.InputStreamReader(asciiStream_, "US-ASCII"); dataType_ = CHARACTER_STREAM; } catch (java.io.UnsupportedEncodingException e) { throw new SqlException(agent_.logWriter_, e.getMessage()); } } // this method is primarily for mixed clob length calculations. // it was introduced to prevent recursion in the actual char length calculation public long getByteLength() throws SqlException { if (lengthObtained_ == true) { return lengthInBytes_; } length(); return lengthInBytes_; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?