1 21 22 package org.apache.derby.impl.store.access.conglomerate; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.services.monitor.Monitor; 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 import org.apache.derby.iapi.services.io.Storable; 29 30 import org.apache.derby.iapi.error.StandardException; 31 import org.apache.derby.iapi.store.access.RowUtil; 32 33 import org.apache.derby.iapi.types.DataValueDescriptor; 34 35 import org.apache.derby.iapi.types.SQLLongint; 36 37 import org.apache.derby.iapi.services.io.FormatableBitSet; 38 39 public final class TemplateRow 40 { 41 42 45 46 private TemplateRow() { 47 } 48 49 50 51 52 67 private static DataValueDescriptor[] allocate_objects( 68 int num_cols_to_allocate, 69 FormatableBitSet column_list, 70 int[] format_ids) 71 throws StandardException 72 { 73 int dest_pos = 0; 74 75 DataValueDescriptor[] ret_row = 76 new DataValueDescriptor[num_cols_to_allocate]; 77 int num_cols = 78 (column_list == null ? format_ids.length : column_list.size()); 79 80 for (int i = 0; i < num_cols; i++) 81 { 82 if ((column_list != null) && (!column_list.get(i))) 84 { 85 } 87 else 88 { 89 91 ret_row[i] = (DataValueDescriptor) 93 Monitor.newInstanceFromIdentifier(format_ids[i]); 94 95 if (SanityManager.DEBUG) 96 { 97 DataValueDescriptor o = ret_row[i]; 98 99 if (o == null) 100 { 101 SanityManager.THROWASSERT( 102 "obj from Monitor.newInstanceFromIdentifier() null." + 103 ";src column position = " + i + 104 ";dest column position = " + i + 105 ";num_cols = " + num_cols + 106 ";format_ids.length = " + format_ids.length); 107 108 } 109 110 if ( ! (o instanceof Storable)) 111 SanityManager.THROWASSERT( 112 "object:(" + o.getClass() +"):(" + o + 113 ") not an instanceof Storable"); 114 } 115 } 116 } 117 118 return(ret_row); 119 } 120 121 122 123 126 public static DataValueDescriptor[] newU8Row(int nkeys) 127 { 128 DataValueDescriptor[] columns = new DataValueDescriptor[nkeys]; 129 130 for (int i = 0; i < columns.length; i++) 131 { 132 columns[i] = new SQLLongint(Long.MIN_VALUE); 133 } 134 135 return columns; 136 } 137 138 158 public static DataValueDescriptor[] newRow( 159 DataValueDescriptor[] template) 160 throws StandardException 161 { 162 DataValueDescriptor[] columns = 163 new DataValueDescriptor[template.length]; 164 165 try 166 { 167 for (int i = template.length; i-- > 0 ;) 168 { 169 columns[i] = 171 (DataValueDescriptor) template[i].getClass().newInstance(); 172 } 173 } 174 catch (Throwable t) 175 { 176 throw(StandardException.newException( 181 SQLState.CONGLOMERATE_TEMPLATE_CREATE_ERROR)); 182 } 183 184 return columns; 185 } 186 187 201 public static DataValueDescriptor[] newRow( 202 FormatableBitSet column_list, 203 int[] format_ids) 204 throws StandardException 205 { 206 return(allocate_objects(format_ids.length, column_list, format_ids)); 207 } 208 209 227 public static DataValueDescriptor[] newBranchRow( 228 int[] format_ids, 229 DataValueDescriptor page_ptr) 230 throws StandardException 231 { 232 DataValueDescriptor[] columns = 236 allocate_objects( 237 format_ids.length + 1, (FormatableBitSet) null, format_ids); 238 239 columns[format_ids.length] = page_ptr; 242 243 return(columns); 244 } 245 246 257 static public boolean checkColumnTypes( 258 int[] format_ids, 259 DataValueDescriptor[] row) 260 throws StandardException 261 { 262 boolean ret_val = true; 263 264 while (true) 265 { 266 int nCols = row.length; 267 if (format_ids.length != row.length) 268 { 269 if (SanityManager.DEBUG) 270 { 271 SanityManager.THROWASSERT( 272 "format_ids[] length (" + format_ids.length + 273 ") expected to be = row length (" + row.length + ")"); 274 } 275 ret_val = false; 276 break; 277 } 278 279 if (SanityManager.DEBUG) 280 { 281 Object column; 282 Object column_template; 283 284 for (int colid = 0; colid < nCols; colid++) 285 { 286 column = row[colid]; 287 288 if (column == null) 289 { 290 SanityManager.THROWASSERT( 291 "column[" + colid + "] is null"); 292 } 293 294 column_template = 295 Monitor.newInstanceFromIdentifier(format_ids[colid]); 296 297 298 if (column.getClass() != column_template.getClass()) 300 { 301 SanityManager.DEBUG_PRINT( 302 "check", "row = " + RowUtil.toString(row)); 303 304 SanityManager.THROWASSERT( 305 "column["+colid+"] (" + column.getClass() + 306 ") expected to be instanceof column_tempate() (" + 307 column_template.getClass() + ")" + 308 "column = " + column + 309 "row[colid] = " + row[colid]); 310 } 311 } 312 } 313 break; 314 } 315 316 return(ret_val); 317 } 318 319 330 static public boolean checkPartialColumnTypes( 331 int[] format_ids, 332 FormatableBitSet validColumns, 333 int[] fieldStates, 334 DataValueDescriptor[] row) 335 throws StandardException 336 { 337 boolean ret_val = true; 338 339 return(ret_val); 340 } 341 } 342 | Popular Tags |