1 64 65 package com.jcorporate.expresso.core.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.misc.DateTime; 70 import com.jcorporate.expresso.kernel.util.ClassLocator; 71 72 import java.util.Iterator ; 73 74 75 115 public class HistAuditSecuredDBObject 116 extends AuditedSecuredDBObject { 117 121 public HistAuditSecuredDBObject() 122 throws DBException { 123 super(); 124 } 125 126 134 public HistAuditSecuredDBObject(DBConnection theConnection) 135 throws DBException { 136 super(theConnection); 137 } 138 139 142 private void writeRecordToHistory() 143 throws DBException { 144 145 try { 148 Class clazz = ClassLocator.loadClass(getHistoryTableClassName()); 149 SecuredDBObject histObject = (SecuredDBObject) clazz.newInstance(); 150 151 if (histObject == null) { 152 throw new DBException("The history object is null."); 153 } 154 155 Iterator fieldsIterator = this.getJDBCMetaData().getFieldListArray().iterator(); 156 String fieldName = null; 157 158 while (fieldsIterator.hasNext()) { 159 fieldName = (String ) fieldsIterator.next(); 160 histObject.setField(fieldName, this.getField(fieldName)); 161 } 162 163 histObject.setField("HISTORY_DATE", DateTime.getDateTimeForDB(this.getDataContext())); 164 histObject.add(); 165 } catch (Exception e) { 166 throw new DBException("An error occured while trying to write to the history table: " + 167 e.toString()); 168 } 169 } 170 171 177 public String getHistoryTableClassName() { 178 return this.getClass().getName() + "History"; 179 } 180 181 186 public synchronized void add() 187 throws DBException { 188 super.add(); 189 this.writeRecordToHistory(); 190 } 191 192 195 public synchronized void update() 196 throws DBException { 197 super.update(); 198 this.writeRecordToHistory(); 199 } 200 } | Popular Tags |