Package com.j256.ormlite.stmt

Examples of com.j256.ormlite.stmt.SelectArg


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

      ArgumentHolder selectArg = (ArgumentHolder) argOrValue;
      selectArg.setMetaInfo(columnName, fieldType);
      argList.add(selectArg);
    } else if (fieldType.isSelectArgRequired()) {
      sb.append('?');
      ArgumentHolder selectArg = new SelectArg();
      selectArg.setMetaInfo(columnName, fieldType);
      // conversion is done when the getValue() is called
      selectArg.setValue(argOrValue);
      argList.add(selectArg);
    } else if (fieldType.isForeign() && fieldType.getFieldType() == 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.
View Full Code Here

    }
  }

  protected PreparedQuery<T> getPreparedQuery() throws SQLException {
    if (preparedQuery == null) {
      SelectArg fieldArg = new SelectArg();
      fieldArg.setValue(fieldValue);
      QueryBuilder<T, ID> qb = dao.queryBuilder();
      if (orderColumn != null) {
        qb.orderBy(orderColumn, true);
      }
      preparedQuery = qb.where().eq(fieldName, fieldArg).prepare();
View Full Code Here

    verify(databaseType);
  }

  @Test
  public void testAppendArgOrValueSelectArg() throws SQLException {
    SelectArg value = new SelectArg();
    StringBuilder sb = new StringBuilder();
    List<ArgumentHolder> argList = new ArrayList<ArgumentHolder>();
    try {
      value.getColumnName();
      fail("Should have thrown");
    } catch (IllegalArgumentException e) {
      // expected
    }
    cmpInt.appendArgOrValue(null, numberFieldType, sb, argList, value);
    assertEquals(1, argList.size());
    assertEquals(INT_COLUMN_NAME, value.getColumnName());
  }
View Full Code Here

      String w = args[i + 1].toString();
      switch (w) {
      case "eq":
      case "=":
      case "==":
        wh.eq(args[i].toString(), new SelectArg(args[i + 2]));
        break;
      case "null":
        wh.isNull(args[i].toString());
        i -= 1;
        break;
      case "notnull":
        wh.isNotNull(args[i].toString());
        i -= 1;
        break;
      case "ne":
      case "!=":
      case "<>":
        wh.ne(args[i].toString()new SelectArg(args[i + 2]));
        break;
      case "gt":
      case ">":
        wh.gt(args[i].toString()new SelectArg(args[i + 2]));
        break;
      case "ge":
      case ">=":
        wh.ge(args[i].toString()new SelectArg(args[i + 2]));
        break;
      case "lt":
      case "<":
        wh.lt(args[i].toString()new SelectArg(args[i + 2]));
        break;
      case "le":
      case "<=":
        wh.le(args[i].toString()new SelectArg(args[i + 2]));
        break;
      case "like":
      case "~":
        wh.like(args[i].toString()new SelectArg(args[i + 2]));
        break;
      case "in":
        wh.in(args[i].toString()(Iterable<?>) args[i + 2]);
        break;
      case "between":
        wh.between(args[i].toString()new SelectArg(args[i + 2])new SelectArg(args[i + 3]));
        i += 1;
        break;
      }
    }
    return wh;
View Full Code Here

        Where where = qb.where();
        where.eq("nightCard", false);
        where.eq("splitCardHalf", false);
        int clausesCount = 2;
        if (name != null) {
            where.like("name", new SelectArg('%' + name + '%'));
            clausesCount++;
        }
        if (rules != null) {
            where.like("rules", new SelectArg('%' + rules + '%'));
            clausesCount++;
        }

        if (doubleFaced != null) {
            where.eq("doubleFaced", doubleFaced);
            clausesCount++;
        }

        for (Rarity rarity : rarities) {
            where.eq("rarity", rarity);
        }
        if (!rarities.isEmpty()) {
            where.or(rarities.size());
            clausesCount++;
        }

        for (String setCode : setCodes) {
            where.eq("setCode", setCode);
        }
        if (!setCodes.isEmpty()) {
            where.or(setCodes.size());
            clausesCount++;
        }


        if (types.size() != 7) { //if all types selected - no selection needed (Tribal and Conspiracy not selectable yet)
            for (CardType type : types) {
                where.like("types", new SelectArg('%' + type.name() + '%'));
            }
            if (!types.isEmpty()) {
                where.or(types.size());
                clausesCount++;
            }
        }

        for (CardType type : notTypes) {
            where.not().like("types", new SelectArg('%' + type.name() + '%'));
            clausesCount++;
        }

        for (String superType : supertypes) {
            where.like("supertypes", new SelectArg('%' + superType + '%'));
            clausesCount++;
        }
        for (String subType : notSupertypes) {
            where.not().like("supertypes", new SelectArg('%' + subType + '%'));
            clausesCount++;
        }

        for (String subType : subtypes) {
            where.like("subtypes", new SelectArg('%' + subType + '%'));
            clausesCount++;
        }

        if (!black || !blue || !green || !red || !white || !colorless) {
            int colorClauses = 0;
            if (black) {
                where.eq("black", true);
                colorClauses++;
            }
            if (blue) {
                where.eq("blue", true);
                colorClauses++;
            }
            if (green) {
                where.eq("green", true);
                colorClauses++;
            }
            if (red) {
                where.eq("red", true);
                colorClauses++;
            }
            if (white) {
                where.eq("white", true);
                colorClauses++;
            }
            if (colorless) {
                where.eq("black", false).eq("blue", false).eq("green", false).eq("red", false).eq("white", false);
                where.and(5);
                colorClauses++;
            }
            if (colorClauses > 0) {
                where.or(colorClauses);
                clausesCount++;
            }
        }

        if (maxCardNumber != Integer.MAX_VALUE) {
            where.le("cardNumber", maxCardNumber);
            clausesCount++;
        }

        if (clausesCount > 0) {
            where.and(clausesCount);
        } else {
            where.eq("cardNumber", new SelectArg(0));
        }



        if (start != null) {
View Full Code Here

    public static boolean isDatabaseObsolete(ConnectionSource connectionSource, String entityName, long version) throws SQLException {
        TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
        Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);

        QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
        queryBuilder.where().eq("entity", new SelectArg(entityName)).and().eq("version", version);
        List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());

        if (dbVersions.isEmpty()) {
            DatabaseVersion dbVersion = new DatabaseVersion();
            dbVersion.setEntity(entityName);
View Full Code Here

    assertEquals(1, accountDao.create(new Account(name1)));
    assertEquals(1, accountDao.create(new Account(name2)));
    assertEquals(1, accountDao.create(new Account(name3)));

    QueryBuilder<Account, Integer> statementBuilder = accountDao.queryBuilder();
    SelectArg selectArg = new SelectArg();
    // build a query with the WHERE clause set to 'name = ?'
    statementBuilder.where().like(Account.NAME_FIELD_NAME, selectArg);
    PreparedQuery<Account> preparedQuery = statementBuilder.prepare();

    // now we can set the select arg (?) and run the query
    selectArg.setValue(name1);
    List<Account> results = accountDao.query(preparedQuery);
    assertEquals("Should have found 1 account matching our query", 1, results.size());
    assertEquals(name1, results.get(0).getName());

    selectArg.setValue(name2);
    results = accountDao.query(preparedQuery);
    assertEquals("Should have found 1 account matching our query", 1, results.size());
    assertEquals(name2, results.get(0).getName());

    selectArg.setValue(name3);
    results = accountDao.query(preparedQuery);
    assertEquals("Should have found 1 account matching our query", 1, results.size());
    assertEquals(name3, results.get(0).getName());
  }
View Full Code Here

  protected PreparedQuery<T> getPreparedQuery() throws SQLException {
    if (dao == null) {
      return null;
    }
    if (preparedQuery == null) {
      SelectArg fieldArg = new SelectArg();
      fieldArg.setValue(parentId);
      QueryBuilder<T, ID> qb = dao.queryBuilder();
      if (orderColumn != null) {
        qb.orderBy(orderColumn, orderAscending);
      }
      preparedQuery = qb.where().eq(foreignFieldType.getColumnName(), fieldArg).prepare();
View Full Code Here

TOP

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

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.