📄 metatable.java
字号:
identifier(constraint.getSchema().getName()), // CONSTRAINT_SCHEMA
identifier(constraint.getName()), // CONSTRAINT_NAME
type, // CONSTRAINT_TYPE
catalog, // TABLE_CATALOG
identifier(table.getSchema().getName()), // TABLE_SCHEMA
tableName, // TABLE_NAME
checkExpression, // CHECK_EXPRESSION
columnList, // COLUMN_LIST
replaceNullWithEmpty(constraint.getComment()), // REMARKS
constraint.getCreateSQL(), // SQL
"" + constraint.getId() // ID
});
}
break;
}
case CONSTANTS: {
ObjectArray constants = database.getAllSchemaObjects(DbObject.CONSTANT);
for (int i = 0; i < constants.size(); i++) {
Constant constant = (Constant) constants.get(i);
ValueExpression expr = constant.getValue();
add(rows, new String[] {
catalog, // CONSTANT_CATALOG
identifier(constant.getSchema().getName()), // CONSTANT_SCHEMA
identifier(constant.getName()), // CONSTANT_NAME
"" + DataType.convertTypeToSQLType(expr.getType()), // CONSTANT_TYPE
replaceNullWithEmpty(constant.getComment()), // REMARKS
expr.getSQL(), // SQL
"" + constant.getId() // ID
});
}
break;
}
case DOMAINS: {
ObjectArray userDataTypes = database.getAllUserDataTypes();
for (int i = 0; i < userDataTypes.size(); i++) {
UserDataType dt = (UserDataType) userDataTypes.get(i);
Column col = dt.getColumn();
add(rows, new String[] {
catalog, // DOMAIN_CATALOG
Constants.SCHEMA_MAIN, // DOMAIN_SCHEMA
identifier(dt.getName()), // DOMAIN_NAME
col.getDefaultSQL(), // COLUMN_DEFAULT
col.getNullable() ? "YES" : "NO", // IS_NULLABLE
"" + col.getDataType().sqlType, // DATA_TYPE
"" + col.getPrecisionAsInt(), // PRECISION INT
"" + col.getScale(), // SCALE INT
col.getDataType().name, // TYPE_NAME
"" + col.getSelectivity(), // SELECTIVITY INT
"" + col.getCheckConstraintSQL(session, "VALUE"), // CHECK_CONSTRAINT
replaceNullWithEmpty(dt.getComment()), // REMARKS
"" + dt.getCreateSQL(), // SQL
"" + dt.getId() // ID
});
}
break;
}
case TRIGGERS: {
ObjectArray triggers = database.getAllSchemaObjects(DbObject.TRIGGER);
for (int i = 0; i < triggers.size(); i++) {
TriggerObject trigger = (TriggerObject) triggers.get(i);
Table table = trigger.getTable();
add(rows, new String[] {
catalog, // TRIGGER_CATALOG
identifier(trigger.getSchema().getName()), // TRIGGER_SCHEMA
identifier(trigger.getName()), // TRIGGER_NAME
trigger.getTypeNameList(), // TRIGGER_TYPE
catalog, // TABLE_CATALOG
identifier(table.getSchema().getName()), // TABLE_SCHEMA
identifier(table.getName()), // TABLE_NAME
"" + trigger.getBefore(), // BEFORE BIT
trigger.getTriggerClassName(), // JAVA_CLASS
"" + trigger.getQueueSize(), // QUEUE_SIZE INT
"" + trigger.getNoWait(), // NO_WAIT BIT
replaceNullWithEmpty(trigger.getComment()), // REMARKS
trigger.getCreateSQL(), // SQL
"" + trigger.getId() // ID
});
}
break;
}
case SESSIONS: {
Session[] sessions = database.getSessions();
boolean admin = session.getUser().getAdmin();
for (int i = 0; i < sessions.length; i++) {
Session s = sessions[i];
if (admin || s == session) {
Command command = s.getCurrentCommand();
add(rows, new String[] {
"" + s.getId(), // ID
s.getUser().getName(), // USER_NAME
new Timestamp(s.getSessionStart()).toString(), // SESSION_START
command == null ? null : command.toString(), // STATEMENT
new Timestamp(s.getCurrentCommandStart()).toString() // STATEMENT_START
});
}
}
break;
}
case LOCKS: {
Session[] sessions = database.getSessions();
boolean admin = session.getUser().getAdmin();
for (int i = 0; i < sessions.length; i++) {
Session s = sessions[i];
if (admin || s == session) {
Table[] locks = s.getLocks();
for (int j = 0; j < locks.length; j++) {
Table table = locks[j];
add(rows, new String[] {
table.getSchema().getName(), // TABLE_SCHEMA
table.getName(), // TABLE_NAME
"" + s.getId(), // SESSION_ID
table.isLockExclusive(s) ? "WRITE" : "READ", // LOCK_TYPE
});
}
}
}
break;
}
default:
throw Message.getInternalError("type="+type);
}
return rows;
}
private int getRefAction(int action) {
switch(action) {
case ConstraintReferential.CASCADE:
return DatabaseMetaData.importedKeyCascade;
case ConstraintReferential.RESTRICT:
return DatabaseMetaData.importedKeyRestrict;
case ConstraintReferential.SET_DEFAULT:
return DatabaseMetaData.importedKeySetDefault;
case ConstraintReferential.SET_NULL:
return DatabaseMetaData.importedKeySetNull;
default:
throw Message.getInternalError("action="+action);
}
}
public void removeRow(Session session, Row row) throws SQLException {
throw Message.getUnsupportedException();
}
public void addRow(Session session, Row row) throws SQLException {
throw Message.getUnsupportedException();
}
public void removeIndex(String indexName) throws SQLException {
throw Message.getUnsupportedException();
}
public void removeChildrenAndResources(Session session) throws SQLException {
throw Message.getUnsupportedException();
}
public void close(Session session) throws SQLException {
// nothing to do
}
public void unlock(Session s) {
// nothing to do
}
private void addPrivileges(ObjectArray rows, DbObject grantee, String catalog, Table table, String column,
int rightMask) throws SQLException {
if ((rightMask & Right.SELECT) != 0) {
addPrivilege(rows, grantee, catalog, table, column, "SELECT");
}
if ((rightMask & Right.INSERT) != 0) {
addPrivilege(rows, grantee, catalog, table, column, "INSERT");
}
if ((rightMask & Right.UPDATE) != 0) {
addPrivilege(rows, grantee, catalog, table, column, "UPDATE");
}
if ((rightMask & Right.DELETE) != 0) {
addPrivilege(rows, grantee, catalog, table, column, "DELETE");
}
}
private void addPrivilege(ObjectArray rows, DbObject grantee, String catalog, Table table, String column,
String right) throws SQLException {
String isGrantable = "NO";
if (grantee.getType() == DbObject.USER) {
User user = (User) grantee;
if (user.getAdmin()) {
// the right is grantable if the grantee is an admin
isGrantable = "YES";
}
}
if (column == null) {
add(rows, new String[] {
null, // GRANTOR
identifier(grantee.getName()), // GRANTEE
catalog, // TABLE_CATALOG
identifier(table.getSchema().getName()), // TABLE_SCHEMA
identifier(table.getName()), // TABLE_NAME
right, // PRIVILEGE_TYPE
isGrantable // IS_GRANTABLE
});
} else {
add(rows, new String[] {
null, // GRANTOR
identifier(grantee.getName()), // GRANTEE
catalog, // TABLE_CATALOG
identifier(table.getSchema().getName()), // TABLE_SCHEMA
identifier(table.getName()), // TABLE_NAME
identifier(column), // COLUMN_NAME
right, // PRIVILEGE_TYPE
isGrantable // IS_GRANTABLE
});
}
}
private void add(ObjectArray rows, String[] strings) throws SQLException {
Value[] values = new Value[strings.length];
for (int i = 0; i < strings.length; i++) {
String s = strings[i];
Value v = (s == null) ? (Value) ValueNull.INSTANCE : ValueString.get(s);
Column col = columns[i];
v = v.convertTo(col.getType());
values[i] = v;
}
Row row = new Row(values, 0);
row.setPos(rows.size());
rows.add(row);
}
public void checkRename() throws SQLException {
throw Message.getUnsupportedException();
}
public void checkSupportAlter() throws SQLException {
throw Message.getUnsupportedException();
}
public void truncate(Session session) throws SQLException {
throw Message.getUnsupportedException();
}
public long getRowCount(Session session) {
throw Message.getInternalError();
}
public boolean canGetRowCount() {
return false;
}
public boolean canDrop() {
return false;
}
public String getTableType() {
return Table.SYSTEM_TABLE;
}
public Index getScanIndex(Session session) throws SQLException {
return new MetaIndex(this, IndexColumn.wrap(columns), true);
}
public ObjectArray getIndexes() {
if (index == null) {
return null;
}
ObjectArray list = new ObjectArray();
list.add(new MetaIndex(this, IndexColumn.wrap(columns), true));
// TODO fixed scan index
list.add(index);
return list;
}
public long getMaxDataModificationId() {
return database.getModificationDataId();
}
public Index getUniqueIndex() {
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -