1 22 23 package org.continuent.sequoia.controller.scheduler.schema; 24 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 29 import org.continuent.sequoia.controller.sql.schema.DatabaseSchema; 30 import org.continuent.sequoia.controller.sql.schema.DatabaseTable; 31 32 39 public class SchedulerDatabaseSchema 40 { 41 42 private ArrayList tables; 43 44 private TransactionExclusiveLock lock = new TransactionExclusiveLock(); 45 46 52 public SchedulerDatabaseSchema(DatabaseSchema schema) 53 { 54 if (schema == null) 55 { 56 tables = new ArrayList (); 57 return; 58 } 59 60 Collection origTables = schema.getTables().values(); 62 int size = origTables.size(); 63 tables = new ArrayList (size); 64 for (Iterator iter = origTables.iterator(); iter.hasNext();) 65 tables.add(new SchedulerDatabaseTable((DatabaseTable) iter.next())); 66 } 67 68 74 public void addTable(SchedulerDatabaseTable table) 75 { 76 tables.add(table); 77 } 78 79 85 public void removeTable(SchedulerDatabaseTable table) 86 { 87 tables.remove(table); 88 } 89 90 97 public void mergeSchema(SchedulerDatabaseSchema databaseSchema) 98 { 99 if (databaseSchema == null) 100 return; 101 102 ArrayList otherTables = databaseSchema.getTables(); 103 if (otherTables == null) 104 return; 105 106 int size = otherTables.size(); 107 for (int i = 0; i < size; i++) 108 { 109 SchedulerDatabaseTable t = (SchedulerDatabaseTable) otherTables.get(i); 110 SchedulerDatabaseTable original = getTable(t.getName()); 111 if (original == null) 112 addTable(t); 113 } 114 } 115 116 122 public ArrayList getTables() 123 { 124 return tables; 125 } 126 127 135 public SchedulerDatabaseTable getTable(String tableName) 136 { 137 SchedulerDatabaseTable t; 138 int size = tables.size(); 139 for (int i = 0; i < size; i++) 140 { 141 t = (SchedulerDatabaseTable) tables.get(i); 142 if (tableName.equalsIgnoreCase(t.getName())) 143 return t; 144 } 145 return null; 146 } 147 148 155 public boolean hasTable(String tableName) 156 { 157 int size = tables.size(); 158 for (int i = 0; i < size; i++) 159 { 160 SchedulerDatabaseTable t = (SchedulerDatabaseTable) tables.get(i); 161 if (tableName.equals(t.getName())) 162 return true; 163 } 164 return false; 165 } 166 167 173 public TransactionExclusiveLock getLock() 174 { 175 return lock; 176 } 177 178 185 public boolean equals(Object other) 186 { 187 if (!(other instanceof SchedulerDatabaseSchema)) 188 return false; 189 190 if (tables == null) 191 return ((SchedulerDatabaseSchema) other).getTables() == null; 192 else 193 return tables.equals(((SchedulerDatabaseSchema) other).getTables()); 194 } 195 196 203 public String getInformation(boolean longFormat) 204 { 205 StringBuffer result = new StringBuffer (); 206 SchedulerDatabaseTable t; 207 int size = tables.size(); 208 for (int i = 0; i < size; i++) 209 { 210 t = (SchedulerDatabaseTable) tables.get(i); 211 result.append(t.getInformation(longFormat)); 212 result.append(System.getProperty("line.separator")); 213 } 214 return result.toString(); 215 } 216 } | Popular Tags |