1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.context.ContextManager; 25 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 29 30 import org.apache.derby.iapi.sql.execute.ExecRow; 31 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 32 import org.apache.derby.iapi.sql.execute.ExecutionContext; 33 import org.apache.derby.iapi.error.StandardException; 34 35 import org.apache.derby.iapi.services.io.FormatableBitSet; 36 import java.util.Vector ; 37 38 44 public class RowUtil 45 { 46 47 53 public static ExecRow getEmptyValueRow(int columnCount, LanguageConnectionContext lcc) 54 { 55 ExecutionContext ec; 56 57 ec = lcc.getExecutionContext(); 58 return ec.getExecutionFactory().getValueRow(columnCount); 59 } 60 61 68 public static ExecIndexRow getEmptyIndexRow(int columnCount, ContextManager cm) 69 { 70 ExecutionContext ec; 71 72 ec = (ExecutionContext) 73 cm.getContext(ExecutionContext.CONTEXT_ID); 74 return ec.getExecutionFactory().getIndexableRow(columnCount); 75 } 76 77 85 public static void copyCloneColumns(ExecRow to, ExecRow from, int count) 86 { 87 for (int ix = 1; ix <= count; ix++) 88 { 89 to.setColumn(ix,from.cloneColumn(ix)); 90 } 91 } 92 93 99 public static void copyRefColumns(ExecRow to, ExecRow from) 100 { 101 Object [] src = from.getRowArray(); 102 Object [] dst = to.getRowArray(); 103 System.arraycopy(src, 0, dst, 0, src.length); 104 } 105 106 113 public static void copyRefColumns(ExecRow to, ExecRow from, int count) 114 throws StandardException 115 { 116 copyRefColumns(to, 0, from, 0, count); 117 } 118 119 127 public static void copyRefColumns(ExecRow to, ExecRow from, 128 int start, int count) 129 throws StandardException 130 { 131 copyRefColumns(to, 0, from, start, count); 132 } 133 134 142 public static void copyRefColumns(ExecRow to, int toStart, ExecRow from, 143 int fromStart, int count) throws StandardException { 144 for (int i = 1; i <= count; i++) 145 { 146 to.setColumn(i+toStart, from.getColumn(i+fromStart)); 148 } 149 } 150 151 158 public static void copyRefColumns(ExecRow to, ExecRow from, int[] positions) 159 throws StandardException 160 { 161 if ( positions == null ) { return; } 162 163 int count = positions.length; 164 for (int ix = 0; ix < count; ix++) 165 { to.setColumn( ix + 1, from.getColumn( positions[ix] ) ); } 166 } 167 168 178 public static void copyRefColumns(ExecRow to, ExecRow from, FormatableBitSet positions) 179 throws StandardException 180 { 181 if (positions == null) 182 { 183 return; 184 } 185 186 int max = to.getRowArray().length; 187 int toCount = 1; 188 int fromCount = 1; 189 for (;toCount <= max; toCount++) 190 { 191 if (positions.get(toCount)) 192 { 193 to.setColumn(toCount, from.getColumn(fromCount)); 194 fromCount++; 195 } 196 } 197 } 198 199 206 public static void copyRefColumns(ExecRow setMe) 207 throws StandardException 208 { 209 for (int ix = 1; ix <= setMe.nColumns(); ix++) 210 { 211 setMe.setColumn(ix,null); 212 } 213 } 214 215 222 public static String toString(ExecRow row) 223 { 224 if (SanityManager.DEBUG) 225 { 226 return (row == null) ? "null" : toString(row.getRowArray()); 227 } 228 else 229 { 230 return ""; 231 } 232 } 233 234 241 public static String toString(Object [] objs) 242 { 243 if (SanityManager.DEBUG) 244 { 245 StringBuffer strbuf = new StringBuffer (); 246 247 if (objs == null) 248 return "null"; 249 250 strbuf.append("("); 251 for (int i = 0; i < objs.length; i++) 252 { 253 if (i > 0) 254 { 255 strbuf.append(","); 256 } 257 strbuf.append(objs[i]); 258 } 259 strbuf.append(")"); 260 return strbuf.toString(); 261 } 262 else 263 { 264 return ""; 265 } 266 } 267 268 277 public static String toString(ExecRow row, int startPoint, int endPoint) 278 { 279 return toString(row.getRowArray(), startPoint, endPoint); 280 } 281 282 291 public static String toString(Object [] objs, int startPoint, int endPoint) 292 { 293 StringBuffer strbuf = new StringBuffer (); 294 295 if (SanityManager.DEBUG) 296 { 297 if (endPoint >= objs.length) 298 { 299 SanityManager.THROWASSERT("endPoint "+endPoint+" is too high,"+ 300 " array only has "+objs.length+" elements"); 301 } 302 } 303 strbuf.append("("); 304 for (int i = startPoint; i <= endPoint; i++) 305 { 306 if (i > 0) 307 { 308 strbuf.append(","); 309 } 310 strbuf.append(objs[i]); 311 } 312 strbuf.append(")"); 313 return strbuf.toString(); 314 } 315 316 317 325 public static String toString(ExecRow row, int[] positions) 326 { 327 return toString(row.getRowArray(), positions); 328 } 329 330 338 public static String toString(Object [] objs, int[] positions) 339 { 340 if (positions == null) 341 { 342 return (String ) null; 343 } 344 345 StringBuffer strbuf = new StringBuffer (); 346 347 strbuf.append("("); 348 for (int i = 0; i < positions.length; i++) 349 { 350 351 if (i > 0) 352 { 353 strbuf.append(","); 354 } 355 strbuf.append(objs[positions[i] - 1]); 356 } 357 strbuf.append(")"); 358 return strbuf.toString(); 359 } 360 361 368 public static String intArrayToString(int[] colMap) 369 { 370 StringBuffer strbuf = new StringBuffer (); 371 372 strbuf.append("("); 373 for (int i = 0; i < colMap.length; i++) 374 { 375 if (i > 0) 376 { 377 strbuf.append(","); 378 } 379 strbuf.append(colMap[i]); 380 } 381 strbuf.append(")"); 382 return strbuf.toString(); 383 } 384 385 public static boolean inAscendingOrder(int[] colMap) 386 { 387 if (colMap != null) 388 { 389 int lastCol = -1; 390 for (int i = 0; i < colMap.length; i++) 391 { 392 if (lastCol > colMap[i]) 393 { 394 return false; 395 } 396 lastCol = colMap[i]; 397 } 398 } 399 return true; 400 } 401 410 public static FormatableBitSet shift(FormatableBitSet bitSet, int n) 411 { 412 FormatableBitSet out = null; 413 if (bitSet != null) 414 { 415 int size = bitSet.size(); 416 out = new FormatableBitSet(size); 417 for (int i = n; i < size; i++) 418 { 419 if (bitSet.get(i)) 420 { 421 out.set(i-n); 422 } 423 } 424 } 425 return out; 426 } 427 } 428 | Popular Tags |