@Override public ResultSet getCatalogs() throws SQLException { StringBuilder buf = new StringBuilder("select \n" + " DISTINCT " + TENANT_ID + " " + TABLE_CAT + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null" + " and " + COLUMN_FAMILY + " is null" + " and " + TENANT_ID + " is not null"); addTenantIdFilter(buf, null); buf.append(" order by " + TENANT_ID); Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
@Override // TODO does this need to change to use the PARENT_TABLE link public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { StringBuilder buf = new StringBuilder("select \n" + TENANT_ID + " " + TABLE_CAT + "," + // Use tenantId for catalog TABLE_SCHEM + "," + TABLE_NAME + "," + COLUMN_FAMILY + " " + SUPERTABLE_NAME + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null" + " and " + LINK_TYPE + " = " + LinkType.PHYSICAL_TABLE.getSerializedValue()); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + (schemaPattern.length() == 0 ? " is null" : " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'" )); } if (tableNamePattern != null) { buf.append(" and " + TABLE_NAME + " like '" + StringUtil.escapeStringConstant(tableNamePattern) + "'" ); } buf.append(" order by " + TENANT_ID + "," + TABLE_SCHEM + "," +TABLE_NAME + "," + SUPERTABLE_NAME); Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
@Override public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { StringBuilder buf = new StringBuilder("select distinct \n" + TABLE_SCHEM + "," + TENANT_ID + " " + TABLE_CATALOG + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null"); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'"); } if (SchemaUtil.isNamespaceMappingEnabled(null, connection.getQueryServices().getProps())) { buf.append(" and " + TABLE_NAME + " = '" + MetaDataClient.EMPTY_TABLE + "'"); } // TODO: we should union this with SYSTEM.SEQUENCE too, but we only have support for // UNION ALL and we really need UNION so that it dedups. Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
buf.append("\nand " + DATA_TABLE_NAME + " = '" + StringUtil.escapeStringConstant(table) + "'" ); buf.append("\nand " + COLUMN_NAME + " is not null" ); addTenantIdFilter(buf, catalog); buf.append("\norder by INDEX_NAME," + ORDINAL_POSITION); Statement stmt = connection.createStatement();
" and " + COLUMN_FAMILY + " is null" + " and " + TABLE_NAME + " != '" + MetaDataClient.EMPTY_TABLE + "'"); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + (schemaPattern.length() == 0 ? " is null" : " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'" )); " from " + SYSTEM_SEQUENCE + "\n"); StringBuilder whereClause = new StringBuilder(); addTenantIdFilter(whereClause, catalog); if (schemaPattern != null) { appendConjunction(whereClause);
@Override public ResultSet getCatalogs() throws SQLException { StringBuilder buf = new StringBuilder("select \n" + " DISTINCT " + TENANT_ID + " " + TABLE_CAT + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null" + " and " + COLUMN_FAMILY + " is null" + " and " + TENANT_ID + " is not null"); addTenantIdFilter(buf, null); buf.append(" order by " + TENANT_ID); Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
@Override public ResultSet getCatalogs() throws SQLException { StringBuilder buf = new StringBuilder("select \n" + " DISTINCT " + TENANT_ID + " " + TABLE_CAT + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null" + " and " + COLUMN_FAMILY + " is null" + " and " + TENANT_ID + " is not null"); addTenantIdFilter(buf, null); buf.append(" order by " + TENANT_ID); Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
@Override // TODO does this need to change to use the PARENT_TABLE link public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { StringBuilder buf = new StringBuilder("select \n" + TENANT_ID + " " + TABLE_CAT + "," + // Use tenantId for catalog TABLE_SCHEM + "," + TABLE_NAME + "," + COLUMN_FAMILY + " " + SUPERTABLE_NAME + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null" + " and " + LINK_TYPE + " = " + LinkType.PHYSICAL_TABLE.getSerializedValue()); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + (schemaPattern.length() == 0 ? " is null" : " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'" )); } if (tableNamePattern != null) { buf.append(" and " + TABLE_NAME + " like '" + StringUtil.escapeStringConstant(tableNamePattern) + "'" ); } buf.append(" order by " + TENANT_ID + "," + TABLE_SCHEM + "," +TABLE_NAME + "," + SUPERTABLE_NAME); Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
@Override public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { StringBuilder buf = new StringBuilder("select \n" + TENANT_ID + " " + TABLE_CAT + "," + // Use tenantId for catalog TABLE_SCHEM + "," + TABLE_NAME + "," + COLUMN_FAMILY + " " + SUPERTABLE_NAME + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null" + " and " + LINK_TYPE + " = " + LinkType.PHYSICAL_TABLE.getSerializedValue()); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + (schemaPattern.length() == 0 ? " is null" : " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'" )); } if (tableNamePattern != null) { buf.append(" and " + TABLE_NAME + " like '" + StringUtil.escapeStringConstant(tableNamePattern) + "'" ); } buf.append(" order by " + TENANT_ID + "," + TABLE_SCHEM + "," +TABLE_NAME + "," + SUPERTABLE_NAME); Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
@Override public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { if (table == null || table.length() == 0) { return emptyResultSet; } StringBuilder buf = new StringBuilder("select \n" + TENANT_ID + " " + TABLE_CAT + "," + // use catalog for tenant_id TABLE_SCHEM + "," + TABLE_NAME + " ," + COLUMN_NAME + "," + KEY_SEQ + "," + PK_NAME + "," + "CASE WHEN " + SORT_ORDER + " = " + (SortOrder.DESC.getSystemValue()) + " THEN 'D' ELSE 'A' END ASC_OR_DESC," + ExternalSqlTypeIdFunction.NAME + "(" + DATA_TYPE + ") AS " + DATA_TYPE + "," + SqlTypeNameFunction.NAME + "(" + DATA_TYPE + ") AS " + TYPE_NAME + "," + COLUMN_SIZE + "," + DATA_TYPE + " " + TYPE_ID + "," + // raw type id VIEW_CONSTANT + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where "); buf.append(TABLE_SCHEM + (schema == null || schema.length() == 0 ? " is null" : " = '" + StringUtil.escapeStringConstant(schema) + "'" )); buf.append(" and " + TABLE_NAME + " = '" + StringUtil.escapeStringConstant(table) + "'" ); buf.append(" and " + COLUMN_NAME + " is not null"); buf.append(" and " + COLUMN_FAMILY + " is null"); addTenantIdFilter(buf, catalog); buf.append(" order by " + TENANT_ID + "," + TABLE_SCHEM + "," + TABLE_NAME + " ," + COLUMN_NAME); ResultSet rs = connection.createStatement().executeQuery(buf.toString()); return rs; }
@Override public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { StringBuilder buf = new StringBuilder("select distinct \n" + TABLE_SCHEM + "," + TENANT_ID + " " + TABLE_CATALOG + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null"); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'"); } if (SchemaUtil.isNamespaceMappingEnabled(null, connection.getQueryServices().getProps())) { buf.append(" and " + TABLE_NAME + " = '" + MetaDataClient.EMPTY_TABLE + "'"); } // TODO: we should union this with SYSTEM.SEQUENCE too, but we only have support for // UNION ALL and we really need UNION so that it dedups. Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
@Override public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { StringBuilder buf = new StringBuilder("select distinct \n" + TABLE_SCHEM + "," + TENANT_ID + " " + TABLE_CATALOG + " from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + " where " + COLUMN_NAME + " is null"); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'"); } if (SchemaUtil.isNamespaceMappingEnabled(null, connection.getQueryServices().getProps())) { buf.append(" and " + TABLE_NAME + " = '" + MetaDataClient.EMPTY_TABLE + "'"); } // TODO: we should union this with SYSTEM.SEQUENCE too, but we only have support for // UNION ALL and we really need UNION so that it dedups. Statement stmt = connection.createStatement(); return stmt.executeQuery(buf.toString()); }
buf.append("\nand " + DATA_TABLE_NAME + " = '" + StringUtil.escapeStringConstant(table) + "'" ); buf.append("\nand " + COLUMN_NAME + " is not null" ); addTenantIdFilter(buf, catalog); buf.append("\norder by INDEX_NAME," + ORDINAL_POSITION); Statement stmt = connection.createStatement();
buf.append("\nand " + DATA_TABLE_NAME + " = '" + StringUtil.escapeStringConstant(table) + "'" ); buf.append("\nand " + COLUMN_NAME + " is not null" ); addTenantIdFilter(buf, catalog); buf.append("\norder by INDEX_NAME," + ORDINAL_POSITION); Statement stmt = connection.createStatement();
" and " + COLUMN_FAMILY + " is null" + " and " + TABLE_NAME + " != '" + MetaDataClient.EMPTY_TABLE + "'"); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + (schemaPattern.length() == 0 ? " is null" : " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'" )); " from " + SYSTEM_SEQUENCE + "\n"); StringBuilder whereClause = new StringBuilder(); addTenantIdFilter(whereClause, catalog); if (schemaPattern != null) { appendConjunction(whereClause);
" and " + COLUMN_FAMILY + " is null" + " and " + TABLE_NAME + " != '" + MetaDataClient.EMPTY_TABLE + "'"); addTenantIdFilter(buf, catalog); if (schemaPattern != null) { buf.append(" and " + TABLE_SCHEM + (schemaPattern.length() == 0 ? " is null" : " like '" + StringUtil.escapeStringConstant(schemaPattern) + "'" )); " from " + SYSTEM_SEQUENCE + "\n"); StringBuilder whereClause = new StringBuilder(); addTenantIdFilter(whereClause, catalog); if (schemaPattern != null) { appendConjunction(whereClause);
" from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS + "(" + TENANT_POS_SHIFT + " BOOLEAN)"); StringBuilder where = new StringBuilder(); addTenantIdFilter(where, catalog); if (schemaPattern != null) { appendConjunction(where);