1 package com.daffodilwoods.daffodildb.server.serversystem.deeprecordcopy; 2 3 import java.util.*; 4 5 import com.daffodilwoods.database.general.*; 6 import com.daffodilwoods.database.resource.*; 7 public class MappingHandler { 8 9 HashMap mappingOfTables; 10 11 12 public MappingHandler() { 13 mappingOfTables = new HashMap(); 14 15 } 16 17 public void addVector(QualifiedIdentifier tableName,Vector recMappings){ 18 mappingOfTables.put(tableName,recMappings); 19 } 20 21 public Vector getVector(QualifiedIdentifier tableName){ 22 return (Vector)mappingOfTables.get(tableName); 23 } 24 25 26 public Object getColumnValue(QualifiedIdentifier tableName,int referencedColumn,Object oldRecordValue) throws DException,NullPointerException { 27 Vector mappings = getVector(tableName); 28 for (int i = 0; i < mappings.size(); i++) { 29 RecordMapping recMapping = (RecordMapping)mappings.get(i); 30 Object [] oldrec =((Object [])recMapping.getOldRecord()); 31 32 if(com.daffodilwoods.daffodildb.server.sql99.common.Check.getObject( oldrec[referencedColumn] , oldRecordValue ) == 0 ){ 33 return recMapping.getNewRecord()[referencedColumn]; 34 } 35 } 36 return null; 37 38 } 39 40 41 public boolean isCopied(Object [] newRecord,QualifiedIdentifier tableName) throws DException{ 42 Vector mappings = getVector(tableName); 43 for (int i = 0; i < mappings.size(); i++) { 44 RecordMapping recMap = (RecordMapping)mappings.get(i); 45 if(equal(recMap.getNewRecord(),newRecord)) 46 return true; 47 } 48 return false; 49 } 50 51 52 53 54 public boolean equal(Object [] oldRec,Object [] newRec) throws DException{ 55 if(oldRec == null){ 56 return false; 57 } 58 if(oldRec.length != newRec.length){ 59 return false; 60 } 61 for (int i = 5; i < oldRec.length; i++) { 62 if(!oldRec[i].equals(newRec[i])) 63 return false; 64 } 65 return true; 66 } 67 } 68 | Popular Tags |