Package com.j256.ormlite.field

Examples of com.j256.ormlite.field.FieldType


  /**
   * Add "ORDER BY" clause to the SQL query statement. This can be called multiple times to add additional "ORDER BY"
   * clauses. Ones earlier are applied first.
   */
  public QueryBuilder<T, ID> orderBy(String columnName, boolean ascending) {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new IllegalArgumentException("Can't orderBy foreign colletion field: " + columnName);
    }
    addOrderBy(new OrderBy(columnName, ascending));
    return this;
  }
View Full Code Here


   * Match up our joined fields so we can throw a nice exception immediately if you can't join with this type.
   */
  private void matchJoinedFields(JoinInfo joinInfo, QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException {
    for (FieldType fieldType : tableInfo.getFieldTypes()) {
      // if this is a foreign field and its foreign-id field is the same as the other's id
      FieldType foreignIdField = fieldType.getForeignIdField();
      if (fieldType.isForeign() && foreignIdField.equals(joinedQueryBuilder.tableInfo.getIdField())) {
        joinInfo.localField = fieldType;
        joinInfo.remoteField = foreignIdField;
        return;
      }
    }
View Full Code Here

          sb.append(", ");
        }
        sb.append(select.getRawSql());
        continue;
      }
      FieldType fieldType = tableInfo.getFieldTypeByColumnName(select.getColumnName());
      /*
       * If this is a foreign-collection then we add it to our field-list but _not_ to the select list because
       * foreign collections don't have a column in the database.
       */
      if (fieldType.isForeignCollection()) {
        fieldTypeList.add(fieldType);
        continue;
      }
      if (first) {
        first = false;
View Full Code Here

    } else if (fieldType.isForeign() && fieldType.getType().isAssignableFrom(argOrValue.getClass())) {
      /*
       * If we have a foreign field and our argument is an instance of the foreign object (i.e. not its id), then
       * we need to extract the id. We allow super-classes of the field but not sub-classes.
       */
      FieldType idFieldType = fieldType.getForeignIdField();
      appendArgOrValue(databaseType, idFieldType, sb, argList, idFieldType.extractJavaFieldValue(argOrValue));
      // no need for the space since it was done in the recursion
      appendSpace = false;
    } else if (fieldType.isEscapedValue()) {
      databaseType.appendEscapedWord(sb, fieldType.convertJavaFieldToSqlArgValue(argOrValue).toString());
    } else if (fieldType.isForeign()) {
View Full Code Here

      Object[] args = getFieldObjects(data);
      Object versionDefaultValue = null;
      // implement {@link DatabaseField#version()}
      if (versionFieldTypeIndex >= 0 && args[versionFieldTypeIndex] == null) {
        // if the version is null then we need to initialize it before create
        FieldType versionFieldType = argFieldTypes[versionFieldTypeIndex];
        versionDefaultValue = versionFieldType.moveToNextValue(null);
        args[versionFieldTypeIndex] = versionFieldType.convertJavaFieldToSqlArgValue(versionDefaultValue);
      }

      int rowC;
      try {
        rowC = databaseConnection.insert(statement, args, argFieldTypes, keyHolder);
View Full Code Here

        }
        sb.append("?");
      }
      sb.append(")");
    }
    FieldType idField = tableInfo.getIdField();
    String queryNext = buildQueryNextSequence(databaseType, idField);
    return new MappedCreate<T, ID>(tableInfo, sb.toString(), argFieldTypes, queryNext, versionFieldTypeIndex);
  }
View Full Code Here

    this.versionFieldTypeIndex = versionFieldTypeIndex;
  }

  public static <T, ID> MappedUpdate<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
      throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot update " + tableInfo.getDataClass() + " because it doesn't have an id field");
    }
    StringBuilder sb = new StringBuilder(64);
    appendTableName(databaseType, sb, "UPDATE ", tableInfo.getTableName());
    boolean first = true;
    int argFieldC = 0;
    FieldType versionFieldType = null;
    int versionFieldTypeIndex = -1;
    // first we count up how many arguments we are going to have
    for (FieldType fieldType : tableInfo.getFieldTypes()) {
      if (isFieldUpdatable(fieldType, idField)) {
        if (fieldType.isVersion()) {
View Full Code Here

    return true;
  }

  public ID extractId(T data) throws SQLException {
    checkForInitialized();
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Class " + dataClass + " does not have an id field");
    }
    @SuppressWarnings("unchecked")
    ID id = (ID) idField.extractJavaFieldValue(data);
    return id;
  }
View Full Code Here

  /**
   * Add a column to be set to a value for UPDATE statements. This will generate something like columnName = 'value'
   * with the value escaped if necessary.
   */
  public UpdateBuilder<T, ID> updateColumnValue(String columnName, Object value) throws SQLException {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new SQLException("Can't update foreign colletion field: " + columnName);
    }
    addUpdateColumnToList(columnName, new SetValue(columnName, fieldType, value));
    return this;
  }
View Full Code Here

   * {@link #escapeValue(StringBuilder, String)} methods and should have any column names escaped using the
   * {@link #escapeColumnName(String)} or {@link #escapeColumnName(StringBuilder, String)} methods.
   * </p>
   */
  public UpdateBuilder<T, ID> updateColumnExpression(String columnName, String expression) throws SQLException {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new SQLException("Can't update foreign colletion field: " + columnName);
    }
    addUpdateColumnToList(columnName, new SetExpression(columnName, fieldType, expression));
    return this;
  }
View Full Code Here

TOP

Related Classes of com.j256.ormlite.field.FieldType

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.