Package com.j256.ormlite.stmt.mapped

Examples of com.j256.ormlite.stmt.mapped.BaseMappedStatement


        tableInfo.getFieldTypes(), "query-for-id");
  }

  protected static <T, ID> String buildStatement(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
      throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot query-for-id with " + tableInfo.getDataClass()
          + " because it doesn't have an id field");
    }
    // build the select statement by hand
View Full Code Here


    super(tableInfo, statement, argFieldTypes);
  }

  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");
    }
    if (tableInfo.getFieldTypes().length == 1) {
      throw new SQLException("Cannot update " + tableInfo.getDataClass()
View Full Code Here

   * NOTE: Use of this means that the resulting objects may not have a valid ID column value so cannot be deleted or
   * updated.
   * </p>
   */
  public QueryBuilder<T, ID> groupBy(String columnName) {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new IllegalArgumentException("Can't groupBy foreign colletion field: " + columnName);
    }
    if (groupByList == null) {
      groupByList = new ArrayList<String>();
    }
View Full Code Here

   */
  public static <T> FieldType extractIdFieldType(ConnectionSource connectionSource, Class<T> clazz, String tableName)
      throws SQLException {
    for (Class<?> classWalk = clazz; classWalk != null; classWalk = classWalk.getSuperclass()) {
      for (Field field : classWalk.getDeclaredFields()) {
        FieldType fieldType = FieldType.createFieldType(connectionSource, tableName, field, clazz);
        if (fieldType != null
            && (fieldType.isId() || fieldType.isGeneratedId() || fieldType.isGeneratedIdSequence())) {
          return fieldType;
        }
      }
    }
    return null;
View Full Code Here

  /**
   * Add "ORDER BY" clause to the SQL query statement.
   */
  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);
    }
    if (orderByList == null) {
      orderByList = new ArrayList<OrderBy>();
    }
View Full Code Here

    }
    appendOffset(sb);
  }

  private void addSelectColumnToList(String columnName) {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new IllegalArgumentException("Can't select from foreign colletion field: " + columnName);
    }
    selectColumnList.add(columnName);
  }
View Full Code Here

  private static <T> FieldType[] extractFieldTypes(ConnectionSource connectionSource, Class<T> clazz, String tableName)
      throws SQLException {
    List<FieldType> fieldTypes = new ArrayList<FieldType>();
    for (Class<?> classWalk = clazz; classWalk != null; classWalk = classWalk.getSuperclass()) {
      for (Field field : classWalk.getDeclaredFields()) {
        FieldType fieldType = FieldType.createFieldType(connectionSource, tableName, field, clazz);
        if (fieldType != null) {
          fieldTypes.add(fieldType);
        }
      }
    }
View Full Code Here

      if (first) {
        first = false;
      } else {
        sb.append(',');
      }
      FieldType fieldType = tableInfo.getFieldTypeByColumnName(columnName);
      appendFieldColumnName(sb, fieldType, fieldTypeList);
      if (fieldType == idField) {
        hasId = true;
      }
    }
View Full Code Here

  private FieldType[] convertFieldConfigs(ConnectionSource connectionSource, String tableName,
      List<DatabaseFieldConfig> fieldConfigs) throws SQLException {
    List<FieldType> fieldTypes = new ArrayList<FieldType>();
    for (DatabaseFieldConfig fieldConfig : fieldConfigs) {
      FieldType fieldType = null;
      // walk up the classes until we find the field
      for (Class<?> classWalk = dataClass; classWalk != null; classWalk = classWalk.getSuperclass()) {
        Field field;
        try {
          field = classWalk.getDeclaredField(fieldConfig.getFieldName());
        } catch (NoSuchFieldException e) {
          // we ignore this and just loop hopefully finding it in a upper class
          continue;
        }
        if (field != null) {
          fieldType = new FieldType(connectionSource, tableName, field, fieldConfig, dataClass);
          break;
        }
      }

      if (fieldType == null) {
View Full Code Here

    if (value == null) {
      return null;
    } else if (fieldType == null) {
      return value;
    } else if (fieldType.isForeign() && fieldType.getFieldType() == value.getClass()) {
      FieldType idFieldType = fieldType.getForeignIdField();
      return idFieldType.extractJavaFieldValue(value);
    } else {
      return fieldType.convertJavaFieldToSqlArgValue(value);
    }
  }
View Full Code Here

TOP

Related Classes of com.j256.ormlite.stmt.mapped.BaseMappedStatement

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.