1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.io.Storable; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.reference.SQLState; 29 30 import org.apache.derby.iapi.sql.execute.ExecRow; 31 import org.apache.derby.iapi.sql.execute.ExecutionContext; 32 import org.apache.derby.iapi.types.DataValueDescriptor; 33 34 import org.apache.derby.iapi.reference.SQLState; 35 36 import org.apache.derby.iapi.types.RowLocation; 37 38 import org.apache.derby.iapi.services.sanity.SanityManager; 39 40 import org.apache.derby.iapi.services.io.Formatable; 41 import org.apache.derby.iapi.services.io.ArrayUtil; 42 import org.apache.derby.iapi.services.io.StoredFormatIds; 43 import org.apache.derby.iapi.services.io.FormatIdUtil; 44 45 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 46 47 import java.io.ObjectOutput ; 48 import java.io.ObjectInput ; 49 import java.io.IOException ; 50 51 import org.apache.derby.iapi.services.io.FormatableBitSet; 52 53 58 public class ValueRow implements ExecRow, Formatable 59 { 60 73 74 80 private DataValueDescriptor[] column; 81 private int ncols; 82 83 89 93 public ValueRow() {} 94 95 100 public ValueRow(int ncols) 101 { 102 column = new DataValueDescriptor[ncols]; 103 this.ncols = ncols; 104 } 105 106 107 113 public int nColumns() { 115 return ncols; 116 } 117 118 public void getNewObjectArray() 120 { 121 column = new DataValueDescriptor[ncols]; 122 } 123 124 127 public DataValueDescriptor getColumn (int position) { 129 if (position <= column.length) 130 return (DataValueDescriptor) (column[position-1]); 131 else 132 return (DataValueDescriptor)null; 133 } 134 135 public void setColumn(int position, DataValueDescriptor col) { 137 138 if (position > column.length) 139 realloc(position); column[position-1] = col; 141 } 142 143 144 147 148 public ExecRow getClone() 150 { 151 return getClone((FormatableBitSet) null); 152 } 153 154 public ExecRow getClone(FormatableBitSet clonedCols) 155 { 156 int numColumns = column.length; 157 158 159 ExecRow rowClone = cloneMe(); 160 161 for (int colCtr = 0; colCtr < numColumns; colCtr++) 162 { 163 if (clonedCols != null && !(clonedCols.get(colCtr + 1))) 165 { 166 167 rowClone.setColumn(colCtr + 1, (DataValueDescriptor) column[colCtr]); 168 continue; 169 } 170 171 if (column[colCtr] != null) 172 { 173 174 rowClone.setColumn(colCtr + 1, column[colCtr].getClone()); 175 } 176 } 177 return rowClone; 178 } 179 180 public ExecRow getNewNullRow() 182 { 183 int numColumns = column.length; 184 ExecRow rowClone = cloneMe(); 185 186 187 for (int colCtr = 0; colCtr < numColumns; colCtr++) 188 { 189 if (column[colCtr] != null) 190 { 191 192 if (column[colCtr] instanceof RowLocation) 193 { 194 200 rowClone.setColumn(colCtr + 1, column[colCtr].getClone()); 201 } 202 else 203 { 204 rowClone.setColumn(colCtr + 1, 206 ((DataValueDescriptor) (column[colCtr])).getNewNull()); 207 } 208 } 209 } 210 return rowClone; 211 } 212 213 ExecRow cloneMe() { 214 return new ValueRow(ncols); 215 } 216 217 public final DataValueDescriptor cloneColumn(int columnPosition) 219 { 220 return column[columnPosition -1].getClone(); 221 } 222 223 226 public String toString() { 227 String s = "{ "; 230 for (int i = 0; i < column.length; i++) 231 { 232 if (column[i] == null) 233 s += "null"; 234 else 235 s += column[i].toString(); 236 if (i < (column.length - 1)) 237 s += ", "; 238 } 239 s += " }"; 240 return s; 241 } 242 243 244 249 public DataValueDescriptor[] getRowArray() { 250 return column; 251 } 252 253 258 public DataValueDescriptor[] getRowArrayClone() 259 { 260 int numColumns = column.length; 261 DataValueDescriptor[] columnClones = new DataValueDescriptor[numColumns]; 262 263 for (int colCtr = 0; colCtr < numColumns; colCtr++) 264 { 265 if (column[colCtr] != null) 266 { 267 columnClones[colCtr] = column[colCtr].getClone(); 268 } 269 } 270 271 return columnClones; 272 } 273 274 279 public void setRowArray(DataValueDescriptor[] value) 280 { 281 column = value; 282 } 283 284 public void setRowArray(Storable[] value) { 285 if (value instanceof DataValueDescriptor[]) { 286 column = (DataValueDescriptor[]) value; 287 return; 288 } 289 290 if ((column == null) || (column.length != value.length)) 291 column = new DataValueDescriptor[value.length]; 292 293 294 System.arraycopy(value, 0, column, 0, column.length); 295 } 296 297 protected void realloc(int ncols) { 300 DataValueDescriptor[] newcol = new DataValueDescriptor[ncols]; 301 302 System.arraycopy(column, 0, newcol, 0, column.length); 303 column = newcol; 304 } 305 306 312 320 public void readExternal( ObjectInput in ) 321 throws IOException , ClassNotFoundException 322 { 323 column = new DataValueDescriptor[ArrayUtil.readArrayLength(in)]; 324 ArrayUtil.readArrayItems(in, column); 325 ncols = column.length; 326 } 327 328 335 public void writeExternal( ObjectOutput out ) 336 throws IOException 337 { 338 ArrayUtil.writeArrayLength(out, column); 339 ArrayUtil.writeArrayItems(out, column); 340 } 341 342 347 public int getTypeFormatId() { return StoredFormatIds.VALUE_ROW_V01_ID; } 348 349 } 350 | Popular Tags |