1 package com.daffodilwoods.daffodildb.server.datasystem.utility; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record; 4 5 import com.daffodilwoods.database.resource.*; 6 import java.util.*; 7 public class RecordVersion implements java.io.Serializable { 8 9 HashMap columnIndexesMap; 10 RecordVersion rv ; 11 _Record currentRecord; 12 13 public RecordVersion( _Record record0 ) throws DException { 14 currentRecord = record0; 15 } 16 17 18 public _Record getPreviousRecord()throws DException{ 19 _Record record = (_Record)currentRecord.clone();; 20 if(columnIndexesMap == null) 21 return record; 22 Set keySet = columnIndexesMap.keySet(); 23 Iterator iter = keySet.iterator(); 24 for(int i =0 ; i< columnIndexesMap.size();i++){ 25 Object columnIndex = iter.next(); 26 record.update(columnIndex.hashCode(),columnIndexesMap.get(columnIndex)); 27 } 28 return (_Record)record; 29 } 30 31 public _Record getCurrentRecord() throws DException { 32 return (_Record)currentRecord.clone(); 33 } 34 35 36 public void update(String columnName,Object newValue) throws DException { 37 throw new InternalError (" method not implemented "); 38 } 39 40 public void update(String [] columnName,Object [] newValue) throws DException { 41 throw new InternalError (" method not implemented "); 42 } 43 44 public void update(int[] columnIndexes,Object [] newValues)throws DException{ 45 for(int i =0;i< columnIndexes.length ;i++) 46 update(columnIndexes[i],newValues[i]); 47 } 48 49 public void update(int columnIndex,Object newValue)throws DException{ 50 Object oldValue = currentRecord.getObject(columnIndex); 51 Integer column = new Integer (columnIndex); 52 if(columnIndexesMap == null) 53 columnIndexesMap = new HashMap(); 54 columnIndexesMap.put(column,oldValue); 55 currentRecord.update(columnIndex,newValue); 56 } 57 58 public Object Clone() throws CloneNotSupportedException { 59 try { 60 rv = new RecordVersion((_Record)currentRecord.clone()); 61 if(columnIndexesMap == null) 62 rv.setColumnIndexMap(null); 63 else 64 rv.setColumnIndexMap((HashMap)columnIndexesMap.clone()); 65 } 66 catch (DException ex) { 67 68 } 69 return rv; 70 } 71 72 public void setColumnIndexMap(HashMap columnIndexesMap) throws DException{ 73 this.columnIndexesMap = columnIndexesMap; 74 } 75 76 79 } 80 | Popular Tags |