ALF-11668: Add position identifiers (same as seq elements in current schema dump tool)

As for current schemadump tool, table columns and primary key column names have order associated with them.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32296 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-11-24 18:17:41 +00:00
parent f939783d70
commit 462994f3eb
16 changed files with 503 additions and 313 deletions

View File

@@ -34,6 +34,7 @@ import org.alfresco.util.schemacomp.Result.Strength;
public class PrimaryKey extends AbstractDbObject
{
private final List<String> columnNames = new ArrayList<String>();
private final List<Integer> columnOrders = new ArrayList<Integer>();
public PrimaryKey(String name)
@@ -47,10 +48,24 @@ public class PrimaryKey extends AbstractDbObject
* @param name
* @param columnNames
*/
public PrimaryKey(Table table, String name, List<String> columnNames)
public PrimaryKey(Table table, String name, List<String> columnNames, List<Integer> columnOrders)
{
super(table, name);
this.columnNames.addAll(columnNames);
this.columnOrders.addAll(columnOrders);
checkColumnOrders();
}
/**
* Ensure that if columnOrders are being used, there are
* as many of them as there are column names.
*/
private void checkColumnOrders()
{
if (columnOrders.size() > 0 && columnOrders.size() != columnNames.size())
{
throw new IllegalArgumentException("columnOrders size does not match columnNames");
}
}
/**
@@ -69,6 +84,23 @@ public class PrimaryKey extends AbstractDbObject
this.columnNames.clear();
this.columnNames.addAll(columnNames);
}
/**
* @return the columnOrders
*/
public List<Integer> getColumnOrders()
{
return this.columnOrders;
}
/**
* @param columnOrders the columnOrders to set
*/
public void setColumnOrders(List<Integer> columnOrders)
{
this.columnOrders.clear();
this.columnOrders.addAll(columnOrders);
}
@Override
public int hashCode()
@@ -76,6 +108,7 @@ public class PrimaryKey extends AbstractDbObject
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.columnNames == null) ? 0 : this.columnNames.hashCode());
result = prime * result + ((this.columnOrders == null) ? 0 : this.columnOrders.hashCode());
return result;
}
@@ -91,23 +124,35 @@ public class PrimaryKey extends AbstractDbObject
if (other.columnNames != null) return false;
}
else if (!this.columnNames.equals(other.columnNames)) return false;
if (this.columnOrders == null)
{
if (other.columnOrders != null) return false;
}
else if (!this.columnOrders.equals(other.columnOrders)) return false;
return true;
}
@Override
protected void doDiff(DbObject right, DiffContext ctx, Strength strength)
{
checkColumnOrders();
PrimaryKey rightPK = (PrimaryKey) right;
comparisonUtils.compareSimpleCollections(
new DbProperty(this, "columnNames"),
new DbProperty(rightPK, "columnNames"),
ctx,
strength);
comparisonUtils.compareSimpleCollections(
new DbProperty(this, "columnOrders"),
new DbProperty(rightPK, "columnOrders"),
ctx,
strength);
}
@Override
public void accept(DbObjectVisitor visitor)
{
checkColumnOrders();
visitor.visit(this);
}
}