ALF-11668: Add position identifiers (same as seq elements in current schema dump tool)

As for current schemadump tool, table columns and primary key column names have order associated with them.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32296 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-11-24 18:17:41 +00:00
parent f939783d70
commit 462994f3eb
16 changed files with 503 additions and 313 deletions

View File

@@ -18,7 +18,6 @@
*/
package org.alfresco.util.schemacomp;
import java.util.Collection;
import java.util.List;
import org.alfresco.util.schemacomp.model.Column;
@@ -136,6 +135,11 @@ public class DbObjectXMLTransformer
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()));
}
}
private void transformDbObject(DbObject dbObject) throws SAXException
@@ -223,12 +227,12 @@ public class DbObjectXMLTransformer
private void transformIndex(Index index) throws SAXException
{
columnNameList(index.getColumnNames());
columnNameList(index.getColumnNames(), null);
}
private void transformPrimaryKey(PrimaryKey pk) throws SAXException
{
columnNameList(pk.getColumnNames());
columnNameList(pk.getColumnNames(), pk.getColumnOrders());
}
@@ -260,12 +264,40 @@ public class DbObjectXMLTransformer
xmlOut.endElement("", "", tag);
}
private void columnNameList(Collection<String> columnNames) throws SAXException
/**
* Outputs a list of columnname elements sandwiched within a columnnames element.
* <p>
* The columnOrders parameter will provide a corresponding list of integers that will be
* provided in each columnname element's order attribute. This parameter may be null
* in which case order attributes will be ommitted.
*
* @param columnNames
* @param columnOrders
* @throws SAXException
*/
private void columnNameList(List<String> columnNames,
List<Integer> columnOrders) throws SAXException
{
simpleStartTag(XML.EL_COLUMN_NAMES);
for (String columnName : columnNames)
for (int i = 0; i < columnNames.size(); i++)
{
simpleElement(XML.EL_COLUMN_NAME, columnName);
String columnName = columnNames.get(i);
final AttributesImpl attribs = new AttributesImpl();
if (columnOrders != null)
{
int columnOrder = columnOrders.get(i);
attribs.addAttribute("", "", XML.ATTR_ORDER, "CDATA", Integer.toString(columnOrder));
}
// Create a <columnname> or <columnname order="n"> start tag
xmlOut.startElement("", "", XML.EL_COLUMN_NAME, attribs);
// Provide the elements content
char[] chars = columnName.toCharArray();
xmlOut.characters(chars, 0, chars.length);
// Provide the closing tag
simpleEndTag(XML.EL_COLUMN_NAME);
}
simpleEndTag(XML.EL_COLUMN_NAMES);
}