00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.controller.cache.result.schema;
00026
00027 import java.io.Serializable;
00028 import java.sql.SQLException;
00029 import java.util.ArrayList;
00030
00031 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema;
00032 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable;
00033
00034
00035
00036
00037
00038
00039
00040
00041 public class CacheDatabaseSchema implements Serializable
00042 {
00043
00044 private ArrayList tables;
00045
00046
00047
00048
00049
00050
00051
00052 public CacheDatabaseSchema(DatabaseSchema dbs)
00053 {
00054 if (dbs == null)
00055 {
00056 tables = new ArrayList();
00057 return;
00058 }
00059
00060
00061 ArrayList origTables = dbs.getTables();
00062 int size = origTables.size();
00063 tables = new ArrayList(size);
00064 for (int i = 0; i < size; i++)
00065 tables.add(new CacheDatabaseTable((DatabaseTable) origTables.get(i)));
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 public void addTable(CacheDatabaseTable table)
00075 {
00076 tables.add(table);
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 public void removeTable(CacheDatabaseTable table)
00086 {
00087 tables.remove(table);
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 public void mergeSchema(CacheDatabaseSchema databaseSchema)
00099 throws SQLException
00100 {
00101 if (databaseSchema == null)
00102 return;
00103
00104 ArrayList otherTables = databaseSchema.getTables();
00105 if (otherTables == null)
00106 return;
00107
00108 int size = otherTables.size();
00109 for (int i = 0; i < size; i++)
00110 {
00111 CacheDatabaseTable t = (CacheDatabaseTable) otherTables.get(i);
00112 CacheDatabaseTable original = getTable(t.getName());
00113 if (original == null)
00114 addTable(t);
00115 else
00116 original.mergeColumns(t);
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 public ArrayList getTables()
00127 {
00128 return tables;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138 public CacheDatabaseTable getTable(String tableName)
00139 {
00140 int size = tables.size();
00141 for (int i = 0; i < size; i++)
00142 {
00143 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i);
00144 if (t.getName().compareTo(tableName) == 0)
00145 return t;
00146 }
00147 return null;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157 public boolean hasTable(String tableName)
00158 {
00159 int size = tables.size();
00160 for (int i = 0; i < size; i++)
00161 {
00162 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i);
00163 if (tableName.equals(t.getName()))
00164 return true;
00165 }
00166 return false;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176 public boolean equals(Object other)
00177 {
00178 if (!(other instanceof CacheDatabaseSchema))
00179 return false;
00180
00181 if (tables == null)
00182 return ((CacheDatabaseSchema) other).getTables() == null;
00183 else
00184 return tables.equals(((CacheDatabaseSchema) other).getTables());
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194 public String getInformation(boolean longFormat)
00195 {
00196 String result = "";
00197 int size = tables.size();
00198 for (int i = 0; i < size; i++)
00199 {
00200 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i);
00201 result += t.getInformation(longFormat) + "\n";
00202 }
00203 return result;
00204 }
00205
00206 }