diff --git a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java index d2694b42cb..0ae82bda1d 100644 --- a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java +++ b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java @@ -295,7 +295,18 @@ public class DefaultComparisonUtils implements ComparisonUtils else { // neither are null - if (left.equals(right)) + boolean objectsAreEqual; + // Strings are compared case-insensitively, e.g. table names. + if (left instanceof String && right instanceof String) + { + objectsAreEqual = ((String) left).equalsIgnoreCase((String) right); + } + else + { + objectsAreEqual = left.equals(right); + } + + if (objectsAreEqual) { where = Where.IN_BOTH_NO_DIFFERENCE; } diff --git a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java index be2cd142a7..ba823c0905 100644 --- a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java +++ b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java @@ -69,6 +69,9 @@ public class DefaultComparisonUtilsTest comparisonUtils.compareSimple(prop("not_null_string"), prop("not_null_string"), ctx); verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, prop("not_null_string"), prop("not_null_string")); + comparisonUtils.compareSimple(prop("Not_Null_String"), prop("NOT_NULL_STRING"), ctx); + verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, prop("Not_Null_String"), prop("NOT_NULL_STRING")); + comparisonUtils.compareSimple(prop("left"), prop("right"), ctx); verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, prop("left"), prop("right")); diff --git a/source/java/org/alfresco/util/schemacomp/ExportDb.java b/source/java/org/alfresco/util/schemacomp/ExportDb.java index 7ca3242936..ab434e904c 100644 --- a/source/java/org/alfresco/util/schemacomp/ExportDb.java +++ b/source/java/org/alfresco/util/schemacomp/ExportDb.java @@ -25,7 +25,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; import java.util.TreeMap; -import java.util.logging.Logger; import javax.sql.DataSource; @@ -45,8 +44,6 @@ import org.hibernate.dialect.Dialect; import org.hibernate.dialect.TypeNames; import org.springframework.context.ApplicationContext; -import com.sun.crypto.provider.DESCipher; - /** * Exports a database schema to an in-memory {@link Schema} object. @@ -205,13 +202,24 @@ public class ExportDb String schemaName = getSchemaName(dbmd); schema = new Schema(schemaName, namePrefix, schemaVersion); - String prefixFilter = namePrefixFilter(dbmd); + String[] prefixFilters = namePrefixFilters(dbmd); + for (String filter : prefixFilters) + { + extractSchema(dbmd, schemaName, filter); + } + } + + + private void extractSchema(DatabaseMetaData dbmd, String schemaName, String prefixFilter) + throws SQLException, IllegalArgumentException, IllegalAccessException + { if (log.isDebugEnabled()) { log.debug("Retrieving tables: schemaName=[" + schemaName + "], prefixFilter=[" + prefixFilter + "]"); } + final ResultSet tables = dbmd.getTables(null, schemaName, prefixFilter, new String[] { "TABLE", "VIEW", "SEQUENCE" @@ -371,7 +379,6 @@ public class ExportDb tables.close(); } - /** * Assume that if there are schemas, we want the one named after the connection user * or the one called "dbo" (MS SQL hack) @@ -481,35 +488,16 @@ public class ExportDb return this.namePrefix; } - private String namePrefixFilter(DatabaseMetaData dbmd) throws SQLException + private String[] namePrefixFilters(DatabaseMetaData dbmd) throws SQLException { String filter = namePrefix + "%"; - - // Note, MySQL on Linux reports true for: - // dbmd.storesMixedCaseIdentifiers() - // dbmd.storesMixedCaseQuotedIdentifiers() - // dbmd.storesUpperCaseQuotedIdentifiers() - // and false for the other storesXYZ() methods. In reality it stores - // the table names in whatever case was provided, quoted or not. - - // Make sure the filter works for the particular DBMS. - if (dbmd.storesLowerCaseIdentifiers()) + // We're assuming the prefixes are either PREFIX_ or prefix_ + // but not mixed-case. + return new String[] { - if (log.isDebugEnabled()) - { - log.debug("DB uses lowercase identifiers"); - } - filter = filter.toLowerCase(); - } - else if (dbmd.storesUpperCaseIdentifiers()) - { - if (log.isDebugEnabled()) - { - log.debug("DB uses uppercase identifiers"); - } - filter = filter.toUpperCase(); - } - return filter; + filter.toLowerCase(), + filter.toUpperCase() + }; } diff --git a/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java b/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java index ddaab6b31a..2f94c2bf7a 100644 --- a/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java +++ b/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java @@ -103,7 +103,7 @@ public abstract class AbstractDbObject implements DbObject sameParent = true; } // Same parent & same name - it must be considered the same object. - return sameParent && getName().equals(other.getName()); + return sameParent && getName().equalsIgnoreCase(other.getName()); } return false;