1 24 25 package org.objectweb.cjdbc.controller.cache.result.schema; 26 27 import java.sql.SQLException ; 28 import java.util.ArrayList ; 29 30 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema; 31 import org.objectweb.cjdbc.common.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 ArrayList origTables = dbs.getTables(); 61 int size = origTables.size(); 62 tables = new ArrayList (size); 63 for (int i = 0; i < size; i++) 64 tables.add(new CacheDatabaseTable((DatabaseTable) origTables.get(i))); 65 } 66 67 73 public void addTable(CacheDatabaseTable table) 74 { 75 tables.add(table); 76 } 77 78 84 public void removeTable(CacheDatabaseTable table) 85 { 86 tables.remove(table); 87 } 88 89 97 public void mergeSchema(CacheDatabaseSchema databaseSchema) 98 throws SQLException 99 { 100 if (databaseSchema == null) 101 return; 102 103 ArrayList otherTables = databaseSchema.getTables(); 104 if (otherTables == null) 105 return; 106 107 int size = otherTables.size(); 108 for (int i = 0; i < size; i++) 109 { 110 CacheDatabaseTable t = (CacheDatabaseTable) otherTables.get(i); 111 CacheDatabaseTable original = getTable(t.getName()); 112 if (original == null) 113 addTable(t); 114 else 115 original.mergeColumns(t); 116 } 117 } 118 119 125 public ArrayList getTables() 126 { 127 return tables; 128 } 129 130 137 public CacheDatabaseTable getTable(String tableName) 138 { 139 int size = tables.size(); 140 for (int i = 0; i < size; i++) 141 { 142 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 143 if (t.getName().compareTo(tableName) == 0) 144 return t; 145 } 146 return null; 147 } 148 149 156 public boolean hasTable(String tableName) 157 { 158 int size = tables.size(); 159 for (int i = 0; i < size; i++) 160 { 161 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 162 if (tableName.equals(t.getName())) 163 return true; 164 } 165 return false; 166 } 167 168 175 public boolean equals(Object other) 176 { 177 if (!(other instanceof CacheDatabaseSchema)) 178 return false; 179 180 if (tables == null) 181 return ((CacheDatabaseSchema) other).getTables() == null; 182 else 183 return tables.equals(((CacheDatabaseSchema) other).getTables()); 184 } 185 186 193 public String getInformation(boolean longFormat) 194 { 195 String result = ""; 196 int size = tables.size(); 197 for (int i = 0; i < size; i++) 198 { 199 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 200 result += t.getInformation(longFormat) + "\n"; 201 } 202 return result; 203 } 204 205 } 206 | Popular Tags |