1 package com.daffodilwoods.daffodildb.client; 2 3 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata._SelectColumnCharacteristics; 4 5 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata._RowReader; 6 7 import java.sql.SQLException ; 8 import com.daffodilwoods.database.resource.*; 9 10 import com.daffodilwoods.database.utility.*; 11 import java.util.*; 12 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata._AllColumnRowReader; 13 public class JDBCRecord implements _Record { 14 15 private Object values; 16 private _RecordSetBuffer recordSetBuffer; 17 private _RowReader rowReader; 18 private Object currentKey; 19 private ArrayList updateColumnsList; 20 private ArrayList newValuesList; 21 private boolean isUpdateable; 22 private int hash; 23 private Object [] primaryValues; 24 25 public JDBCRecord(boolean isUpdateable0) { 26 isUpdateable = isUpdateable0; 27 } 28 29 public Object getColumnValue(int columnIndex) throws java.sql.SQLException { 30 try{ 31 if( values==null ) 32 return null; 33 int idx = updateColumnsList == null ? -1 :updateColumnsList.indexOf(new Integer (columnIndex)); 34 35 Object columnValue = idx == -1 ? rowReader.getObject(columnIndex,values): 36 newValuesList.get(idx); 37 return columnValue; 38 }catch(DException ex){ 39 throw new SQLException (ex.getMessage()); 40 } 41 } 42 public Object getColumnValue(String columnName) throws java.sql.SQLException { 43 try{ 44 return getColumnValue(recordSetBuffer.getColumnCharacteristics().getColumnIndex(columnName)); 45 }catch(DException ex){ 46 throw ex.getSqlException(null); 47 } 48 49 } 50 public void updateInitiate(int columnIndex, Object value) throws java.sql.SQLException { 51 52 try{ 53 Object prevValue=getColumnValue(columnIndex); 54 if((prevValue==null && value==null) || (prevValue!=null && prevValue.equals(value)) || (value!=null && value.equals(prevValue))){ 55 return ; 56 } 57 if(updateColumnsList == null){ 58 updateColumnsList = new ArrayList(); 59 newValuesList = new ArrayList(); 60 } 61 Integer index = new Integer (columnIndex); 62 int idx=updateColumnsList.indexOf(index); 63 if(idx==-1){ 64 updateColumnsList.add(index); 65 newValuesList.add(value); 66 } 67 else{ 68 newValuesList.set(idx,value); 69 } 70 }catch(Exception E){ 71 } 72 } 73 74 public void loadRecord(_Record record) throws java.sql.SQLException { 75 JDBCRecord dRecord = (JDBCRecord)record; 76 dRecord.values = values; 77 dRecord.currentKey = currentKey; 78 dRecord.isUpdateable = isUpdateable; 79 dRecord.primaryValues = primaryValues; 80 dRecord.hash = hash; 81 dRecord.updateColumnsList = null; 82 dRecord.newValuesList = null; 83 dRecord.setBuffer(recordSetBuffer); 84 } 85 public _Record getRecord(String parm1) throws java.sql.SQLException { 86 87 throw new java.lang.UnsupportedOperationException ("Method getRecord() not yet implemented."); 88 } 89 public Object getIdentity() throws java.sql.SQLException { 90 if(isUpdateable) 91 return this; 92 throw new java.lang.UnsupportedOperationException ("Method getIdentity() not yet implemented."); 93 } 94 public _RecordSetBuffer getRecordSetBuffer() { 95 return recordSetBuffer; 96 } 97 public boolean isLoaded() { 98 99 throw new java.lang.UnsupportedOperationException ("Method isLoaded() not yet implemented."); 100 } 101 public boolean wasUpdated() { 102 103 throw new java.lang.UnsupportedOperationException ("Method wasUpdated() not yet implemented."); 104 } 105 public void unLoad() { 106 107 throw new java.lang.UnsupportedOperationException ("Method unLoad() not yet implemented."); 108 } 109 110 public void setValues(Object values) throws SQLException { 111 if(isUpdateable){ 112 try { 113 primaryValues = ( (_AllColumnRowReader) rowReader). 114 getPrimaryKeyConditionalColumnValues( (Object []) values); 115 } 116 catch (DException ex) { 117 throw ex.getSqlException(null); 118 } 119 } 120 this.values = values; 121 } 122 123 public void setBuffer(_RecordSetBuffer rsb) { 124 recordSetBuffer = rsb; 125 try{ 126 rowReader = rsb.getRowReader(); 127 } catch (Exception ex){ 128 } 129 } 130 131 void setKey(Object key){ 132 currentKey = key; 133 } 134 135 public void cancelUpdate(){ 136 137 throw new java.lang.UnsupportedOperationException ("Method cancelUpdate() not yet implemented."); 138 } 139 140 public String toString(){ 141 try { 142 return super.toString()+" "+P.print(values); 143 } 144 catch (Exception ex) { 145 return null; 146 } 147 } 148 public _Record getRecord(int parm1) throws java.sql.SQLException { 149 150 throw new java.lang.UnsupportedOperationException ("Method getRecord() not yet implemented."); 151 } 152 public _SelectColumnCharacteristics getColumnCharacteristics() { 153 154 throw new java.lang.UnsupportedOperationException ("Method getColumnCharacteristics() not yet implemented."); 155 } 156 157 int[] getUpdatedColumns(){ 158 if (updateColumnsList == null ) 159 return null; 160 else{ 161 int size = updateColumnsList.size(); 162 int[] indexes = new int[size]; 163 164 165 for(int i=size;i-- > 0;) 166 indexes[i] = updateColumnsList.get(i).hashCode(); 167 return indexes; 168 } 169 } 170 171 172 Object [] getValuesForUpdation(){ 173 return newValuesList == null ? null : newValuesList.toArray(); 174 } 175 176 void flushUpdateColumnsAndValues(){ 177 updateColumnsList = null; 178 newValuesList = null; 179 } 180 181 Object getKey(){ 182 return currentKey; 183 } 184 185 Object getValues(){ 186 return values; 187 } 188 189 private boolean inserted ; 190 public void setInserted(boolean inserted1){ 191 inserted = inserted1; 192 } 193 public boolean isInserted(){ 194 return inserted; 195 } 196 197 198 public boolean equals(Object o){ 199 if (o == this) 200 return true; 201 if(!isUpdateable) 202 return o == this; 203 if (!(o instanceof JDBCRecord)) 204 return false; 205 Object [] e1 = primaryValues; 206 Object [] e2 = ((JDBCRecord)o).primaryValues; 207 boolean wasInserted = ((JDBCRecord)o).inserted; 208 if(wasInserted ^ inserted) 209 return false; 210 int length1 = e1.length; 211 int length2 = e2.length; 212 if(length1 != length2) 213 return false; 214 for (int i = 0; i < length1; i++) { 215 Object o1 = e1[i]; 216 Object o2 = e2[i]; 217 if (!(o1==null ? o2==null : o1.equals(o2))) 218 return false; 219 } 220 return true; 221 } 222 223 public int hashCode() { 224 if(!isUpdateable) 225 return super.hashCode(); 226 int hashCode = hash; 227 if (hashCode == 0) { 228 if(primaryValues != null ){ 229 hashCode = 1; 230 for (int i = 0 ; i < primaryValues.length ; i++){ 231 Object obj = primaryValues[i]; 232 hashCode = 31*hashCode + (obj == null ? 0 : obj.hashCode()); 233 } 234 } 235 else 236 hashCode= -1 ; 237 } 238 return hashCode; 239 } 240 241 } 242 | Popular Tags |