Skip to content

Commit

Permalink
重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
陈佳志 committed Nov 18, 2017
1 parent 0be69c7 commit 09b0438
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/main/java/MainReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static void main(String[] args) throws DocumentException {
String fileName = args[0];
System.out.println(Ansi.ansi().fg(YELLOW).a("File path:") + Ansi.ansi().fg(Ansi.Color.GREEN).a(fileName).toString());


long start = System.currentTimeMillis();

SAXReader saxReader = new SAXReader();
Expand All @@ -35,15 +34,12 @@ public static void main(String[] args) throws DocumentException {
Element rootObject = rootElement.element(new QName("RootObject", oNamespace));

Element children = rootObject.element(new QName("Children", cNamespace));
// System.out.println(children);
Element model = children.element(new QName("Model", oNamespace));
// System.out.println(model);
Element tables = model.element(new QName("Tables", cNamespace));
List<Element> tablelist = tables.elements(new QName("Table", oNamespace));

System.out.println(Ansi.ansi().fg(YELLOW).a("Table size:") + Ansi.ansi().fg(Ansi.Color.GREEN).a(tablelist.size()).toString());


System.out.println(Ansi.ansi().fgDefault().a(" "));

int i = 0;
Expand All @@ -54,34 +50,27 @@ public static void main(String[] args) throws DocumentException {
System.out.println("------>" + Ansi.ansi().fg(BLUE).a("NO." + i) + Ansi.ansi().fg(RED).a(" " + name.getText() + " ") +
Ansi.ansi().fg(YELLOW).a(code.getText()) + Ansi.ansi().fgDefault().a("<-------"));


//解析主键
Element primaryKeyEle = tableElement.element(new QName("PrimaryKey", cNamespace));
// System.out.println(pk);
List<String> pkIds = new ArrayList<>();
if (primaryKeyEle != null) {
List<Element> pks = primaryKeyEle.elements(new QName("Key", oNamespace));
for (Element pk1 : pks) {
// System.out.println(pk1.attribute("Ref").getValue());
pkIds.add(pk1.attribute("Ref").getValue());
}
}


Element keysEle = tableElement.element(new QName("Keys", cNamespace));
// System.out.println(keysEle);
List<String> pkColumnIds = new ArrayList<>();
if (keysEle != null) {
List<Element> keyEleList = keysEle.elements(new QName("Key", oNamespace));
for (Element keyEle : keyEleList) {
// System.out.println(keyEle);
Attribute id = keyEle.attribute("Id");
if (pkIds.contains(id.getValue())) {
List<Element> list = keyEle.element(new QName("Key.Columns", cNamespace)).elements(new QName("Column", oNamespace));
for (Element element : list) {
pkColumnIds.add(element.attribute("Ref").getValue());
}
// System.out.println(keyEle);
}
}
}
Expand All @@ -97,7 +86,6 @@ public static void main(String[] args) throws DocumentException {
Element cComment = columnEle.element(new QName("Comment", aNamespace));
Element nullable = columnEle.element(new QName("Column.Mandatory", aNamespace));


System.out.print(getPadString(ccode.getText(), 20));
System.out.print(getPadString(getTextFromEle(cDataType), 15));
System.out.print(getPadString(getTextFromEle(cLength), 7));
Expand All @@ -116,7 +104,7 @@ public static void main(String[] args) throws DocumentException {

System.out.print(cname.getText());
if (cComment != null) {
System.out.print(" (" + getTextFromEle(cComment).replace("\n"," ") + ")");
System.out.print(" (" + getTextFromEle(cComment).replace("\n", " ") + ")");
}
System.out.println();
}
Expand All @@ -139,7 +127,7 @@ static String getTextFromEle(Element element) {
}

/**
* like pringf()
* @see String#format(String, Object...)
*/
static String getPadString(String str, int length) {
int size = str.length();
Expand All @@ -158,6 +146,4 @@ static String getBlank(int length) {
}
return s.toString();
}


}

0 comments on commit 09b0438

Please sign in to comment.