提交 3510a7f9 authored 作者: noelgrandin's avatar noelgrandin

add some comments to this large method

上级 13f10ade
...@@ -70,8 +70,10 @@ public class ScriptCommand extends ScriptBase { ...@@ -70,8 +70,10 @@ public class ScriptCommand extends ScriptBase {
private Set<String> schemaNames; private Set<String> schemaNames;
private Collection<Table> tables; private Collection<Table> tables;
private boolean passwords; private boolean passwords;
/** true if we're generating the INSERT..VALUES statements for row values */
private boolean data; private boolean data;
private boolean settings; private boolean settings;
/** true if we're generating the DROP statements */
private boolean drop; private boolean drop;
private boolean simple; private boolean simple;
private LocalResult result; private LocalResult result;
...@@ -188,7 +190,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -188,7 +190,8 @@ public class ScriptCommand extends ScriptBase {
Constant constant = (Constant) obj; Constant constant = (Constant) obj;
add(constant.getCreateSQL(), false); add(constant.getCreateSQL(), false);
} }
ArrayList<Table> tables = db.getAllTablesAndViews(false);
final ArrayList<Table> tables = db.getAllTablesAndViews(false);
// sort by id, so that views are after tables and views on views // sort by id, so that views are after tables and views on views
// after the base views // after the base views
Collections.sort(tables, new Comparator<Table>() { Collections.sort(tables, new Comparator<Table>() {
...@@ -196,6 +199,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -196,6 +199,8 @@ public class ScriptCommand extends ScriptBase {
return t1.getId() - t2.getId(); return t1.getId() - t2.getId();
} }
}); });
// Generate the DROP XXX ... IF EXISTS
for (Table table : tables) { for (Table table : tables) {
if (excludeSchema(table.getSchema())) { if (excludeSchema(table.getSchema())) {
continue; continue;
...@@ -241,6 +246,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -241,6 +246,8 @@ public class ScriptCommand extends ScriptBase {
} }
add(sequence.getCreateSQL(), false); add(sequence.getCreateSQL(), false);
} }
// Generate CREATE TABLE and INSERT...VALUES
int count = 0; int count = 0;
for (Table table : tables) { for (Table table : tables) {
if (excludeSchema(table.getSchema())) { if (excludeSchema(table.getSchema())) {
...@@ -253,14 +260,14 @@ public class ScriptCommand extends ScriptBase { ...@@ -253,14 +260,14 @@ public class ScriptCommand extends ScriptBase {
continue; continue;
} }
table.lock(session, false, false); table.lock(session, false, false);
String sql = table.getCreateSQL(); String createTableSql = table.getCreateSQL();
if (sql == null) { if (createTableSql == null) {
// null for metadata tables // null for metadata tables
continue; continue;
} }
String tableType = table.getTableType(); final String tableType = table.getTableType();
add(sql, false); add(createTableSql, false);
ArrayList<Constraint> constraints = table.getConstraints(); final ArrayList<Constraint> constraints = table.getConstraints();
if (constraints != null) { if (constraints != null) {
for (Constraint constraint : constraints) { for (Constraint constraint : constraints) {
if (Constraint.PRIMARY_KEY.equals(constraint.getConstraintType())) { if (Constraint.PRIMARY_KEY.equals(constraint.getConstraintType())) {
...@@ -349,7 +356,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -349,7 +356,8 @@ public class ScriptCommand extends ScriptBase {
add("DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB", true); add("DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB", true);
tempLobTableCreated = false; tempLobTableCreated = false;
} }
ArrayList<SchemaObject> constraints = db.getAllSchemaObjects(DbObject.CONSTRAINT); // Generate CREATE CONSTRAINT ...
final ArrayList<SchemaObject> constraints = db.getAllSchemaObjects(DbObject.CONSTRAINT);
Collections.sort(constraints, new Comparator<SchemaObject>() { Collections.sort(constraints, new Comparator<SchemaObject>() {
public int compare(SchemaObject c1, SchemaObject c2) { public int compare(SchemaObject c1, SchemaObject c2) {
return ((Constraint) c1).compareTo((Constraint) c2); return ((Constraint) c1).compareTo((Constraint) c2);
...@@ -370,6 +378,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -370,6 +378,7 @@ public class ScriptCommand extends ScriptBase {
add(constraint.getCreateSQLWithoutIndexes(), false); add(constraint.getCreateSQLWithoutIndexes(), false);
} }
} }
// Generate CREATE TRIGGER ...
for (SchemaObject obj : db.getAllSchemaObjects(DbObject.TRIGGER)) { for (SchemaObject obj : db.getAllSchemaObjects(DbObject.TRIGGER)) {
if (excludeSchema(obj.getSchema())) { if (excludeSchema(obj.getSchema())) {
continue; continue;
...@@ -380,6 +389,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -380,6 +389,7 @@ public class ScriptCommand extends ScriptBase {
} }
add(trigger.getCreateSQL(), false); add(trigger.getCreateSQL(), false);
} }
// Generate GRANT ...
for (Right right : db.getAllRights()) { for (Right right : db.getAllRights()) {
Table table = right.getGrantedTable(); Table table = right.getGrantedTable();
if (table != null) { if (table != null) {
...@@ -392,6 +402,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -392,6 +402,7 @@ public class ScriptCommand extends ScriptBase {
} }
add(right.getCreateSQL(), false); add(right.getCreateSQL(), false);
} }
// Generate COMMENT ON ...
for (Comment comment : db.getAllComments()) { for (Comment comment : db.getAllComments()) {
add(comment.getCreateSQL(), false); add(comment.getCreateSQL(), false);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论