1 package jimm.datavision.source.ncsql; 2 import jimm.datavision.*; 3 import jimm.datavision.source.*; 4 import jimm.util.XMLWriter; 5 import java.util.*; 6 7 14 public class NCDatabase extends DataSource { 15 16 protected static final String ORPHANS_TABLE = "no_table"; 17 18 protected TreeMap tables; 19 20 public NCDatabase(Report report) { 21 super(report, new NCQuery(report)); 22 tables = new TreeMap(); 23 } 24 25 public boolean canRunReports() { return false; } 26 public boolean canJoinTables() { return true; } 27 public boolean isSQLGenerated() { return true; } 28 public boolean isConnectionEditable() { return false; } 29 public boolean areRecordsSelectable() { return true; } 30 public boolean areRecordsSortable() { return true; } 31 public boolean canGroupRecords() { return true; } 32 33 39 public void addColumn(Column col) { 40 43 String fullName = col.fullName(); 46 int lastDotPos = fullName.lastIndexOf('.'); 47 String tableName = null; 48 String colName = null; 49 if (lastDotPos == -1) { 50 tableName = ORPHANS_TABLE; 51 colName = fullName; 52 } 53 else { 54 tableName = fullName.substring(0, lastDotPos); 55 colName = fullName.substring(lastDotPos + 1); 56 } 57 58 NCTable table = (NCTable)tables.get(tableName); 60 if (table == null) { 61 table = new NCTable(this, tableName); 62 tables.put(tableName, table); 63 } 64 65 table.addColumn(new NCColumn(table, colName, col.getType())); 66 } 67 68 78 public Column findColumn(Object id) { 79 if (tables == null) 80 return null; 81 82 for (Iterator iter = tables.values().iterator(); iter.hasNext(); ) { 83 Column col = ((Table)iter.next()).findColumn(id); 84 if (col != null) 85 return col; 86 } 87 return null; 88 } 89 90 public Iterator tables() { 91 return tables.values().iterator(); 92 } 93 94 public Iterator tablesUsedInReport() { 95 return ((NCQuery)query).getTablesUsed().iterator(); 96 } 97 98 public Iterator columns() { 99 return new ColumnIterator(tables.values().iterator()); 100 } 101 102 public DataCursor execute() { return null; } 103 104 109 protected void doWriteXML(XMLWriter out) { 110 out.startElement("nc-database"); 111 if (metadataURL != null) 112 out.textElement("metadata-url", metadataURL); 113 else 114 for (Iterator iter = columns(); iter.hasNext(); ) 115 ((Column)iter.next()).writeXML(out); 116 out.endElement(); 117 } 118 119 } 120 | Popular Tags |