1 24 25 package org.objectweb.cjdbc.controller.scheduler.schema; 26 27 import java.io.Serializable ; 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 SchedulerDatabaseSchema implements Serializable 41 { 42 43 private ArrayList tables; 44 45 private TransactionExclusiveLock lock = new TransactionExclusiveLock(); 46 47 53 public SchedulerDatabaseSchema(DatabaseSchema schema) 54 { 55 if (schema == null) 56 { 57 tables = new ArrayList (); 58 return; 59 } 60 61 ArrayList origTables = schema.getTables(); 63 int size = origTables.size(); 64 tables = new ArrayList (size); 65 for (int i = 0; i < size; i++) 66 tables.add(new SchedulerDatabaseTable((DatabaseTable) origTables.get(i))); 67 } 68 69 75 public void addTable(SchedulerDatabaseTable table) 76 { 77 tables.add(table); 78 } 79 80 86 public void removeTable(SchedulerDatabaseTable table) 87 { 88 tables.remove(table); 89 } 90 91 98 public void mergeSchema(SchedulerDatabaseSchema databaseSchema) 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 SchedulerDatabaseTable t = (SchedulerDatabaseTable) otherTables.get(i); 111 SchedulerDatabaseTable original = getTable(t.getName()); 112 if (original == null) 113 addTable(t); 114 } 115 } 116 117 123 public ArrayList getTables() 124 { 125 return tables; 126 } 127 128 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 |