Package com.j256.ormlite.db

Examples of com.j256.ormlite.db.DatabaseType


  /**
   * 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

   * <b>NOTE:</b> I couldn't remove the code warning associated with this method when used with more than 2 arguments.
   * </p>
   */
  public Where<T, ID> and(Where<T, ID> first, Where<T, ID> second, Where<T, ID>... others) {
    Clause[] clauses = buildClauseArray(others, "AND");
    Clause secondClause = pop("AND");
    Clause firstClause = pop("AND");
    addClause(new ManyClause(firstClause, secondClause, clauses, ManyClause.AND_OPERATION));
    return this;
  }
View Full Code Here

   * <b>NOTE:</b> I can't remove the code warning associated with this method. Use the iterator method below.
   * </p>
   */
  public Where<T, ID> or(Where<T, ID> left, Where<T, ID> right, Where<T, ID>... others) {
    Clause[] clauses = buildClauseArray(others, "OR");
    Clause secondClause = pop("OR");
    Clause firstClause = pop("OR");
    addClause(new ManyClause(firstClause, secondClause, clauses, ManyClause.OR_OPERATION));
    return this;
  }
View Full Code Here

  @Override
  public String toString() {
    if (clauseStackLevel == 0) {
      return "empty where clause";
    } else {
      Clause clause = peek();
      return "where clause: " + clause;
    }
  }
View Full Code Here

  private Clause pop(String label) {
    if (clauseStackLevel == 0) {
      throw new IllegalStateException("Expecting there to be a clause already defined for '" + label
          + "' operation");
    }
    Clause clause = clauseStack[--clauseStackLevel];
    // to help gc
    clauseStack[clauseStackLevel] = null;
    return clause;
  }
View Full Code Here

   * </p>
   */
  public Where<T, ID> exists(QueryBuilder<?, ?> subQueryBuilder) throws SQLException {
    // we do this to turn off the automatic addition of the ID column in the select column list
    subQueryBuilder.enableInnerQuery();
    addClause(new Exists(new InternalQueryBuilderWrapper(subQueryBuilder)));
    return this;
  }
View Full Code Here

  /**
   * Add a IN clause so the column must be equal-to one of the objects from the list passed in.
   */
  public Where<T, ID> in(String columnName, Iterable<?> objects) throws SQLException {
    addClause(new In(columnName, findColumnFieldType(columnName), objects));
    return this;
  }
View Full Code Here

TOP

Related Classes of com.j256.ormlite.db.DatabaseType

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.