if (method.hasConnectionParam() && k == 0) {
continue;
}
Class<?> clazz = columnList[k];
int dataType = DataType.getTypeFromClass(clazz);
DataType dt = DataType.getDataType(dataType);
int nullable = clazz.isPrimitive() ? DatabaseMetaData.columnNoNulls
: DatabaseMetaData.columnNullable;
add(rows,
// ALIAS_CATALOG
catalog,
// ALIAS_SCHEMA
alias.getSchema().getName(),
// ALIAS_NAME
identifier(alias.getName()),
// JAVA_CLASS
alias.getJavaClassName(),
// JAVA_METHOD
alias.getJavaMethodName(),
// COLUMN_COUNT
"" + method.getParameterCount(),
// POS INT
"" + (k + (method.hasConnectionParam() ? 0 : 1)),
// COLUMN_NAME
"P" + (k + 1),
// DATA_TYPE
"" + DataType.convertTypeToSQLType(dt.type),
// TYPE_NAME
dt.name,
// PRECISION INT
"" + MathUtils.convertLongToInt(dt.defaultPrecision),
// SCALE
"" + dt.defaultScale,
// RADIX
"10",
// NULLABLE SMALLINT
"" + nullable,
// COLUMN_TYPE
"" + DatabaseMetaData.procedureColumnIn,
// REMARKS
"",
// COLUMN_DEFAULT
null
);
}
}
}
break;
}
case SCHEMATA: {
String collation = database.getCompareMode().getName();
for (Schema schema : database.getAllSchemas()) {
add(rows,
// CATALOG_NAME
catalog,
// SCHEMA_NAME
identifier(schema.getName()),
// SCHEMA_OWNER
identifier(schema.getOwner().getName()),
// DEFAULT_CHARACTER_SET_NAME
CHARACTER_SET_NAME,
// DEFAULT_COLLATION_NAME
collation,
// IS_DEFAULT
Constants.SCHEMA_MAIN.equals(schema.getName()) ? "TRUE" : "FALSE",
// REMARKS
replaceNullWithEmpty(schema.getComment()),
// ID
"" + schema.getId()
);
}
break;
}
case TABLE_PRIVILEGES: {
for (Right r : database.getAllRights()) {
Table table = r.getGrantedTable();
if (table == null || hideTable(table, session)) {
continue;
}
String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
addPrivileges(rows, r.getGrantee(), catalog, table, null, r.getRightMask());
}
break;
}
case COLUMN_PRIVILEGES: {
for (Right r : database.getAllRights()) {
Table table = r.getGrantedTable();
if (table == null || hideTable(table, session)) {
continue;
}
String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
DbObject grantee = r.getGrantee();
int mask = r.getRightMask();
for (Column column : table.getColumns()) {
addPrivileges(rows, grantee, catalog, table, column.getName(), mask);
}
}
break;
}
case COLLATIONS: {
for (Locale l : Collator.getAvailableLocales()) {
add(rows,
// NAME
CompareMode.getName(l),
// KEY
l.toString()
);
}
break;
}
case VIEWS: {
for (Table table : getAllTables(session)) {
if (!table.getTableType().equals(Table.VIEW)) {
continue;
}
String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
TableView view = (TableView) table;
add(rows,
// TABLE_CATALOG
catalog,
// TABLE_SCHEMA
identifier(table.getSchema().getName()),
// TABLE_NAME
tableName,
// VIEW_DEFINITION
table.getCreateSQL(),
// CHECK_OPTION
"NONE",
// IS_UPDATABLE
"NO",
// STATUS
view.isInvalid() ? "INVALID" : "VALID",
// REMARKS
replaceNullWithEmpty(view.getComment()),
// ID
"" + view.getId()
);
}
break;
}
case IN_DOUBT: {
ArrayList<InDoubtTransaction> prepared = database.getInDoubtTransactions();
if (prepared != null && admin) {
for (InDoubtTransaction prep : prepared) {
add(rows,
// TRANSACTION
prep.getTransaction(),
// STATE
prep.getState()
);
}
}
break;
}
case CROSS_REFERENCES: {
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.CONSTRAINT)) {
Constraint constraint = (Constraint) obj;
if (!(constraint.getConstraintType().equals(Constraint.REFERENTIAL))) {
continue;
}
ConstraintReferential ref = (ConstraintReferential) constraint;
IndexColumn[] cols = ref.getColumns();
IndexColumn[] refCols = ref.getRefColumns();
Table tab = ref.getTable();
Table refTab = ref.getRefTable();
String tableName = identifier(refTab.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
int update = getRefAction(ref.getUpdateAction());
int delete = getRefAction(ref.getDeleteAction());
for (int j = 0; j < cols.length; j++) {
add(rows,
// PKTABLE_CATALOG
catalog,
// PKTABLE_SCHEMA
identifier(refTab.getSchema().getName()),
// PKTABLE_NAME
identifier(refTab.getName()),
// PKCOLUMN_NAME
identifier(refCols[j].column.getName()),
// FKTABLE_CATALOG
catalog,
// FKTABLE_SCHEMA
identifier(tab.getSchema().getName()),
// FKTABLE_NAME
identifier(tab.getName()),
// FKCOLUMN_NAME
identifier(cols[j].column.getName()),
// ORDINAL_POSITION
String.valueOf(j + 1),
// UPDATE_RULE SMALLINT
String.valueOf(update),
// DELETE_RULE SMALLINT
String.valueOf(delete),
// FK_NAME
identifier(ref.getName()),
// PK_NAME
identifier(ref.getUniqueIndex().getName()),
// DEFERRABILITY
"" + DatabaseMetaData.importedKeyNotDeferrable
);
}
}
break;
}
case CONSTRAINTS: {
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.CONSTRAINT)) {
Constraint constraint = (Constraint) obj;
String constraintType = constraint.getConstraintType();
String checkExpression = null;
IndexColumn[] indexColumns = null;
Table table = constraint.getTable();
if (hideTable(table, session)) {
continue;
}
Index index = constraint.getUniqueIndex();
String uniqueIndexName = null;
if (index != null) {
uniqueIndexName = index.getName();
}
String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
if (constraintType.equals(Constraint.CHECK)) {
checkExpression = ((ConstraintCheck) constraint).getExpression().getSQL();
} else if (constraintType.equals(Constraint.UNIQUE) || constraintType.equals(Constraint.PRIMARY_KEY)) {
indexColumns = ((ConstraintUnique) constraint).getColumns();
} 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: {