Package org.apache.metamodel.schema

Examples of org.apache.metamodel.schema.ColumnType


        Column column = selectItems[0].getColumn();
        assertNotNull(column);
       
        // the columns used to create the object did not have column types assigned.
        ColumnType type = column.getType();
        assertNull(type);
    }
View Full Code Here


        if (_operand == null) {
            require("Can only use EQUALS or DIFFERENT_FROM operator with null-operand",
                    _operator == OperatorType.DIFFERENT_FROM || _operator == OperatorType.EQUALS_TO);
        }
        if (_operator == OperatorType.LIKE) {
            ColumnType type = _selectItem.getColumn().getType();
            if (type != null) {
                require("Can only use LIKE operator with strings", type.isLiteral()
                        && (_operand instanceof String || _operand instanceof SelectItem));
            }
        }
        require("SelectItem cannot be null", _selectItem != null);
    }
View Full Code Here

                if (operand instanceof SelectItem) {
                    final String selectItemString = ((SelectItem) operand).getSameQueryAlias(includeSchemaInColumnPaths);
                    sb.append(selectItemString);
                } else {
                    ColumnType columnType = _selectItem.getExpectedColumnType();
                    final String sqlValue = FormatHelper.formatSqlValue(columnType, operand);
                    sb.append(sqlValue);
                }
            }
        } else {
View Full Code Here

   * @throws SQLException
   */
  public static void setStatementValue(final PreparedStatement st,
      final int valueIndex, final Column column, Object value)
      throws SQLException {
    final ColumnType type = (column == null ? null : column.getType());

    if (type == null || type == ColumnType.OTHER) {
      // type is not known - nothing more we can do to narrow the type
      st.setObject(valueIndex, value);
      return;
    }

    if (value == null && type != null) {
      try {
        final int jdbcType = type.getJdbcType();
        st.setNull(valueIndex, jdbcType);
        return;
      } catch (Exception e) {
        logger.warn(
            "Exception occurred while calling setNull(...) for value index "
                + valueIndex
                + ". Attempting value-based setter method instead.",
            e);
      }
    }

    if (type == ColumnType.VARCHAR && value instanceof Date) {
      // some drivers (SQLite and JTDS for MS SQL server) treat dates as
      // VARCHARS. In that case we need to convert the dates to the
      // correct format
      String nativeType = column.getNativeType();
      Date date = (Date) value;
      if ("DATE".equalsIgnoreCase(nativeType)) {
        value = FormatHelper
            .formatSqlTime(ColumnType.DATE, date, false);
      } else if ("TIME".equalsIgnoreCase(nativeType)) {
        value = FormatHelper
            .formatSqlTime(ColumnType.TIME, date, false);
      } else if ("TIMESTAMP".equalsIgnoreCase(nativeType)
          || "DATETIME".equalsIgnoreCase(nativeType)) {
        value = FormatHelper.formatSqlTime(ColumnType.TIMESTAMP, date,
            false);
      }
    }

    if (type != null && type.isTimeBased() && value instanceof String) {
      value = FormatHelper.parseSqlTime(type, (String) value);
    }

    try {
      if (type == ColumnType.DATE && value instanceof Date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime((Date) value);
        st.setDate(valueIndex,
            new java.sql.Date(cal.getTimeInMillis()), cal);
      } else if (type == ColumnType.TIME && value instanceof Date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime((Date) value);
        st.setTime(valueIndex,
            new java.sql.Time(cal.getTimeInMillis()), cal);
      } else if (type == ColumnType.TIMESTAMP && value instanceof Date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime((Date) value);
        st.setTimestamp(valueIndex,
            new java.sql.Timestamp(cal.getTimeInMillis()), cal);
      } else if (type == ColumnType.CLOB || type == ColumnType.NCLOB) {
        if (value instanceof InputStream) {
          InputStream inputStream = (InputStream) value;
          st.setAsciiStream(valueIndex, inputStream);
        } else if (value instanceof Reader) {
          Reader reader = (Reader) value;
          st.setCharacterStream(valueIndex, reader);
        } else if (value instanceof NClob) {
          NClob nclob = (NClob) value;
          st.setNClob(valueIndex, nclob);
        } else if (value instanceof Clob) {
          Clob clob = (Clob) value;
          st.setClob(valueIndex, clob);
        } else if (value instanceof String) {
          st.setString(valueIndex, (String) value);
        } else {
          st.setObject(valueIndex, value);
        }
      } else if (type == ColumnType.BLOB || type == ColumnType.BINARY) {
        if (value instanceof byte[]) {
          byte[] bytes = (byte[]) value;
          st.setBytes(valueIndex, bytes);
        } else if (value instanceof InputStream) {
          InputStream inputStream = (InputStream) value;
          st.setBinaryStream(valueIndex, inputStream);
        } else if (value instanceof Blob) {
          Blob blob = (Blob) value;
          st.setBlob(valueIndex, blob);
        } else {
          st.setObject(valueIndex, value);
        }
      } else if (type.isLiteral()) {
        final String str;
        if (value instanceof Reader) {
          Reader reader = (Reader) value;
          str = FileHelper.readAsString(reader);
        } else {
View Full Code Here

  public static String getValueAsSql(Column column, Object value,
      IQueryRewriter queryRewriter) {
    if (value == null) {
      return "NULL";
    }
    final ColumnType columnType = column.getType();
    if (columnType.isLiteral() && value instanceof String) {
      value = queryRewriter.escapeQuotes((String) value);
    }
    String formatSqlValue = FormatHelper.formatSqlValue(columnType, value);
    return formatSqlValue;
  }
View Full Code Here

        final SelectItem selectItem = getHeader().getSelectItem(i);
        final int columnIndex = i + 1;
        if (selectItem.getFunction() == null) {
            Column column = selectItem.getColumn();
            if (column != null) {
                ColumnType type = column.getType();
                try {
                    if (type == ColumnType.TIME) {
                        return _resultSet.getTime(columnIndex);
                    } else if (type == ColumnType.DATE) {
                        return _resultSet.getDate(columnIndex);
                    } else if (type == ColumnType.TIMESTAMP) {
                        return _resultSet.getTimestamp(columnIndex);
                    } else if (type == ColumnType.BLOB) {
                        final Blob blob = _resultSet.getBlob(columnIndex);
                        return blob;
                    } else if (type == JdbcDataContext.COLUMN_TYPE_BLOB_AS_BYTES) {
                        final Blob blob = _resultSet.getBlob(columnIndex);
                        final InputStream inputStream = blob.getBinaryStream();
                        final byte[] bytes = FileHelper.readAsBytes(inputStream);
                        return bytes;
                    } else if (type.isBinary()) {
                        return _resultSet.getBytes(columnIndex);
                    } else if (type == ColumnType.CLOB || type == ColumnType.NCLOB) {
                        final Clob clob = _resultSet.getClob(columnIndex);
                        return clob;
                    } else if (type == JdbcDataContext.COLUMN_TYPE_CLOB_AS_STRING) {
                        final Clob clob = _resultSet.getClob(columnIndex);
                        final Reader reader = clob.getCharacterStream();
                        final String result = FileHelper.readAsString(reader);
                        return result;
                    } else if (type.isBoolean()) {
                        return _resultSet.getBoolean(columnIndex);
                    }
                } catch (Exception e) {
                    logger.warn("Failed to retrieve " + type
                            + " value using type-specific getter, retrying with generic getObject(...) method", e);
View Full Code Here

            if (i != 0) {
                sb.append(',');
            }
            Column column = columns[i];
            sb.append(column.getName());
            ColumnType type = column.getType();
            if (type != null) {
                sb.append(' ');
                sb.append(type.toString());
                Integer columnSize = column.getColumnSize();
                if (columnSize != null) {
                    sb.append('(');
                    sb.append(columnSize);
                    sb.append(')');
View Full Code Here

            sb.append('\'');
        } else if (operand instanceof Number) {
            sb.append(operand);
        } else if (operand instanceof Date) {
            final SimpleDateFormat dateFormat;
            ColumnType expectedColumnType = selectItem.getExpectedColumnType();
            if (expectedColumnType == ColumnType.DATE) {
                // note: we don't apply the timezone for DATE fields, since they
                // don't contain time-of-day information.
                dateFormat = new SimpleDateFormat(SOQL_DATE_FORMAT_OUT);
            } else if (expectedColumnType == ColumnType.TIME) {
View Full Code Here

                    final String columnName = field.getName();
                    final String columnLabel = field.getLabel();
                    final Boolean nillable = field.isNillable();
                    final FieldType type = field.getType();
                    final Integer columnSize = field.getLength();
                    final ColumnType columnType = toColumnType(type);

                    final MutableColumn column = new MutableColumn(columnName, columnType);
                    column.setTable(SalesforceTable.this);
                    column.setRemarks(columnLabel);
                    column.setNullable(nillable);
View Full Code Here

        }
        _columnTypes.add(columnType);
    }

    public void addObservation(Class<?> valueType) {
        final ColumnType columnType = ColumnTypeImpl.convertColumnType(valueType);
        addObservation(columnType);
    }
View Full Code Here

TOP

Related Classes of org.apache.metamodel.schema.ColumnType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.