public class ClobTest extends BaseJDBCTestCase
Clob
interface.
Only methods defined by JDBC 3 or earlier are tested here, and the focus of the test is the interface methods. Less attention is given to inserting Clobs and fetching Clobs from the database.
Modifier and Type | Class and Description |
---|---|
private static class |
ClobTest.ClobTestSetup
Decorator creating the neccessary test data.
|
Modifier and Type | Field and Description |
---|---|
private java.sql.Clob |
clob
The Clob used for testing.
|
private static int |
nextUniqueId
Next unique id for a Clob.
|
private static java.lang.String |
NORWEGIAN_LETTERS
Test data, 18 characters long, containing only Norwegian letters.
|
private static int |
SET_ASCII_STREAM
Constant for Clob.setAsciiStream method.
|
private static int |
SET_CHARACTER_STREAM
Constant for Clob.setCharacterStream method.
|
private static int |
SET_STRING
Constant for Clob.setString method.
|
private static int |
TRANSFER_BUFFER_SIZE
Buffer size to use when transferring data between streams.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
ClobTest(java.lang.String testName) |
Modifier and Type | Method and Description |
---|---|
private void |
executeTestPositionWithStringToken(java.lang.String token,
long prefixLength)
Insert text into a Clob using
Clob.setAsciiStream(long) and
then search for the specified token. |
private void |
insertClob(int streamLength,
java.lang.String tableName) |
private void |
insertDataWithToken(java.lang.String token,
long pre,
long post,
int mode)
Inserts data into the test Clob, referenced by
this.clob . |
static java.sql.Clob |
replace(java.sql.Clob clob,
java.lang.String target,
java.lang.String replacement) |
protected void |
setUp()
Obtain a Clob containing the empty string.
|
static junit.framework.Test |
suite() |
protected void |
tearDown()
Nullify reference to Clob.
|
void |
test_4544()
Verify that generated columns don't interfere with streaming Clobs.
|
private void |
testCloningThroughAddBatch(boolean sourceAsStream,
boolean autoCommit)
Adds a series of Clobs into the test table using a batch, then deletes
the Clobs inserted.
|
void |
testCloningThroughAddBatchWithStream()
Tests that cloning an SQLClob object works when a stream has been set as
the source of the Clob.
|
void |
testCloningThroughAddBatchWithString()
Tests that cloning an SQLClob object works when a string has been set as
the source of the Clob.
|
void |
testGetLengthAfterTruncate()
Tests that the length of a Clob isn't cached in such a way that the
length isn't updated after truncation.
|
void |
testGetSubString_BiggerThanInternalBuffer()
Tests if big strings can be handled.
|
void |
testGetSubString_PosNegative() |
void |
testGetSubString_PosOneTooBig() |
void |
testGetSubString_PosTooBig() |
void |
testGetSubString_RequestZeroLength_PosTooBig() |
void |
testGetSubString_RequestZeroLength_PosValid() |
void |
testInsertCharacter_ReadOnlyToTemporary()
Tests that Derby specific end-of-stream markers aren't passed over to
the temporary Clob, which doesn't use such markers.
|
void |
testInsertStringInMiddle_Multibyte() |
void |
testInsertStringOnEmptyClob_Multibyte() |
void |
testInsertStringOnEmptyClob_Singlebyte() |
void |
testLengthAfterInsertOnEmpty()
Tests that the length is updated correctly when inserting data.
|
void |
testLengthAfterInsertOnLarge()
Tests that the length is updated correctly when inserting data.
|
void |
testLengthOnEmptyClob() |
void |
testPositionWithString_ASCII_SimplePartialRecurringPattern() |
void |
testPositionWithString_CJK() |
void |
testPositionWithString_IOS88591() |
void |
testPositionWithString_USASCII() |
void |
testReplaceMultibyteWithSingleByteBackwards() |
void |
testReplaceMultibyteWithSingleByteForwards() |
void |
testSetStringOnWrongOffset()
Test setString() refuses wrong offset.
|
void |
testSetStringWithBigPos()
Test setString() refuses pos bigger than clob.length() + 1.
|
void |
testSetStringWithEmptyString()
Test setString() accepts a empty String, and just return 0.
|
void |
testSetStringWithNull()
Test setStrinng() refuses a Null String.
|
void |
testSetStringWithWrongLen()
Test setString() refuses wrong len.
|
void |
testTruncateExactInMemory()
Truncating a Clob to the current length should work.
|
void |
testTruncateExactOnDisk()
Truncating a Clob to the current length should work.
|
void |
testTruncateTooLongInMemory()
Specify a position that is larger then the Clob length.
|
void |
testTruncateTooLongOnDisk()
Specify a position that is larger then the Clob length.
|
void |
testTruncateZeroInMemory()
Truncating a Clob to the empty string.
|
void |
testTruncateZeroOnDisk()
Truncating a Clob to the empty string.
|
private int |
transferData(java.io.InputStream source,
java.io.OutputStream dest,
int tz)
Transfer data from an input stream to an output stream.
|
private int |
transferData(java.io.Reader source,
int tz) |
private int |
transferData(java.io.Reader source,
java.io.Writer dest,
int tz)
Transfer data from a source Reader to a destination Writer.
|
private void |
truncateToZero(long initSize)
Truncates the default Clob to zero length and checks some basic
operations on the empty Clob.
|
private void |
vetClob(int streamLength,
java.lang.String tableName) |
private void |
vetTable(int streamLength,
java.lang.String gencol,
java.lang.String expectedValue) |
private void |
vetTable(java.lang.String tableName,
java.lang.String expectedValue) |
assertCallError, assertCheckTable, assertCommitError, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertErrorCode, assertGetIntError, assertNextError, assertPreparedStatementError, assertResults, assertResults, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertStatementErrorUnordered, assertTableRowCount, assertUpdateCount, assertUpdateCount, assertWarning, chattyPrepare, chattyPrepareCall, checkAllConsistency, checkEstimatedRowCount, closeStatement, commit, createStatement, createStatement, createStatement, dropTable, dropTable, dropView, dropView, dumpRs, dumpRs, emptyStatementCache, executeQuery, expectCompilationError, expectCompilationError, expectExecutionError, getClientTransactionID, getConnection, getDatabaseProperty, getLastSQLException, goodStatement, goodUpdate, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runBare, runBareOverridable, runScript, runScript, runSQLCommands, setAutoCommit, usingDB2Client, usingDerbyNetClient, usingEmbedded
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, toString
private static final int TRANSFER_BUFFER_SIZE
private static final int SET_STRING
private static final int SET_ASCII_STREAM
private static final int SET_CHARACTER_STREAM
private static int nextUniqueId
private static final java.lang.String NORWEGIAN_LETTERS
private java.sql.Clob clob
public void testGetSubString_PosOneTooBig() throws java.sql.SQLException
java.sql.SQLException
public void testGetSubString_PosTooBig()
public void testGetSubString_PosNegative() throws java.sql.SQLException
java.sql.SQLException
public void testGetSubString_RequestZeroLength_PosValid() throws java.sql.SQLException
java.sql.SQLException
public void testGetSubString_RequestZeroLength_PosTooBig() throws java.sql.SQLException
java.sql.SQLException
public void testGetSubString_BiggerThanInternalBuffer() throws java.io.IOException, java.sql.SQLException
The motivation for the test is to make sure big buffers are filled with the call to read inside a loop. Big in this sense means bigger than some internal buffer. This is typically around 8 KB or so, but we try something considerably bigger. If a char/byte array is attempted filled with a single call to read, the resulting string wil typically contain at positions after the size of the internal buffer.
java.io.IOException
java.sql.SQLException
public void testLengthOnEmptyClob() throws java.sql.SQLException
java.sql.SQLException
public void testInsertStringOnEmptyClob_Singlebyte() throws java.sql.SQLException
java.sql.SQLException
public void testInsertStringOnEmptyClob_Multibyte() throws java.sql.SQLException
java.sql.SQLException
public void testInsertStringInMiddle_Multibyte() throws java.sql.SQLException
java.sql.SQLException
public void testLengthAfterInsertOnEmpty() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testLengthAfterInsertOnLarge() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testReplaceMultibyteWithSingleByteForwards() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testReplaceMultibyteWithSingleByteBackwards() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testInsertCharacter_ReadOnlyToTemporary() throws java.io.IOException, java.sql.SQLException
Passing the marker over will normally result in a UTF encoding exception.
ID USAGE: reads id 2, writes id 10002
java.io.IOException
java.sql.SQLException
public void testPositionWithString_ASCII_SimplePartialRecurringPattern() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testPositionWithString_USASCII() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testPositionWithString_IOS88591() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testPositionWithString_CJK() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testSetStringOnWrongOffset() throws java.sql.SQLException
java.sql.SQLException
public void testSetStringWithWrongLen() throws java.sql.SQLException
java.sql.SQLException
public void testSetStringWithBigPos() throws java.sql.SQLException
java.sql.SQLException
public void testSetStringWithNull() throws java.sql.SQLException
java.sql.SQLException
public void testSetStringWithEmptyString() throws java.sql.SQLException
java.sql.SQLException
public void testTruncateZeroOnDisk() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testTruncateZeroInMemory() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void truncateToZero(long initSize) throws java.io.IOException, java.sql.SQLException
initSize
- the expected size of the Clob to truncatejava.io.IOException
java.sql.SQLException
public void testTruncateExactOnDisk() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testTruncateExactInMemory() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testTruncateTooLongOnDisk() throws java.io.IOException, java.sql.SQLException
This operation should fail and raise an exception.
java.io.IOException
java.sql.SQLException
public void testTruncateTooLongInMemory() throws java.io.IOException, java.sql.SQLException
This operation should fail and raise an exception.
java.io.IOException
java.sql.SQLException
public void testGetLengthAfterTruncate() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testCloningThroughAddBatchWithStream() throws java.sql.SQLException
See DERBY-4278
java.sql.SQLException
- if something goes wrongpublic void testCloningThroughAddBatchWithString() throws java.sql.SQLException
java.sql.SQLException
- if something goes wrongprivate void testCloningThroughAddBatch(boolean sourceAsStream, boolean autoCommit) throws java.sql.SQLException
sourceAsStream
- whether the source shall be specified as a stream
or a stringautoCommit
- auto commit mode to run withjava.sql.SQLException
- if something goes wrongpublic void test_4544() throws java.lang.Exception
java.lang.Exception
private void vetTable(int streamLength, java.lang.String gencol, java.lang.String expectedValue) throws java.lang.Exception
java.lang.Exception
private void vetTable(java.lang.String tableName, java.lang.String expectedValue) throws java.lang.Exception
java.lang.Exception
private void insertClob(int streamLength, java.lang.String tableName) throws java.lang.Exception
java.lang.Exception
private void vetClob(int streamLength, java.lang.String tableName) throws java.lang.Exception
java.lang.Exception
public static java.sql.Clob replace(java.sql.Clob clob, java.lang.String target, java.lang.String replacement) throws java.lang.Exception
java.lang.Exception
private void executeTestPositionWithStringToken(java.lang.String token, long prefixLength) throws java.io.IOException, java.sql.SQLException
Clob.setAsciiStream(long)
and
then search for the specified token.
Some data is inserted before and after the token, and the specified token is converted to bytes by using the ISO-8859-1 encoding. Note that ascii in JDBC is equivalent to ISO-8859-1, not US-ASCII.
java.io.IOException
java.sql.SQLException
protected void setUp() throws java.lang.Exception
setUp
in class junit.framework.TestCase
java.lang.Exception
protected void tearDown() throws java.lang.Exception
tearDown
in class BaseJDBCTestCase
java.lang.Exception
public static junit.framework.Test suite()
private int transferData(java.io.InputStream source, java.io.OutputStream dest, int tz) throws java.io.IOException
source
- source datadest
- destination to write totz
- buffer size in number of bytes. Must be 1 or greater.java.io.IOException
private int transferData(java.io.Reader source, java.io.Writer dest, int tz) throws java.io.IOException
source
- source datadest
- destination to write totz
- buffer size in number of characters. Must be 1 or greater.java.io.IOException
private int transferData(java.io.Reader source, int tz) throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void insertDataWithToken(java.lang.String token, long pre, long post, int mode) throws java.io.IOException, java.sql.SQLException
this.clob
.token
- a token to insert into the Clob, cannot be null
but
the empty string is acceptedpre
- number of characters to insert before the token, using the
repeating alphabet stream (latin lower-case)post
- number of characters to insert after the token, using the
repeating alphabet stream (latin lower-case)mode
- insertion mode; SET_STRING, SET_ASCII_STREAM or
SET_CHARACTER_STREAMjava.io.IOException
- if inserting data fails for some reasonjava.sql.SQLException
- if inserting data fails for some reasonApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.