1 22 23 package org.continuent.sequoia.controller.cache.result.schema; 24 25 import java.sql.SQLException ; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 30 import org.continuent.sequoia.controller.sql.schema.DatabaseSchema; 31 import org.continuent.sequoia.controller.sql.schema.DatabaseTable; 32 33 40 public class CacheDatabaseSchema 41 { 42 43 private ArrayList tables; 44 45 51 public CacheDatabaseSchema(DatabaseSchema dbs) 52 { 53 if (dbs == null) 54 { 55 tables = new ArrayList (); 56 return; 57 } 58 59 Collection origTables = dbs.getTables().values(); 61 int size = origTables.size(); 62 tables = new ArrayList (size); 63 for (Iterator iter = origTables.iterator(); iter.hasNext();) 64 for (int i = 0; i < size; i++) 65 tables.add(new CacheDatabaseTable((DatabaseTable) iter.next())); 66 } 67 68 74 public void addTable(CacheDatabaseTable table) 75 { 76 tables.add(table); 77 } 78 79 85 public void removeTable(CacheDatabaseTable table) 86 { 87 tables.remove(table); 88 } 89 90 98 public void mergeSchema(CacheDatabaseSchema databaseSchema) 99 throws SQLException  100 { 101 if (databaseSchema == null) 102 return; 103 104 ArrayList otherTables = databaseSchema.getTables(); 105 if (otherTables == null) 106 return; 107 108 int size = otherTables.size(); 109 for (int i = 0; i < size; i++) 110 { 111 CacheDatabaseTable t = (CacheDatabaseTable) otherTables.get(i); 112 CacheDatabaseTable original = getTable(t.getName()); 113 if (original == null) 114 addTable(t); 115 else 116 original.mergeColumns(t); 117 } 118 } 119 120 126 public ArrayList getTables() 127 { 128 return tables; 129 } 130 131 138 public CacheDatabaseTable getTable(String tableName) 139 { 140 if (tableName == null) 141 return null; 142 int size = tables.size(); 143 for (int i = 0; i < size; i++) 144 { 145 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 146 if (t.getName().compareTo(tableName) == 0) 147 return t; 148 } 149 return null; 150 } 151 152 159 public boolean hasTable(String tableName) 160 { 161 int size = tables.size(); 162 for (int i = 0; i < size; i++) 163 { 164 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 165 if (tableName.equals(t.getName())) 166 return true; 167 } 168 return false; 169 } 170 171 178 public boolean equals(Object other) 179 { 180 if (!(other instanceof CacheDatabaseSchema)) 181 return false; 182 183 if (tables == null) 184 return ((CacheDatabaseSchema) other).getTables() == null; 185 else 186 return tables.equals(((CacheDatabaseSchema) other).getTables()); 187 } 188 189 196 public String getInformation(boolean longFormat) 197 { 198 String result = ""; 199 int size = tables.size(); 200 for (int i = 0; i < size; i++) 201 { 202 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 203 result += t.getInformation(longFormat) + "\n"; 204 } 205 return result; 206 } 207 208 } 209 | Popular Tags |