Program: 15680
Project: 15680
Buggy source:
/** 
 * Generate the data for the given metadata table using the given first and last row filters.
 * @param session the session
 * @param first the first row to return
 * @param last the last row to return
 * @return the generated rows
 */
public ArrayList<Row> generateRows(Session session,SearchRow first,SearchRow last){
  Value indexFrom=null, indexTo=null;
  if (indexColumn >= 0) {
    if (first != null) {
      indexFrom=first.getValue(indexColumn);
    }
    if (last != null) {
      indexTo=last.getValue(indexColumn);
    }
  }
  ArrayList<Row> rows=New.arrayList();
  String catalog=identifier(database.getShortName());
  boolean admin=session.getUser().isAdmin();
switch (type) {
case TABLES:
{
      for (      Table table : getAllTables(session)) {
        String tableName=identifier(table.getName());
        if (!checkIndex(session,tableName,indexFrom,indexTo)) {
          continue;
        }
        if (hideTable(table,session)) {
          continue;
        }
        String storageType;
        if (table.isTemporary()) {
          if (table.isGlobalTemporary()) {
            storageType="String_Node_Str";
          }
 else {
            storageType="String_Node_Str";
          }
        }
 else {
          storageType=table.isPersistIndexes() ? "String_Node_Str" : "String_Node_Str";
        }
        String sql=table.getCreateSQL();
        if (!admin) {
          if (sql != null && sql.contains(JdbcSQLException.HIDE_SQL)) {
            sql="String_Node_Str";
          }
        }
        add(rows,catalog,identifier(table.getSchema().getName()),tableName,table.getTableType().toString(),storageType,sql,replaceNullWithEmpty(table.getComment()),"String_Node_Str" + table.getMaxDataModificationId(),"String_Node_Str" + table.getId(),null,table.getClass().getName(),"String_Node_Str" + table.getRowCountApproximation());
      }
      break;
    }
case COLUMNS:
{
    final ArrayList<Table> tablesToList;
    if (indexFrom != null && indexTo != null && indexFrom.equals(indexTo)) {
      String tableName=identifier(indexFrom.getString());
      tablesToList=getTablesByName(session,tableName);
    }
 else {
      tablesToList=getAllTables(session);
    }
    for (    Table table : tablesToList) {
      String tableName=identifier(table.getName());
      if (!checkIndex(session,tableName,indexFrom,indexTo)) {
        continue;
      }
      if (hideTable(table,session)) {
        continue;
      }
      Column[] cols=table.getColumns();
      String collation=database.getCompareMode().getName();
      for (int j=0; j < cols.length; j++) {
        Column c=cols[j];
        Sequence sequence=c.getSequence();
        add(rows,catalog,identifier(table.getSchema().getName()),tableName,identifier(c.getName()),String.valueOf(j + 1),c.getDefaultSQL(),c.isNullable() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + DataType.convertTypeToSQLType(c.getType()),"String_Node_Str" + c.getPrecisionAsInt(),"String_Node_Str" + c.getPrecisionAsInt(),"String_Node_Str" + c.getPrecisionAsInt(),"String_Node_Str","String_Node_Str" + c.getScale(),CHARACTER_SET_NAME,collation,identifier(DataType.getDataType(c.getType()).name),"String_Node_Str" + (c.isNullable() ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls),"String_Node_Str" + (c.getComputed() ? "String_Node_Str" : "String_Node_Str"),"String_Node_Str" + (c.getSelectivity()),c.getCheckConstraintSQL(session,c.getName()),sequence == null ? null : sequence.getName(),replaceNullWithEmpty(c.getComment()),null);
      }
    }
    break;
  }
case INDEXES:
{
  final ArrayList<Table> tablesToList;
  if (indexFrom != null && indexTo != null && indexFrom.equals(indexTo)) {
    String tableName=identifier(indexFrom.getString());
    tablesToList=getTablesByName(session,tableName);
  }
 else {
    tablesToList=getAllTables(session);
  }
  for (  Table table : tablesToList) {
    String tableName=identifier(table.getName());
    if (!checkIndex(session,tableName,indexFrom,indexTo)) {
      continue;
    }
    if (hideTable(table,session)) {
      continue;
    }
    ArrayList<Index> indexes=table.getIndexes();
    ArrayList<Constraint> constraints=table.getConstraints();
    for (int j=0; indexes != null && j < indexes.size(); j++) {
      Index index=indexes.get(j);
      if (index.getCreateSQL() == null) {
        continue;
      }
      String constraintName=null;
      for (int k=0; constraints != null && k < constraints.size(); k++) {
        Constraint constraint=constraints.get(k);
        if (constraint.usesIndex(index)) {
          if (index.getIndexType().isPrimaryKey()) {
            if (constraint.getConstraintType().equals(Constraint.PRIMARY_KEY)) {
              constraintName=constraint.getName();
            }
          }
 else {
            constraintName=constraint.getName();
          }
        }
      }
      IndexColumn[] cols=index.getIndexColumns();
      String indexClass;
      if (index instanceof MultiVersionIndex) {
        indexClass=((MultiVersionIndex)index).getBaseIndex().getClass().getName();
      }
 else {
        indexClass=index.getClass().getName();
      }
      for (int k=0; k < cols.length; k++) {
        IndexColumn idxCol=cols[k];
        Column column=idxCol.column;
        add(rows,catalog,identifier(table.getSchema().getName()),tableName,index.getIndexType().isUnique() ? "String_Node_Str" : "String_Node_Str",identifier(index.getName()),"String_Node_Str" + (k + 1),identifier(column.getName()),"String_Node_Str",index.getIndexType().isPrimaryKey() ? "String_Node_Str" : "String_Node_Str",index.getIndexType().getSQL(),index.getIndexType().getBelongsToConstraint() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + DatabaseMetaData.tableIndexOther,(idxCol.sortType & SortOrder.DESCENDING) != 0 ? "String_Node_Str" : "String_Node_Str","String_Node_Str","String_Node_Str",replaceNullWithEmpty(index.getComment()),index.getCreateSQL(),"String_Node_Str" + index.getId(),"String_Node_Str" + idxCol.sortType,constraintName,indexClass,index.getIndexType().isAffinity() ? "String_Node_Str" : "String_Node_Str");
      }
    }
  }
  break;
}
case TABLE_TYPES:
{
add(rows,TableType.TABLE.toString());
add(rows,TableType.TABLE_LINK.toString());
add(rows,TableType.SYSTEM_TABLE.toString());
add(rows,TableType.VIEW.toString());
add(rows,TableType.EXTERNAL_TABLE_ENGINE.toString());
break;
}
case CATALOGS:
{
add(rows,catalog);
break;
}
case SETTINGS:
{
for (Setting s : database.getAllSettings()) {
String value=s.getStringValue();
if (value == null) {
value="String_Node_Str" + s.getIntValue();
}
add(rows,identifier(s.getName()),value);
}
add(rows,"String_Node_Str","String_Node_Str" + Constants.BUILD_ID);
add(rows,"String_Node_Str","String_Node_Str" + Constants.VERSION_MAJOR);
add(rows,"String_Node_Str","String_Node_Str" + Constants.VERSION_MINOR);
add(rows,"String_Node_Str","String_Node_Str" + Constants.getFullVersion());
if (admin) {
String[] settings={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
for (String s : settings) {
add(rows,"String_Node_Str" + s,Utils.getProperty(s,"String_Node_Str"));
}
}
add(rows,"String_Node_Str",database.getExclusiveSession() == null ? "String_Node_Str" : "String_Node_Str");
add(rows,"String_Node_Str",database.getMode().getName());
add(rows,"String_Node_Str",database.isMultiThreaded() ? "String_Node_Str" : "String_Node_Str");
add(rows,"String_Node_Str",database.isMultiVersion() ? "String_Node_Str" : "String_Node_Str");
add(rows,"String_Node_Str","String_Node_Str" + session.getQueryTimeout());
add(rows,"String_Node_Str","String_Node_Str" + database.getRetentionTime());
add(rows,"String_Node_Str","String_Node_Str" + database.getLogMode());
ArrayList<String> settingNames=New.arrayList();
HashMap<String,String> s=database.getSettings().getSettings();
for (String k : s.keySet()) {
settingNames.add(k);
}
Collections.sort(settingNames);
for (String k : settingNames) {
add(rows,k,s.get(k));
}
if (database.isPersistent()) {
PageStore store=database.getPageStore();
if (store != null) {
add(rows,"String_Node_Str","String_Node_Str" + store.getWriteCountTotal());
add(rows,"String_Node_Str","String_Node_Str" + store.getWriteCount());
add(rows,"String_Node_Str","String_Node_Str" + store.getReadCount());
add(rows,"String_Node_Str","String_Node_Str" + store.getPageCount());
add(rows,"String_Node_Str","String_Node_Str" + store.getPageSize());
add(rows,"String_Node_Str","String_Node_Str" + store.getCache().getMaxMemory());
add(rows,"String_Node_Str","String_Node_Str" + store.getCache().getMemory());
}
Store mvStore=database.getMvStore();
if (mvStore != null) {
FileStore fs=mvStore.getStore().getFileStore();
add(rows,"String_Node_Str","String_Node_Str" + fs.getWriteCount());
add(rows,"String_Node_Str","String_Node_Str" + fs.getReadCount());
long size;
try {
  size=fs.getFile().size();
}
 catch (IOException e) {
  throw DbException.convertIOException(e,"String_Node_Str");
}
int pageSize=4 * 1024;
long pageCount=size / pageSize;
add(rows,"String_Node_Str","String_Node_Str" + pageCount);
add(rows,"String_Node_Str","String_Node_Str" + pageSize);
add(rows,"String_Node_Str","String_Node_Str" + mvStore.getStore().getCacheSize());
add(rows,"String_Node_Str","String_Node_Str" + mvStore.getStore().getCacheSizeUsed());
}
}
break;
}
case TYPE_INFO:
{
for (DataType t : DataType.getTypes()) {
if (t.hidden || t.sqlType == Value.NULL) {
continue;
}
add(rows,t.name,String.valueOf(t.sqlType),String.valueOf(MathUtils.convertLongToInt(t.maxPrecision)),t.prefix,t.suffix,t.params,String.valueOf(t.autoIncrement),String.valueOf(t.minScale),String.valueOf(t.maxScale),t.decimal ? "String_Node_Str" : null,String.valueOf(t.sqlTypePos),String.valueOf(t.caseSensitive),"String_Node_Str" + DatabaseMetaData.typeNullable,"String_Node_Str" + DatabaseMetaData.typeSearchable);
}
break;
}
case HELP:
{
String resource="String_Node_Str";
try {
byte[] data=Utils.getResource(resource);
Reader reader=new InputStreamReader(new ByteArrayInputStream(data));
Csv csv=new Csv();
csv.setLineCommentCharacter('#');
ResultSet rs=csv.read(reader,null);
for (int i=0; rs.next(); i++) {
add(rows,String.valueOf(i),rs.getString(1).trim(),rs.getString(2).trim(),rs.getString(3).trim(),rs.getString(4).trim());
}
}
 catch (Exception e) {
throw DbException.convert(e);
}
break;
}
case SEQUENCES:
{
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.SEQUENCE)) {
Sequence s=(Sequence)obj;
add(rows,catalog,identifier(s.getSchema().getName()),identifier(s.getName()),String.valueOf(s.getCurrentValue()),String.valueOf(s.getIncrement()),s.getBelongsToTable() ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(s.getComment()),String.valueOf(s.getCacheSize()),String.valueOf(s.getMinValue()),String.valueOf(s.getMaxValue()),s.getCycle() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + s.getId());
}
break;
}
case USERS:
{
for (User u : database.getAllUsers()) {
if (admin || session.getUser() == u) {
add(rows,identifier(u.getName()),String.valueOf(u.isAdmin()),replaceNullWithEmpty(u.getComment()),"String_Node_Str" + u.getId());
}
}
break;
}
case ROLES:
{
for (Role r : database.getAllRoles()) {
if (admin || session.getUser().isRoleGranted(r)) {
add(rows,identifier(r.getName()),replaceNullWithEmpty(r.getComment()),"String_Node_Str" + r.getId());
}
}
break;
}
case RIGHTS:
{
if (admin) {
for (Right r : database.getAllRights()) {
Role role=r.getGrantedRole();
DbObject grantee=r.getGrantee();
String rightType=grantee.getType() == DbObject.USER ? "String_Node_Str" : "String_Node_Str";
if (role == null) {
DbObject object=r.getGrantedObject();
Schema schema=null;
Table table=null;
if (object != null) {
if (object instanceof Schema) {
schema=(Schema)object;
}
 else if (object instanceof Table) {
table=(Table)object;
schema=table.getSchema();
}
}
String tableName=(table != null) ? identifier(table.getName()) : "String_Node_Str";
String schemaName=(schema != null) ? identifier(schema.getName()) : "String_Node_Str";
if (!checkIndex(session,tableName,indexFrom,indexTo)) {
continue;
}
add(rows,identifier(grantee.getName()),rightType,"String_Node_Str",r.getRights(),schemaName,tableName,"String_Node_Str" + r.getId());
}
 else {
add(rows,identifier(grantee.getName()),rightType,identifier(role.getName()),"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str" + r.getId());
}
}
}
break;
}
case FUNCTION_ALIASES:
{
for (SchemaObject aliasAsSchemaObject : database.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)) {
FunctionAlias alias=(FunctionAlias)aliasAsSchemaObject;
JavaMethod[] methods;
try {
methods=alias.getJavaMethods();
}
 catch (DbException e) {
methods=new JavaMethod[0];
}
for (FunctionAlias.JavaMethod method : methods) {
int returnsResult=method.getDataType() == Value.NULL ? DatabaseMetaData.procedureNoResult : DatabaseMetaData.procedureReturnsResult;
add(rows,catalog,alias.getSchema().getName(),identifier(alias.getName()),alias.getJavaClassName(),alias.getJavaMethodName(),"String_Node_Str" + DataType.convertTypeToSQLType(method.getDataType()),DataType.getDataType(method.getDataType()).name,"String_Node_Str" + method.getParameterCount(),"String_Node_Str" + returnsResult,replaceNullWithEmpty(alias.getComment()),"String_Node_Str" + alias.getId(),alias.getSource());
}
}
for (UserAggregate agg : database.getAllAggregates()) {
int returnsResult=DatabaseMetaData.procedureReturnsResult;
add(rows,catalog,Constants.SCHEMA_MAIN,identifier(agg.getName()),agg.getJavaClassName(),"String_Node_Str","String_Node_Str" + DataType.convertTypeToSQLType(Value.NULL),DataType.getDataType(Value.NULL).name,"String_Node_Str","String_Node_Str" + returnsResult,replaceNullWithEmpty(agg.getComment()),"String_Node_Str" + agg.getId(),"String_Node_Str");
}
break;
}
case FUNCTION_COLUMNS:
{
for (SchemaObject aliasAsSchemaObject : database.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)) {
FunctionAlias alias=(FunctionAlias)aliasAsSchemaObject;
JavaMethod[] methods;
try {
methods=alias.getJavaMethods();
}
 catch (DbException e) {
methods=new JavaMethod[0];
}
for (FunctionAlias.JavaMethod method : methods) {
if (method.getDataType() != Value.NULL) {
DataType dt=DataType.getDataType(method.getDataType());
add(rows,catalog,alias.getSchema().getName(),identifier(alias.getName()),alias.getJavaClassName(),alias.getJavaMethodName(),"String_Node_Str" + method.getParameterCount(),"String_Node_Str","String_Node_Str","String_Node_Str" + DataType.convertTypeToSQLType(method.getDataType()),dt.name,"String_Node_Str" + MathUtils.convertLongToInt(dt.defaultPrecision),"String_Node_Str" + dt.defaultScale,"String_Node_Str","String_Node_Str" + DatabaseMetaData.columnNullableUnknown,"String_Node_Str" + DatabaseMetaData.procedureColumnReturn,"String_Node_Str",null);
}
Class<?>[] columnList=method.getColumnClasses();
for (int k=0; k < columnList.length; k++) {
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,catalog,alias.getSchema().getName(),identifier(alias.getName()),alias.getJavaClassName(),alias.getJavaMethodName(),"String_Node_Str" + method.getParameterCount(),"String_Node_Str" + (k + (method.hasConnectionParam() ? 0 : 1)),"String_Node_Str" + (k + 1),"String_Node_Str" + DataType.convertTypeToSQLType(dt.type),dt.name,"String_Node_Str" + MathUtils.convertLongToInt(dt.defaultPrecision),"String_Node_Str" + dt.defaultScale,"String_Node_Str","String_Node_Str" + nullable,"String_Node_Str" + DatabaseMetaData.procedureColumnIn,"String_Node_Str",null);
}
}
}
break;
}
case SCHEMATA:
{
String collation=database.getCompareMode().getName();
for (Schema schema : database.getAllSchemas()) {
add(rows,catalog,identifier(schema.getName()),identifier(schema.getOwner().getName()),CHARACTER_SET_NAME,collation,Constants.SCHEMA_MAIN.equals(schema.getName()) ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(schema.getComment()),"String_Node_Str" + schema.getId());
}
break;
}
case TABLE_PRIVILEGES:
{
for (Right r : database.getAllRights()) {
DbObject object=r.getGrantedObject();
if (!(object instanceof Table)) {
continue;
}
Table table=(Table)object;
if (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()) {
DbObject object=r.getGrantedObject();
if (!(object instanceof Table)) {
continue;
}
Table table=(Table)object;
if (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,CompareMode.getName(l),l.toString());
}
break;
}
case VIEWS:
{
for (Table table : getAllTables(session)) {
if (table.getTableType() != TableType.VIEW) {
continue;
}
String tableName=identifier(table.getName());
if (!checkIndex(session,tableName,indexFrom,indexTo)) {
continue;
}
TableView view=(TableView)table;
add(rows,catalog,identifier(table.getSchema().getName()),tableName,table.getCreateSQL(),"String_Node_Str","String_Node_Str",view.isInvalid() ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(view.getComment()),"String_Node_Str" + view.getId());
}
break;
}
case IN_DOUBT:
{
ArrayList<InDoubtTransaction> prepared=database.getInDoubtTransactions();
if (prepared != null && admin) {
for (InDoubtTransaction prep : prepared) {
add(rows,prep.getTransactionName(),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,catalog,identifier(refTab.getSchema().getName()),identifier(refTab.getName()),identifier(refCols[j].column.getName()),catalog,identifier(tab.getSchema().getName()),identifier(tab.getName()),identifier(cols[j].column.getName()),String.valueOf(j + 1),String.valueOf(update),String.valueOf(delete),identifier(ref.getName()),identifier(ref.getUniqueIndex().getName()),"String_Node_Str" + 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("String_Node_Str");
buff.append(col.column.getName());
}
columnList=buff.toString();
}
add(rows,catalog,identifier(constraint.getSchema().getName()),identifier(constraint.getName()),constraintType,catalog,identifier(table.getSchema().getName()),tableName,uniqueIndexName,checkExpression,columnList,replaceNullWithEmpty(constraint.getComment()),constraint.getCreateSQL(),"String_Node_Str" + constraint.getId());
}
break;
}
case CONSTANTS:
{
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.CONSTANT)) {
Constant constant=(Constant)obj;
ValueExpression expr=constant.getValue();
add(rows,catalog,identifier(constant.getSchema().getName()),identifier(constant.getName()),"String_Node_Str" + DataType.convertTypeToSQLType(expr.getType()),replaceNullWithEmpty(constant.getComment()),expr.getSQL(),"String_Node_Str" + constant.getId());
}
break;
}
case DOMAINS:
{
for (UserDataType dt : database.getAllUserDataTypes()) {
Column col=dt.getColumn();
add(rows,catalog,Constants.SCHEMA_MAIN,identifier(dt.getName()),col.getDefaultSQL(),col.isNullable() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + col.getDataType().sqlType,"String_Node_Str" + col.getPrecisionAsInt(),"String_Node_Str" + col.getScale(),col.getDataType().name,"String_Node_Str" + col.getSelectivity(),"String_Node_Str" + col.getCheckConstraintSQL(session,"String_Node_Str"),replaceNullWithEmpty(dt.getComment()),"String_Node_Str" + dt.getCreateSQL(),"String_Node_Str" + dt.getId());
}
break;
}
case TRIGGERS:
{
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.TRIGGER)) {
TriggerObject trigger=(TriggerObject)obj;
Table table=trigger.getTable();
add(rows,catalog,identifier(trigger.getSchema().getName()),identifier(trigger.getName()),trigger.getTypeNameList(),catalog,identifier(table.getSchema().getName()),identifier(table.getName()),"String_Node_Str" + trigger.isBefore(),trigger.getTriggerClassName(),"String_Node_Str" + trigger.getQueueSize(),"String_Node_Str" + trigger.isNoWait(),replaceNullWithEmpty(trigger.getComment()),trigger.getCreateSQL(),"String_Node_Str" + 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,"String_Node_Str" + s.getId(),s.getUser().getName(),new Timestamp(s.getSessionStart()).toString(),command == null ? null : command.toString(),new Timestamp(start).toString(),"String_Node_Str" + s.containsUncommitted());
}
}
break;
}
case LOCKS:
{
for (Session s : database.getSessions(false)) {
if (admin || s == session) {
for (Table table : s.getLocks()) {
add(rows,table.getSchema().getName(),table.getName(),"String_Node_Str" + s.getId(),table.isLockedExclusivelyBy(s) ? "String_Node_Str" : "String_Node_Str");
}
}
}
break;
}
case SESSION_STATE:
{
for (String name : session.getVariableNames()) {
Value v=session.getVariable(name);
add(rows,"String_Node_Str" + name,"String_Node_Str" + name + "String_Node_Str"+ v.getSQL());
}
for (Table table : session.getLocalTempTables()) {
add(rows,"String_Node_Str" + table.getName(),table.getCreateSQL());
}
String[] path=session.getSchemaSearchPath();
if (path != null && path.length > 0) {
StatementBuilder buff=new StatementBuilder("String_Node_Str");
for (String p : path) {
buff.appendExceptFirst("String_Node_Str");
buff.append(StringUtils.quoteIdentifier(p));
}
add(rows,"String_Node_Str",buff.toString());
}
String schema=session.getCurrentSchemaName();
if (schema != null) {
add(rows,"String_Node_Str","String_Node_Str" + StringUtils.quoteIdentifier(schema));
}
break;
}
case QUERY_STATISTICS:
{
QueryStatisticsData control=database.getQueryStatisticsData();
if (control != null) {
for (QueryStatisticsData.QueryEntry entry : control.getQueries()) {
add(rows,entry.sqlStatement,"String_Node_Str" + entry.count,"String_Node_Str" + entry.executionTimeMinNanos / 1000d / 1000,"String_Node_Str" + entry.executionTimeMaxNanos / 1000d / 1000,"String_Node_Str" + entry.executionTimeCumulativeNanos / 1000d / 1000,"String_Node_Str" + entry.executionTimeMeanNanos / 1000d / 1000,"String_Node_Str" + entry.getExecutionTimeStandardDeviation() / 1000d / 1000,"String_Node_Str" + entry.rowCountMin,"String_Node_Str" + entry.rowCountMax,"String_Node_Str" + entry.rowCountCumulative,"String_Node_Str" + entry.rowCountMean,"String_Node_Str" + entry.getRowCountStandardDeviation());
}
}
break;
}
case SYNONYMS:
{
for (Table table : getAllTables(session)) {
if (!table.getTableType().equals(Table.SYNONYM)) {
continue;
}
String synonymName=identifier(table.getName());
TableSynonym synonym=(TableSynonym)table;
add(rows,catalog,identifier(table.getSchema().getName()),synonymName,synonym.getSynonymForName(),synonym.isInvalid() ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(synonym.getComment()),"String_Node_Str" + synonym.getId());
}
break;
}
default :
DbException.throwInternalError("String_Node_Str" + type);
}
return rows;
}

Fixed version (ground truth):
/** 
 * Generate the data for the given metadata table using the given first and last row filters.
 * @param session the session
 * @param first the first row to return
 * @param last the last row to return
 * @return the generated rows
 */
public ArrayList<Row> generateRows(Session session,SearchRow first,SearchRow last){
  Value indexFrom=null, indexTo=null;
  if (indexColumn >= 0) {
    if (first != null) {
      indexFrom=first.getValue(indexColumn);
    }
    if (last != null) {
      indexTo=last.getValue(indexColumn);
    }
  }
  ArrayList<Row> rows=New.arrayList();
  String catalog=identifier(database.getShortName());
  boolean admin=session.getUser().isAdmin();
switch (type) {
case TABLES:
{
      for (      Table table : getAllTables(session)) {
        String tableName=identifier(table.getName());
        if (!checkIndex(session,tableName,indexFrom,indexTo)) {
          continue;
        }
        if (hideTable(table,session)) {
          continue;
        }
        String storageType;
        if (table.isTemporary()) {
          if (table.isGlobalTemporary()) {
            storageType="String_Node_Str";
          }
 else {
            storageType="String_Node_Str";
          }
        }
 else {
          storageType=table.isPersistIndexes() ? "String_Node_Str" : "String_Node_Str";
        }
        String sql=table.getCreateSQL();
        if (!admin) {
          if (sql != null && sql.contains(JdbcSQLException.HIDE_SQL)) {
            sql="String_Node_Str";
          }
        }
        add(rows,catalog,identifier(table.getSchema().getName()),tableName,table.getTableType().toString(),storageType,sql,replaceNullWithEmpty(table.getComment()),"String_Node_Str" + table.getMaxDataModificationId(),"String_Node_Str" + table.getId(),null,table.getClass().getName(),"String_Node_Str" + table.getRowCountApproximation());
      }
      break;
    }
case COLUMNS:
{
    final ArrayList<Table> tablesToList;
    if (indexFrom != null && indexTo != null && indexFrom.equals(indexTo)) {
      String tableName=identifier(indexFrom.getString());
      tablesToList=getTablesByName(session,tableName);
    }
 else {
      tablesToList=getAllTables(session);
    }
    for (    Table table : tablesToList) {
      String tableName=identifier(table.getName());
      if (!checkIndex(session,tableName,indexFrom,indexTo)) {
        continue;
      }
      if (hideTable(table,session)) {
        continue;
      }
      Column[] cols=table.getColumns();
      String collation=database.getCompareMode().getName();
      for (int j=0; j < cols.length; j++) {
        Column c=cols[j];
        Sequence sequence=c.getSequence();
        add(rows,catalog,identifier(table.getSchema().getName()),tableName,identifier(c.getName()),String.valueOf(j + 1),c.getDefaultSQL(),c.isNullable() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + DataType.convertTypeToSQLType(c.getType()),"String_Node_Str" + c.getPrecisionAsInt(),"String_Node_Str" + c.getPrecisionAsInt(),"String_Node_Str" + c.getPrecisionAsInt(),"String_Node_Str","String_Node_Str" + c.getScale(),CHARACTER_SET_NAME,collation,identifier(DataType.getDataType(c.getType()).name),"String_Node_Str" + (c.isNullable() ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls),"String_Node_Str" + (c.getComputed() ? "String_Node_Str" : "String_Node_Str"),"String_Node_Str" + (c.getSelectivity()),c.getCheckConstraintSQL(session,c.getName()),sequence == null ? null : sequence.getName(),replaceNullWithEmpty(c.getComment()),null);
      }
    }
    break;
  }
case INDEXES:
{
  final ArrayList<Table> tablesToList;
  if (indexFrom != null && indexTo != null && indexFrom.equals(indexTo)) {
    String tableName=identifier(indexFrom.getString());
    tablesToList=getTablesByName(session,tableName);
  }
 else {
    tablesToList=getAllTables(session);
  }
  for (  Table table : tablesToList) {
    String tableName=identifier(table.getName());
    if (!checkIndex(session,tableName,indexFrom,indexTo)) {
      continue;
    }
    if (hideTable(table,session)) {
      continue;
    }
    ArrayList<Index> indexes=table.getIndexes();
    ArrayList<Constraint> constraints=table.getConstraints();
    for (int j=0; indexes != null && j < indexes.size(); j++) {
      Index index=indexes.get(j);
      if (index.getCreateSQL() == null) {
        continue;
      }
      String constraintName=null;
      for (int k=0; constraints != null && k < constraints.size(); k++) {
        Constraint constraint=constraints.get(k);
        if (constraint.usesIndex(index)) {
          if (index.getIndexType().isPrimaryKey()) {
            if (constraint.getConstraintType().equals(Constraint.PRIMARY_KEY)) {
              constraintName=constraint.getName();
            }
          }
 else {
            constraintName=constraint.getName();
          }
        }
      }
      IndexColumn[] cols=index.getIndexColumns();
      String indexClass;
      if (index instanceof MultiVersionIndex) {
        indexClass=((MultiVersionIndex)index).getBaseIndex().getClass().getName();
      }
 else {
        indexClass=index.getClass().getName();
      }
      for (int k=0; k < cols.length; k++) {
        IndexColumn idxCol=cols[k];
        Column column=idxCol.column;
        add(rows,catalog,identifier(table.getSchema().getName()),tableName,index.getIndexType().isUnique() ? "String_Node_Str" : "String_Node_Str",identifier(index.getName()),"String_Node_Str" + (k + 1),identifier(column.getName()),"String_Node_Str",index.getIndexType().isPrimaryKey() ? "String_Node_Str" : "String_Node_Str",index.getIndexType().getSQL(),index.getIndexType().getBelongsToConstraint() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + DatabaseMetaData.tableIndexOther,(idxCol.sortType & SortOrder.DESCENDING) != 0 ? "String_Node_Str" : "String_Node_Str","String_Node_Str","String_Node_Str",replaceNullWithEmpty(index.getComment()),index.getCreateSQL(),"String_Node_Str" + index.getId(),"String_Node_Str" + idxCol.sortType,constraintName,indexClass,index.getIndexType().isAffinity() ? "String_Node_Str" : "String_Node_Str");
      }
    }
  }
  break;
}
case TABLE_TYPES:
{
add(rows,TableType.TABLE.toString());
add(rows,TableType.TABLE_LINK.toString());
add(rows,TableType.SYSTEM_TABLE.toString());
add(rows,TableType.VIEW.toString());
add(rows,TableType.EXTERNAL_TABLE_ENGINE.toString());
break;
}
case CATALOGS:
{
add(rows,catalog);
break;
}
case SETTINGS:
{
for (Setting s : database.getAllSettings()) {
String value=s.getStringValue();
if (value == null) {
value="String_Node_Str" + s.getIntValue();
}
add(rows,identifier(s.getName()),value);
}
add(rows,"String_Node_Str","String_Node_Str" + Constants.BUILD_ID);
add(rows,"String_Node_Str","String_Node_Str" + Constants.VERSION_MAJOR);
add(rows,"String_Node_Str","String_Node_Str" + Constants.VERSION_MINOR);
add(rows,"String_Node_Str","String_Node_Str" + Constants.getFullVersion());
if (admin) {
String[] settings={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
for (String s : settings) {
add(rows,"String_Node_Str" + s,Utils.getProperty(s,"String_Node_Str"));
}
}
add(rows,"String_Node_Str",database.getExclusiveSession() == null ? "String_Node_Str" : "String_Node_Str");
add(rows,"String_Node_Str",database.getMode().getName());
add(rows,"String_Node_Str",database.isMultiThreaded() ? "String_Node_Str" : "String_Node_Str");
add(rows,"String_Node_Str",database.isMultiVersion() ? "String_Node_Str" : "String_Node_Str");
add(rows,"String_Node_Str","String_Node_Str" + session.getQueryTimeout());
add(rows,"String_Node_Str","String_Node_Str" + database.getRetentionTime());
add(rows,"String_Node_Str","String_Node_Str" + database.getLogMode());
ArrayList<String> settingNames=New.arrayList();
HashMap<String,String> s=database.getSettings().getSettings();
for (String k : s.keySet()) {
settingNames.add(k);
}
Collections.sort(settingNames);
for (String k : settingNames) {
add(rows,k,s.get(k));
}
if (database.isPersistent()) {
PageStore store=database.getPageStore();
if (store != null) {
add(rows,"String_Node_Str","String_Node_Str" + store.getWriteCountTotal());
add(rows,"String_Node_Str","String_Node_Str" + store.getWriteCount());
add(rows,"String_Node_Str","String_Node_Str" + store.getReadCount());
add(rows,"String_Node_Str","String_Node_Str" + store.getPageCount());
add(rows,"String_Node_Str","String_Node_Str" + store.getPageSize());
add(rows,"String_Node_Str","String_Node_Str" + store.getCache().getMaxMemory());
add(rows,"String_Node_Str","String_Node_Str" + store.getCache().getMemory());
}
Store mvStore=database.getMvStore();
if (mvStore != null) {
FileStore fs=mvStore.getStore().getFileStore();
add(rows,"String_Node_Str","String_Node_Str" + fs.getWriteCount());
add(rows,"String_Node_Str","String_Node_Str" + fs.getReadCount());
long size;
try {
  size=fs.getFile().size();
}
 catch (IOException e) {
  throw DbException.convertIOException(e,"String_Node_Str");
}
int pageSize=4 * 1024;
long pageCount=size / pageSize;
add(rows,"String_Node_Str","String_Node_Str" + pageCount);
add(rows,"String_Node_Str","String_Node_Str" + pageSize);
add(rows,"String_Node_Str","String_Node_Str" + mvStore.getStore().getCacheSize());
add(rows,"String_Node_Str","String_Node_Str" + mvStore.getStore().getCacheSizeUsed());
}
}
break;
}
case TYPE_INFO:
{
for (DataType t : DataType.getTypes()) {
if (t.hidden || t.sqlType == Value.NULL) {
continue;
}
add(rows,t.name,String.valueOf(t.sqlType),String.valueOf(MathUtils.convertLongToInt(t.maxPrecision)),t.prefix,t.suffix,t.params,String.valueOf(t.autoIncrement),String.valueOf(t.minScale),String.valueOf(t.maxScale),t.decimal ? "String_Node_Str" : null,String.valueOf(t.sqlTypePos),String.valueOf(t.caseSensitive),"String_Node_Str" + DatabaseMetaData.typeNullable,"String_Node_Str" + DatabaseMetaData.typeSearchable);
}
break;
}
case HELP:
{
String resource="String_Node_Str";
try {
byte[] data=Utils.getResource(resource);
Reader reader=new InputStreamReader(new ByteArrayInputStream(data));
Csv csv=new Csv();
csv.setLineCommentCharacter('#');
ResultSet rs=csv.read(reader,null);
for (int i=0; rs.next(); i++) {
add(rows,String.valueOf(i),rs.getString(1).trim(),rs.getString(2).trim(),rs.getString(3).trim(),rs.getString(4).trim());
}
}
 catch (Exception e) {
throw DbException.convert(e);
}
break;
}
case SEQUENCES:
{
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.SEQUENCE)) {
Sequence s=(Sequence)obj;
add(rows,catalog,identifier(s.getSchema().getName()),identifier(s.getName()),String.valueOf(s.getCurrentValue()),String.valueOf(s.getIncrement()),s.getBelongsToTable() ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(s.getComment()),String.valueOf(s.getCacheSize()),String.valueOf(s.getMinValue()),String.valueOf(s.getMaxValue()),s.getCycle() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + s.getId());
}
break;
}
case USERS:
{
for (User u : database.getAllUsers()) {
if (admin || session.getUser() == u) {
add(rows,identifier(u.getName()),String.valueOf(u.isAdmin()),replaceNullWithEmpty(u.getComment()),"String_Node_Str" + u.getId());
}
}
break;
}
case ROLES:
{
for (Role r : database.getAllRoles()) {
if (admin || session.getUser().isRoleGranted(r)) {
add(rows,identifier(r.getName()),replaceNullWithEmpty(r.getComment()),"String_Node_Str" + r.getId());
}
}
break;
}
case RIGHTS:
{
if (admin) {
for (Right r : database.getAllRights()) {
Role role=r.getGrantedRole();
DbObject grantee=r.getGrantee();
String rightType=grantee.getType() == DbObject.USER ? "String_Node_Str" : "String_Node_Str";
if (role == null) {
DbObject object=r.getGrantedObject();
Schema schema=null;
Table table=null;
if (object != null) {
if (object instanceof Schema) {
schema=(Schema)object;
}
 else if (object instanceof Table) {
table=(Table)object;
schema=table.getSchema();
}
}
String tableName=(table != null) ? identifier(table.getName()) : "String_Node_Str";
String schemaName=(schema != null) ? identifier(schema.getName()) : "String_Node_Str";
if (!checkIndex(session,tableName,indexFrom,indexTo)) {
continue;
}
add(rows,identifier(grantee.getName()),rightType,"String_Node_Str",r.getRights(),schemaName,tableName,"String_Node_Str" + r.getId());
}
 else {
add(rows,identifier(grantee.getName()),rightType,identifier(role.getName()),"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str" + r.getId());
}
}
}
break;
}
case FUNCTION_ALIASES:
{
for (SchemaObject aliasAsSchemaObject : database.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)) {
FunctionAlias alias=(FunctionAlias)aliasAsSchemaObject;
JavaMethod[] methods;
try {
methods=alias.getJavaMethods();
}
 catch (DbException e) {
methods=new JavaMethod[0];
}
for (FunctionAlias.JavaMethod method : methods) {
int returnsResult=method.getDataType() == Value.NULL ? DatabaseMetaData.procedureNoResult : DatabaseMetaData.procedureReturnsResult;
add(rows,catalog,alias.getSchema().getName(),identifier(alias.getName()),alias.getJavaClassName(),alias.getJavaMethodName(),"String_Node_Str" + DataType.convertTypeToSQLType(method.getDataType()),DataType.getDataType(method.getDataType()).name,"String_Node_Str" + method.getParameterCount(),"String_Node_Str" + returnsResult,replaceNullWithEmpty(alias.getComment()),"String_Node_Str" + alias.getId(),alias.getSource());
}
}
for (UserAggregate agg : database.getAllAggregates()) {
int returnsResult=DatabaseMetaData.procedureReturnsResult;
add(rows,catalog,Constants.SCHEMA_MAIN,identifier(agg.getName()),agg.getJavaClassName(),"String_Node_Str","String_Node_Str" + DataType.convertTypeToSQLType(Value.NULL),DataType.getDataType(Value.NULL).name,"String_Node_Str","String_Node_Str" + returnsResult,replaceNullWithEmpty(agg.getComment()),"String_Node_Str" + agg.getId(),"String_Node_Str");
}
break;
}
case FUNCTION_COLUMNS:
{
for (SchemaObject aliasAsSchemaObject : database.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)) {
FunctionAlias alias=(FunctionAlias)aliasAsSchemaObject;
JavaMethod[] methods;
try {
methods=alias.getJavaMethods();
}
 catch (DbException e) {
methods=new JavaMethod[0];
}
for (FunctionAlias.JavaMethod method : methods) {
if (method.getDataType() != Value.NULL) {
DataType dt=DataType.getDataType(method.getDataType());
add(rows,catalog,alias.getSchema().getName(),identifier(alias.getName()),alias.getJavaClassName(),alias.getJavaMethodName(),"String_Node_Str" + method.getParameterCount(),"String_Node_Str","String_Node_Str","String_Node_Str" + DataType.convertTypeToSQLType(method.getDataType()),dt.name,"String_Node_Str" + MathUtils.convertLongToInt(dt.defaultPrecision),"String_Node_Str" + dt.defaultScale,"String_Node_Str","String_Node_Str" + DatabaseMetaData.columnNullableUnknown,"String_Node_Str" + DatabaseMetaData.procedureColumnReturn,"String_Node_Str",null);
}
Class<?>[] columnList=method.getColumnClasses();
for (int k=0; k < columnList.length; k++) {
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,catalog,alias.getSchema().getName(),identifier(alias.getName()),alias.getJavaClassName(),alias.getJavaMethodName(),"String_Node_Str" + method.getParameterCount(),"String_Node_Str" + (k + (method.hasConnectionParam() ? 0 : 1)),"String_Node_Str" + (k + 1),"String_Node_Str" + DataType.convertTypeToSQLType(dt.type),dt.name,"String_Node_Str" + MathUtils.convertLongToInt(dt.defaultPrecision),"String_Node_Str" + dt.defaultScale,"String_Node_Str","String_Node_Str" + nullable,"String_Node_Str" + DatabaseMetaData.procedureColumnIn,"String_Node_Str",null);
}
}
}
break;
}
case SCHEMATA:
{
String collation=database.getCompareMode().getName();
for (Schema schema : database.getAllSchemas()) {
add(rows,catalog,identifier(schema.getName()),identifier(schema.getOwner().getName()),CHARACTER_SET_NAME,collation,Constants.SCHEMA_MAIN.equals(schema.getName()) ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(schema.getComment()),"String_Node_Str" + schema.getId());
}
break;
}
case TABLE_PRIVILEGES:
{
for (Right r : database.getAllRights()) {
DbObject object=r.getGrantedObject();
if (!(object instanceof Table)) {
continue;
}
Table table=(Table)object;
if (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()) {
DbObject object=r.getGrantedObject();
if (!(object instanceof Table)) {
continue;
}
Table table=(Table)object;
if (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,CompareMode.getName(l),l.toString());
}
break;
}
case VIEWS:
{
for (Table table : getAllTables(session)) {
if (table.getTableType() != TableType.VIEW) {
continue;
}
String tableName=identifier(table.getName());
if (!checkIndex(session,tableName,indexFrom,indexTo)) {
continue;
}
TableView view=(TableView)table;
add(rows,catalog,identifier(table.getSchema().getName()),tableName,table.getCreateSQL(),"String_Node_Str","String_Node_Str",view.isInvalid() ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(view.getComment()),"String_Node_Str" + view.getId());
}
break;
}
case IN_DOUBT:
{
ArrayList<InDoubtTransaction> prepared=database.getInDoubtTransactions();
if (prepared != null && admin) {
for (InDoubtTransaction prep : prepared) {
add(rows,prep.getTransactionName(),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,catalog,identifier(refTab.getSchema().getName()),identifier(refTab.getName()),identifier(refCols[j].column.getName()),catalog,identifier(tab.getSchema().getName()),identifier(tab.getName()),identifier(cols[j].column.getName()),String.valueOf(j + 1),String.valueOf(update),String.valueOf(delete),identifier(ref.getName()),identifier(ref.getUniqueIndex().getName()),"String_Node_Str" + 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("String_Node_Str");
buff.append(col.column.getName());
}
columnList=buff.toString();
}
add(rows,catalog,identifier(constraint.getSchema().getName()),identifier(constraint.getName()),constraintType,catalog,identifier(table.getSchema().getName()),tableName,uniqueIndexName,checkExpression,columnList,replaceNullWithEmpty(constraint.getComment()),constraint.getCreateSQL(),"String_Node_Str" + constraint.getId());
}
break;
}
case CONSTANTS:
{
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.CONSTANT)) {
Constant constant=(Constant)obj;
ValueExpression expr=constant.getValue();
add(rows,catalog,identifier(constant.getSchema().getName()),identifier(constant.getName()),"String_Node_Str" + DataType.convertTypeToSQLType(expr.getType()),replaceNullWithEmpty(constant.getComment()),expr.getSQL(),"String_Node_Str" + constant.getId());
}
break;
}
case DOMAINS:
{
for (UserDataType dt : database.getAllUserDataTypes()) {
Column col=dt.getColumn();
add(rows,catalog,Constants.SCHEMA_MAIN,identifier(dt.getName()),col.getDefaultSQL(),col.isNullable() ? "String_Node_Str" : "String_Node_Str","String_Node_Str" + col.getDataType().sqlType,"String_Node_Str" + col.getPrecisionAsInt(),"String_Node_Str" + col.getScale(),col.getDataType().name,"String_Node_Str" + col.getSelectivity(),"String_Node_Str" + col.getCheckConstraintSQL(session,"String_Node_Str"),replaceNullWithEmpty(dt.getComment()),"String_Node_Str" + dt.getCreateSQL(),"String_Node_Str" + dt.getId());
}
break;
}
case TRIGGERS:
{
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.TRIGGER)) {
TriggerObject trigger=(TriggerObject)obj;
Table table=trigger.getTable();
add(rows,catalog,identifier(trigger.getSchema().getName()),identifier(trigger.getName()),trigger.getTypeNameList(),catalog,identifier(table.getSchema().getName()),identifier(table.getName()),"String_Node_Str" + trigger.isBefore(),trigger.getTriggerClassName(),"String_Node_Str" + trigger.getQueueSize(),"String_Node_Str" + trigger.isNoWait(),replaceNullWithEmpty(trigger.getComment()),trigger.getCreateSQL(),"String_Node_Str" + 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,"String_Node_Str" + s.getId(),s.getUser().getName(),new Timestamp(s.getSessionStart()).toString(),command == null ? null : command.toString(),new Timestamp(start).toString(),"String_Node_Str" + s.containsUncommitted());
}
}
break;
}
case LOCKS:
{
for (Session s : database.getSessions(false)) {
if (admin || s == session) {
for (Table table : s.getLocks()) {
add(rows,table.getSchema().getName(),table.getName(),"String_Node_Str" + s.getId(),table.isLockedExclusivelyBy(s) ? "String_Node_Str" : "String_Node_Str");
}
}
}
break;
}
case SESSION_STATE:
{
for (String name : session.getVariableNames()) {
Value v=session.getVariable(name);
add(rows,"String_Node_Str" + name,"String_Node_Str" + name + "String_Node_Str"+ v.getSQL());
}
for (Table table : session.getLocalTempTables()) {
add(rows,"String_Node_Str" + table.getName(),table.getCreateSQL());
}
String[] path=session.getSchemaSearchPath();
if (path != null && path.length > 0) {
StatementBuilder buff=new StatementBuilder("String_Node_Str");
for (String p : path) {
buff.appendExceptFirst("String_Node_Str");
buff.append(StringUtils.quoteIdentifier(p));
}
add(rows,"String_Node_Str",buff.toString());
}
String schema=session.getCurrentSchemaName();
if (schema != null) {
add(rows,"String_Node_Str","String_Node_Str" + StringUtils.quoteIdentifier(schema));
}
break;
}
case QUERY_STATISTICS:
{
QueryStatisticsData control=database.getQueryStatisticsData();
if (control != null) {
for (QueryStatisticsData.QueryEntry entry : control.getQueries()) {
add(rows,entry.sqlStatement,"String_Node_Str" + entry.count,"String_Node_Str" + entry.executionTimeMinNanos / 1000d / 1000,"String_Node_Str" + entry.executionTimeMaxNanos / 1000d / 1000,"String_Node_Str" + entry.executionTimeCumulativeNanos / 1000d / 1000,"String_Node_Str" + entry.executionTimeMeanNanos / 1000d / 1000,"String_Node_Str" + entry.getExecutionTimeStandardDeviation() / 1000d / 1000,"String_Node_Str" + entry.rowCountMin,"String_Node_Str" + entry.rowCountMax,"String_Node_Str" + entry.rowCountCumulative,"String_Node_Str" + entry.rowCountMean,"String_Node_Str" + entry.getRowCountStandardDeviation());
}
}
break;
}
case SYNONYMS:
{
for (Table table : getAllTables(session)) {
if (!table.getTableType().equals(TableType.SYNONYM)) {
continue;
}
String synonymName=identifier(table.getName());
TableSynonym synonym=(TableSynonym)table;
add(rows,catalog,identifier(table.getSchema().getName()),synonymName,synonym.getSynonymForName(),synonym.isInvalid() ? "String_Node_Str" : "String_Node_Str",replaceNullWithEmpty(synonym.getComment()),"String_Node_Str" + synonym.getId());
}
break;
}
default :
DbException.throwInternalError("String_Node_Str" + type);
}
return rows;
}