private String getRange(LUWDataPartition partition, Collection keyCols) {
    StringBuffer buffer = new StringBuffer();
    String startStr = "";
    String endStr = "";

    for (Iterator keyIter = keyCols.iterator(); keyIter.hasNext(); ) {
      Column keyCol = (Column) keyIter.next();
      for (Iterator iter = partition.getPartitionElements().iterator(); iter.hasNext(); ) {
        LUWPartitionElement element = (LUWPartitionElement) iter.next();
        Column column = element.getLUWPartitionExpression().getColumn();

        if (column != keyCol) continue;
        DataType type = element.getLUWPartitionExpression().getColumn().getDataType();
        if (type instanceof CharacterStringDataType
            || type instanceof DateDataType
            || type instanceof TimeDataType) {
          String rangeValue = element.getStarting();
          if (rangeValue.equalsIgnoreCase("MINVALUE") || rangeValue.equalsIgnoreCase("MAXVALUE")) {
            startStr += rangeValue;
          } else {
            startStr += this.getSingleQuotedString(rangeValue);
          }

          rangeValue = element.getEnding();
          if (rangeValue.equalsIgnoreCase("MINVALUE") || rangeValue.equalsIgnoreCase("MAXVALUE")) {
            endStr += rangeValue;
          } else {
            endStr += this.getSingleQuotedString(rangeValue);
          }
        } else {
          startStr += element.getStarting();
          endStr += element.getEnding();
        }

        if (keyIter.hasNext()) {
          startStr += ",";
          endStr += ",";
        }
      }
    }
    buffer
        .append(SPACE)
        .append(STARTING)
        .append(SPACE)
        .append(FROM)
        .append(SPACE)
        .append(LEFT_PARENTHESIS)
        .append(startStr)
        .append(RIGHT_PARENTHESIS)
        .append(SPACE);
    if (!partition.isLowInclusive()) {
      buffer.append(SPACE).append(EXCLUSIVE).append(SPACE);
    }

    buffer
        .append(ENDING)
        .append(SPACE)
        .append(AT)
        .append(SPACE)
        .append(LEFT_PARENTHESIS)
        .append(endStr)
        .append(RIGHT_PARENTHESIS);
    if (!partition.isHighInclusive()) {
      buffer.append(SPACE).append(EXCLUSIVE).append(SPACE);
    }

    return buffer.toString();
  }
  private String getRangePartitions(LUWDataPartitionKey partitionKey) {
    StringBuffer buffer = new StringBuffer();

    boolean hasKey = false;
    StringBuffer keyBuffer = new StringBuffer();
    keyBuffer
        .append(NEWLINE)
        .append(TAB)
        .append(PARTITION_BY)
        .append(SPACE)
        .append(RANGE)
        .append(LEFT_PARENTHESIS);

    Collection keyCols = new ArrayList();
    Iterator it = partitionKey.getPartitionExpressions().iterator();
    while (it.hasNext()) {
      hasKey = true;
      LUWPartitionExpression expression = (LUWPartitionExpression) it.next();
      Column column = expression.getColumn();
      keyBuffer.append(column.getName());
      keyCols.add(column);

      if (expression.isNullsLast()) {
        keyBuffer.append(SPACE).append(NULLS_LAST);
      }

      if (it.hasNext()) {
        keyBuffer.append(", "); // $NON-NLS-1$
      }
    }

    keyBuffer.append(RIGHT_PARENTHESIS); // $NON-NLS-1$

    if (hasKey) {
      buffer.append(keyBuffer);
    }

    boolean hasDataPartition = false;
    StringBuffer datapartBuffer = new StringBuffer();
    datapartBuffer.append(NEWLINE).append(TAB).append(LEFT_PARENTHESIS);
    LUWStorageTable table = partitionKey.getTable();
    for (Iterator iter = table.getDataPartitions().iterator(); iter.hasNext(); ) {
      hasDataPartition = true;
      LUWDataPartition partition = (LUWDataPartition) iter.next();
      String partName = partition.getName();
      if (partName != null && !partName.equals("")) {
        datapartBuffer.append(PARTITION).append(SPACE).append(partName);
      }

      datapartBuffer.append(this.getRange(partition, keyCols));

      LUWTableSpace tsp = partition.getRegularDataTableSpace();
      if (tsp != null) {
        datapartBuffer.append(SPACE).append(IN).append(SPACE).append(tsp.getName());
      }
      tsp = partition.getLOBDataTableSpace();
      if (tsp != null) {
        datapartBuffer
            .append(SPACE)
            .append(LONG)
            .append(SPACE)
            .append(IN)
            .append(SPACE)
            .append(tsp.getName());
      }

      if (iter.hasNext()) {
        datapartBuffer.append(", ").append(NEWLINE).append(TAB); // $NON-NLS-1$
      }
    }
    datapartBuffer.append(RIGHT_PARENTHESIS);

    if (hasDataPartition) {
      buffer.append(datapartBuffer);
    }

    return buffer.toString();
  }