protected void compareIndexDescription( TableDescription xmlTableDescription, TableDescription databaseTableDescription) { for (int i = 0; i < xmlTableDescription.getIndexSize(); i++) { IndexDescription xmlIndexDescription = xmlTableDescription.getIndex(i); IndexDescription databaseIndexDescription = null; if (xmlIndexDescription.getIndexName() != null) { databaseIndexDescription = databaseTableDescription.getIndex(xmlIndexDescription.getIndexName()); } else { for (IndexDescription each : databaseTableDescription.getIndices()) { if (indexColumnsEqual(xmlIndexDescription, each)) { databaseIndexDescription = each; break; } } if (databaseIndexDescription == null) databaseIndexDescription = databaseTableDescription.getPrimaryKey(); } compareSingleIndexDescription(xmlIndexDescription, databaseIndexDescription); } }
private boolean indexColumnsEqual( IndexDescription xmlIndexDescription, IndexDescription databaseIndexDescription) { boolean columnsOK = xmlIndexDescription.getColumnSize() == databaseIndexDescription.getColumnSize(); if (columnsOK) { for (int i = 0; i < xmlIndexDescription.getColumnSize(); i++) { String xmlColumn = xmlIndexDescription.getColumn(i); String dbColumn = databaseIndexDescription.getColumn(i); if (xmlColumn.equalsIgnoreCase(dbColumn)) { assertTrue( "Table: " + xmlIndexDescription.getTableName() + "... Wrong Orderdirection! Column:" + xmlIndexDescription.getColumn(i) + " expected OrderDirection: " + xmlIndexDescription.getOrderDirection(i) + " databaseOrderDirection: " + databaseIndexDescription.getOrderDirection(i), xmlIndexDescription.getOrderDirection(i) == databaseIndexDescription.getOrderDirection(i)); } else { columnsOK = false; } } } return columnsOK; }
protected void compareSingleIndexDescription( IndexDescription xmlIndexDescription, IndexDescription databaseIndexDescription) { if (xmlIndexDescription == null && databaseIndexDescription == null) return; if (xmlIndexDescription == null) { assertTrue( "Table: " + databaseIndexDescription.getTableName() + "... IndexName not expected! " + databaseIndexDescription.getIndexName() + " databaseIndexName: " + databaseIndexDescription.getIndexName(), false); return; } if (databaseIndexDescription == null) { assertTrue( "Table: " + xmlIndexDescription.getTableName() + "...DatabaseIndexName not found!! Expected IndexName: " + xmlIndexDescription.getIndexName(), false); return; } if (xmlIndexDescription.isFunctionBased() || databaseIndexDescription.isFunctionBased()) { log("function based not yet supported"); // todo [RSt] nyi return; } if (xmlIndexDescription.getIndexName() == null || xmlIndexDescription .getIndexName() .equalsIgnoreCase(databaseIndexDescription.getIndexName())) { boolean columnsOK = indexColumnsEqual(xmlIndexDescription, databaseIndexDescription); if (!columnsOK) { assertTrue( "Table: " + xmlIndexDescription.getTableName() + ", index: " + xmlIndexDescription.getIndexName() + "... Columns differ! expected: " + xmlIndexDescription.getColumns() + " but was " + databaseIndexDescription.getColumns(), false); } } else { assertTrue( "Table: " + xmlIndexDescription.getTableName() + "... Wrong Indexname! Expected IndexName: " + xmlIndexDescription.getIndexName() + " databaseIndexName: " + databaseIndexDescription.getIndexName(), false); } }