com.j256.ormlite.stmt.Where.or()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中com.j256.ormlite.stmt.Where.or()方法的一些代码示例,展示了Where.or()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Where.or()方法的具体详情如下:
包路径:com.j256.ormlite.stmt.Where
类名称:Where
方法名:or

Where.or介绍

[英]OR operation which takes the previous clause and the next clause and OR's them together.
[中]或将上一个子句和下一个子句合并在一起的操作。

代码示例

代码示例来源:origin: magefree/mage

where.or(rarities.size());
clausesCount++;
where.or(setCodes.size());
clausesCount++;
  where.or(types.size());
  clausesCount++;
  where.or(colorClauses);
  clausesCount++;

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();
where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter);
where.or();
where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter);
where.or();
where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter);

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();
where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter);
where.or(3);

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();

where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter);
where.or(3);

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();
where.or(where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter),
     where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter),
     where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter));

代码示例来源:origin: org.mycontroller.standalone/mycontroller-core

@Override
public void deleteBySensorId(Integer sensorId) {
  try {
    List<Integer> ids = DaoUtils.getSensorVariableDao().getSensorVariableIds(sensorId);
    DeleteBuilder<ForwardPayload, Integer> deleteBuilder = this.getDao().deleteBuilder();
    deleteBuilder.where().in(ForwardPayload.KEY_SOURCE_ID, ids).or()
        .in(ForwardPayload.KEY_DESTINATION_ID, ids);
    Integer deleteCount = deleteBuilder.delete();
    _logger.debug("Deleted SensorId:[{}], delete count:{}", sensorId, deleteCount);
  } catch (SQLException ex) {
    _logger.error("unable to delete SensorId:{}", sensorId, ex);
  }
}

代码示例来源:origin: mycontroller-org/mycontroller

@Override
public void deleteBySensorId(Integer sensorId) {
  try {
    List<Integer> ids = DaoUtils.getSensorVariableDao().getSensorVariableIds(sensorId);
    DeleteBuilder<ForwardPayload, Integer> deleteBuilder = this.getDao().deleteBuilder();
    deleteBuilder.where().in(ForwardPayload.KEY_SOURCE_ID, ids).or()
        .in(ForwardPayload.KEY_DESTINATION_ID, ids);
    Integer deleteCount = deleteBuilder.delete();
    _logger.debug("Deleted SensorId:[{}], delete count:{}", sensorId, deleteCount);
  } catch (SQLException ex) {
    _logger.error("unable to delete SensorId:{}", sensorId, ex);
    throw new McDatabaseException(ex);
  }
}

代码示例来源:origin: j256/ormlite-core

@Test
public void testOrManyOne() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val1 = 1312313;
  where.eq(Foo.VAL_COLUMN_NAME, val1);
  where.or(1);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  sb.append('(');
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  // NOTE: they are done in reverse order
  sb.append(" = ").append(val1);
  sb.append(" ) ");
  assertEquals(sb.toString(), whereSb.toString());
}

代码示例来源:origin: j256/ormlite-core

@Test
public void testOrFuture() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val = 112;
  where.eq(Foo.VAL_COLUMN_NAME, val);
  where.or();
  where.eq(Foo.VAL_COLUMN_NAME, val);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  sb.append('(');
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" = ").append(val);
  sb.append(" OR ");
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" = ").append(val);
  sb.append(" ) ");
  assertEquals(sb.toString(), whereSb.toString());
}

代码示例来源:origin: j256/ormlite-core

@SuppressWarnings("unchecked")
@Test
public void testOrAbsorb() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val = 112;
  where.or(where.eq(Foo.VAL_COLUMN_NAME, val), where.eq(Foo.VAL_COLUMN_NAME, val));
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  sb.append('(');
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" = ").append(val);
  sb.append(" OR ");
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" = ").append(val);
  sb.append(" ) ");
  assertEquals(sb.toString(), whereSb.toString());
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = IllegalArgumentException.class)
public void testOrManyZero() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  where.or(0);
}

代码示例来源:origin: mil.nga.geopackage/geopackage-core

/**
 * Delete by table name, either feature or tile table name
 * 
 * @param tableName
 *            table name, feature or tile
 * @return rows deleted
 * @throws SQLException
 *             upon failure
 */
public int deleteByTableName(String tableName) throws SQLException {
  DeleteBuilder<FeatureTileLink, FeatureTileLinkKey> db = deleteBuilder();
  db.where().eq(FeatureTileLink.COLUMN_FEATURE_TABLE_NAME, tableName)
      .or().eq(FeatureTileLink.COLUMN_TILE_TABLE_NAME, tableName);
  PreparedDelete<FeatureTileLink> deleteQuery = db.prepare();
  int deleted = delete(deleteQuery);
  return deleted;
}

代码示例来源:origin: mil.nga.geopackage/geopackage-core

/**
 * Get the relations to the table, both base table and related table
 * 
 * @param table
 *            table name
 * @return extended relations
 * @throws SQLException
 *             upon failure
 */
public List<ExtendedRelation> getTableRelations(String table)
    throws SQLException {
  QueryBuilder<ExtendedRelation, TableColumnKey> qb = queryBuilder();
  qb.where().like(ExtendedRelation.COLUMN_BASE_TABLE_NAME, table).or()
      .like(ExtendedRelation.COLUMN_RELATED_TABLE_NAME, table);
  PreparedQuery<ExtendedRelation> preparedQuery = qb.prepare();
  return query(preparedQuery);
}

代码示例来源:origin: QuickBlox/q-municate-android

public List<Message> getTempMessagesByDialogId(String dialogId){
  List<Message> messagesList = new ArrayList<>();
  try {
    QueryBuilder<Message, Long> messageQueryBuilder = dao.queryBuilder();
    QueryBuilder<DialogOccupant, Long> dialogOccupantQueryBuilder = dialogOccupantDao.queryBuilder();
    QueryBuilder<Dialog, Long> dialogQueryBuilder = dialogDao.queryBuilder();
    dialogQueryBuilder.where().eq(Dialog.Column.ID, dialogId);
    dialogOccupantQueryBuilder.join(dialogQueryBuilder);
    messageQueryBuilder.join(dialogOccupantQueryBuilder);
    Where<Message, Long> where = messageQueryBuilder.where();
    where.or(where.eq(Message.Column.STATE, State.TEMP_LOCAL),
        where.eq(Message.Column.STATE, State.TEMP_LOCAL_UNREAD));
    PreparedQuery<Message> preparedQuery = messageQueryBuilder.prepare();
    messagesList = dao.query(preparedQuery);
  } catch (SQLException e) {
    e.printStackTrace();
  }
  return messagesList;
}

代码示例来源:origin: QuickBlox/q-municate-android

public void deleteTempMessages(List<Long> dialogOccupantsIdsList) {
  try {
    DeleteBuilder<Message, Long> deleteBuilder = dao.deleteBuilder();
    Where<Message, Long> where = deleteBuilder.where();
    where.and(
        where.in(DialogOccupant.Column.ID, dialogOccupantsIdsList),
        where.or(
            where.eq(Message.Column.STATE, State.TEMP_LOCAL),
            where.eq(Message.Column.STATE, State.TEMP_LOCAL_UNREAD)
        )
    );
    if (deleteBuilder.delete() > 0) {
      //TODO VT need to think how to send IDs to observers
      notifyObserversDeletedById(dialogOccupantsIdsList);
    }
  } catch (SQLException e) {
    ErrorUtils.logError(e);
  }
}

代码示例来源:origin: QuickBlox/q-municate-android

public Message getLastTempMessagesByDialogId(String dialogId){
  Message message = null;
  try {
    QueryBuilder<Message, Long> messageQueryBuilder = dao.queryBuilder();
    QueryBuilder<DialogOccupant, Long> dialogOccupantQueryBuilder = dialogOccupantDao.queryBuilder();
    QueryBuilder<Dialog, Long> dialogQueryBuilder = dialogDao.queryBuilder();
    dialogQueryBuilder.where().eq(Dialog.Column.ID, dialogId);
    dialogOccupantQueryBuilder.join(dialogQueryBuilder);
    messageQueryBuilder.join(dialogOccupantQueryBuilder);
    Where<Message, Long> where = messageQueryBuilder.where();
    where.or(where.eq(Message.Column.STATE, State.TEMP_LOCAL),
        where.eq(Message.Column.STATE, State.TEMP_LOCAL_UNREAD));
    messageQueryBuilder.orderBy(Message.Column.CREATED_DATE, false);
    PreparedQuery<Message> preparedQuery = messageQueryBuilder.prepare();
    message = dao.queryForFirst(preparedQuery);
  } catch (SQLException e) {
    e.printStackTrace();
  }
  return message;
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
@SuppressWarnings("unchecked")
public void testOr() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  // test Or + Eq
  qb.where().eq(Foo.ID_COLUMN_NAME, foo1.id).or().eq(Foo.VAL_COLUMN_NAME, foo1.val);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertEquals(foo1, results.get(0));
  // test Or + Eq not inline
  Where<Foo, String> where = qb.where();
  where.eq(Foo.ID_COLUMN_NAME, foo2.id);
  where.or();
  where.eq(Foo.VAL_COLUMN_NAME, foo2.val);
  results = fooDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertEquals(foo2, results.get(0));
  // test Or of ands
  where = qb.where();
  where.or(where.and(where.eq(Foo.ID_COLUMN_NAME, foo1.id), where.eq(Foo.VAL_COLUMN_NAME, foo1.val)),
      where.eq(Foo.ID_COLUMN_NAME, foo2.id).and().eq(Foo.VAL_COLUMN_NAME, foo2.val));
  results = fooDao.query(qb.prepare());
  assertEquals(2, results.size());
  assertEquals(foo1, results.get(0));
  assertEquals(foo2, results.get(1));
}

代码示例来源:origin: QuickBlox/q-municate-android

public List<Message> getUnreadMessages(List<Long> dialogOccupantsIdsList, int currentUserId) {
  try {
    QueryBuilder<Message, Long> queryBuilder = dao.queryBuilder();
    QueryBuilder<DialogOccupant, Long> dialogOccupantQueryBuilder = dialogOccupantDao.queryBuilder();
    dialogOccupantQueryBuilder.where().ne(QMUserColumns.ID, currentUserId);
    queryBuilder.join(dialogOccupantQueryBuilder);
    Where<Message, Long> where = queryBuilder.where();
    where.and(
        where.in(DialogOccupant.Column.ID, dialogOccupantsIdsList),
        where.or(
            where.eq(Message.Column.STATE, State.DELIVERED),
            where.eq(Message.Column.STATE, State.TEMP_LOCAL_UNREAD)
        )
    );
    PreparedQuery<Message> preparedQuery = queryBuilder.prepare();
    return dao.query(preparedQuery);
  } catch (SQLException e) {
    ErrorUtils.logError(e);
  }
  return null;
}

代码示例来源:origin: j256/ormlite-core

@SuppressWarnings("unchecked")
@Test
public void testUseOfOrMany() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  assertEquals(0, dao.countOf());
  Foo foo1 = new Foo();
  int val = 1231231;
  foo1.val = val;
  assertEquals(1, dao.create(foo1));
  Foo foo2 = new Foo();
  foo2.val = val + 1;
  assertEquals(1, dao.create(foo2));
  Where<Foo, Integer> where = dao.queryBuilder().where();
  where.or(where.eq(Foo.ID_COLUMN_NAME, foo1.id), where.eq(Foo.ID_COLUMN_NAME, foo2.id),
      where.eq(Foo.VAL_COLUMN_NAME, val), where.eq(Foo.VAL_COLUMN_NAME, foo2.val));
  List<Foo> results = where.query();
  assertEquals(2, results.size());
  assertEquals(foo1.id, results.get(0).id);
  assertEquals(foo2.id, results.get(1).id);
}

代码示例来源:origin: j256/ormlite-core

@Test
public void testUseOfOrInt() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  assertEquals(0, dao.countOf());
  Foo foo1 = new Foo();
  int val = 1231231;
  foo1.val = val;
  assertEquals(1, dao.create(foo1));
  Foo foo2 = new Foo();
  foo2.val = val + 1;
  assertEquals(1, dao.create(foo2));
  Where<Foo, Integer> where = dao.queryBuilder().where();
  where.eq(Foo.ID_COLUMN_NAME, foo1.id);
  where.eq(Foo.ID_COLUMN_NAME, foo2.id);
  where.eq(Foo.VAL_COLUMN_NAME, val);
  where.eq(Foo.VAL_COLUMN_NAME, val + 1);
  where.or(4);
  List<Foo> results = where.query();
  assertEquals(2, results.size());
  assertEquals(foo1.id, results.get(0).id);
  assertEquals(foo2.id, results.get(1).id);
}

相关文章