Exemple #1
0
  private void appendColumnOptions(BaseColumn column) {
    StringBuilder options = new StringBuilder();
    addCommonOptions(options, column);

    if (!column.getDatatype().isBuiltin()) {
      addOption(
          options,
          UDT,
          column.getDatatype().getName()
              + "("
              + column.getLength()
              + ", "
              + column.getPrecision()
              + ", "
              + column.getScale()
              + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    }

    if (column.getDatatype().getRadix() != 0
        && column.getRadix() != column.getDatatype().getRadix()) {
      addOption(options, RADIX, column.getRadix());
    }

    buildColumnOptions(column, options);

    if (options.length() != 0) {
      append(SPACE).append(OPTIONS).append(SPACE).append(LPAREN).append(options).append(RPAREN);
    }
  }
Exemple #2
0
 private void appendDefault(BaseColumn column) {
   if (column.getDefaultValue() != null) {
     append(SPACE).append(DEFAULT).append(SPACE);
     if (BaseColumn.EXPRESSION_DEFAULT.equalsIgnoreCase(
         column.getProperty(BaseColumn.DEFAULT_HANDLING, false))) {
       append(column.getDefaultValue());
     } else {
       append(TICK)
           .append(StringUtil.replaceAll(column.getDefaultValue(), TICK, TICK + TICK))
           .append(TICK);
     }
   }
 }
Exemple #3
0
  private void buildColumnOptions(BaseColumn baseColumn, StringBuilder options) {
    if (baseColumn instanceof Column) {
      Column column = (Column) baseColumn;
      if (!column.isSelectable()) {
        addOption(options, SELECTABLE, column.isSelectable());
      }

      // if table is already updatable, then columns are implicitly updatable.
      if (!column.isUpdatable()
          && column.getParent() instanceof Table
          && ((Table) column.getParent()).supportsUpdate()) {
        addOption(options, UPDATABLE, column.isUpdatable());
      }

      if (column.isCurrency()) {
        addOption(options, CURRENCY, column.isCurrency());
      }

      // only record if not default
      if (!column.isCaseSensitive() && column.getDatatype().isCaseSensitive()) {
        addOption(options, CASE_SENSITIVE, column.isCaseSensitive());
      }

      if (!column.isSigned() && column.getDatatype().isSigned()) {
        addOption(options, SIGNED, column.isSigned());
      }
      if (column.isFixedLength()) {
        addOption(options, FIXED_LENGTH, column.isFixedLength());
      }
      // length and octet length should be same. so this should be never be true.
      // TODO - this is not quite valid since we are dealing with length representing chars in
      // UTF-16, then there should be twice the bytes
      if (column.getCharOctetLength() != 0 && column.getLength() != column.getCharOctetLength()) {
        addOption(options, CHAR_OCTET_LENGTH, column.getCharOctetLength());
      }

      // by default the search type is default data type search, so avoid it.
      if (column.getSearchType() != null
          && (!column.getSearchType().equals(column.getDatatype().getSearchType())
              || column.isSearchTypeSet())) {
        addOption(options, SEARCHABLE, column.getSearchType().name());
      }

      if (column.getMinimumValue() != null) {
        addOption(options, MIN_VALUE, column.getMinimumValue());
      }

      if (column.getMaximumValue() != null) {
        addOption(options, MAX_VALUE, column.getMaximumValue());
      }

      if (column.getNullValues() != -1) {
        addOption(options, NULL_VALUE_COUNT, column.getNullValues());
      }

      if (column.getDistinctValues() != -1) {
        addOption(options, DISTINCT_VALUES, column.getDistinctValues());
      }
    }

    if (baseColumn.getNativeType() != null) {
      addOption(options, NATIVE_TYPE, baseColumn.getNativeType());
    }

    buildOptions(baseColumn, options);
  }
Exemple #4
0
 private void appendColumn(BaseColumn column, boolean includeName, boolean includeType) {
   if (includeName) {
     append(SQLStringVisitor.escapeSinglePart(column.getName()));
   }
   if (includeType) {
     Datatype datatype = column.getDatatype();
     String runtimeTypeName = column.getRuntimeType();
     if (datatype != null) {
       runtimeTypeName = datatype.getRuntimeTypeName();
     }
     if (includeName) {
       append(SPACE);
     }
     append(runtimeTypeName);
     if (LENGTH_DATATYPES.contains(runtimeTypeName)) {
       if (column.getLength() != 0
           && (datatype == null || column.getLength() != datatype.getLength())) {
         append(LPAREN).append(column.getLength()).append(RPAREN);
       }
     } else if (PRECISION_DATATYPES.contains(runtimeTypeName)
         && !column.isDefaultPrecisionScale()) {
       append(LPAREN).append(column.getPrecision());
       if (column.getScale() != 0) {
         append(COMMA).append(column.getScale());
       }
       append(RPAREN);
     }
     if (datatype != null) {
       for (int dims = column.getArrayDimensions(); dims > 0; dims--) {
         append(Tokens.LSBRACE).append(Tokens.RSBRACE);
       }
     }
     if (column.getNullType() == NullType.No_Nulls) {
       append(SPACE).append(NOT_NULL);
     }
   }
 }