1 21 package oracle.toplink.essentials.exceptions; 23 24 import java.util.*; 25 import java.io.*; 26 import oracle.toplink.essentials.internal.helper.*; 27 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 28 import oracle.toplink.essentials.internal.sessions.AbstractSession; 29 30 35 public class IntegrityChecker implements Serializable { 36 37 38 protected Vector caughtExceptions = null; 39 40 41 protected Vector tables = null; 42 43 44 protected boolean shouldCatchExceptions; 45 46 47 protected boolean shouldCheckDatabase; 48 49 50 protected boolean shouldCheckInstantiationPolicy; 51 52 58 public IntegrityChecker() { 59 super(); 60 this.shouldCatchExceptions = true; 61 this.shouldCheckDatabase = false; 62 this.shouldCheckInstantiationPolicy = true; 63 } 64 65 69 public void catchExceptions() { 70 setShouldCatchExceptions(true); 71 } 72 73 77 public void checkDatabase() { 78 setShouldCheckDatabase(true); 79 } 80 81 85 public void checkInstantiationPolicy() { 86 setShouldCheckInstantiationPolicy(true); 87 } 88 89 93 public boolean checkTable(DatabaseTable table, AbstractSession session) { 94 if (getTables().size() == 0) { 95 initializeTables(session); 97 } 98 if (session.getPlatform().isMySQL()) { 100 return getTables().contains(table.getName().toLowerCase()); 101 } 102 return getTables().contains(table.getName()); 103 } 104 105 109 public void dontCatchExceptions() { 110 setShouldCatchExceptions(false); 111 } 112 113 117 public void dontCheckDatabase() { 118 setShouldCheckDatabase(false); 119 } 120 121 125 public void dontCheckInstantiationPolicy() { 126 setShouldCheckInstantiationPolicy(false); 127 } 128 129 133 public Vector getCaughtExceptions() { 134 if (caughtExceptions == null) { 135 caughtExceptions = new Vector(); 136 } 137 return caughtExceptions; 138 } 139 140 144 public Vector getTables() { 145 if (tables == null) { 146 tables = new Vector(); 147 } 148 return tables; 149 } 150 151 156 public void handleError(RuntimeException runtimeException) { 157 if (!shouldCatchExceptions()) { 158 throw runtimeException; 159 } 160 getCaughtExceptions().addElement(runtimeException); 161 } 162 163 167 public boolean hasErrors() { 168 if ((caughtExceptions != null) && (caughtExceptions.size() > 0)) { 169 return true; 170 } 171 return false; 172 } 173 174 178 public boolean hasRuntimeExceptions() { 179 if (hasErrors()) { 180 for (Enumeration exceptionsEnum = getCaughtExceptions().elements(); 181 exceptionsEnum.hasMoreElements();) { 182 if (exceptionsEnum.nextElement() instanceof RuntimeException ) { 183 return true; 184 } 185 } 186 } 187 return false; 188 } 189 190 194 public void initializeTables(AbstractSession session) { 195 Vector result = session.getAccessor().getTableInfo(null, null, null, null, session); 196 for (Enumeration resultEnum = result.elements(); resultEnum.hasMoreElements();) { 197 AbstractRecord row = (AbstractRecord)resultEnum.nextElement(); 198 tables.addElement(row.get("TABLE_NAME")); 199 } 200 } 201 202 205 public void setCaughtExceptions(Vector exceptions) { 206 this.caughtExceptions = exceptions; 207 } 208 209 214 public void setShouldCatchExceptions(boolean answer) { 215 shouldCatchExceptions = answer; 216 } 217 218 223 public void setShouldCheckDatabase(boolean answer) { 224 shouldCheckDatabase = answer; 225 } 226 227 232 public void setShouldCheckInstantiationPolicy(boolean answer) { 233 shouldCheckInstantiationPolicy = answer; 234 } 235 236 240 public boolean shouldCatchExceptions() { 241 return shouldCatchExceptions; 242 } 243 244 248 public boolean shouldCheckDatabase() { 249 return shouldCheckDatabase; 250 } 251 252 256 public boolean shouldCheckInstantiationPolicy() { 257 return shouldCheckInstantiationPolicy; 258 } 259 } 260 | Popular Tags |