You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2007/06/12 10:06:17 UTC
svn commit: r546409 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/jdbc/ClobStreamControl.java
engine/org/apache/derby/impl/jdbc/EmbedClob.java
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTruncateTest.java
Author: kristwaa
Date: Tue Jun 12 01:06:16 2007
New Revision: 546409
URL: http://svn.apache.org/viewvc?view=rev&rev=546409
Log:
A general code formatting cleanup: Trailing whitespace, lines longer than 80 characters and fixed some outdated JavaDoc descriptions. No functional changes have been made.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobStreamControl.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTruncateTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobStreamControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobStreamControl.java?view=diff&rev=546409&r1=546408&r2=546409
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobStreamControl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobStreamControl.java Tue Jun 12 01:06:16 2007
@@ -77,7 +77,7 @@
newClob.copyClobContent(clob);
return newClob;
}
-
+
/**
* Clones the content of another internal Clob.
*
@@ -182,7 +182,7 @@
bytePos = this.posCache.getBytePos();
} else {
long startingBytePosition = 0L; // Default to start at position 0.
- long charsToSkip = charPos -1; // Subtract one to get number to skip.
+ long charsToSkip = charPos -1; // Subtract one to get number to skip
if (charPos > this.posCache.getCharPos()) {
// Exploit the last known character position.
startingBytePosition = this.posCache.getBytePos();
@@ -206,7 +206,8 @@
* @throws IOException
* @throws SQLException if the specified position is invalid
*/
- public synchronized Writer getWriter (long pos) throws IOException, SQLException {
+ public synchronized Writer getWriter (long pos)
+ throws IOException, SQLException {
checkIfValid();
// If pos is too large, an error will first be thrown when the writer
// is written to. Is this okay behavior, is does it break the spec?
@@ -335,8 +336,7 @@
/**
* Truncate the Clob to the specifiec size.
- *
- *
+ *
* @param newCharLength the new length, in characters, of the Clob
* @throws IOException if accessing the underlying I/O resources fails
*/
@@ -344,9 +344,9 @@
throws IOException, SQLException {
checkIfValid();
try {
- //get the byteLength in bytes
+ // Get the length in bytes.
long byteLength = UTF8Util.skipFully (
- new BufferedInputStream (getRawByteStream()), newCharLength);
+ new BufferedInputStream(getRawByteStream()), newCharLength);
this.bytes.truncate(byteLength);
if (newCharLength <= this.posCache.getCharPos()) {
// Reset the cache if last cached position has been cut away.
@@ -403,10 +403,10 @@
throw Util.generateCsSQLException(se);
}
}
-
+
/**
* Copies the content of another Clob into this one.
- *
+ *
* @param clob the Clob to copy from
* @param charLength number of chars to copy
* @throws IOException if accessing I/O resources fail (both read and write)
@@ -415,14 +415,16 @@
private void copyClobContent(InternalClob clob, long charLength)
throws IOException, SQLException {
try {
- long byteLength = UTF8Util.skipFully (
- new BufferedInputStream(clob.getRawByteStream()), charLength);
+ long byteLength = UTF8Util.skipFully(
+ new BufferedInputStream(clob.getRawByteStream()),
+ charLength);
this.bytes.copyData(
- new BufferedInputStream(clob.getRawByteStream()), byteLength);
+ new BufferedInputStream(clob.getRawByteStream()),
+ byteLength);
} catch (StandardException se) {
throw Util.generateCsSQLException(se);
}
- }
+ }
/**
* Makes sure the Clob has not been released.
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?view=diff&rev=546409&r1=546408&r2=546409
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Tue Jun 12 01:06:16 2007
@@ -108,7 +108,8 @@
// if the underlying column is null, ResultSet.getClob will return null,
// never should get this far
if (SanityManager.DEBUG)
- SanityManager.ASSERT(!dvd.isNull(), "clob is created on top of a null column");
+ SanityManager.ASSERT(!dvd.isNull(),
+ "clob is created on top of a null column");
InputStream storeStream = dvd.getStream();
// See if a String or a stream will be the source of the Clob.
@@ -178,9 +179,11 @@
* designated by this <code>Clob</code> object.
* <p>
* The substring begins at position <code>pos</code> and has up to
- * * <code>length</code> consecutive characters. The starting position must be
- * between 1 and the length of the CLOB plus 1. This allows for zero-length
- * CLOB values, from which only zero-length substrings can be returned.
+ * * <code>length</code> consecutive characters. The starting position must
+ * be between 1 and the length of the CLOB plus 1. This allows for
+ * zero-length CLOB values, from which only zero-length substrings can be
+ * returned.
+ * <p>
* If a larger length is requested than there are characters available,
* characters from the start position to the end of the CLOB are returned.
* <p>
@@ -190,9 +193,9 @@
* @param pos the first character of the substring to be extracted.
* The first character is at position 1.
* @param length the number of consecutive characters to be copied
- * @return a <code>String</code> that is the specified substring in
- * the <code>CLOB</code> value designated by this <code>Clob</code> object
- * @exception SQLException if there is an error accessing the
+ * @return A <code>String</code> that is the specified substring in the
+ * <code>CLOB</code> value designated by this <code>Clob</code> object
+ * @exception SQLException if there is an error accessing the
* <code>CLOB</code>
*/
public String getSubString(long pos, int length) throws SQLException
@@ -259,8 +262,8 @@
/**
* Gets the <code>CLOB</code> value designated by this <code>Clob</code>
* object as a stream of Ascii bytes.
- * @return An Ascii stream containing the <code>CLOB</code> data. Valid values
- * in the stream are 0 - 255.
+ * @return An Ascii stream containing the <code>CLOB</code> data. Valid
+ * values in the stream are 0 - 255.
* @exception SQLException if there is an error accessing the
* <code>CLOB</code> value
*/
@@ -272,22 +275,23 @@
/**
* Determines the character position at which the specified substring
- * <code>searchStr</code> appears in the <code>CLOB</code> value. The search
- * begins at position <code>start</code>. The method uses the following
- * algorithm for the search:
+ * <code>searchStr</code> appears in the <code>CLOB</code> value.
+ * <p>
+ * The search begins at position <code>start</code>. The method uses the
+ * following algorithm for the search:
* <p>
* If the <code>CLOB</code> value is materialized as a string, use
* <code>String.indexOf</code>.
* <p>
- * If the <code>CLOB</code> value is represented as a stream, read a block of
- * chars from the start position and compare the chars with
+ * If the <code>CLOB</code> value is represented as a stream, read a block
+ * of chars from the start position and compare the chars with
* <code>searchStr</code>. Then:
* <ul> <li>If a matching char is found, increment <code>matchCount</code>.
* <li>If <code>matchCount</code> is equal to the length of
* <code>searchStr</code>, return with the current start position.
* <li>If no match is found, and there is more data, restart search
* (see below).
- * <li>If all data is processed without a match, return <code>-1</code>.
+ * <li>If no match is found, return <code>-1</code>.
* </ul>
* <p>
* The position where the stream has a char equal to the first char of
@@ -440,11 +444,13 @@
Reader patternReader = searchClob.getCharacterStream();
for (;;) {
- int read = patternReader.read(subPatternChar, 0, subPatternChar.length);
+ int read = patternReader.read(subPatternChar, 0,
+ subPatternChar.length);
if (read == -1) {
//empty pattern
if (!seenOneCharacter)
- return start; // matches DB2 SQL LOCATE function
+ // matches DB2 SQL LOCATE function
+ return start;
return firstPosition;
}
if (read == 0) {
@@ -452,7 +458,8 @@
}
seenOneCharacter = true;
- String subPattern = new String(subPatternChar, 0, read);
+ String subPattern =
+ new String(subPatternChar, 0, read);
long position = position(subPattern, start);
if (position == -1) {
// never seen any match
@@ -466,7 +473,7 @@
if (firstPosition == -1)
firstPosition = position;
else if (position != start) {
- // must match at the first character of the segment
+ // must match at the first character of segment
start = firstPosition + 1;
continue restartScan;
}
@@ -502,13 +509,13 @@
/**
* JDBC 3.0
*
- * Writes the given Java String to the CLOB value that this Clob object designates
- * at the position pos.
+ * 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 pos the position at which to start writing to the CLOB value that
+ * this Clob object represents
* @return the number of characters written
- * @exception SQLException Feature not implemented for now.
+ * @throws SQLException if writing the string fails
*/
public int setString(long pos, String str) throws SQLException {
return setString (pos, str, 0, str.length());
@@ -517,15 +524,17 @@
/**
* JDBC 3.0
*
- * Writes len characters of str, starting at character offset, to the CLOB value
- * that this Clob represents.
+ * 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
+ * @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.
+ * @exception SQLException if writing the string fails
*/
public int setString(long pos, String str, int offset, int len)
throws SQLException {
@@ -558,9 +567,9 @@
* 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
+ * @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.
+ * @exception SQLException if obtaining the stream fails
*/
public java.io.OutputStream setAsciiStream(long pos) throws SQLException {
checkValidity();
@@ -574,12 +583,12 @@
/**
* 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.
+ * Retrieves a stream to be used to write a stream of 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
+ * @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.
+ * @exception SQLException if obtaining the stream fails
*/
public java.io.Writer setCharacterStream(long pos) throws SQLException {
checkValidity();
@@ -596,11 +605,12 @@
/**
* JDBC 3.0
*
- * Truncates the CLOB value that this Clob designates to have a length of len characters
+ * 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.
+ * @param len the length, in characters, to which the CLOB value should be
+ * truncated
+ * @exception SQLException if truncating the CLOB value fails
*/
public void truncate(long len) throws SQLException
{
@@ -691,15 +701,16 @@
this, toBeAbandoned);
toBeAbandoned.release();
}
-
+
/**
* Makes a writable clone of the current Clob.
* <p>
* This is called when we have a {@link StoreStreamClob} and the user calls
* a method updating the content of the Clob. A temporary Clob will then be
* created to hold the updated content.
- * @param len number of chars to be cloned (should be smaller
- * than clob lenght)
+ *
+ * @param len number of characters to be cloned (should be smaller
+ * than clob length)
* @throws IOException if accessing underlying I/O resources fail
* @throws SQLException if accessing underlying resources fail
*/
@@ -710,5 +721,5 @@
getEmbedConnection().getDBName(),
this, toBeAbandoned, len);
toBeAbandoned.release();
- }
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTruncateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTruncateTest.java?view=diff&rev=546409&r1=546408&r2=546409
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTruncateTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTruncateTest.java Tue Jun 12 01:06:16 2007
@@ -40,11 +40,11 @@
* Test case for Clob.truncate
*/
public class ClobTruncateTest extends BaseJDBCTestCase {
-
+
public ClobTruncateTest (String name) {
super (name);
}
-
+
private void insertClobs () throws SQLException, IOException {
PreparedStatement ps = prepareStatement (
"insert into truncateclob" +
@@ -58,24 +58,25 @@
ps.setCharacterStream (2, new StringReader (sb.toString()), length);
ps.setInt (3, length/2);
ps.execute();
-
+
//insert a large clob
LoopingAlphabetReader reader = new LoopingAlphabetReader (1024 * 1024);
ps.setInt (1, 1024 * 1024);
ps.setCharacterStream (2, reader, 1024 * 1024);
ps.setInt (3, 1024 * 1024 / 2);
ps.execute();
-
+
//insert a non ascii clob
- LoopingAlphabetReader uReader =
- new LoopingAlphabetReader (300000, CharAlphabet.tamil());
+ LoopingAlphabetReader uReader =
+ new LoopingAlphabetReader (300000, CharAlphabet.tamil());
ps.setInt (1, 300000);
ps.setCharacterStream (2, uReader, 300000);
ps.setInt (3, 150000);
- ps.execute();
+ ps.execute();
}
-
- private void checkTruncate (int size, Clob clob, int newSize) throws SQLException {
+
+ private void checkTruncate (int size, Clob clob, int newSize)
+ throws SQLException {
assertEquals ("unexpected clob size", size, clob.length());
clob.truncate (newSize);
assertEquals ("truncate failed ", newSize, clob.length());
@@ -83,7 +84,7 @@
clob.truncate (newSize/2);
assertEquals ("truncate failed ", newSize/2, clob.length());
}
-
+
public void testTruncateOnClob () throws SQLException, IOException {
insertClobs();
getConnection().setAutoCommit (false);
@@ -112,9 +113,9 @@
stmt.executeUpdate ("create table truncateclob " +
"(size integer, data clob, newSize integer)");
}
-
+
public static Test suite() {
//client code is caching clob length so this test will fail
return TestConfiguration.embeddedSuite(ClobTruncateTest.class);
- }
+ }
}