use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class XMLToSchema method endElement.
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals(XML.EL_TABLE)) {
Table table = (Table) stack.pop();
schema.add(table);
} else if (qName.equals(XML.EL_COLUMN)) {
Column column = (Column) stack.pop();
Table table = (Table) stack.peek();
column.setParent(table);
table.getColumns().add(column);
} else if (qName.equals(XML.EL_PRIMARY_KEY)) {
PrimaryKey pk = (PrimaryKey) stack.pop();
Table table = (Table) stack.peek();
table.setPrimaryKey(pk);
} else if (qName.equals(XML.EL_FOREIGN_KEY)) {
ForeignKey fk = (ForeignKey) stack.pop();
Table table = (Table) stack.peek();
fk.setParent(table);
table.getForeignKeys().add(fk);
} else if (qName.equals(XML.EL_INDEX)) {
Index index = (Index) stack.pop();
Table table = (Table) stack.peek();
index.setParent(table);
table.getIndexes().add(index);
} else if (qName.equals(XML.EL_SEQUENCE)) {
Sequence seq = (Sequence) stack.pop();
seq.setParent(schema);
schema.add(seq);
} else if (qName.equals(XML.EL_VALIDATOR)) {
DbValidator validator = (DbValidator) stack.pop();
DbObject dbo = (DbObject) stack.peek();
dbo.getValidators().add(validator);
}
// Deal with elements that contain text.
if (lastText.length() != 0) {
if (qName.equals(XML.EL_TYPE)) {
Column column = (Column) stack.peek();
column.setType(lastText.toString());
} else if (qName.equals(XML.EL_NULLABLE)) {
Column column = (Column) stack.peek();
column.setNullable(Boolean.parseBoolean(lastText.toString()));
} else if (qName.equals(XML.EL_AUTOINCREMENT)) {
Column column = (Column) stack.peek();
column.setAutoIncrement(Boolean.parseBoolean(lastText.toString()));
} else if (qName.equals(XML.EL_COLUMN_NAME)) {
if (stack.peek() instanceof PrimaryKey) {
PrimaryKey pk = (PrimaryKey) stack.peek();
pk.getColumnNames().add(lastText.toString());
} else if (stack.peek() instanceof Index) {
Index index = (Index) stack.peek();
index.getColumnNames().add(lastText.toString());
}
} else if (qName.equals(XML.EL_LOCAL_COLUMN)) {
ForeignKey fk = (ForeignKey) stack.peek();
fk.setLocalColumn(lastText.toString());
} else if (qName.equals(XML.EL_TARGET_TABLE)) {
ForeignKey fk = (ForeignKey) stack.peek();
fk.setTargetTable(lastText.toString());
} else if (qName.equals(XML.EL_TARGET_COLUMN)) {
ForeignKey fk = (ForeignKey) stack.peek();
fk.setTargetColumn(lastText.toString());
} else if (qName.equals(XML.EL_PROPERTY)) {
String propValue = lastText.toString();
String propName = (String) stack.pop();
if (stack.peek() instanceof DbValidator) {
@SuppressWarnings("unchecked") DbValidator validator = (DbValidator) stack.peek();
validator.setProperty(propName, propValue);
}
}
}
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtils method compareSimple.
@Override
public void compareSimple(DbProperty leftProperty, DbProperty rightProperty, DiffContext ctx) {
// Check whether the leftProperty should be compared to the rightProperty
DbObject leftDbObject = leftProperty.getDbObject();
if (leftDbObject.hasValidators()) {
for (DbValidator validator : leftDbObject.getValidators()) {
if (validator.validates(leftProperty.getPropertyName())) {
// Don't perform differencing on this property - a validator will handle it.
return;
}
}
}
Where where = null;
Object left = leftProperty.getPropertyValue();
checkNotDbObject(left);
Object right = rightProperty.getPropertyValue();
checkNotDbObject(right);
if (left == right) {
// Same object, or both nulls
where = Where.IN_BOTH_NO_DIFFERENCE;
} else if (left == null) {
// right can't be null, or left == right would have been true
where = Where.ONLY_IN_TARGET;
} else if (right == null) {
// left can't be null, or left == right would have been true
where = Where.ONLY_IN_REFERENCE;
} else {
// neither are null
boolean objectsAreEqual;
// Strings are compared case-insensitively, e.g. table names.
if (left instanceof String && right instanceof String) {
objectsAreEqual = ((String) left).equalsIgnoreCase((String) right);
} else {
objectsAreEqual = left.equals(right);
}
if (objectsAreEqual) {
where = Where.IN_BOTH_NO_DIFFERENCE;
} else {
where = Where.IN_BOTH_BUT_DIFFERENCE;
}
}
ctx.getComparisonResults().add(where, leftProperty, rightProperty);
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtils method compareSimpleCollections.
@Override
public void compareSimpleCollections(DbProperty leftProp, DbProperty rightProp, DiffContext ctx) {
// Check whether the leftProperty should be compared to the rightProperty
DbObject leftDbObject = leftProp.getDbObject();
if (leftDbObject.hasValidators()) {
for (DbValidator validator : leftDbObject.getValidators()) {
if (validator.validates(leftProp.getPropertyName())) {
// Don't perform differencing on this property - a validator will handle it.
return;
}
}
}
@SuppressWarnings("unchecked") Collection<? extends Object> leftCollection = (Collection<? extends Object>) leftProp.getPropertyValue();
@SuppressWarnings("unchecked") Collection<? extends Object> rightCollection = (Collection<? extends Object>) rightProp.getPropertyValue();
ArrayList<? extends Object> leftList = new ArrayList<Object>(leftCollection);
ArrayList<? extends Object> rightList = new ArrayList<Object>(rightCollection);
Results differences = ctx.getComparisonResults();
for (int leftIndex = 0; leftIndex < leftList.size(); leftIndex++) {
Object leftObj = leftList.get(leftIndex);
DbProperty leftIndexedProp = new DbProperty(leftProp.getDbObject(), leftProp.getPropertyName(), leftIndex);
int rightIndex;
if ((rightIndex = rightList.indexOf(leftObj)) != -1) {
// The same valued object in the right hand collection as in the left.
// Note: it isn't possible to determine a result of Where.IN_BOTH_BUT_DIFFERENCE
// with a 'simple' value — as there is no way of knowing if the term represents the same value
// (e.g. two strings {red_value, green_value}, are these meant to be the same or different?)
DbProperty rightIndexedProp = new DbProperty(rightProp.getDbObject(), rightProp.getPropertyName(), rightIndex);
differences.add(Where.IN_BOTH_NO_DIFFERENCE, leftIndexedProp, rightIndexedProp);
} else {
// No equivalent object in the right hand collection.
// Using rightIndexedProperty would result in index out of bounds error.
differences.add(Where.ONLY_IN_REFERENCE, leftIndexedProp, rightProp);
}
}
// Identify objects in the right collection but not the left
for (int rightIndex = 0; rightIndex < rightList.size(); rightIndex++) {
Object rightObj = rightList.get(rightIndex);
if (!leftCollection.contains(rightObj)) {
DbProperty rightIndexedProp = new DbProperty(rightProp.getDbObject(), rightProp.getPropertyName(), rightIndex);
// No equivalent object in the left hand collection.
differences.add(Where.ONLY_IN_TARGET, leftProp, rightIndexedProp);
}
}
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DbProperty method getPath.
/**
* Work backwards from this DbProperty's DbObject to the root object to create a path in the
* following format:
* <p>
* root.child.grandchild[...].property
* <p>
* e.g. myschema.person.age.nullable
* <p>
* This isn't exactly the same as a FQ database object name, for example the property name could be indexed:
* <p>
* e.g. myschema.person.pk_person.columnNames[2]
* <p>
* to reflect the third column name in the primary key named "pk_person" on the person table.
*
* @return String path
*/
public String getPath() {
StringBuffer sb = new StringBuffer();
if (getPropertyName() != null) {
sb.append(".");
sb.append(getPropertyName());
}
for (DbObject pathElement = dbObject; pathElement != null; pathElement = pathElement.getParent()) {
sb.insert(0, pathElement.getName());
if (pathElement.getParent() != null) {
sb.insert(0, ".");
}
}
return sb.toString();
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtils method compareSimpleOrderedLists.
@Override
public void compareSimpleOrderedLists(DbProperty refProp, DbProperty targetProp, DiffContext ctx) {
checkPropertyContainsList(refProp);
checkPropertyContainsList(targetProp);
// Check whether the leftProperty should be compared to the rightProperty
DbObject leftDbObject = refProp.getDbObject();
if (leftDbObject.hasValidators()) {
for (DbValidator validator : leftDbObject.getValidators()) {
if (validator.validates(refProp.getPropertyName())) {
// Don't perform differencing on this property - a validator will handle it.
return;
}
}
}
@SuppressWarnings("unchecked") ArrayList<Object> refList = new ArrayList<Object>((List<Object>) refProp.getPropertyValue());
@SuppressWarnings("unchecked") ArrayList<Object> targetList = new ArrayList<Object>((List<Object>) targetProp.getPropertyValue());
Results differences = ctx.getComparisonResults();
int maxSize = Math.max(refList.size(), targetList.size());
for (int i = 0; i < maxSize; i++) {
if (i < refList.size() && i < targetList.size()) {
DbProperty refIndexedProp = new DbProperty(refProp.getDbObject(), refProp.getPropertyName(), i);
DbProperty targetIndexedProp = new DbProperty(targetProp.getDbObject(), targetProp.getPropertyName(), i);
if (refList.get(i).equals(targetList.get(i))) {
differences.add(Where.IN_BOTH_NO_DIFFERENCE, refIndexedProp, targetIndexedProp);
} else {
differences.add(Where.IN_BOTH_BUT_DIFFERENCE, refIndexedProp, targetIndexedProp);
}
} else if (i < refList.size()) {
DbProperty indexedProp = new DbProperty(refProp.getDbObject(), refProp.getPropertyName(), i);
differences.add(Where.ONLY_IN_REFERENCE, indexedProp, null);
} else {
DbProperty indexedProp = new DbProperty(targetProp.getDbObject(), targetProp.getPropertyName(), i);
// No equivalent object in the reference collection.
differences.add(Where.ONLY_IN_TARGET, null, indexedProp);
}
}
}
Aggregations