コード例 #1
0
  /**
   * Append the specified IEntryResult[] to the IEntryResult to create a single result representing
   * an index entry that was split across multiple index records.
   *
   * @param result
   * @param continuationResults
   * @param blockSize
   */
  public static IEntryResult joinEntryResults(
      final IEntryResult result, final IEntryResult[] continuationResults, final int blockSize) {
    CoreArgCheck.isNotNull(result);

    // If the IEntryResult is not continued on another record, return the original
    char[] baseResult = result.getWord();
    if (baseResult.length < blockSize
        || baseResult[blockSize - 1] != IndexConstants.RECORD_TYPE.RECORD_CONTINUATION) {
      return result;
    }

    // Extract the UUID string from the original result
    String baseStr = new String(baseResult);
    String objectID = extractUUIDString(result);

    // Create and initialize a StringBuffer to store the concatenated result
    StringBuffer sb = new StringBuffer();
    sb.append(baseStr.substring(0, blockSize - 1));

    // Append the continuation results onto the original -
    // assumes the IEntryResult[] are in ascending order of segment number
    final IEntryResult[] sortedResults = sortContinuationResults(objectID, continuationResults);
    for (int i = 0; i < sortedResults.length; i++) {
      char[] continuation = sortedResults[i].getWord();
      int segNumber = getContinuationSegmentNumber(objectID, sortedResults[i]);
      int beginIndex = objectID.length() + Integer.toString(segNumber).length() + 5;
      for (int j = beginIndex; j < continuation.length; j++) {
        if (j < blockSize - 1) {
          sb.append(continuation[j]);
        }
      }
    }

    return new EntryResult(sb.toString().toCharArray(), result.getFileReferences());
  }
コード例 #2
0
  public static int getContinuationSegmentNumber(
      final String objectID, final IEntryResult continuationResult) {
    // The header portion of the continuation record is of the form:
    // RECORD_CONTINUATION|objectID|segmentCount|
    char[] record = continuationResult.getWord();

    int segNumber = -1;

    int index = objectID.length() + 4;
    if (record[index + 1] == IndexConstants.RECORD_STRING.RECORD_DELIMITER) {
      // segment count < 10
      segNumber = Character.getNumericValue(record[index]);
    } else if (record[index + 2] == IndexConstants.RECORD_STRING.RECORD_DELIMITER) {
      // 9 < segment count < 100
      char[] temp = new char[] {record[index], record[index + 1]};
      String segCount = new String(temp);
      segNumber = Integer.parseInt(segCount);
    } else if (record[index + 3] == IndexConstants.RECORD_STRING.RECORD_DELIMITER) {
      // 99 < segment count < 1000
      char[] temp = new char[] {record[index], record[index + 1], record[index + 2]};
      String segCount = new String(temp);
      segNumber = Integer.parseInt(segCount);
    }
    return segNumber;
  }
コード例 #3
0
 /**
  * Return the {@link org.teiid.designer.metadata.runtime.MetadataRecord} instances for specified
  * IEntryResult.
  *
  * @param entryResult
  * @param container Container reference to be set on the record
  */
 public static MetadataRecord getMetadataRecord(
     final IEntryResult queryResult, final EObjectFinder container) {
   MetadataRecord record = getMetadataRecord(queryResult.getWord());
   if (record instanceof AbstractMetadataRecord) {
     ((AbstractMetadataRecord) record).setEObjectFinder(container);
   }
   return record;
 }
コード例 #4
0
  /**
   * Extract the UUID string from the IEntryResult
   *
   * @param result
   */
  public static String extractUUIDString(final IEntryResult result) {
    CoreArgCheck.isNotNull(result);

    char[] word = result.getWord();
    String baseStr = new String(word);
    int beginIndex = baseStr.indexOf(UUID.PROTOCOL);
    int endIndex = word.length;
    CoreArgCheck.isNonNegative(beginIndex);
    for (int i = beginIndex; i < word.length; i++) {
      if (word[i] == IndexConstants.RECORD_STRING.RECORD_DELIMITER) {
        endIndex = i;
        break;
      }
    }
    CoreArgCheck.isTrue(beginIndex < endIndex, "begin index should be less than end index");
    return baseStr.substring(beginIndex, endIndex);
  }