public class ConstraintCharacteristicsTest extends BaseJDBCTestCase
Modifier and Type | Field and Description |
---|---|
(package private) static java.lang.String[] |
checkForms |
(package private) static java.lang.String[] |
checkSpec |
private static java.lang.String[] |
columnConstraintTypes |
private static java.lang.String[][] |
defaultCharacteristics |
(package private) static java.lang.String |
DID |
private static java.lang.String |
expImpDataFile |
private static java.lang.String |
expImpDataWithNullsFile |
private static boolean |
exportFilesCreatedClient |
private static boolean |
exportFilesCreatedEmbedded |
(package private) static java.lang.String[] |
fkForms |
private static java.lang.String[] |
illegalAlterCharacteristics |
private static java.lang.String[] |
illegalCharacteristics |
(package private) static java.lang.String[][] |
initialContents |
private static java.util.Map<java.lang.String,java.lang.String[]> |
inverseState |
private static java.lang.String |
LANG_ADD_CHECK_CONSTRAINT_FAILED |
private static java.lang.String |
LANG_CHECK_CONSTRAINT_VIOLATED |
private static java.lang.String |
LANG_DB2_DUPLICATE_NAMES |
private static java.lang.String |
LANG_DEFERRED_CHECK_VIOLATION_S |
private static java.lang.String |
LANG_DEFERRED_CHECK_VIOLATION_T |
private static java.lang.String |
LANG_DEFERRED_DUP_VIOLATION_S |
private static java.lang.String |
LANG_DEFERRED_DUP_VIOLATION_T |
private static java.lang.String |
LANG_DEFERRED_FK_VIOLATION_S |
private static java.lang.String |
LANG_DEFERRED_FK_VIOLATION_T |
private static java.lang.String |
LANG_DROP_OR_ALTER_NON_EXISTING_C |
private static java.lang.String |
LANG_DUPLICATE_KEY_CONSTRAINT |
private static java.lang.String |
LANG_INCONSISTENT_C_CHARACTERISTICS |
private static java.lang.String |
LANG_NOT_NULL_CHARACTERISTICS |
private static java.lang.String |
LANG_OBJECT_NOT_FOUND |
private static java.lang.String |
LANG_SYNTAX_ERROR |
private static java.lang.String |
LOCK_TIMEOUT |
(package private) static java.lang.String[][] |
negatedInitialContents |
(package private) static long |
NO_OF_INSERTED_ROWS |
private static java.lang.String[][] |
nonDefaultCharacteristics |
private static java.lang.String |
NOT_IMPLEMENTED |
(package private) static java.lang.String[] |
setConstraintsForms |
private static java.lang.String[] |
tableConstraintTypes |
(package private) static java.lang.String[] |
uniqueForms |
(package private) static java.lang.String[] |
uniqueSpec |
private static int |
WAIT_TIMEOUT_DURATION |
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
ConstraintCharacteristicsTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
private void |
assertAlterDictState(java.sql.Statement s,
java.lang.String enforcement)
Check that the altered dictionary state resulting from new
characteristics equals . |
private void |
assertAlterInconsistentCharacteristics(java.sql.Statement s,
java.lang.String characteristics) |
private static void |
assertColumnLevelDefaultBehaviorAccepted(java.sql.Connection c,
java.sql.Statement s)
Assert that we accept characteristics that merely specify the default
behavior anyway.
|
private static void |
assertColumnLevelNonDefaultAccepted(java.sql.Statement s)
Assert that we allow non defaults
|
private void |
assertCreateInconsistentCharacteristics(java.sql.Statement s,
java.lang.String characteristics) |
private void |
assertDictState(java.sql.Statement s,
java.lang.String characteristics,
java.lang.String code)
Check that the dictionary state resulting from
characteristics
equals . |
private static void |
assertTableLevelDefaultBehaviorAccepted(java.sql.Connection c,
java.sql.Statement s)
Assert that we accept characteristics that merely specify the default
behavior anyway.
|
private static void |
assertTableLevelNonDefaultAccepted(java.sql.Statement s)
Assert that we fail with feature not implemented
until feature is implemented (for characteristics that are not Derby
default).
|
private void |
assertXidRolledBack(javax.transaction.xa.XAResource xar,
javax.transaction.xa.Xid xid) |
private static junit.framework.Test |
baseSuite1(java.lang.String name) |
private static junit.framework.Test |
baseSuite2(java.lang.String name) |
private static junit.framework.Test |
baseSuite3(java.lang.String name) |
static void |
calledNested(boolean isCheckConstraint) |
static void |
calledNestedFk() |
static void |
calledNestedSetImmediate() |
private static void |
checkConsistencyOfBaseTableAndIndex(java.sql.Statement s) |
private java.lang.String |
computeNewState(java.lang.String oldState,
java.lang.String enforcement) |
private void |
declareCalledNested(java.sql.Statement s) |
private void |
declareCalledNestedFk(java.sql.Statement s) |
private void |
declareCalledNestedSetImmediate(java.sql.Statement s) |
private void |
dontThrow(java.sql.Statement st,
java.lang.String stm) |
private javax.transaction.xa.Xid |
doXAWorkCheck(java.sql.Statement s,
javax.transaction.xa.XAResource xar) |
private javax.transaction.xa.Xid |
doXAWorkUniquePK(java.sql.Statement s,
javax.transaction.xa.XAResource xar) |
private static void |
dropTab1(java.sql.Connection c) |
private static void |
executeThreads(ConstraintCharacteristicsTest thisTest,
int isolation1,
int isolation2,
boolean commit)
Deletes a record in a transaction and tries to insert the same
from a different transaction.
|
static org.apache.derby.iapi.sql.conn.LanguageConnectionContext |
getLCC(java.sql.Connection conn)
Privileged lookup of the LCC from a Connection.
|
private java.lang.String |
getOldState(java.sql.Statement s) |
private static java.lang.String |
rs2Values(java.lang.String[][] rs)
Format rows to single string in syntax suitable for VALUES statement:
"{@code (v1,v2,..
|
protected void |
setUp() |
private static void |
setupTab1(java.sql.Connection c) |
static junit.framework.Test |
suite() |
protected void |
tearDown()
Tear down this fixture, sub-classes should call
super.tearDown().
|
void |
testAlmostRemovedAllDups()
Remove all duplicates except the last
|
void |
testAlterConstraintDictionaryEncodings()
Check that constraint characteristics are correctly encoded
into the STATE column in SYS.SYSCONSTRAINTS.
|
void |
testAlterConstraintInvalidation()
Check that altering constraint characteristics invalidates prepared
statements.
|
void |
testBasicDeferral() |
void |
testCheckConstraintsWithDeferredRows()
A bit of white box testing to cover different code paths.
|
void |
testCompressTableOKUnique() |
void |
testCreateConstraintDictionaryEncodings()
Check that constraint characteristics are correctly encoded
into the STATE column in SYS.SYSCONSTRAINTS.
|
void |
testDatabaseMetaData() |
void |
testDeferredRowsInvalidation() |
void |
testDerby6374() |
void |
testDerby6666()
DERBY-6666.
|
void |
testDerby6670_a()
DERBY-6670 test cases.
|
void |
testDerby6670_b()
Similarly to what happened for dropping of constraints, when we revert
from deferred constraint mode to immediate, and no violations are seen,
we used to drop the violation information, if any.
|
void |
testDerby6773()
DERBY-6773: check the Derby-specific subclass of the standard
SQLIntegrityConstraintViolationException.
|
void |
testDropNotNullOnUniqueColumn() |
void |
testImport()
Import uses other code paths than normal insert, so test it.
|
void |
testLockingForUniquePK() |
void |
testLockingForUniquePKWithCommit()
Test inserting a duplicate record while original is deleted in a
transaction and later committed.
|
void |
testLockingForUniquePKWithRollback()
Test inserting a duplicate record while original is deleted in
a transaction and later rolled back.
|
void |
testManySimilarDuplicates() |
void |
testRoutines()
Test that if the constraint mode is immediate and a routine has changed
this to introduce duplicates, we raise an error and roll back on exit
from the routine.
|
void |
testSeveralCheckConstraints()
We can have several constraints broken on one row write,
test is we register all correctly
|
void |
testSyntaxAndBinding() |
void |
testXA() |
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 java.lang.String LANG_DUPLICATE_KEY_CONSTRAINT
private static final java.lang.String LANG_DEFERRED_DUP_VIOLATION_T
private static final java.lang.String LANG_DEFERRED_DUP_VIOLATION_S
private static final java.lang.String LANG_CHECK_CONSTRAINT_VIOLATED
private static final java.lang.String LANG_DEFERRED_CHECK_VIOLATION_T
private static final java.lang.String LANG_DEFERRED_CHECK_VIOLATION_S
private static final java.lang.String LANG_DEFERRED_FK_VIOLATION_T
private static final java.lang.String LANG_DEFERRED_FK_VIOLATION_S
private static final java.lang.String LOCK_TIMEOUT
private static final java.lang.String LANG_INCONSISTENT_C_CHARACTERISTICS
private static final java.lang.String LANG_DROP_OR_ALTER_NON_EXISTING_C
private static final java.lang.String LANG_SYNTAX_ERROR
private static final java.lang.String NOT_IMPLEMENTED
private static final java.lang.String LANG_NOT_NULL_CHARACTERISTICS
private static final java.lang.String LANG_OBJECT_NOT_FOUND
private static final java.lang.String LANG_DB2_DUPLICATE_NAMES
private static final java.lang.String LANG_ADD_CHECK_CONSTRAINT_FAILED
private static java.lang.String expImpDataFile
private static java.lang.String expImpDataWithNullsFile
private static boolean exportFilesCreatedEmbedded
private static boolean exportFilesCreatedClient
private static final int WAIT_TIMEOUT_DURATION
static final java.lang.String[] uniqueForms
static final java.lang.String[] uniqueSpec
static final java.lang.String[] checkForms
static final java.lang.String[] fkForms
static final java.lang.String[] checkSpec
static final java.lang.String[][] initialContents
static final java.lang.String[][] negatedInitialContents
static final java.lang.String[] setConstraintsForms
static final long NO_OF_INSERTED_ROWS
static final java.lang.String DID
private static final java.lang.String[] tableConstraintTypes
private static final java.lang.String[] columnConstraintTypes
private static final java.lang.String[][] defaultCharacteristics
private static final java.lang.String[][] nonDefaultCharacteristics
private static final java.lang.String[] illegalCharacteristics
private static final java.lang.String[] illegalAlterCharacteristics
private static final java.util.Map<java.lang.String,java.lang.String[]> inverseState
public ConstraintCharacteristicsTest(java.lang.String name)
public static junit.framework.Test suite()
private static junit.framework.Test baseSuite3(java.lang.String name)
private static junit.framework.Test baseSuite2(java.lang.String name)
private static junit.framework.Test baseSuite1(java.lang.String name)
protected void setUp() throws java.lang.Exception
setUp
in class junit.framework.TestCase
java.lang.Exception
protected void tearDown() throws java.lang.Exception
BaseJDBCTestCase
tearDown
in class BaseJDBCTestCase
java.lang.Exception
public void testSyntaxAndBinding() throws java.sql.SQLException
java.sql.SQLException
public void testCreateConstraintDictionaryEncodings() throws java.sql.SQLException
java.sql.SQLException
public void testAlterConstraintDictionaryEncodings() throws java.sql.SQLException
java.sql.SQLException
public void testAlterConstraintInvalidation() throws java.sql.SQLException
java.sql.SQLException
public void testDatabaseMetaData() throws java.sql.SQLException
java.sql.SQLException
public void testLockingForUniquePK() throws java.sql.SQLException
java.sql.SQLException
public void testBasicDeferral() throws java.sql.SQLException
java.sql.SQLException
public void testRoutines() throws java.sql.SQLException
java.sql.SQLException
public void testDeferredRowsInvalidation() throws java.sql.SQLException
java.sql.SQLException
public void testImport() throws java.sql.SQLException
java.sql.SQLException
public void testDropNotNullOnUniqueColumn() throws java.sql.SQLException
java.sql.SQLException
public void testDerby6374() throws java.sql.SQLException
java.sql.SQLException
public void testXA() throws java.sql.SQLException, javax.transaction.xa.XAException
java.sql.SQLException
javax.transaction.xa.XAException
public void testCompressTableOKUnique() throws java.sql.SQLException
java.sql.SQLException
public void testManySimilarDuplicates() throws java.sql.SQLException
java.sql.SQLException
public void testAlmostRemovedAllDups() throws java.sql.SQLException
java.sql.SQLException
private static void setupTab1(java.sql.Connection c) throws java.sql.SQLException
java.sql.SQLException
private static void dropTab1(java.sql.Connection c) throws java.sql.SQLException
java.sql.SQLException
public void testLockingForUniquePKWithCommit() throws java.lang.Exception
IndexChanger
) by using a
BTree scan. Iff the constraint mode is deferred, we treat any
lock or deadlock timeout as if it were a duplicate, allowing us
to defer the check till commit time, as so possibly gain more
concurrency. To get speed in this case, the scan returns
immediately if it can't get a lock. The error was that, if the
constraint mode is not deferred (i.e. immediate), we
should wait for the lock, and we didn't. This was exposed by
this test since the 2 seconds wait makes it work in the normal
case (the lock would be released), but in the no-wait scan, we
saw a the lock time-out error.java.lang.Exception
public void testLockingForUniquePKWithRollback() throws java.lang.Exception
testLockingForUniquePKWithCommit()
.java.lang.Exception
public void testCheckConstraintsWithDeferredRows() throws java.sql.SQLException
java.sql.SQLException
public void testSeveralCheckConstraints() throws java.sql.SQLException
java.sql.SQLException
private static void executeThreads(ConstraintCharacteristicsTest thisTest, int isolation1, int isolation2, boolean commit) throws java.lang.Exception
thisTest
- the test object to operate onisolation1
- isolation level for 1st threadisolation2
- isolation level for 2nd threadcommit
- whether or not to commit
(Lifted from UniqueConstraintMultiThrededTest to test with deferrable
constraint.)java.lang.Exception
private javax.transaction.xa.Xid doXAWorkUniquePK(java.sql.Statement s, javax.transaction.xa.XAResource xar) throws java.sql.SQLException, javax.transaction.xa.XAException
java.sql.SQLException
javax.transaction.xa.XAException
private javax.transaction.xa.Xid doXAWorkCheck(java.sql.Statement s, javax.transaction.xa.XAResource xar) throws java.sql.SQLException, javax.transaction.xa.XAException
java.sql.SQLException
javax.transaction.xa.XAException
private void assertXidRolledBack(javax.transaction.xa.XAResource xar, javax.transaction.xa.Xid xid)
private static java.lang.String rs2Values(java.lang.String[][] rs)
(v1,v2,..,vn), (v1,v2,..,vn),....
"rs
- result set stringsprivate static void checkConsistencyOfBaseTableAndIndex(java.sql.Statement s) throws java.sql.SQLException
java.sql.SQLException
private static void assertTableLevelNonDefaultAccepted(java.sql.Statement s) throws java.sql.SQLException
s
- statementjava.sql.SQLException
private static void assertColumnLevelNonDefaultAccepted(java.sql.Statement s) throws java.sql.SQLException
s
- statementjava.sql.SQLException
private static void assertTableLevelDefaultBehaviorAccepted(java.sql.Connection c, java.sql.Statement s) throws java.sql.SQLException
c
- connections
- statementjava.sql.SQLException
private static void assertColumnLevelDefaultBehaviorAccepted(java.sql.Connection c, java.sql.Statement s) throws java.sql.SQLException
c
- connections
- statementjava.sql.SQLException
private void assertDictState(java.sql.Statement s, java.lang.String characteristics, java.lang.String code) throws java.sql.SQLException
characteristics
equals .s
- Statement to usecharacteristics
- A table level constraint characteristics stringcode
- Character encoding for characteristicsjava.sql.SQLException
private void assertAlterDictState(java.sql.Statement s, java.lang.String enforcement) throws java.sql.SQLException
characteristics
equals .s
- The statement object to useenforcement
- String containing ENFORCED or NOT ENFORCEDjava.sql.SQLException
private java.lang.String getOldState(java.sql.Statement s) throws java.sql.SQLException
java.sql.SQLException
private java.lang.String computeNewState(java.lang.String oldState, java.lang.String enforcement)
private void assertCreateInconsistentCharacteristics(java.sql.Statement s, java.lang.String characteristics) throws java.sql.SQLException
java.sql.SQLException
private void assertAlterInconsistentCharacteristics(java.sql.Statement s, java.lang.String characteristics) throws java.sql.SQLException
java.sql.SQLException
private void declareCalledNested(java.sql.Statement s) throws java.sql.SQLException
java.sql.SQLException
private void declareCalledNestedFk(java.sql.Statement s) throws java.sql.SQLException
java.sql.SQLException
private void declareCalledNestedSetImmediate(java.sql.Statement s) throws java.sql.SQLException
java.sql.SQLException
public static void calledNested(boolean isCheckConstraint) throws java.sql.SQLException
java.sql.SQLException
public static void calledNestedFk() throws java.sql.SQLException
java.sql.SQLException
public static void calledNestedSetImmediate() throws java.sql.SQLException
java.sql.SQLException
private void dontThrow(java.sql.Statement st, java.lang.String stm)
public void testDerby6670_a() throws java.sql.SQLException
java.sql.SQLException
public void testDerby6670_b() throws java.sql.SQLException
java.sql.SQLException
- test errorpublic void testDerby6666() throws java.sql.SQLException
derby.language.logQueryPlan
is set to true
, which it is is here.java.sql.SQLException
public void testDerby6773() throws java.lang.Exception
java.lang.Exception
public static org.apache.derby.iapi.sql.conn.LanguageConnectionContext getLCC(java.sql.Connection conn)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.