⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 embedclob.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						// absolute position of a possible match						long matchPosition = -1;						// absolute position of the next possible match						long nextBestMatchPosition = -1;						//System.out.println("restartPattern: " + start);search:						for (;;)						{							//System.out.println("search: " + needPattern + " -- " + clobOffset);							if (needPattern) {								String tmpPatternS;								if ((patternLength - patternIndex) > 256)									tmpPatternS = searchStr.substring(patternIndex, 256);								else									tmpPatternS = searchStr;								tmpPattern = tmpPatternS.toCharArray();								needPattern = false;								matchCount = 0;							}							if (clobOffset == -1) {																read = clobReader.read(tmpClob, 0, tmpClob.length);							//System.out.println("MORE DATA " + read);								if (read == -1)									return -1;								if (read == 0)									continue search;								clobOffset = 0;							}							// find matches within our two temp arrays.compareArrays:							for (; clobOffset < read; clobOffset++) {								//System.out.println("compareArrays " + clobOffset);								char clobC = tmpClob[clobOffset];								if (clobC == tmpPattern[matchCount])								{									if (matchPosition == -1) {										matchPosition = currentPosition + clobOffset;									}									matchCount++;									// have we matched the entire pattern segment									if (matchCount == tmpPattern.length)									{										// move onto the next segment.										patternIndex += tmpPattern.length;										if (patternIndex == patternLength) {											// complete match !!											clobReader.close();											//System.out.println("COMPLETE@" + matchPosition);											return matchPosition;										}										needPattern = true;										continue search;									}									if (clobC == tmpPattern[0]) {										// save the next best start position.										// must be the first character of the actual pattern										if (patternIndex == 0) {											// must not be just a repeat of the match of the first character											if (matchCount != 1) {												// must not have a previous next best.												if (nextBestMatchPosition == -1) {													nextBestMatchPosition = currentPosition + clobOffset;												}											}										}									}									continue compareArrays;								}								else								{									// not a match									//									// 									if (matchPosition != -1) {										// failed after we matched some amount of the pattern										matchPosition = -1;										// See if we found a next best match										if (nextBestMatchPosition == -1)										{											// NO - just continue on, re-starting at this character											if (patternIndex != 0) {												needPattern = true;												continue search;											}										}										else if (nextBestMatchPosition >= currentPosition)										{											// restart in the current array											clobOffset = (int) (nextBestMatchPosition - currentPosition);											nextBestMatchPosition = -1;																				if (patternIndex != 0) {												needPattern = true;												continue search;											}										}										else										{											clobReader.close();											start = nextBestMatchPosition;											continue restartPattern;										}										clobOffset--; // since the continue will increment it										matchCount = 0;										continue compareArrays;									}																		// no current match, just continue								}							}							currentPosition += read;							// indicates we need to read more data							clobOffset = -1;						}					}				}            }        }        catch (Throwable t)        {			throw noStateChangeLOB(t);        }        finally        {            if (pushStack)                restoreContextStack();        }    }  /**   * Determines 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,   * else -1; the first position is 1   * @exception SQLException if there is an error accessing the   * <code>CLOB</code> value   */    public long position(Clob searchClob, long start)        throws SQLException    {        boolean pushStack = false;        try        {            if (start < 1)                throw StandardException.newException(                    SQLState.BLOB_BAD_POSITION, new Long(start));            if (searchClob == null)                throw StandardException.newException(SQLState.BLOB_NULL_PATTERN);            synchronized (getConnectionSynchronization())            {				char[] subPatternChar = new char[256];				boolean seenOneCharacter = false;				//System.out.println("BEGIN CLOB SEARCH @ " + start);restartScan:				for (;;) {					long firstPosition = -1;					Reader patternReader = searchClob.getCharacterStream();					//System.out.println("RESTART CLOB SEARCH @ " + start);					try {						for (;;) {							int read = patternReader.read(subPatternChar, 0, subPatternChar.length);							if (read == -1) {								//empty pattern								if (!seenOneCharacter)									return start; // matches DB2 SQL LOCATE function								return firstPosition;							}							if (read == 0) {								//System.out.println("STUCK IN READ 0 HELL");								continue;							}							seenOneCharacter = true;							String subPattern = new String(subPatternChar, 0, read);					//System.out.println("START CLOB SEARCH @ " + start + " -- " + subPattern);							long position = position(subPattern, start);					//System.out.println("DONE SUB CLOB SEARCH @ " + start + " -- " + position);							if (position == -1) {								// never seen any match								if (firstPosition == -1)									return -1;								start = firstPosition + 1;								continue restartScan;							}							if (firstPosition == -1)								firstPosition = position;							else if (position != start) {								// must match at the first character of the segment								start = firstPosition + 1;								continue restartScan;							}							// read is the length of the subPattern string							start = position + read;					}					} finally {						patternReader.close();					}				}            }        }        catch (Throwable t)        {			throw noStateChangeLOB(t);        }        finally        {            if (pushStack)                restoreContextStack();        }    }    /*     If we have a stream, release the resources associated with it.     */    protected void finalize()    {        // System.out.println("finalizer called");        if (!isString)            ((Resetable)myStream).closeStream();    }	/**    Following methods are for the new JDBC 3.0 methods in java.sql.Clob    (see the JDBC 3.0 spec). We have the JDBC 3.0 methods in Local20    package, so we don't have to have a new class in Local30.    The new JDBC 3.0 methods don't make use of any new JDBC3.0 classes and    so this will work fine in jdbc2.0 configuration.	*/	/////////////////////////////////////////////////////////////////////////	//	//	JDBC 3.0	-	New public methods	//	/////////////////////////////////////////////////////////////////////////	/**    * JDBC 3.0    *    * Writes the given Java String to the CLOB value that this Clob object designates    * at the position pos.    *    * @param pos - the position at which to start writing to the CLOB value that    * this Clob object represents    * @param str - the string to be written to the CLOB value that this Clob designates    * @return the number of characters written     * @exception SQLException Feature not implemented for now.	*/	public int setString(long pos, String parameterName)    throws SQLException	{		throw Util.notImplemented();	}	/**    * JDBC 3.0    *    * Writes len characters of str, starting at character offset, to the CLOB value    * that this Clob represents.    *    * @param pos - the position at which to start writing to this Clob object    * @param str - the string to be written to the CLOB value that this Clob designates    * @param offset - the offset into str 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 Feature not implemented for now.	*/	public int setString(long pos, String str, int offset, int len)    throws SQLException	{		throw Util.notImplemented();	}	/**    * JDBC 3.0    *    * Retrieves a stream to be used to write Ascii characters to the CLOB    * value that this Clob object represents, starting at position pos.    *    * @param pos - the position at which to start writing to this Clob object    * @return the stream to which ASCII encoded characters can be written     * @exception SQLException Feature not implemented for now.	*/	public java.io.OutputStream setAsciiStream(long pos)    throws SQLException	{		throw Util.notImplemented();	}	/**    * JDBC 3.0    *    * Retrieves a stream to be used to write a stream of Unicode characters to the    * CLOB value that this Clob object represents, starting at position pos.    *    * @param pos - the position at which to start writing to this Clob object    * @return the stream to which Unicode encoded characters can be written     * @exception SQLException Feature not implemented for now.	*/	public java.io.Writer setCharacterStream(long pos)    throws SQLException	{		throw Util.notImplemented();	}  	/**    * JDBC 3.0    *    * Truncates the CLOB value that this Clob designates to have a length of len characters    *    * @param len - the length, in bytes, to which the CLOB value that this Blob    * value should be truncated    * @exception SQLException Feature not implemented for now.	*/	public void truncate(long len)    throws SQLException	{		throw Util.notImplemented();	}	/*	**	*/	static SQLException noStateChangeLOB(Throwable t) {        if (t instanceof StandardException)        {            // container closed means the blob or clob was accessed after commit            if (((StandardException) t).getMessageId().equals(SQLState.DATA_CONTAINER_CLOSED))            {                t = StandardException.newException(SQLState.BLOB_ACCESSED_AFTER_COMMIT);            }        }		return org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(t);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -