diff --git a/source/java/org/alfresco/util/schemacomp/ComparisonUtils.java b/source/java/org/alfresco/util/schemacomp/ComparisonUtils.java index 189dac3a9a..068705499e 100644 --- a/source/java/org/alfresco/util/schemacomp/ComparisonUtils.java +++ b/source/java/org/alfresco/util/schemacomp/ComparisonUtils.java @@ -38,8 +38,7 @@ public interface ComparisonUtils DbObject findSameObjectAs(Collection objects, final DbObject objToFind); void compareSimpleCollections(Collection leftCollection, - Collection rightCollection, Differences differences, - Strength strength); + Collection rightCollection, DiffContext ctx, Strength strength); /** * Compare collections, reporting differences using the default {@link Result.Strength} @@ -47,7 +46,7 @@ public interface ComparisonUtils * @see #compareCollections(Collection, Collection, Differences, Strength) */ void compareCollections(Collection leftCollection, - Collection rightCollection, Differences differences); + Collection rightCollection, DiffContext ctx); /** * Compare collections of {@link DbObject}s using their {@link DbObject#diff(DbObject, Differences)} method. @@ -59,7 +58,7 @@ public interface ComparisonUtils * @param strength */ void compareCollections(Collection leftCollection, - Collection rightCollection, Differences differences, + Collection rightCollection, DiffContext ctx, Strength strength); /** @@ -67,7 +66,7 @@ public interface ComparisonUtils * * @see #compareSimple(Object, Object, Differences, Strength) */ - void compareSimple(Object left, Object right, Differences differences); + void compareSimple(Object left, Object right, DiffContext ctx); /** * Compare two 'simple' (i.e. non-{@link DbObject} objects) using their {@link Object#equals(Object)} method @@ -78,6 +77,6 @@ public interface ComparisonUtils * @param differences * @param strength */ - void compareSimple(Object left, Object right, Differences differences, Strength strength); + void compareSimple(Object left, Object right, DiffContext ctx, Strength strength); } \ No newline at end of file diff --git a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java index 3c48e649e7..f83bb2dd09 100644 --- a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java +++ b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtils.java @@ -55,8 +55,9 @@ public class DefaultComparisonUtils implements ComparisonUtils @Override public void compareSimpleCollections(Collection leftCollection, - Collection rightCollection, Differences differences, Strength strength) + Collection rightCollection, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); for (Object leftObj : leftCollection) { if (rightCollection.contains(leftObj)) @@ -92,9 +93,9 @@ public class DefaultComparisonUtils implements ComparisonUtils */ @Override public void compareCollections(Collection leftCollection, - Collection rightCollection, Differences differences) + Collection rightCollection, DiffContext ctx) { - compareCollections(leftCollection, rightCollection, differences, null); + compareCollections(leftCollection, rightCollection, ctx, null); } /** @@ -108,8 +109,9 @@ public class DefaultComparisonUtils implements ComparisonUtils */ @Override public void compareCollections(Collection leftCollection, - Collection rightCollection, Differences differences, Strength strength) + Collection rightCollection, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); for (DbObject leftObj : leftCollection) { DbObject rightObj = findSameObjectAs(rightCollection, leftObj); @@ -118,7 +120,7 @@ public class DefaultComparisonUtils implements ComparisonUtils { // There is an equivalent object in the right hand collection as // in the left. - leftObj.diff(rightObj, differences, strength); + leftObj.diff(rightObj, ctx, strength); } else { @@ -144,9 +146,9 @@ public class DefaultComparisonUtils implements ComparisonUtils * @see #compareSimple(Object, Object, Differences, Strength) */ @Override - public void compareSimple(Object left, Object right, Differences differences) + public void compareSimple(Object left, Object right, DiffContext ctx) { - compareSimple(left, right, differences, null); + compareSimple(left, right, ctx, null); } /** @@ -159,7 +161,7 @@ public class DefaultComparisonUtils implements ComparisonUtils * @param strength */ @Override - public void compareSimple(Object left, Object right, Differences differences, Strength strength) + public void compareSimple(Object left, Object right, DiffContext ctx, Strength strength) { Where where = null; @@ -192,6 +194,6 @@ public class DefaultComparisonUtils implements ComparisonUtils } } - differences.add(where, left, right, strength); + ctx.getDifferences().add(where, left, right, strength); } } diff --git a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java index b712b3ee7d..00beeb8d35 100644 --- a/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java +++ b/source/java/org/alfresco/util/schemacomp/DefaultComparisonUtilsTest.java @@ -33,6 +33,7 @@ import java.util.List; import org.alfresco.util.schemacomp.Result.Strength; import org.alfresco.util.schemacomp.Result.Where; import org.alfresco.util.schemacomp.model.DbObject; +import org.hibernate.dialect.Dialect; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,29 +50,32 @@ public class DefaultComparisonUtilsTest { private @Mock Differences differences; private DefaultComparisonUtils comparisonUtils; + private DiffContext ctx; + private @Mock Dialect dialect; @Before public void setUp() { comparisonUtils = new DefaultComparisonUtils(); + ctx = new DiffContext(dialect, differences); } @Test public void compareSimple() { - comparisonUtils.compareSimple(null, null, differences, Strength.ERROR); + comparisonUtils.compareSimple(null, null, ctx, Strength.ERROR); verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, null, null, Strength.ERROR); - comparisonUtils.compareSimple("not_null_string", "not_null_string", differences, Strength.ERROR); + comparisonUtils.compareSimple("not_null_string", "not_null_string", ctx, Strength.ERROR); verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, "not_null_string", "not_null_string", Strength.ERROR); - comparisonUtils.compareSimple("left", "right", differences, Strength.ERROR); + comparisonUtils.compareSimple("left", "right", ctx, Strength.ERROR); verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, "left", "right", Strength.ERROR); - comparisonUtils.compareSimple("left", null, differences, Strength.ERROR); + comparisonUtils.compareSimple("left", null, ctx, Strength.ERROR); verify(differences).add(Where.ONLY_IN_LEFT, "left", null, Strength.ERROR); - comparisonUtils.compareSimple(null, "right", differences, Strength.ERROR); + comparisonUtils.compareSimple(null, "right", ctx, Strength.ERROR); verify(differences).add(Where.ONLY_IN_RIGHT, null, "right", Strength.ERROR); } @@ -94,11 +98,11 @@ public class DefaultComparisonUtilsTest Collection right = new ArrayList(); Collections.addAll(right, db1, db3, db4); - comparisonUtils.compareCollections(left, right, differences, Strength.ERROR); + comparisonUtils.compareCollections(left, right, ctx, Strength.ERROR); // Objects in both are asked for their differences - verify(db1).diff(db1, differences, Strength.ERROR); - verify(db4).diff(db4, differences, Strength.ERROR); + verify(db1).diff(db1, ctx, Strength.ERROR); + verify(db4).diff(db4, ctx, Strength.ERROR); // Objects in only one collections are marked as such verify(differences).add(Where.ONLY_IN_LEFT, db2, null, Strength.ERROR); @@ -130,7 +134,7 @@ public class DefaultComparisonUtilsTest rightCollection.add("both"); rightCollection.add("one more right only"); - comparisonUtils.compareSimpleCollections(leftCollection, rightCollection, differences, Strength.WARN); + comparisonUtils.compareSimpleCollections(leftCollection, rightCollection, ctx, Strength.WARN); verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, 123, 123, Strength.WARN); verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, "both", "both", Strength.WARN); diff --git a/source/java/org/alfresco/util/schemacomp/DiffContext.java b/source/java/org/alfresco/util/schemacomp/DiffContext.java new file mode 100644 index 0000000000..438199014d --- /dev/null +++ b/source/java/org/alfresco/util/schemacomp/DiffContext.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.util.schemacomp; + +import org.hibernate.dialect.Dialect; + +/** + * A context made available to schema differencing and validation operations. It supplies information + * about the {@link Dialect database dialect} that should be used when validating database properties + * and the {@link Differences} object that should be populated with schema differences and validation errors. + * + * @author Matt Ward + */ +public class DiffContext +{ + private final Dialect dialect; + private final Differences differences; + + + /** + * @param dialect + * @param differences + */ + public DiffContext(Dialect dialect, Differences differences) + { + this.dialect = dialect; + this.differences = differences; + } + + /** + * @return the dialect + */ + public Dialect getDialect() + { + return this.dialect; + } + + /** + * @return the differences + */ + public Differences getDifferences() + { + return this.differences; + } +} diff --git a/source/java/org/alfresco/util/schemacomp/Differences.java b/source/java/org/alfresco/util/schemacomp/Differences.java index 6bb8971638..8fd1f62198 100644 --- a/source/java/org/alfresco/util/schemacomp/Differences.java +++ b/source/java/org/alfresco/util/schemacomp/Differences.java @@ -69,6 +69,13 @@ public class Differences implements Iterable Result result = new Result(where, left, right, path.getCurrentPath(), strength); items.add(result); } + + + public void add(Where where, Object left, Object right) + { + add(where, left, right, null); + } + /** * Obtain an iterator for the top-level items held in this schema - since this is a hierarchical model, @@ -126,7 +133,6 @@ public class Differences implements Iterable private void makeCurrentPath() { current = StringUtils.join(components, "."); - } - + } } } diff --git a/source/java/org/alfresco/util/schemacomp/SchemaComparator.java b/source/java/org/alfresco/util/schemacomp/SchemaComparator.java index caa01d46d0..d20cfbd49e 100644 --- a/source/java/org/alfresco/util/schemacomp/SchemaComparator.java +++ b/source/java/org/alfresco/util/schemacomp/SchemaComparator.java @@ -20,6 +20,7 @@ package org.alfresco.util.schemacomp; import org.alfresco.util.schemacomp.Result.Strength; import org.alfresco.util.schemacomp.model.Schema; +import org.hibernate.dialect.Dialect; /** * Compares two abstract database schemas, a 'left' schema and a 'right' schema. The left schema is the primary @@ -31,7 +32,7 @@ public class SchemaComparator { private final Schema leftSchema; private final Schema rightSchema; - private final Differences differences = new Differences(); + private final DiffContext ctx; /** * Construct a comparator to compare schemas left and right. @@ -39,17 +40,18 @@ public class SchemaComparator * @param left * @param right */ - public SchemaComparator(Schema left, Schema right) + public SchemaComparator(Schema left, Schema right, Dialect dialect) { this.leftSchema = left; this.rightSchema = right; + this.ctx = new DiffContext(dialect, new Differences()); } public void compare() { // Check the left schema against the right schema and record any differences. - leftSchema.diff(rightSchema, differences, Strength.ERROR); + leftSchema.diff(rightSchema, ctx, Strength.ERROR); } @@ -58,6 +60,6 @@ public class SchemaComparator */ public Differences getDifferences() { - return this.differences; + return this.ctx.getDifferences(); } } diff --git a/source/java/org/alfresco/util/schemacomp/SchemaComparatorTest.java b/source/java/org/alfresco/util/schemacomp/SchemaComparatorTest.java index 80b6b43a7c..006bee5e7e 100644 --- a/source/java/org/alfresco/util/schemacomp/SchemaComparatorTest.java +++ b/source/java/org/alfresco/util/schemacomp/SchemaComparatorTest.java @@ -38,6 +38,8 @@ import org.alfresco.util.schemacomp.model.PrimaryKey; import org.alfresco.util.schemacomp.model.Schema; import org.alfresco.util.schemacomp.model.Table; import org.apache.commons.lang.ArrayUtils; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.MySQL5InnoDBDialect; import org.junit.Before; import org.junit.Test; @@ -51,12 +53,14 @@ public class SchemaComparatorTest private SchemaComparator comparator; private Schema left; private Schema right; + private Dialect dialect; @Before public void setup() { left = new Schema("left_schema"); right = new Schema("right_schema"); + dialect = new MySQL5InnoDBDialect(); } @@ -80,7 +84,7 @@ public class SchemaComparatorTest right.add(table("table_in_right")); - comparator = new SchemaComparator(left, right); + comparator = new SchemaComparator(left, right, dialect); comparator.compare(); dumpDiffs(comparator.getDifferences(), true); @@ -144,7 +148,7 @@ public class SchemaComparatorTest indexes("sys_random_idx_name id"))); - comparator = new SchemaComparator(left, right); + comparator = new SchemaComparator(left, right, dialect); comparator.compare(); dumpDiffs(comparator.getDifferences(), true); diff --git a/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java b/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java index 0456cec4b4..1e49070a5e 100644 --- a/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java +++ b/source/java/org/alfresco/util/schemacomp/model/AbstractDbObject.java @@ -19,6 +19,7 @@ package org.alfresco.util.schemacomp.model; import org.alfresco.util.schemacomp.ComparisonUtils; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; import org.alfresco.util.schemacomp.DefaultComparisonUtils; @@ -154,8 +155,10 @@ public abstract class AbstractDbObject implements DbObject * its diff correctly. */ @Override - public void diff(DbObject right, Differences differences, Strength strength) + public void diff(DbObject right, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); + if (name != null && StringUtils.hasText(name)) { differences.pushPath(name); @@ -164,10 +167,11 @@ public abstract class AbstractDbObject implements DbObject { differences.pushPath("<" + getClass().getSimpleName() + ">"); } - comparisonUtils.compareSimple(name, right.getName(), differences, getNameStrength()); - doDiff(right, differences, strength); + comparisonUtils.compareSimple(name, right.getName(), ctx, getNameStrength()); + doDiff(right, ctx, strength); differences.popPath(); } + /** * Override this method to provide subclass specific diffing logic. @@ -176,9 +180,10 @@ public abstract class AbstractDbObject implements DbObject * @param differences * @param strength */ - protected void doDiff(DbObject right, Differences differences, Strength strength) + protected void doDiff(DbObject right, DiffContext ctx, Strength strength) { } + /** * If a ComparisonUtils other than the default is required, then this setter can be used. diff --git a/source/java/org/alfresco/util/schemacomp/model/AbstractDbObjectTest.java b/source/java/org/alfresco/util/schemacomp/model/AbstractDbObjectTest.java index c86a22a209..fda45161a2 100644 --- a/source/java/org/alfresco/util/schemacomp/model/AbstractDbObjectTest.java +++ b/source/java/org/alfresco/util/schemacomp/model/AbstractDbObjectTest.java @@ -23,9 +23,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.inOrder; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; import org.alfresco.util.schemacomp.Result.Where; +import org.hibernate.dialect.Dialect; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,6 +45,8 @@ public class AbstractDbObjectTest { private ConcreteDbObject dbObject; private @Mock Differences differences; + private DiffContext ctx; + private @Mock Dialect dialect; /** * @throws java.lang.Exception @@ -51,6 +55,7 @@ public class AbstractDbObjectTest public void setUp() throws Exception { dbObject = new ConcreteDbObject("the_object"); + ctx = new DiffContext(dialect, differences); } @Test @@ -81,7 +86,7 @@ public class AbstractDbObjectTest ConcreteDbObject otherObject = new ConcreteDbObject("the_other_object"); dbObject.setNameStrength(Strength.WARN); - dbObject.diff(otherObject, differences, Strength.ERROR); + dbObject.diff(otherObject, ctx, Strength.ERROR); InOrder inOrder = inOrder(differences); // The name of the object should be pushed on to the differences path. @@ -89,7 +94,7 @@ public class AbstractDbObjectTest // The name of the object should be diffed inOrder.verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, "the_object", "the_other_object", Strength.WARN); // Then the doDiff() method should be processed - inOrder.verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, "left", "right", Strength.ERROR); + inOrder.verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, "left", "right"); // Later, the path should be popped again inOrder.verify(differences).popPath(); } @@ -106,9 +111,10 @@ public class AbstractDbObjectTest } @Override - protected void doDiff(DbObject right, Differences differences, Strength strength) + protected void doDiff(DbObject right, DiffContext ctx, Strength strength) { - differences.add(Where.IN_BOTH_BUT_DIFFERENCE, "left", "right", strength); + Differences differences = ctx.getDifferences(); + differences.add(Where.IN_BOTH_BUT_DIFFERENCE, "left", "right"); } } } diff --git a/source/java/org/alfresco/util/schemacomp/model/Column.java b/source/java/org/alfresco/util/schemacomp/model/Column.java index 67ad47a393..7f7b747678 100644 --- a/source/java/org/alfresco/util/schemacomp/model/Column.java +++ b/source/java/org/alfresco/util/schemacomp/model/Column.java @@ -18,6 +18,7 @@ */ package org.alfresco.util.schemacomp.model; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; @@ -105,10 +106,11 @@ public class Column extends AbstractDbObject } @Override - protected void doDiff(DbObject right, Differences differences, Strength strength) + protected void doDiff(DbObject right, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); Column rightColumn = (Column) right; - comparisonUtils.compareSimple(type, rightColumn.type, differences); - comparisonUtils.compareSimple(nullable, rightColumn.nullable, differences); + comparisonUtils.compareSimple(type, rightColumn.type, ctx); + comparisonUtils.compareSimple(nullable, rightColumn.nullable, ctx); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/ColumnTest.java b/source/java/org/alfresco/util/schemacomp/model/ColumnTest.java index edb52c1e29..594277ff2e 100644 --- a/source/java/org/alfresco/util/schemacomp/model/ColumnTest.java +++ b/source/java/org/alfresco/util/schemacomp/model/ColumnTest.java @@ -53,8 +53,8 @@ public class ColumnTest extends DbObjectTestBase @Override protected void doDiffTests() { - inOrder.verify(comparisonUtils).compareSimple(thisColumn.getType(), thatColumn.getType(), differences); - inOrder.verify(comparisonUtils).compareSimple(thisColumn.isNullable(), thatColumn.isNullable(), differences); + inOrder.verify(comparisonUtils).compareSimple(thisColumn.getType(), thatColumn.getType(), ctx); + inOrder.verify(comparisonUtils).compareSimple(thisColumn.isNullable(), thatColumn.isNullable(), ctx); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/DbObject.java b/source/java/org/alfresco/util/schemacomp/model/DbObject.java index 66707bbd9f..5d6d5e9450 100644 --- a/source/java/org/alfresco/util/schemacomp/model/DbObject.java +++ b/source/java/org/alfresco/util/schemacomp/model/DbObject.java @@ -18,6 +18,7 @@ */ package org.alfresco.util.schemacomp.model; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; @@ -56,7 +57,7 @@ public interface DbObject * object passed in to this method. * * @param right The object to compare against. - * @param differences A collector of differences. + * @param ctx The DiffContext */ - void diff(DbObject right, Differences differences, Strength strength); + void diff(DbObject right, DiffContext ctx, Strength strength); } diff --git a/source/java/org/alfresco/util/schemacomp/model/DbObjectTestBase.java b/source/java/org/alfresco/util/schemacomp/model/DbObjectTestBase.java index 85351a36e0..1a53d4a01a 100644 --- a/source/java/org/alfresco/util/schemacomp/model/DbObjectTestBase.java +++ b/source/java/org/alfresco/util/schemacomp/model/DbObjectTestBase.java @@ -24,8 +24,10 @@ import java.util.ArrayList; import java.util.List; import org.alfresco.util.schemacomp.ComparisonUtils; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; +import org.hibernate.dialect.Dialect; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,18 +43,21 @@ import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public abstract class DbObjectTestBase { + protected @Mock Dialect dialect; protected @Mock Differences differences; + protected DiffContext ctx; protected @Mock ComparisonUtils comparisonUtils; protected InOrder inOrder; protected abstract T getThisObject(); protected abstract T getThatObject(); @Before - public void setUpMockito() + public void baseSetUp() { // Check that the correct calls happened in the correct order. List mocks = getMocksUsedInDiff(); inOrder = inOrder(mocks.toArray()); + ctx = new DiffContext(dialect, differences); } @@ -79,7 +84,7 @@ public abstract class DbObjectTestBase thatObject.setComparisonUtils(comparisonUtils); // Invoke the method under test - thisObject.diff(thatObject, differences, Strength.ERROR); + thisObject.diff(thatObject, ctx, Strength.ERROR); // The name of the object should be pushed on to the differences path. inOrder.verify(differences).pushPath(thisObject.getName()); @@ -88,7 +93,7 @@ public abstract class DbObjectTestBase inOrder.verify(comparisonUtils).compareSimple( thisObject.getName(), thatObject.getName(), - differences, + ctx, thisObject.getNameStrength()); // Then the doDiff() method should be processed... diff --git a/source/java/org/alfresco/util/schemacomp/model/ForeignKey.java b/source/java/org/alfresco/util/schemacomp/model/ForeignKey.java index 24cb734b14..853c7126be 100644 --- a/source/java/org/alfresco/util/schemacomp/model/ForeignKey.java +++ b/source/java/org/alfresco/util/schemacomp/model/ForeignKey.java @@ -18,6 +18,7 @@ */ package org.alfresco.util.schemacomp.model; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; @@ -137,11 +138,12 @@ public class ForeignKey extends AbstractDbObject @Override - protected void doDiff(DbObject right, Differences differences, Strength strength) + protected void doDiff(DbObject right, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); ForeignKey rightFK = (ForeignKey) right; - comparisonUtils.compareSimple(localColumn, rightFK.localColumn, differences); - comparisonUtils.compareSimple(targetTable, rightFK.targetTable, differences); - comparisonUtils.compareSimple(targetColumn, rightFK.targetColumn, differences); + comparisonUtils.compareSimple(localColumn, rightFK.localColumn, ctx); + comparisonUtils.compareSimple(targetTable, rightFK.targetTable, ctx); + comparisonUtils.compareSimple(targetColumn, rightFK.targetColumn, ctx); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/ForeignKeyTest.java b/source/java/org/alfresco/util/schemacomp/model/ForeignKeyTest.java index af49e4c8e9..2cd71bb344 100644 --- a/source/java/org/alfresco/util/schemacomp/model/ForeignKeyTest.java +++ b/source/java/org/alfresco/util/schemacomp/model/ForeignKeyTest.java @@ -56,8 +56,8 @@ public class ForeignKeyTest extends DbObjectTestBase @Override protected void doDiffTests() { - inOrder.verify(comparisonUtils).compareSimple(thisFK.getLocalColumn(), thatFK.getLocalColumn(), differences); - inOrder.verify(comparisonUtils).compareSimple(thisFK.getTargetTable(), thatFK.getTargetTable(), differences); - inOrder.verify(comparisonUtils).compareSimple(thisFK.getTargetColumn(), thatFK.getTargetColumn(), differences); + inOrder.verify(comparisonUtils).compareSimple(thisFK.getLocalColumn(), thatFK.getLocalColumn(), ctx); + inOrder.verify(comparisonUtils).compareSimple(thisFK.getTargetTable(), thatFK.getTargetTable(), ctx); + inOrder.verify(comparisonUtils).compareSimple(thisFK.getTargetColumn(), thatFK.getTargetColumn(), ctx); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/Index.java b/source/java/org/alfresco/util/schemacomp/model/Index.java index b01ba50d7f..4e428b3032 100644 --- a/source/java/org/alfresco/util/schemacomp/model/Index.java +++ b/source/java/org/alfresco/util/schemacomp/model/Index.java @@ -20,6 +20,7 @@ package org.alfresco.util.schemacomp.model; import java.util.List; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; @@ -108,9 +109,10 @@ public class Index extends AbstractDbObject @Override - protected void doDiff(DbObject right, Differences differences, Strength strength) + protected void doDiff(DbObject right, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); Index rightIndex = (Index) right; - comparisonUtils.compareSimpleCollections(columnNames, rightIndex.columnNames, differences, strength); + comparisonUtils.compareSimpleCollections(columnNames, rightIndex.columnNames, ctx, strength); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/IndexTest.java b/source/java/org/alfresco/util/schemacomp/model/IndexTest.java index fbe8f25102..7515be8549 100644 --- a/source/java/org/alfresco/util/schemacomp/model/IndexTest.java +++ b/source/java/org/alfresco/util/schemacomp/model/IndexTest.java @@ -60,7 +60,7 @@ public class IndexTest extends DbObjectTestBase inOrder.verify(comparisonUtils).compareSimpleCollections( thisIndex.getColumnNames(), thatIndex.getColumnNames(), - differences, + ctx, Strength.ERROR); } diff --git a/source/java/org/alfresco/util/schemacomp/model/PrimaryKey.java b/source/java/org/alfresco/util/schemacomp/model/PrimaryKey.java index 0c15ab4749..6b4710418b 100644 --- a/source/java/org/alfresco/util/schemacomp/model/PrimaryKey.java +++ b/source/java/org/alfresco/util/schemacomp/model/PrimaryKey.java @@ -20,6 +20,7 @@ package org.alfresco.util.schemacomp.model; import java.util.List; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; @@ -85,9 +86,10 @@ public class PrimaryKey extends AbstractDbObject } @Override - protected void doDiff(DbObject right, Differences differences, Strength strength) + protected void doDiff(DbObject right, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); PrimaryKey rightPK = (PrimaryKey) right; - comparisonUtils.compareSimpleCollections(columnNames, rightPK.columnNames, differences, strength); + comparisonUtils.compareSimpleCollections(columnNames, rightPK.columnNames, ctx, strength); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/PrimaryKeyTest.java b/source/java/org/alfresco/util/schemacomp/model/PrimaryKeyTest.java index 7a4ebaefa4..0408f0d215 100644 --- a/source/java/org/alfresco/util/schemacomp/model/PrimaryKeyTest.java +++ b/source/java/org/alfresco/util/schemacomp/model/PrimaryKeyTest.java @@ -59,7 +59,7 @@ public class PrimaryKeyTest extends DbObjectTestBase inOrder.verify(comparisonUtils).compareSimpleCollections( thisPK.getColumnNames(), thatPK.getColumnNames(), - differences, + ctx, Strength.ERROR); } diff --git a/source/java/org/alfresco/util/schemacomp/model/Schema.java b/source/java/org/alfresco/util/schemacomp/model/Schema.java index da5ee3a261..441cbec83d 100644 --- a/source/java/org/alfresco/util/schemacomp/model/Schema.java +++ b/source/java/org/alfresco/util/schemacomp/model/Schema.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; @@ -90,9 +91,10 @@ public class Schema extends AbstractDbObject implements Iterable @Override - protected void doDiff(DbObject right, Differences differences, Strength strength) + protected void doDiff(DbObject right, DiffContext ctx, Strength strength) { + Differences differences = ctx.getDifferences(); Schema rightSchema = (Schema) right; - comparisonUtils.compareCollections(objects, rightSchema.objects, differences); + comparisonUtils.compareCollections(objects, rightSchema.objects, ctx); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/SchemaTest.java b/source/java/org/alfresco/util/schemacomp/model/SchemaTest.java index 899d4529f1..cefe30d417 100644 --- a/source/java/org/alfresco/util/schemacomp/model/SchemaTest.java +++ b/source/java/org/alfresco/util/schemacomp/model/SchemaTest.java @@ -57,6 +57,6 @@ public class SchemaTest extends DbObjectTestBase { // In addition to the base class functionality, Schema.diff() compares // the DbObjects held in the other schema with its own DbObjects. - inOrder.verify(comparisonUtils).compareCollections(left.objects, right.objects, differences); + inOrder.verify(comparisonUtils).compareCollections(left.objects, right.objects, ctx); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/Table.java b/source/java/org/alfresco/util/schemacomp/model/Table.java index 8a9d2811a5..0a2a5df564 100644 --- a/source/java/org/alfresco/util/schemacomp/model/Table.java +++ b/source/java/org/alfresco/util/schemacomp/model/Table.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.alfresco.util.schemacomp.DiffContext; import org.alfresco.util.schemacomp.Differences; import org.alfresco.util.schemacomp.Result.Strength; @@ -175,12 +176,13 @@ public class Table extends AbstractDbObject @Override - protected void doDiff(DbObject other, Differences differences, Strength strength) - { + protected void doDiff(DbObject other, DiffContext ctx, Strength strength) + { + Differences differences = ctx.getDifferences(); Table rightTable = (Table) other; - comparisonUtils.compareCollections(columns, rightTable.columns, differences); - primaryKey.diff(rightTable.primaryKey, differences, strength); - comparisonUtils.compareCollections(foreignKeys, rightTable.foreignKeys, differences); - comparisonUtils.compareCollections(indexes, rightTable.indexes, differences); + comparisonUtils.compareCollections(columns, rightTable.columns, ctx); + primaryKey.diff(rightTable.primaryKey, ctx, strength); + comparisonUtils.compareCollections(foreignKeys, rightTable.foreignKeys, ctx); + comparisonUtils.compareCollections(indexes, rightTable.indexes, ctx); } } diff --git a/source/java/org/alfresco/util/schemacomp/model/TableTest.java b/source/java/org/alfresco/util/schemacomp/model/TableTest.java index 6cb9fe21ed..83ff6e0bec 100644 --- a/source/java/org/alfresco/util/schemacomp/model/TableTest.java +++ b/source/java/org/alfresco/util/schemacomp/model/TableTest.java @@ -74,18 +74,18 @@ public class TableTest extends DbObjectTestBase public void doDiffTests() { // Check columns - inOrder.verify(comparisonUtils).compareCollections(table.getColumns(), otherTable.getColumns(), differences); + inOrder.verify(comparisonUtils).compareCollections(table.getColumns(), otherTable.getColumns(), ctx); // Check primary key - inOrder.verify(primaryKey).diff(otherTable.getPrimaryKey(), differences, Strength.ERROR); + inOrder.verify(primaryKey).diff(otherTable.getPrimaryKey(), ctx, Strength.ERROR); // Check foreign keys inOrder.verify(comparisonUtils).compareCollections( - table.getForeignKeys(), otherTable.getForeignKeys(), differences); + table.getForeignKeys(), otherTable.getForeignKeys(), ctx); // Check indexes inOrder.verify(comparisonUtils).compareCollections( - table.getIndexes(), otherTable.getIndexes(), differences); + table.getIndexes(), otherTable.getIndexes(), ctx); } @Override