public class AutoGenJDBC30Test extends BaseJDBCTestCase
Converts the old jdbcapi/autoGeneratedJdbc30.java test to JUnit. The old harness test number is preserved in the comment for each fixture.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
ROUTINES
Routines that should be created before the tests are run.
|
private static java.lang.String[][] |
TABLES
Tables that should be created before the tests are run.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
AutoGenJDBC30Test(java.lang.String name)
Creates a new AutoGenJDBC30Test instance.
|
Modifier and Type | Method and Description |
---|---|
static int |
addMe(int p1)
External code for the AddMe SQL function, which is called by
the testInsertAutoGenExecuteSQLfunc fixture.
|
private static junit.framework.Test |
baseSuite(java.lang.String name)
Tests are only run if JDBC 3.0 available, and database objects get
created only once for the suite run.
|
int |
getKeyValue(java.sql.ResultSet r)
Gets the key value from the result set.
|
static java.lang.String |
MyMethodWithNoInsert()
External code for the MMWNI() SQL function, which is called by
the testInsertNoAutoGenExecuteSQLfunc fixture.
|
void |
runInsertFourWaysKeyIsNull(java.lang.String sql)
Runs the same SQL INSERT statement four ways:
Statement.execute,
Statement.executeUpdate,
PreparedStatement.execute, and
PreparedStatement.executeUpdate,
and expects the resulting key value to be NULL.
|
void |
setUp()
Sets up the connection for a test case, clears all tables and resets
all auto-generated keys used by the test fixtures.
|
static junit.framework.Test |
suite()
Implements suite() to run in embedded and client configurations.
|
void |
testColumnIndexes()
Test that use of columnIndexes to indicate which keys should be
made available works as expected.
|
void |
testColumnNames()
Test that use of columnNames to indicate which keys should be
made available works as expected.
|
void |
testDelete()
Requests generated keys for an DELETE statement.
|
void |
testDeleteAutoGenNoGenKeysJDBC20syntax()
Deletes rows from a table with an auto-generated column in the JDBC 2.0
way (with no generated key feature), then fetches key.
|
void |
testDerby5823()
Regression test for DERBY-5823 where the temporary row holder code
failed when switching from an in-memory to an on-disk representation.
|
void |
testGetKeyAfterCommit()
Does a one-row insert into a table with a generated column, commits,
then requests generated keys for an insert into a table without a
generated column.
|
void |
testGetKeyAfterRollback()
Does a one-row insert into a table with a generated column, next does
a rollback, then requests generated keys for an insert into a table
without a generated column.
|
void |
testGetKeyAfterSavepointRollback()
Inserts one row into a table with an auto-generated column while inside
a savepoint unit, does a rollback, then gets keys after an insert
into a table without an auto-generated column.
|
void |
testGetKeyMetadataAfterInsert()
Inserts one row into a table with an auto-generated column, then
examines the metadata for the generatedKeys ResultSet.
|
void |
testInsertAutoGenExecuteSQLfunc()
Inserts a row into a table with a SQL function in the VALUES clause;
the table has an auto-generated column.
|
void |
testInsertJDBC20syntax()
Inserts one row into a table with an auto-generated column, but
in the JDBC 2.0 way (with no generated key feature).
|
void |
testInsertManyRowsAfterOneRowKey()
Requests generated keys for a multi-row insert statement after a
one-row insert into a table with an auto-generated key.
|
void |
testInsertManyRowsNoPriorKey()
Requests generated keys for a multi-row insert statement.
|
void |
testInsertNoAutoGen()
Requests generated keys after doing an insert into a table that doesn't
have a generated column (and there hasn't been a one row insert into
a table with auto-generated keys yet).
|
void |
testInsertNoAutoGenExecuteSQLfunc()
Inserts a row into a table with a SQL function in the VALUES clause;
the table does not have an auto-generated column.
|
void |
testInsertNoGenColAfterOneRowKey()
After a one-row insert into a table with an auto-generated key, next
inserts into a table that does not have an auto-generated key, then
requests generated keys.
|
void |
testInsertNoGenKeys()
Inserts one row into a table with an auto-generated column, but
with NO_GENERATED_KEYS.
|
void |
testInsertOneRowKey()
Requests generated keys after doing a one-row insert into a table
that has an auto-generated column.
|
void |
testInsertSubqueryNoWhereClause()
Requests generated keys after doing a one-row insert into a table that
has a generated column, but the insert is via a subquery with no where
clause.
|
void |
testInsertSubqueryWhere1is2()
Requests generated keys after doing a one-row insert into a table
that has a generated column, but the insert is via a subquery with
a "where 1=2" clause.
|
void |
testInsertSubqueryWhereClause()
Requests generated keys after doing a one-row insert into a table
that has a generated column, but the insert is via a subquery with
a "where c21=23" clause.
|
void |
testNoSql()
Requests generated keys for a new statement that hasn't executed any
SQL yet.
|
void |
testResultSetGarbageCollection()
Verifies fix for an old issue in which the ResultSet returned by
getGenerateKeys was incorrectly tied to the activation of the
PreparedStatement; so, when the ResultSet was garbage collected, the
activation was closed, resulting in an "Activation closed, operation
execute not permitted" exception on subsequent executes (warning:
this fixture takes a noticeable time to run).
|
void |
testSelect()
Requests generated keys for a Select statement (non-insert).
|
void |
testUpdateAutoGenNoGenKeys()
Updates a row in a table with an auto-generated column and
NO_GENERATED_KEYS, then fetches key.
|
void |
testUpdateManyRowsAfterOneRowKey()
Requests generated keys for a multi-row update statement after a
one-row update into a table with an auto-generated key.
|
void |
testUpdateOneRowKey()
Requests generated keys for an UPDATE statement.
|
private void |
testUserGivenColumns(int[] colIndexes,
java.lang.String[] colNames,
int expectedVal)
Verify that if user specifies *valid* column indexes or column
names to indicate which keys should be made available, Derby will
return the correct results.
|
void |
testUserGivenColumnsEmpty()
Verify that if user specifies an empty array for columNames or columnIndexes,
it is the same as NO_GENERATED_KEYS
|
private void |
testUserGivenColumnsError(int[] colIndexes,
java.lang.String[] colNames)
Verify that if user specifies *INvalid* column indexes or column
names to indicate which keys should be made available, Derby will
throw an appropriate error.
|
void |
testUserGivenColumnsNull()
Verify that if a user specifies a *NULL* column index or column
name array to indicate which keys should be made available, Derby will
effectively disable autogenerated keys (i.e. same as if user passed
NO_GENERATED_KEYS).
|
void |
verifyNullKey(java.lang.String description,
java.sql.ResultSet r)
Verifies that the generated key in a result set is null.
|
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, tearDown, 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 java.lang.String[] ROUTINES
private static final java.lang.String[][] TABLES
public AutoGenJDBC30Test(java.lang.String name)
name
- name of the testpublic static junit.framework.Test suite()
private static junit.framework.Test baseSuite(java.lang.String name)
name
- name of the testpublic void setUp() throws java.sql.SQLException
setUp
in class junit.framework.TestCase
java.sql.SQLException
public void testNoSql() throws java.sql.SQLException
java.sql.SQLException
public void testSelect() throws java.sql.SQLException
java.sql.SQLException
public void testInsertManyRowsNoPriorKey() throws java.sql.SQLException
java.sql.SQLException
public void testUpdateManyRowsAfterOneRowKey() throws java.sql.SQLException
java.sql.SQLException
public void testInsertManyRowsAfterOneRowKey() throws java.sql.SQLException
java.sql.SQLException
public void testInsertNoAutoGen() throws java.sql.SQLException
java.sql.SQLException
public void testDerby5823() throws java.sql.SQLException
Regression test for DERBY-5823 where the temporary row holder code failed when switching from an in-memory to an on-disk representation.
Note that ideally the transition should never have happened in the first place, so this test verifies that either the transition logic can deal with the degenerate case where the row template is zero-length, or the insert code is smart enough to understand that there are no auto-generated keys for the query.
java.sql.SQLException
public void testInsertSubqueryNoWhereClause() throws java.sql.SQLException
java.sql.SQLException
public void testInsertSubqueryWhere1is2() throws java.sql.SQLException
java.sql.SQLException
public void testInsertSubqueryWhereClause() throws java.sql.SQLException
java.sql.SQLException
public void testInsertOneRowKey() throws java.sql.SQLException
java.sql.SQLException
public void testInsertNoGenColAfterOneRowKey() throws java.sql.SQLException
java.sql.SQLException
public void testUpdateOneRowKey() throws java.sql.SQLException
java.sql.SQLException
public void testDelete() throws java.sql.SQLException
java.sql.SQLException
public void testGetKeyAfterCommit() throws java.sql.SQLException
java.sql.SQLException
public void testGetKeyAfterRollback() throws java.sql.SQLException
java.sql.SQLException
public void testGetKeyAfterSavepointRollback() throws java.sql.SQLException
java.sql.SQLException
public void testGetKeyMetadataAfterInsert() throws java.sql.SQLException
java.sql.SQLException
public void testInsertNoGenKeys() throws java.sql.SQLException
java.sql.SQLException
public void testInsertJDBC20syntax() throws java.sql.SQLException
java.sql.SQLException
public void testUpdateAutoGenNoGenKeys() throws java.sql.SQLException
java.sql.SQLException
public void testDeleteAutoGenNoGenKeysJDBC20syntax() throws java.sql.SQLException
java.sql.SQLException
public void testInsertNoAutoGenExecuteSQLfunc() throws java.sql.SQLException
java.sql.SQLException
public void testInsertAutoGenExecuteSQLfunc() throws java.sql.SQLException
java.sql.SQLException
public void testResultSetGarbageCollection() throws java.sql.SQLException
java.sql.SQLException
public void testColumnIndexes() throws java.sql.SQLException
java.sql.SQLException
public void testColumnNames() throws java.sql.SQLException
java.sql.SQLException
public void testUserGivenColumnsEmpty() throws java.sql.SQLException
java.sql.SQLException
public void testUserGivenColumnsNull() throws java.sql.SQLException
java.sql.SQLException
private void testUserGivenColumns(int[] colIndexes, java.lang.String[] colNames, int expectedVal) throws java.sql.SQLException
colIndexes
- Array of column indexes indicating which keys
should be made available. Must be null if colNames is non-null.colNames
- Array of column names indicating which keys should
be made available. Must be null if colIndexes is non-null.expectedVal
- First expected autogenerated key; will be
incremented for each successful INSERT statement.java.sql.SQLException
private void testUserGivenColumnsError(int[] colIndexes, java.lang.String[] colNames) throws java.sql.SQLException
colIndexes
- Array of column indexes indicating which keys
should be made available. Must be null if colNames is non-null.colNames
- Array of column names indicating which keys should
be made available. Must be null if colIndexes is non-null.java.sql.SQLException
public void runInsertFourWaysKeyIsNull(java.lang.String sql) throws java.sql.SQLException
sql
- The SQL statement to be executedjava.sql.SQLException
- if a database error occurspublic void verifyNullKey(java.lang.String description, java.sql.ResultSet r) throws java.sql.SQLException
description
- Text to be output for the assertionr
- ResultSetjava.sql.SQLException
- if a database error occurspublic int getKeyValue(java.sql.ResultSet r) throws java.sql.SQLException
r
- ResultSetjava.sql.SQLException
- if a database error occurspublic static java.lang.String MyMethodWithNoInsert() throws java.sql.SQLException
java.sql.SQLException
- if a database error occurspublic static int addMe(int p1) throws java.sql.SQLException
p1
- integer input argument to be used in calculationjava.sql.SQLException
- if a database error occursApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.