use of org.alfresco.util.schemacomp.model.Schema in project alfresco-repository by Alfresco.
the class DbObjectXMLTransformer method addAttributes.
/**
* Add class-specific attributes.
*
* @param dbObject DbObject
* @param attribs AttributesImpl
*/
private void addAttributes(DbObject dbObject, AttributesImpl attribs) {
if (dbObject instanceof Schema) {
Schema schema = (Schema) dbObject;
attribs.addAttribute("", "", XML.ATTR_DB_PREFIX, "CDATA", schema.getDbPrefix());
attribs.addAttribute("", "", XML.ATTR_VERSION, "CDATA", Integer.toString(schema.getVersion()));
attribs.addAttribute("", "", XML.ATTR_TABLE_COLUMN_ORDER, "CDATA", Boolean.toString(schema.isCheckTableColumnOrder()));
} else if (dbObject instanceof Index) {
Index index = (Index) dbObject;
attribs.addAttribute("", "", XML.ATTR_UNIQUE, "CDATA", Boolean.toString(index.isUnique()));
} else if (dbObject instanceof Column) {
Column column = (Column) dbObject;
attribs.addAttribute("", "", XML.ATTR_ORDER, "CDATA", Integer.toString(column.getOrder()));
}
}
use of org.alfresco.util.schemacomp.model.Schema in project alfresco-repository by Alfresco.
the class DbToXML method execute.
public void execute() {
ExportDb exporter = new ExportDb(context);
exporter.setNamePrefix(namePrefix);
exporter.setDbSchemaName(dbSchemaName);
exporter.execute();
Schema schema = exporter.getSchema();
// Write to a string buffer and then write the results to a file
// since we need to write windows line endings - and even passing in a suitable
// PrintWriter to StreamResult does not seem to result in the correct line endings.
StringWriter stringWriter = new StringWriter();
SchemaToXML schemaToXML = new SchemaToXML(schema, new StreamResult(stringWriter));
schemaToXML.execute();
writeToFile(stringWriter.getBuffer().toString());
}
use of org.alfresco.util.schemacomp.model.Schema in project alfresco-repository by Alfresco.
the class ExportDb method execute.
private void execute(Connection con, int schemaVersion) throws Exception {
final DatabaseMetaData dbmd = con.getMetaData();
String schemaName = databaseMetaDataHelper.getSchema(con);
schema = new Schema(schemaName, namePrefix, schemaVersion, true);
String[] prefixFilters = namePrefixFilters(dbmd);
for (String filter : prefixFilters) {
extractSchema(dbmd, schemaName, filter);
}
}
use of org.alfresco.util.schemacomp.model.Schema in project alfresco-repository by Alfresco.
the class XMLToSchema method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
lastText.setLength(0);
if (qName.equals(XML.EL_SCHEMA)) {
String name = atts.getValue(XML.ATTR_NAME);
String dbPrefix = atts.getValue(XML.ATTR_DB_PREFIX);
int version = Integer.parseInt(atts.getValue(XML.ATTR_VERSION));
String attrTableColumnOrder = atts.getValue(XML.ATTR_TABLE_COLUMN_ORDER);
// Should column order be checked for tables?
boolean compareTableColOrder = attrTableColumnOrder != null ? Boolean.parseBoolean(attrTableColumnOrder) : true;
schema = new Schema(name, dbPrefix, version, compareTableColOrder);
stack.push(schema);
} else if (qName.equals(XML.EL_TABLE)) {
stack.push(new Table(atts.getValue(XML.ATTR_NAME)));
} else if (qName.equals(XML.EL_COLUMN)) {
Column column = new Column(atts.getValue(XML.ATTR_NAME));
if (atts.getValue(XML.ATTR_ORDER) != null) {
int order = Integer.parseInt(atts.getValue(XML.ATTR_ORDER));
column.setOrder(order);
}
column.setCompareOrder(schema.isCheckTableColumnOrder());
stack.push(column);
} else if (qName.equals(XML.EL_COLUMN_NAME)) {
if (stack.peek() instanceof PrimaryKey && atts.getValue(XML.ATTR_ORDER) != null) {
PrimaryKey pk = (PrimaryKey) stack.peek();
Integer columnOrder = Integer.parseInt(atts.getValue(XML.ATTR_ORDER));
pk.getColumnOrders().add(columnOrder);
}
} else if (qName.equals(XML.EL_PRIMARY_KEY)) {
stack.push(new PrimaryKey(atts.getValue(XML.ATTR_NAME)));
} else if (qName.equals(XML.EL_FOREIGN_KEY)) {
stack.push(new ForeignKey(atts.getValue(XML.ATTR_NAME)));
} else if (qName.equals(XML.EL_INDEX)) {
Index index = new Index(atts.getValue(XML.ATTR_NAME));
boolean unique = Boolean.parseBoolean(atts.getValue(XML.ATTR_UNIQUE));
index.setUnique(unique);
stack.push(index);
} else if (qName.equals(XML.EL_SEQUENCE)) {
stack.push(new Sequence(atts.getValue(XML.ATTR_NAME)));
} else if (qName.equals(XML.EL_VALIDATOR)) {
String className = atts.getValue(XML.ATTR_CLASS);
DbValidator validator = null;
try {
validator = (DbValidator) Class.forName(className).newInstance();
} catch (Throwable e) {
throw new RuntimeException("Couldn't create validator, class: " + className, e);
}
stack.push(validator);
} else if (qName.equals(XML.EL_PROPERTY)) {
String name = atts.getValue(XML.ATTR_NAME);
stack.push(name);
}
}
use of org.alfresco.util.schemacomp.model.Schema in project alfresco-repository by Alfresco.
the class SchemaVersionValidator method validate.
@Override
public void validate(DbObject referenceObj, DbObject targetObj, DiffContext ctx) {
Schema reference = (Schema) referenceObj;
Schema target = (Schema) targetObj;
if (target.getVersion() < reference.getVersion()) {
DbProperty targetProperty = new DbProperty(target, "version");
String message = I18NUtil.getMessage("system.schema_comp.schema_version_validator", reference.getVersion());
ctx.getComparisonResults().add(new ValidationResult(targetProperty, message));
}
}
Aggregations