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

@@ -32,6 +32,7 @@ public class Column extends AbstractDbObject
{
private String type;
private boolean nullable;
private int order;
public Column(String name)
@@ -86,16 +87,34 @@ public class Column extends AbstractDbObject
this.nullable = nullable;
}
/**
* @return the order
*/
public int getOrder()
{
return this.order;
}
/**
* @param order the order to set
*/
public void setOrder(int order)
{
this.order = order;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + (this.nullable ? 1231 : 1237);
result = prime * result + this.order;
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
@@ -104,6 +123,7 @@ public class Column extends AbstractDbObject
if (getClass() != obj.getClass()) return false;
Column other = (Column) obj;
if (this.nullable != other.nullable) return false;
if (this.order != other.order) return false;
if (this.type == null)
{
if (other.type != null) return false;
@@ -117,13 +137,16 @@ public class Column extends AbstractDbObject
{
DbProperty thisTypeProp = new DbProperty(this, "type");
DbProperty thisNullableProp = new DbProperty(this, "nullable");
DbProperty thisOrderProp = new DbProperty(this, "order");
Column thatColumn = (Column) right;
DbProperty thatTypeProp = new DbProperty(thatColumn, "type");
DbProperty thatNullableProp = new DbProperty(thatColumn, "nullable");
DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
comparisonUtils.compareSimple(thisTypeProp, thatTypeProp, ctx);
comparisonUtils.compareSimple(thisNullableProp, thatNullableProp, ctx);
comparisonUtils.compareSimple(thisOrderProp, thatOrderProp, ctx);
}
@Override

View File

@@ -63,8 +63,11 @@ public class ColumnTest extends DbObjectTestBase<Column>
DbProperty thisNullableProp = new DbProperty(thisColumn, "nullable");
DbProperty thatNullableProp = new DbProperty(thatColumn, "nullable");
inOrder.verify(comparisonUtils).compareSimple(thisNullableProp, thatNullableProp, ctx);
DbProperty thisOrderProp = new DbProperty(thisColumn, "order");
DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
inOrder.verify(comparisonUtils).compareSimple(thisOrderProp, thatOrderProp, ctx);
}
@Test

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);
}
}

View File

@@ -41,8 +41,16 @@ public class PrimaryKeyTest extends DbObjectTestBase<PrimaryKey>
@Before
public void setUp()
{
thisPK = new PrimaryKey(null, "this_pk", Arrays.asList("id", "name", "age"));
thatPK = new PrimaryKey(null, "that_pk", Arrays.asList("a", "b"));
thisPK = new PrimaryKey(
null,
"this_pk",
Arrays.asList("id", "name", "age"),
Arrays.asList(2, 1, 3));
thatPK = new PrimaryKey(
null,
"that_pk",
Arrays.asList("a", "b"),
Arrays.asList(1, 2));
}
@Override
@@ -65,6 +73,11 @@ public class PrimaryKeyTest extends DbObjectTestBase<PrimaryKey>
new DbProperty(thatPK, "columnNames"),
ctx,
Strength.ERROR);
inOrder.verify(comparisonUtils).compareSimpleCollections(
new DbProperty(thisPK, "columnOrders"),
new DbProperty(thatPK, "columnOrders"),
ctx,
Strength.ERROR);
}
@Test