use of org.alfresco.util.schemacomp.model.PrimaryKey in project alfresco-repository by Alfresco.
the class PostgreSQLDialectExportTester method checkExampleTable.
private void checkExampleTable(Schema schema, Table exampleTable) {
assertNotNull("Couldn't find export_test_example", exampleTable);
assertSame("Incorrect parent or no parent set", schema, exampleTable.getParent());
assertEquals("export_test_example", exampleTable.getName());
Iterator<Column> colIt = exampleTable.getColumns().iterator();
Column col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("id", col.getName());
assertEquals("int8", col.getType());
assertEquals(false, col.isNullable());
assertEquals(1, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("description", col.getName());
assertEquals("varchar(1024)", col.getType());
assertEquals(true, col.isNullable());
assertEquals(2, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("fixes_from_schema", col.getName());
assertEquals("int4", col.getType());
assertEquals(true, col.isNullable());
assertEquals(3, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("fixes_to_schema", col.getName());
assertEquals("int4", col.getType());
assertEquals(true, col.isNullable());
assertEquals(4, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("applied_to_schema", col.getName());
assertEquals("int4", col.getType());
assertEquals(true, col.isNullable());
assertEquals(5, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("target_schema", col.getName());
assertEquals("int4", col.getType());
assertEquals(true, col.isNullable());
assertEquals(6, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("applied_on_date", col.getName());
assertEquals("timestamp", col.getType());
assertEquals(true, col.isNullable());
assertEquals(7, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("applied_to_server", col.getName());
assertEquals("varchar(64)", col.getType());
assertEquals(true, col.isNullable());
assertEquals(8, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("was_executed", col.getName());
assertEquals("bool", col.getType());
assertEquals(true, col.isNullable());
assertEquals(9, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("succeeded", col.getName());
assertEquals("bool", col.getType());
assertEquals(true, col.isNullable());
assertEquals(10, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("report", col.getName());
assertEquals("varchar(1024)", col.getType());
assertEquals(true, col.isNullable());
assertEquals(11, col.getOrder());
PrimaryKey pk = exampleTable.getPrimaryKey();
assertSame("Incorrect parent or no parent set", exampleTable, pk.getParent());
assertEquals("id", pk.getColumnNames().get(0));
assertEquals(1, pk.getColumnOrders().get(0).intValue());
}
use of org.alfresco.util.schemacomp.model.PrimaryKey in project alfresco-repository by Alfresco.
the class MySQLDialectExportTester method checkExampleTable.
private void checkExampleTable(Schema schema, Table exampleTable) {
assertNotNull("Couldn't find export_test_example", exampleTable);
assertSame("Incorrect parent or no parent set", schema, exampleTable.getParent());
assertEquals("export_test_example", exampleTable.getName());
Iterator<Column> colIt = exampleTable.getColumns().iterator();
Column col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("id", col.getName());
assertEquals("bigint", col.getType());
assertEquals(false, col.isNullable());
assertEquals(1, col.getOrder());
assertEquals(true, col.isAutoIncrement());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("description", col.getName());
assertEquals("text", col.getType());
assertEquals(true, col.isNullable());
assertEquals(2, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("fixes_from_schema", col.getName());
assertEquals("int", col.getType());
assertEquals(true, col.isNullable());
assertEquals(3, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("fixes_to_schema", col.getName());
assertEquals("int", col.getType());
assertEquals(true, col.isNullable());
assertEquals(4, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("applied_to_schema", col.getName());
assertEquals("int", col.getType());
assertEquals(true, col.isNullable());
assertEquals(5, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("target_schema", col.getName());
assertEquals("int", col.getType());
assertEquals(true, col.isNullable());
assertEquals(6, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("applied_on_date", col.getName());
assertEquals("datetime", col.getType());
assertEquals(true, col.isNullable());
assertEquals(7, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("applied_to_server", col.getName());
assertEquals("varchar(64)", col.getType());
assertEquals(true, col.isNullable());
assertEquals(8, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("was_executed", col.getName());
assertEquals("bit", col.getType());
assertEquals(true, col.isNullable());
assertEquals(9, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("succeeded", col.getName());
assertEquals("bit", col.getType());
assertEquals(true, col.isNullable());
assertEquals(10, col.getOrder());
col = colIt.next();
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
assertEquals("report", col.getName());
assertEquals("text", col.getType());
assertEquals(true, col.isNullable());
assertEquals(11, col.getOrder());
PrimaryKey pk = exampleTable.getPrimaryKey();
assertSame("Incorrect parent or no parent set", exampleTable, pk.getParent());
assertEquals("id", pk.getColumnNames().get(0));
assertEquals(1, pk.getColumnOrders().get(0).intValue());
}
use of org.alfresco.util.schemacomp.model.PrimaryKey in project alfresco-repository by Alfresco.
the class SchemaComparatorTest method columnOrderingComparedCorrectlyWhenEnabled.
@Test
public void columnOrderingComparedCorrectlyWhenEnabled() {
reference = new Schema("schema", "alf_", 590, true);
target = new Schema("schema", "alf_", 590, true);
// Reference schema's database objects.
reference.add(new Table(reference, "table_name", columns("id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "my_pk_name", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), fkeys(), indexes()));
// Target schema's database objects - note different column order
target.add(new Table(target, "table_name", columns("id NUMBER(10)", "name VARCHAR2(150)", "nodeRef VARCHAR2(200)"), new PrimaryKey(null, "my_pk_name", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), fkeys(), indexes()));
comparator = new SchemaComparator(reference, target, dialect);
comparator.validateAndCompare();
// See stdout for diagnostics dump...
dumpDiffs(comparator.getComparisonResults(), false);
dumpValidation(comparator.getComparisonResults());
Results results = comparator.getComparisonResults();
Iterator<Result> it = results.iterator();
Difference diff = (Difference) it.next();
assertEquals(Where.IN_BOTH_BUT_DIFFERENCE, diff.getWhere());
assertEquals("schema.table_name.nodeRef.order", diff.getLeft().getPath());
assertEquals("order", diff.getLeft().getPropertyName());
assertEquals(2, diff.getLeft().getPropertyValue());
assertEquals("schema.table_name.nodeRef.order", diff.getRight().getPath());
assertEquals("order", diff.getRight().getPropertyName());
assertEquals(3, diff.getRight().getPropertyValue());
diff = (Difference) it.next();
assertEquals(Where.IN_BOTH_BUT_DIFFERENCE, diff.getWhere());
assertEquals("schema.table_name.name.order", diff.getLeft().getPath());
assertEquals("order", diff.getLeft().getPropertyName());
assertEquals(3, diff.getLeft().getPropertyValue());
assertEquals("schema.table_name.name.order", diff.getRight().getPath());
assertEquals("order", diff.getRight().getPropertyName());
assertEquals(2, diff.getRight().getPropertyValue());
assertFalse("There should be no more differences", it.hasNext());
}
use of org.alfresco.util.schemacomp.model.PrimaryKey in project alfresco-repository by Alfresco.
the class DbObjectXMLTransformerTest method transformObjectWithValidators.
@Test
public void transformObjectWithValidators() throws IOException {
Collection<Column> columns = columns("one VARCHAR2(100)", "two NUMBER(10)");
PrimaryKey pk = new PrimaryKey(null, "pk_for_my_table", Arrays.asList("id"), Arrays.asList(1));
Collection<ForeignKey> fks = fkeys(fk("fk_one", "lc", "tt", "tc"), fk("fk_two", "lc", "tt", "tc"));
Collection<Index> indexes = indexes("index_one col1 col2", "index_two col3 col4");
Table table = new Table(null, "my_table", columns, pk, fks, indexes);
NameValidator nameValidator = new NameValidator();
nameValidator.setPattern(Pattern.compile("match_me_if_you_can"));
List<DbValidator> validators = new ArrayList<DbValidator>();
validators.add(nameValidator);
table.setValidators(validators);
transformer.output(table);
BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
dumpOutput();
assertHasPreamble(reader);
assertEquals("<table name=\"my_table\">", reader.readLine());
assertEquals(" <validators>", reader.readLine());
assertEquals(" <validator class=\"org.alfresco.util.schemacomp.validator.NameValidator\">", reader.readLine());
assertEquals(" <properties>", reader.readLine());
assertEquals(" <property name=\"pattern\">match_me_if_you_can</property>", reader.readLine());
assertEquals(" </properties>", reader.readLine());
assertEquals(" </validator>", reader.readLine());
assertEquals(" </validators>", reader.readLine());
assertEquals(" <columns>", reader.readLine());
skipUntilEnd(" {column}", reader);
skipUntilEnd(" {column}", reader);
assertEquals(" </columns>", reader.readLine());
skipUntilEnd(" {primarykey}", reader);
assertEquals(" <foreignkeys>", reader.readLine());
skipUntilEnd(" {foreignkey}", reader);
skipUntilEnd(" {foreignkey}", reader);
assertEquals(" </foreignkeys>", reader.readLine());
assertEquals(" <indexes>", reader.readLine());
skipUntilEnd(" {index}", reader);
skipUntilEnd(" {index}", reader);
assertEquals(" </indexes>", reader.readLine());
assertEquals("</table>", reader.readLine());
}
use of org.alfresco.util.schemacomp.model.PrimaryKey in project alfresco-repository by Alfresco.
the class SchemaComparatorTest method systemGeneratedPrimaryKeyAndIndex.
/**
* Tests index of primary key validation, problem found when comparing DB2 schemas (now EOLed) which has
* system generated indexes for primary keys, but might still be useful as a test.
*/
@Test
public void systemGeneratedPrimaryKeyAndIndex() {
reference = new Schema("schema", "alf_", 9012, false);
target = new Schema("schema", "alf_", 9012, false);
NameValidator validator = new NameValidator();
validator.setProperty("pattern", "SQL[0-9]+");
final List<DbValidator> validators = new ArrayList<DbValidator>();
validators.add(new NameValidator());
reference.add(new Table(reference, "ALF_ACL_CHANGE_SET", columns(false, "id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "SQL120116153559440", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153559441 [unique] ID_", "fooX ID_")));
// Target schema's database objects
target.add(new Table(target, "ALF_ACL_CHANGE_SET", columns(false, "id NUMBER(10)", "name VARCHAR2(150)", "nodeRef VARCHAR2(200)"), new PrimaryKey(null, "SQL120116153559442", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153559443 [unique] ID_", "fooX ID_")));
reference.add(new Table(reference, "ALF_LOCK_RESOURCE", columns(false, "id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "SQL120116153554310", Arrays.asList("ID", "int"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153616440 [unique] ID_")));
target.add(new Table(reference, "ALF_LOCK_RESOURCE", columns(false, "id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "SQL120116153554313", Arrays.asList("ID", "int"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153616444 [unique] ID_")));
/**
* Now plug in the pattern validator
*/
DbObjectVisitor visitor = new DbObjectVisitor() {
@Override
public void visit(DbObject dbObject) {
if (dbObject instanceof Index) {
dbObject.setValidators(validators);
}
if (dbObject instanceof PrimaryKey) {
dbObject.setValidators(validators);
}
}
};
reference.accept(visitor);
target.accept(visitor);
comparator = new SchemaComparator(reference, target, dialect);
comparator.validateAndCompare();
// See stdout for diagnostics dump...
dumpDiffs(comparator.getComparisonResults(), false);
dumpValidation(comparator.getComparisonResults());
Results results = comparator.getComparisonResults();
// There are no logical differences
assertEquals(0, results.size());
}
Aggregations