dropAll attempts to drop objects in other schemas under Oracle

Description

When we try to dropAll, we see something like the following:

EBUG 7/23/13 11:28 PM:liquibase: Unable to load/access Apache Derby driver class to check version
DEBUG 7/23/13 11:28 PM:liquibase: Connected to MNETTLE@jdbc:oracle:thin:@//xxxxx:yyyy/zzzzz
DEBUG 7/23/13 11:28 PM:liquibase: Setting auto commit to false from true
DEBUG 7/23/13 11:28 PM:liquibase: Executing QUERY database command: SELECT SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = 'MNETTLE'
DEBUG 7/23/13 11:28 PM:liquibase: Executing QUERY database command: SELECT TEXT FROM ALL_VIEWS WHERE upper(VIEW_NAME)='VW_PAYROLL_TOTALS' AND OWNER='MNETTLE'
DEBUG 7/23/13 11:28 PM:liquibase: Executing QUERY database command: SELECT TEXT FROM ALL_VIEWS WHERE upper(VIEW_NAME)='VW_YTD_CONTRIBUTIONS' AND OWNER='MNETTLE'
DEBUG 7/23/13 11:28 PM:liquibase: Executing QUERY database command: SELECT LOCKED FROM MNETTLE.DATABASECHANGELOGLOCK WHERE ID=1 FOR UPDATE
DEBUG 7/23/13 11:28 PM:liquibase: Lock Database
DEBUG 7/23/13 11:28 PM:liquibase: Executing UPDATE database command: UPDATE MNETTLE.DATABASECHANGELOGLOCK SET LOCKED = 1, LOCKEDBY = '10.253.0.192 (10.253.0.192)', LOCKGRANTED = to_date('2013-07-23 23:28:28', 'YYYY-MM-DD HH24:MI:SS') WHERE ID = 1 AND LOCKED = 0
INFO 7/23/13 11:28 PM:liquibase: Successfully acquired change log lock
INFO 7/23/13 11:28 PM:liquibase: Dropping Database Objects in schema: MNETTLE.MNETTLE
DEBUG 7/23/13 11:28 PM:liquibase: Executing QUERY database command: SELECT SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = 'MNETTLE'
INFO 7/23/13 11:31 PM:liquibase: Unknown default value: value ''0'
' type NUMBER (3), assuming it is a function
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: SELECT TEXT FROM ALL_VIEWS WHERE upper(VIEW_NAME)='VW_PAYROLL_TOTALS' AND OWNER='MNETTLE'
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: SELECT TEXT FROM ALL_VIEWS WHERE upper(VIEW_NAME)='VW_YTD_CONTRIBUTIONS' AND OWNER='MNETTLE'
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: SELECT MD5SUM FROM MNETTLE.DATABASECHANGELOG WHERE MD5SUM IS NOT NULL
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: SELECT SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = 'MNETTLE'
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: select uc.constraint_name, uc.table_name,uc.status,uc.deferrable,uc.deferred,ui.tablespace_name from all_constraints uc, all_cons_columns ucc, all_indexes ui where uc.constraint_type='U' and uc.index_name = ui.index_name and uc.constraint_name = ucc.constraint_name and uc.table_name = 'FILE_TYPES' and uc.owner = 'MNETTLE' and ui.table_owner = 'MNETTLE' and ucc.owner = 'MNETTLE'
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: select uc.constraint_name, uc.table_name,uc.status,uc.deferrable,uc.deferred,ui.tablespace_name from all_constraints uc, all_cons_columns ucc, all_indexes ui where uc.constraint_type='U' and uc.index_name = ui.index_name and uc.constraint_name = ucc.constraint_name and uc.table_name = 'ACTION_MAPPINGS' and uc.owner = 'AANWAR_TPA' and ui.table_owner = 'AANWAR_TPA' and ucc.owner = 'AANWAR_TPA'
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: SELECT SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = 'AANWAR_TPA'
DEBUG 7/23/13 11:31 PM:liquibase: Executing QUERY database command: select uc.constraint_name, uc.table_name,uc.status,uc.deferrable,uc.deferred,ui.tablespace_name from all_constraints uc, all_cons_columns ucc, all_indexes ui where uc.constraint_type='U' and uc.index_name = ui.index_name and uc.constraint_name = ucc.constraint_name and uc.table_name = 'PROCESSING_EVENTS' and uc.owner = 'AANWAR_TPA' and ui.table_owner = 'AANWAR_TPA' and ucc.owner = 'AANWAR_TPA'

Note the switch in owners. We did a fair amount of debugging through the code today and it seems that we get into trouble on this line in ForeignKeySnapshotGenerator:

Table fktable = (Table) new Table().setName(row.getString("FKTABLE_NAME")).setSchema(new Schema(row.getString("FKTABLE_CAT"), row.getString("FKTABLE_SCHEM")));

It looks like what's happening is that row.getString("FKTABLE_CAT") returns null, so we end up w/ no catalog and when the code tries to search for the database object the first one it finds happens to not be in the schema that we are trying to drop. Putting a breakpoint in the Schema constructor and manually resetting catalog to "MNETTLE" whenever it is null seems to address the issue, but that's probably not the ideal fix.

Environment

Oracle 10g, Oracle 11.2.0.3 thin driver, MacOSX, Java 1.7, schema on database instance with lots of similar schemas with objects of the same name

Reporter

Matt Nettleton

Fix versions

Affects versions

Priority

Critical
Configure