Package com.j256.ormlite.stmt

Examples of com.j256.ormlite.stmt.SelectArg


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


    int fieldC = 0;
    for (FieldType fieldType : tableInfo.getFieldTypes()) {
      Object fieldValue = fieldType.getFieldValueIfNotDefault(matchObj);
      if (fieldValue != null) {
        if (useArgs) {
          fieldValue = new SelectArg(fieldValue);
        }
        where.eq(fieldType.getColumnName(), fieldValue);
        fieldC++;
      }
    }
View Full Code Here

    QueryBuilder<T, ID> qb = queryBuilder();
    Where<T, ID> where = qb.where();
    for (Map.Entry<String, Object> entry : fieldValues.entrySet()) {
      Object fieldValue = entry.getValue();
      if (useArgs) {
        fieldValue = new SelectArg(fieldValue);
      }
      where.eq(entry.getKey(), fieldValue);
    }
    if (fieldValues.size() == 0) {
      return Collections.emptyList();
View Full Code Here

    Foo foo2 = new Foo();
    assertEquals(1, dao.create(foo2));

    CloseableWrappedIterable<Foo> wrapped =
        dao.getWrappedIterable(dao.queryBuilder().where().eq(Foo.ID_COLUMN_NAME, new SelectArg()).prepare());
    try {
      wrapped.iterator();
      fail("Should have thrown");
    } catch (IllegalStateException e) {
      // expected
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>();
    cmpInt.appendArgOrValue(null, numberFieldType, sb, argList, value);
    assertEquals(1, argList.size());
    assertEquals(INT_COLUMN_NAME, value.getColumnName());
  }
View Full Code Here

    assertEquals(foreign.id, results.get(0).foreign.id);

    /*
     * Now let's try the same thing but with a SelectArg
     */
    SelectArg selectArg = new SelectArg();
    qb.where().eq(ForeignWrapper.FOREIGN_FIELD_NAME, selectArg);
    selectArg.setValue(foreign.id);
    results = wrapperDao.query(qb.prepare());
    assertEquals(1, results.size());
    assertNotNull(results.get(0).foreign);
    assertEquals(foreign.id, results.get(0).foreign.id);

    /*
     * Now let's try the same thing but with a SelectArg with foreign value, not foreign.id
     */
    selectArg = new SelectArg();
    qb.where().eq(ForeignWrapper.FOREIGN_FIELD_NAME, selectArg);
    selectArg.setValue(foreign);
    results = wrapperDao.query(qb.prepare());
    assertEquals(1, results.size());
    assertNotNull(results.get(0).foreign);
    assertEquals(foreign.id, results.get(0).foreign.id);
  }
View Full Code Here

      if (foo2.id > maxId) {
        maxId = foo2.id;
      }
    }
    // using seletArgs
    SelectArg arg1 = new SelectArg();
    SelectArg arg2 = new SelectArg();
    QueryBuilder<Basic, String> bqb = basicDao.queryBuilder();
    bqb.selectColumns(Basic.ID_FIELD);
    bqb.where().eq(Basic.ID_FIELD, arg1);
    PreparedQuery<Foo> preparedQuery =
        fooDao.queryBuilder().where().in(Foo.STUFF_FIELD_NAME, bqb).and().lt(Foo.ID_FIELD_NAME, arg2).prepare();
    arg1.setValue(string1);
    // this should get none
    arg2.setValue(0);
    List<Foo> results = fooDao.query(preparedQuery);
    assertEquals(0, results.size());
  }
View Full Code Here

  @Test
  public void testSerializableWhere() throws Exception {
    Dao<AllTypes, Object> allDao = createDao(AllTypes.class, true);
    try {
      // can't query for a serial field
      allDao.queryBuilder().where().eq(AllTypes.SERIAL_FIELD_NAME, new SelectArg());
      fail("expected exception");
    } catch (SQLException e) {
      // expected
    }
  }
View Full Code Here

      assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
    } else {
      return false;
    }

    SelectArg selectArg = new SelectArg();
    qb.where().eq(fieldName, selectArg);
    selectArg.setValue(value);
    results = allDao.query(qb.prepare());
    assertEquals(1, results.size());
    assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
    return true;
  }
View Full Code Here

  private PreparedQuery<Post> makePostsForUserQuery() throws SQLException {
    // build our inner query for UserPost objects
    QueryBuilder<UserPost, Integer> userPostQb = userPostDao.queryBuilder();
    // just select the post-id field
    userPostQb.selectColumns(UserPost.POST_ID_FIELD_NAME);
    SelectArg userSelectArg = new SelectArg();
    // you could also just pass in user1 here
    userPostQb.where().eq(UserPost.USER_ID_FIELD_NAME, userSelectArg);

    // build our outer query for Post objects
    QueryBuilder<Post, Integer> postQb = postDao.queryBuilder();
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.