ALF-12874: Schema reference files are out of date.

Made comparisons case-insensitve and extract DB metadata for tables matching lower- and upper-case prefixes (e.g. act_ and ACT_).




git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@35399 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2012-04-18 20:15:45 +00:00
parent e31ea91e51
commit 4fc2426815
4 changed files with 35 additions and 33 deletions

View File

@@ -295,7 +295,18 @@ public class DefaultComparisonUtils implements ComparisonUtils
else else
{ {
// neither are null // 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; where = Where.IN_BOTH_NO_DIFFERENCE;
} }

View File

@@ -69,6 +69,9 @@ public class DefaultComparisonUtilsTest
comparisonUtils.compareSimple(prop("not_null_string"), prop("not_null_string"), ctx); 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")); 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); comparisonUtils.compareSimple(prop("left"), prop("right"), ctx);
verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, prop("left"), prop("right")); verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, prop("left"), prop("right"));

View File

@@ -25,7 +25,6 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Logger;
import javax.sql.DataSource; import javax.sql.DataSource;
@@ -45,8 +44,6 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.TypeNames; import org.hibernate.dialect.TypeNames;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import com.sun.crypto.provider.DESCipher;
/** /**
* Exports a database schema to an in-memory {@link Schema} object. * Exports a database schema to an in-memory {@link Schema} object.
@@ -205,13 +202,24 @@ public class ExportDb
String schemaName = getSchemaName(dbmd); String schemaName = getSchemaName(dbmd);
schema = new Schema(schemaName, namePrefix, schemaVersion); 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()) if (log.isDebugEnabled())
{ {
log.debug("Retrieving tables: schemaName=[" + schemaName + "], prefixFilter=[" + prefixFilter + "]"); log.debug("Retrieving tables: schemaName=[" + schemaName + "], prefixFilter=[" + prefixFilter + "]");
} }
final ResultSet tables = dbmd.getTables(null, schemaName, prefixFilter, new String[] final ResultSet tables = dbmd.getTables(null, schemaName, prefixFilter, new String[]
{ {
"TABLE", "VIEW", "SEQUENCE" "TABLE", "VIEW", "SEQUENCE"
@@ -371,7 +379,6 @@ public class ExportDb
tables.close(); tables.close();
} }
/** /**
* Assume that if there are schemas, we want the one named after the connection user * Assume that if there are schemas, we want the one named after the connection user
* or the one called "dbo" (MS SQL hack) * or the one called "dbo" (MS SQL hack)
@@ -481,35 +488,16 @@ public class ExportDb
return this.namePrefix; return this.namePrefix;
} }
private String namePrefixFilter(DatabaseMetaData dbmd) throws SQLException private String[] namePrefixFilters(DatabaseMetaData dbmd) throws SQLException
{ {
String filter = namePrefix + "%"; String filter = namePrefix + "%";
// We're assuming the prefixes are either PREFIX_ or prefix_
// Note, MySQL on Linux reports true for: // but not mixed-case.
// dbmd.storesMixedCaseIdentifiers() return new String[]
// 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())
{ {
if (log.isDebugEnabled()) filter.toLowerCase(),
{ filter.toUpperCase()
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;
} }

View File

@@ -103,7 +103,7 @@ public abstract class AbstractDbObject implements DbObject
sameParent = true; sameParent = true;
} }
// Same parent & same name - it must be considered the same object. // 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; return false;