use of org.alfresco.util.schemacomp.model.Sequence 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.Sequence in project alfresco-repository by Alfresco.
the class DbObjectXMLTransformerTest method transformSchemaNoColumnOrderCheck.
@Test
public void transformSchemaNoColumnOrderCheck() 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 tableOne = new Table(null, "table_one", columns, pk, fks, indexes);
Table tableTwo = new Table(null, "table_two", columns, pk, fks, indexes);
Schema schema = new Schema("my_schema", "alf_", 132, false);
schema.add(tableOne);
schema.add(tableTwo);
schema.add(new Sequence(null, "sequence_one"));
schema.add(new Sequence(null, "sequence_two"));
schema.add(new Sequence(null, "sequence_three"));
schema.setValidators(new ArrayList<DbValidator>());
transformer.output(schema);
BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
dumpOutput();
assertHasPreamble(reader);
assertEquals("<schema " + "xmlns=\"http://www.alfresco.org/repo/db-schema\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\"http://www.alfresco.org/repo/db-schema db-schema.xsd\" " + "name=\"my_schema\" dbprefix=\"alf_\" version=\"132\" tablecolumnorder=\"false\">", reader.readLine());
assertEquals(" <objects>", reader.readLine());
skipUntilEnd(" {table}", reader);
skipUntilEnd(" {table}", reader);
skipUntilEnd(" {sequence}", reader, true);
skipUntilEnd(" {sequence}", reader, true);
skipUntilEnd(" {sequence}", reader, true);
assertEquals(" </objects>", reader.readLine());
assertEquals("</schema>", reader.readLine());
}
use of org.alfresco.util.schemacomp.model.Sequence in project alfresco-repository by Alfresco.
the class DbObjectXMLTransformerTest method transformSequence.
@Test
public void transformSequence() throws IOException {
Sequence sequence = new Sequence(null, "my_sequence");
transformer.output(sequence);
BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
dumpOutput();
assertHasPreamble(reader);
assertEquals("<sequence name=\"my_sequence\"/>", reader.readLine());
}
Aggregations