Package com.j256.ormlite.stmt

Examples of com.j256.ormlite.stmt.Where


    if (columnAnnotation == null && idAnnotation == null && oneToOneAnnotation == null
        && manyToOneAnnotation == null) {
      return null;
    }

    DatabaseFieldConfig config = new DatabaseFieldConfig();
    String fieldName = field.getName();
    if (databaseType.isEntityNamesMustBeUpCase()) {
      fieldName = fieldName.toUpperCase();
    }
    config.setFieldName(fieldName);

    if (columnAnnotation != null) {
      try {
        Method method = columnAnnotation.getClass().getMethod("name");
        String name = (String) method.invoke(columnAnnotation);
        if (name != null && name.length() > 0) {
          config.setColumnName(name);
        }
        method = columnAnnotation.getClass().getMethod("length");
        config.setWidth((Integer) method.invoke(columnAnnotation));
        method = columnAnnotation.getClass().getMethod("nullable");
        config.setCanBeNull((Boolean) method.invoke(columnAnnotation));
        method = columnAnnotation.getClass().getMethod("unique");
        config.setUnique((Boolean) method.invoke(columnAnnotation));
      } catch (Exception e) {
        throw SqlExceptionUtil.create("Problem accessing fields from the Column annotation for field " + field,
            e);
      }
    }
    if (idAnnotation != null) {
      if (generatedValueAnnotation == null) {
        config.setId(true);
      } else {
        // generatedValue only works if it is also an id according to {@link GeneratedValue)
        config.setGeneratedId(true);
      }
    }
    // foreign values are always ones we can't map as primitives (or Strings)
    config.setForeign(oneToOneAnnotation != null || manyToOneAnnotation != null);
    config.setDataPersister(DataPersisterManager.lookupForField(field));
    config.setUseGetSet(DatabaseFieldConfig.findGetMethod(field, false) != null
        && DatabaseFieldConfig.findSetMethod(field, false) != null);
    return config;
  }
View Full Code Here


    }
  }

  public static <T, ID> MappedUpdateId<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
      throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot update-id in " + tableInfo.getDataClass()
          + " because it doesn't have an id field");
    }
    StringBuilder sb = new StringBuilder(64);
View Full Code Here

    super(tableInfo, statement, argFieldTypes);
  }

  public static <T, ID> MappedDelete<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
      throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot delete from " + tableInfo.getDataClass()
          + " because it doesn't have an id field");
    }
    StringBuilder sb = new StringBuilder(64);
View Full Code Here

  /**
   * This is private because the execute is the only method that should be called here.
   */
  private static <T, ID> MappedDeleteCollection<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo,
      int dataSize) throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot delete " + tableInfo.getDataClass()
          + " because it doesn't have an id field defined");
    }
    StringBuilder sb = new StringBuilder(128);
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 StatementBuilder<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

    this.dao = dao;
    this.dataClass = tableConfig.getDataClass();
    this.tableName = tableConfig.getTableName();
    this.fieldTypes = tableConfig.getFieldTypes(databaseType);
    // find the id field
    FieldType findIdFieldType = null;
    for (FieldType fieldType : fieldTypes) {
      if (fieldType.isId() || fieldType.isGeneratedId() || fieldType.isGeneratedIdSequence()) {
        if (findIdFieldType != null) {
          throw new SQLException("More than 1 idField configured for class " + dataClass + " ("
              + findIdFieldType + "," + fieldType + ")");
        }
        findIdFieldType = fieldType;
      }
    }
    // if we just have 1 field and it is a generated-id then inserts will be blank which is not allowed.
    if (fieldTypes.length == 1 && findIdFieldType != null && findIdFieldType.isGeneratedId()) {
      throw new SQLException("Must have more than a single field which is a generated-id for class " + dataClass);
    }
    // can be null if there is no id field
    this.idField = findIdFieldType;
    this.constructor = tableConfig.getConstructor();
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 StatementBuilder<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

      for (FieldType fieldType : fieldTypes) {
        map.put(fieldType.getDbColumnName(), fieldType);
      }
      fieldNameMap = map;
    }
    FieldType fieldType = fieldNameMap.get(columnName);
    // if column name is not found
    if (fieldType == null) {
      // look to see if someone is using the field-name instead of column-name
      for (FieldType fieldType2 : fieldTypes) {
        if (fieldType2.getFieldName().equals(columnName)) {
View Full Code Here

   * Return the array of field objects pulled from the data object.
   */
  protected Object[] getFieldObjects(Object data) throws SQLException {
    Object[] objects = new Object[argFieldTypes.length];
    for (int i = 0; i < argFieldTypes.length; i++) {
      FieldType fieldType = argFieldTypes[i];
      objects[i] = fieldType.extractJavaFieldToSqlArgValue(data);
      if (objects[i] == null && fieldType.getDefaultValue() != null) {
        objects[i] = fieldType.getDefaultValue();
      }
    }
    return objects;
  }
View Full Code Here

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

TOP

Related Classes of com.j256.ormlite.stmt.Where

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.