mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
@@ -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"));
|
||||
|
||||
|
@@ -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()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user