| 30 | /** |
| 31 | */ |
| 32 | public abstract class ASqlHandler extends ADDFFunctionalGroupHandler implements IHandleSql { |
| 33 | |
| 34 | public ASqlHandler(DDF theDDF) { |
| 35 | super(theDDF); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @brief Show tables in the database. |
| 40 | * @return The table names. |
| 41 | */ |
| 42 | public SqlResult showTables() throws DDFException { |
| 43 | List<String> tableNames = new ArrayList<String>(); |
| 44 | for (DDF ddf : this.getManager().listDDFs()) { |
| 45 | if (ddf.getName() != null) { |
| 46 | tableNames.add(ddf.getName()); |
| 47 | } |
| 48 | } |
| 49 | List<Column> columnList = new ArrayList<Column>(); |
| 50 | columnList.add(new Column("table_name", Schema.ColumnType.STRING)); |
| 51 | Schema schema = new Schema("tables", columnList); |
| 52 | return new SqlResult(schema, tableNames); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @brief Get the column information of this table. |
| 57 | * @param name The URI or the name of the ddf. |
| 58 | * @param namespace The namespace. |
| 59 | * @return The column information. |
| 60 | * @throws DDFException |
| 61 | */ |
| 62 | private SqlResult describeTable(String name, String namespace) |
| 63 | throws DDFException { |
| 64 | DDF ddf = null; |
| 65 | try { |
| 66 | ddf = this.getManager().getOrRestoreDDFUri(name); |
| 67 | } catch (Exception e) { |
| 68 | if (null == namespace) { |
| 69 | throw new DDFException("ERROR: there is no ddf " + name); |
| 70 | } |
| 71 | try { |
| 72 | mLog.info("trying to restore " + "ddf://" + namespace + "/" + name); |
| 73 | ddf = this.getManager().getOrRestoreDDFUri("ddf://" + namespace + "/" + name); |
| 74 | } catch (Exception e2) { |
| 75 | throw new DDFException("ERROR: there is no ddf " + name); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | int colSize = ddf.getNumColumns(); |
| 80 | List<String> ret = new ArrayList<String>(); |
| 81 | for (int colIdx = 0; colIdx < colSize; ++colIdx) { |
| 82 | Schema.Column col = ddf.getColumn(ddf.getColumnName(colIdx)); |
| 83 | ret.add(col.getName().concat("\t").concat(col.getType().toString() |
| 84 | .toLowerCase())); |
| 85 | } |
| 86 | List<Column> columnList = new ArrayList<Column>(); |
| 87 | columnList.add(new Column("column_name", Schema.ColumnType.STRING)); |
| 88 | columnList.add(new Column("value_type", Schema.ColumnType.STRING)); |
| 89 | Schema schema = new Schema("table_info", columnList); |
nothing calls this directly
no outgoing calls
no test coverage detected