} // getSchemaByNameInternal() private Schema getInformationSchema() { // Create schema MutableSchema informationSchema = new MutableSchema(INFORMATION_SCHEMA_NAME); MutableTable tablesTable = new MutableTable("tables", TableType.TABLE, informationSchema); MutableTable columnsTable = new MutableTable("columns", TableType.TABLE, informationSchema); MutableTable relationshipsTable = new MutableTable("relationships", TableType.TABLE, informationSchema); informationSchema.addTable(tablesTable).addTable(columnsTable).addTable(relationshipsTable); // Create "tables" table: name, type, num_columns, remarks tablesTable.addColumn(new MutableColumn("name", ColumnTypeConstants.VARCHAR, tablesTable, 0, false)); tablesTable.addColumn(new MutableColumn("type", ColumnTypeConstants.VARCHAR, tablesTable, 1, true)); tablesTable.addColumn(new MutableColumn("num_columns", ColumnTypeConstants.INTEGER, tablesTable, 2, true)); tablesTable.addColumn(new MutableColumn("remarks", ColumnTypeConstants.VARCHAR, tablesTable, 3, true)); // Create "columns" table: name, type, native_type, size, nullable, // indexed, table, remarks columnsTable.addColumn(new MutableColumn("name", ColumnTypeConstants.VARCHAR, columnsTable, 0, false)); columnsTable.addColumn(new MutableColumn("type", ColumnTypeConstants.VARCHAR, columnsTable, 1, true)); columnsTable.addColumn(new MutableColumn("native_type", ColumnTypeConstants.VARCHAR, columnsTable, 2, true)); columnsTable.addColumn(new MutableColumn("size", ColumnTypeConstants.INTEGER, columnsTable, 3, true)); columnsTable.addColumn(new MutableColumn("nullable", ColumnTypeConstants.BOOLEAN, columnsTable, 4, true)); columnsTable.addColumn(new MutableColumn("indexed", ColumnTypeConstants.BOOLEAN, columnsTable, 5, true)); columnsTable.addColumn(new MutableColumn("table", ColumnTypeConstants.VARCHAR, columnsTable, 6, false)); columnsTable.addColumn(new MutableColumn("remarks", ColumnTypeConstants.VARCHAR, columnsTable, 7, true)); // Create "relationships" table: primary_table, primary_column, // foreign_table, foreign_column relationshipsTable .addColumn(new MutableColumn("primary_table", ColumnTypeConstants.VARCHAR, relationshipsTable, 0, false)); relationshipsTable .addColumn(new MutableColumn("primary_column", ColumnTypeConstants.VARCHAR, relationshipsTable, 1, false)); relationshipsTable .addColumn(new MutableColumn("foreign_table", ColumnTypeConstants.VARCHAR, relationshipsTable, 2, false)); relationshipsTable .addColumn(new MutableColumn("foreign_column", ColumnTypeConstants.VARCHAR, relationshipsTable, 3, false)); MutableRelationship.createRelationship(tablesTable.getColumnByName("name"), columnsTable.getColumnByName("table")); MutableRelationship.createRelationship(tablesTable.getColumnByName("name"), relationshipsTable.getColumnByName("primary_table")); MutableRelationship.createRelationship(tablesTable.getColumnByName("name"), relationshipsTable.getColumnByName("foreign_table")); MutableRelationship.createRelationship(columnsTable.getColumnByName("name"), relationshipsTable.getColumnByName("primary_column")); MutableRelationship.createRelationship(columnsTable.getColumnByName("name"), relationshipsTable.getColumnByName("foreign_column")); return(informationSchema); } // getInformationSchema()
// @Override public MutableTable buildTable() { int tableObservations = getObservationCount(); // sort column names by copying them to a TreeSet HashSet <String> columnNames = new HashSet <String>(_columnBuilders.Keys); // new TreeSet<String>(_columnBuilders.keySet()); MutableTable table = new MutableTable(_tableName); int columnNumber = 0; foreach (String columnName in columnNames) { InferentialColumnBuilder columnBuilder = (InferentialColumnBuilder)getColumnBuilder(columnName); MutableColumn column = columnBuilder.build(); column.setTable(table); column.setColumnNumber(columnNumber); int columnObservations = columnBuilder.getObservationCount(); if (tableObservations > columnObservations) { // there may be nulls - some records does not even contain the // column column.setNullable(true); } table.addColumn(column); columnNumber++; } return(table); }
// @Override public MutableSchema build() { MutableSchema schema = new MutableSchema(_schemaName); MutableTable table = new MutableTable(_tableName, schema); table.addColumn(new MutableColumn(_columnName, ColumnTypeConstants.MAP, table, 1, null, null, false, null, false, null)); schema.addTable(table); return(schema); }
} // toString()() /** * Creates a {@link MutableTable} based on this {@link SimpleTableDef}. Note * that the created table will not have any schema set. * * @return a table representation of this table definition. */ public MutableTable toTable() { String name = getName(); String[] columnNames = getColumnNames(); ColumnType[] columnTypes = getColumnTypes(); MutableTable table = new MutableTable(name, TableType.TABLE); for (int i = 0; i < columnNames.Length; i++) { table.addColumn(new MutableColumn(columnNames[i], columnTypes[i], table, i, true)); } return table; } // toTable()