} else if (constraintType.equals(Constraint.REFERENTIAL)) {
indexColumns = ((ConstraintReferential) constraint).getColumns();
}
String columnList = null;
if (indexColumns != null) {
StatementBuilder buff = new StatementBuilder();
for (IndexColumn col : indexColumns) {
buff.appendExceptFirst(",");
buff.append(col.column.getName());
}
columnList = buff.toString();
}
add(rows,
// CONSTRAINT_CATALOG
catalog,
// CONSTRAINT_SCHEMA
identifier(constraint.getSchema().getName()),
// CONSTRAINT_NAME
identifier(constraint.getName()),
// CONSTRAINT_TYPE
constraintType,
// TABLE_CATALOG
catalog,
// TABLE_SCHEMA
identifier(table.getSchema().getName()),
// TABLE_NAME
tableName,
// UNIQUE_INDEX_NAME
uniqueIndexName,
// CHECK_EXPRESSION
checkExpression,
// COLUMN_LIST
columnList,
// REMARKS
replaceNullWithEmpty(constraint.getComment()),
// SQL
constraint.getCreateSQL(),
// ID
"" + constraint.getId()
);
}
break;
}
case CONSTANTS: {
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.CONSTANT)) {
Constant constant = (Constant) obj;
ValueExpression expr = constant.getValue();
add(rows,
// CONSTANT_CATALOG
catalog,
// CONSTANT_SCHEMA
identifier(constant.getSchema().getName()),
// CONSTANT_NAME
identifier(constant.getName()),
// CONSTANT_TYPE
"" + DataType.convertTypeToSQLType(expr.getType()),
// REMARKS
replaceNullWithEmpty(constant.getComment()),
// SQL
expr.getSQL(),
// ID
"" + constant.getId()
);
}
break;
}
case DOMAINS: {
for (UserDataType dt : database.getAllUserDataTypes()) {
Column col = dt.getColumn();
add(rows,
// DOMAIN_CATALOG
catalog,
// DOMAIN_SCHEMA
Constants.SCHEMA_MAIN,
// DOMAIN_NAME
identifier(dt.getName()),
// COLUMN_DEFAULT
col.getDefaultSQL(),
// IS_NULLABLE
col.isNullable() ? "YES" : "NO",
// DATA_TYPE
"" + col.getDataType().sqlType,
// PRECISION INT
"" + col.getPrecisionAsInt(),
// SCALE INT
"" + col.getScale(),
// TYPE_NAME
col.getDataType().name,
// SELECTIVITY INT
"" + col.getSelectivity(),
// CHECK_CONSTRAINT
"" + col.getCheckConstraintSQL(session, "VALUE"),
// REMARKS
replaceNullWithEmpty(dt.getComment()),
// SQL
"" + dt.getCreateSQL(),
// ID
"" + dt.getId()
);
}
break;
}
case TRIGGERS: {
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.TRIGGER)) {
TriggerObject trigger = (TriggerObject) obj;
Table table = trigger.getTable();
add(rows,
// TRIGGER_CATALOG
catalog,
// TRIGGER_SCHEMA
identifier(trigger.getSchema().getName()),
// TRIGGER_NAME
identifier(trigger.getName()),
// TRIGGER_TYPE
trigger.getTypeNameList(),
// TABLE_CATALOG
catalog,
// TABLE_SCHEMA
identifier(table.getSchema().getName()),
// TABLE_NAME
identifier(table.getName()),
// BEFORE BIT
"" + trigger.isBefore(),
// JAVA_CLASS
trigger.getTriggerClassName(),
// QUEUE_SIZE INT
"" + trigger.getQueueSize(),
// NO_WAIT BIT
"" + trigger.isNoWait(),
// REMARKS
replaceNullWithEmpty(trigger.getComment()),
// SQL
trigger.getCreateSQL(),
// ID
"" + trigger.getId()
);
}
break;
}
case SESSIONS: {
long now = System.currentTimeMillis();
for (Session s : database.getSessions(false)) {
if (admin || s == session) {
Command command = s.getCurrentCommand();
long start = s.getCurrentCommandStart();
if (start == 0) {
start = now;
}
add(rows,
// ID
"" + s.getId(),
// USER_NAME
s.getUser().getName(),
// SESSION_START
new Timestamp(s.getSessionStart()).toString(),
// STATEMENT
command == null ? null : command.toString(),
// STATEMENT_START
new Timestamp(start).toString()
);
}
}
break;
}
case LOCKS: {
for (Session s : database.getSessions(false)) {
if (admin || s == session) {
for (Table table : s.getLocks()) {
add(rows,
// TABLE_SCHEMA
table.getSchema().getName(),
// TABLE_NAME
table.getName(),
// SESSION_ID
"" + s.getId(),
// LOCK_TYPE
table.isLockedExclusivelyBy(s) ? "WRITE" : "READ"
);
}
}
}
break;
}
case SESSION_STATE: {
for (String name : session.getVariableNames()) {
Value v = session.getVariable(name);
add(rows,
// KEY
"@" + name,
// SQL
"SET @" + name + " " + v.getSQL()
);
}
for (Table table : session.getLocalTempTables()) {
add(rows,
// KEY
"TABLE " + table.getName(),
// SQL
table.getCreateSQL()
);
}
String[] path = session.getSchemaSearchPath();
if (path != null && path.length > 0) {
StatementBuilder buff = new StatementBuilder("SET SCHEMA_SEARCH_PATH ");
for (String p : path) {
buff.appendExceptFirst(", ");
buff.append(StringUtils.quoteIdentifier(p));
}
add(rows,
// KEY
"SCHEMA_SEARCH_PATH",
// SQL
buff.toString()
);
}
String schema = session.getCurrentSchemaName();
if (schema != null) {
add(rows,