1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 4 import com.daffodilwoods.database.resource.*; 5 import java.util.*; 6 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 7 import com.daffodilwoods.daffodildb.utils.BufferRange; 8 import com.daffodilwoods.database.general.QualifiedIdentifier; 9 10 18 public class ColumnBytesTableHashMap implements _TableList{ 19 HashMap columnBytesHashMap; 20 _TableList table; 21 int CODE; 22 QualifiedIdentifier tableName; 23 boolean testingFlag = false; 24 public static int timeTakenInGettingColumnValues = 0; 25 public static int timeTakenInGetAndPutOfMap = 0; 26 27 public ColumnBytesTableHashMap(HashMap columnBytesHashMap1 , int CODE1,QualifiedIdentifier tableName0) { 28 columnBytesHashMap = columnBytesHashMap1; 29 CODE = CODE1; 30 tableName = tableName0; 31 testingFlag = tableName.catalog .equalsIgnoreCase("users"); 32 } 33 34 public Object insert(_DatabaseUser user, _RecordCluster recordCluster,Object values) throws DException { 35 TableKey tableKey = (TableKey)table.insert(user,recordCluster,values); 36 long startTime = System.currentTimeMillis() ; 37 columnBytesHashMap.put(tableKey,values) ; 38 timeTakenInGetAndPutOfMap += (System.currentTimeMillis() - startTime); 39 return tableKey; 40 } 41 42 43 public void setTable(_TableList table1){ 44 table = table1; 45 } 46 47 48 public Object update(_DatabaseUser user ,_RecordCluster recordCluster,Object key, Object values) throws DException { 49 TableKey tableKey = (TableKey)table.update(user,recordCluster, key,values); 50 long startTime = System.currentTimeMillis() ; 51 columnBytesHashMap.put(tableKey,values); 52 timeTakenInGetAndPutOfMap += (System.currentTimeMillis() - startTime); 53 return tableKey; 54 } 55 56 public Object delete(_DatabaseUser user, _RecordCluster recordCluster, Object key)throws DException { 57 TableKey tableKey = (TableKey)table.delete(user,recordCluster,key); 58 long startTime = System.currentTimeMillis() ; 59 columnBytesHashMap.remove(tableKey) ; 60 timeTakenInGetAndPutOfMap += (System.currentTimeMillis() - startTime); 61 return tableKey; 62 } 63 64 private ArrayList initializeArrayList(int size){ 65 ArrayList retrievedObjects = new ArrayList(size); 66 for(int i= 0; i < size ; i++) 67 retrievedObjects.add(null); 68 return retrievedObjects; 69 } 70 71 public _TableList getTable() { 72 return table; 73 } 74 75 public _TableList getTable(int num) { 76 return CODE == num ? table : table.getTable(num); 77 } 78 79 public int getColumnCount() throws DException{ 80 return table.getColumnCount(); 81 } 82 83 public Object getColumnObjects(_RecordCluster recordCluster,Object key,int[] columns) throws DException{ 84 throw new UnsupportedOperationException ("METHOD NOT IMPLEMENTED"); 85 } 86 87 public Object getRecordBytes(_RecordCluster recordCluster,Object key,int[] columns) throws DException{ 88 return getColumnObjects(recordCluster,key,columns); 89 } 90 91 92 public void checkValidity(_RecordCluster recordCluster, Object key)throws DException { 93 table.checkValidity(recordCluster,key); 94 } 95 96 public TableProperties getTableProperties() throws DException{ 97 return table.getTableProperties(); 98 } 99 100 public _TableCharacteristics getTableCharacteristics() throws DException { 101 102 return table.getTableCharacteristics() ; 103 } 104 105 public void rollBack() throws DException { 106 table.rollBack(); 107 } 108 109 public Object getColumnValues(TableKey key,_RecordCluster cluster)throws DException{ 110 111 long startTime = System.currentTimeMillis() ; 112 Object values = columnBytesHashMap.get(key) ; 113 timeTakenInGetAndPutOfMap += (System.currentTimeMillis() - startTime); 114 if(values != null){ 115 return (BufferRange[]) values; 116 } 117 values = table.getColumnValues(key,cluster ) ; 118 123 return values; 124 125 126 } 127 128 public Object getColumnValues(TableKey key,_RecordCluster cluster,int column) throws DException{ 129 130 Object [] values = (Object [])getColumnValues(key,cluster); 131 return values[column]; 132 133 } 134 135 public Object getColumnValues(TableKey key,_RecordCluster cluster,int[] columns) throws DException{ 136 137 Object [] values = (Object [])getColumnValues(key,cluster); 138 Object [] toReturn = new BufferRange[columns.length ]; 139 for (int i = 0; i < columns.length; i++) { 140 toReturn[i] = values[columns[i]]; 141 } 142 return toReturn; 143 } 144 } 145 | Popular Tags |