mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-11256: SchemaBootstrap must compare running schema against reference dump
Reference schemas (e.g. classpath:org/alfresco/util/schemacomp/reference/PostgreSQLDialect-Reference.xml) are loaded (if present) and the database is compared to that reference schema. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31991 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,34 +26,35 @@ 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
|
||||
* schema and all objects in the right schema are judged relative to it.
|
||||
* Compares two abstract database schemas, a reference schema and a target schema (the schema to check for validity).
|
||||
* The reference schema is the primary schema and all objects in the right schema are judged relative to it.
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
public class SchemaComparator
|
||||
{
|
||||
private final Schema leftSchema;
|
||||
private final Schema rightSchema;
|
||||
private final Schema referenceSchema;
|
||||
private final Schema targetSchema;
|
||||
private final DiffContext ctx;
|
||||
|
||||
/**
|
||||
* Construct a comparator to compare schemas left and right.
|
||||
* Construct a comparator to compare a target schema against a reference schema. Validators supplied
|
||||
* by the reference schema will be used to validate the target schema.
|
||||
*
|
||||
* @param left
|
||||
* @param right
|
||||
* @param referenceSchema
|
||||
* @param targetSchema
|
||||
*/
|
||||
public SchemaComparator(Schema left, Schema right, Dialect dialect)
|
||||
public SchemaComparator(Schema referenceSchema, Schema targetSchema, Dialect dialect)
|
||||
{
|
||||
this.leftSchema = left;
|
||||
this.rightSchema = right;
|
||||
this.ctx = new DiffContext(dialect, new Results(), new ArrayList<ValidationResult>(), leftSchema, rightSchema);
|
||||
this.referenceSchema = referenceSchema;
|
||||
this.targetSchema = targetSchema;
|
||||
this.ctx = new DiffContext(dialect, new Results(), new ArrayList<ValidationResult>(), referenceSchema, targetSchema);
|
||||
}
|
||||
|
||||
|
||||
public void validateAndCompare()
|
||||
{
|
||||
validate();
|
||||
validateTargetSchema();
|
||||
compare();
|
||||
}
|
||||
|
||||
@@ -63,18 +64,17 @@ public class SchemaComparator
|
||||
*/
|
||||
private void compare()
|
||||
{
|
||||
leftSchema.diff(rightSchema, ctx, Strength.ERROR);
|
||||
referenceSchema.diff(targetSchema, ctx, Strength.ERROR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate both schemas.
|
||||
* Validate the target schema against the reference schema using the reference schema's validators.
|
||||
*/
|
||||
private void validate()
|
||||
private void validateTargetSchema()
|
||||
{
|
||||
ValidatingVisitor validatingVisitor = new ValidatingVisitor(ctx);
|
||||
leftSchema.accept(validatingVisitor);
|
||||
rightSchema.accept(validatingVisitor);
|
||||
referenceSchema.accept(validatingVisitor);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user