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

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

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

Where.and介绍

[英]AND operation which takes the previous clause and the next clause and AND's them together.
[中]以及将上一个子句和下一个子句放在一起的运算。

代码示例

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

public CardInfo findCard(String setCode, String cardNumber) {
  try {
    QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
    queryBuilder.limit(1L).where().eq("setCode", new SelectArg(setCode)).and().eq("cardNumber", cardNumber).and().eq("nightCard", false);
    List<CardInfo> result = cardDao.query(queryBuilder.prepare());
    if (!result.isEmpty()) {
      return result.get(0);
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error finding card from DB : " + ex);
  }
  return null;
}

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

public Set<String> getNonbasicLandNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    Where where = qb.where();
    where.and(
        where.not().like("supertypes", '%' + SuperType.BASIC.name() + '%'),
        where.like("types", '%' + CardType.LAND.name() + '%')
    );
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-land names from DB : " + ex);
  }
  return names;
}

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

public Set<String> getNonLandAndNonCreatureNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    Where where = qb.where();
    where.and(
        where.not().like("types", '%' + CardType.CREATURE.name() + '%'),
        where.not().like("types", '%' + CardType.LAND.name() + '%')
    );
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-land and non-creature names from DB : " + ex);
  }
  return names;
}

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

public Set<String> getNonArtifactAndNonLandNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    Where where = qb.where();
    where.and(
        where.not().like("types", '%' + CardType.ARTIFACT.name() + '%'),
        where.not().like("types", '%' + CardType.LAND.name() + '%')
    );
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-artifact non-land names from DB : " + ex);
  }
  return names;
}

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

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);
    dbVersion.setVersion(version);
    dbVersionDao.create(dbVersion);
  }
  return dbVersions.isEmpty();
}

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

public static boolean isNewBuildRun(ConnectionSource connectionSource, String entityName, Class clazz) throws SQLException {
  // build time checks only for releases, not runtime (e.g. IDE debug)
  // that's check uses for cards db cleanup on new version/build
  String currentBuild = JarVersion.getBuildTime(clazz);
  if (!JarVersion.isBuildTimeOk(currentBuild)) {
    return false;
  }
  TableUtils.createTableIfNotExists(connectionSource, DatabaseBuild.class);
  Dao<DatabaseBuild, Object> dbBuildDao = DaoManager.createDao(connectionSource, DatabaseBuild.class);
  QueryBuilder<DatabaseBuild, Object> queryBuilder = dbBuildDao.queryBuilder();
  queryBuilder.where().eq("entity", new SelectArg(entityName)).and().eq("last_build", currentBuild);
  List<DatabaseBuild> dbBuilds = dbBuildDao.query(queryBuilder.prepare());
  if (dbBuilds.isEmpty()) {
    DatabaseBuild dbBuild = new DatabaseBuild();
    dbBuild.setEntity(entityName);
    dbBuild.setLastBuild(currentBuild);
    dbBuildDao.create(dbBuild);
  }
  return dbBuilds.isEmpty();
}

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

where.and(5);
    colorClauses++;
  where.and(clausesCount);
} else {
  where.eq("cardNumber", new SelectArg(0));

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

QueryBuilder<Account, String> qb = accountDao.queryBuilder();
Where where = qb.where();
// the name field must be equal to "foo"
where.eq(Account.NAME_FIELD_NAME, "foo");
// and
where.and();
// the password field must be equal to "_secret"
where.eq(Account.PASSWORD_FIELD_NAME, "_secret");
PreparedQuery<Account, String> preparedQuery = qb.prepareQuery();

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

@Override
public long countOf(AGGREGATION_TYPE aggregationType, long start, long end) {
  QueryBuilder<MetricsBatteryUsage, Object> queryBuilder = getDao().queryBuilder();
  try {
    return queryBuilder.where().gt(MetricsBatteryUsage.KEY_TIMESTAMP, start).and()
        .le(MetricsBatteryUsage.KEY_TIMESTAMP, end).and()
        .eq(MetricsBatteryUsage.KEY_AGGREGATION_TYPE, aggregationType).countOf();
  } catch (Exception ex) {
    _logger.error("Unable to execute countOf query", ex);
    return -1;
  }
}

代码示例来源:origin: zulip/zulip-android

@Override
public Where<Message, Object> modWhere(Where<Message, Object> where)
    throws SQLException {
  where.eq(Message.STREAM_FIELD, new SelectArg(stream));
  if (subject != null) {
    where.and().eq(Message.SUBJECT_FIELD, new SelectArg(subject));
  }
  return where;
}

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

@Override
public Node get(Integer gatewayId, String nodeEui) {
  try {
    QueryBuilder<Node, Integer> queryBuilder = this.getDao().queryBuilder();
    queryBuilder.where().eq(Node.KEY_GATEWAY_ID, gatewayId).and().eq(Node.KEY_EUI, nodeEui);
    return queryBuilder.queryForFirst();
  } catch (SQLException ex) {
    _logger.error("unable to get Node", ex);
    return null;
  }
}

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

@Test(expected = IllegalStateException.class)
public void testAlreadyNeedsClause() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  where.eq(Foo.VAL_COLUMN_NAME, "bar");
  where.and();
  where.and();
  StringBuilder sb = new StringBuilder();
  where.appendSql(null, sb, null);
}

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

@Override
public List<OperationTable> getByTimerIdEnabled(Integer timerId) {
  List<Integer> ids = DaoUtils.getOperationTimerMapDao().getOperationIdsByTimerId(timerId);
  try {
    return this.getDao().queryBuilder().where().in(OperationTable.KEY_ID, ids).and()
        .eq(OperationTable.KEY_ENABLED, true).query();
  } catch (SQLException ex) {
    _logger.error("Exception,", ex);
  }
  return null;
}

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

@Override
public List<OperationTable> getByTimerIdEnabled(Integer timerId) {
  List<Integer> ids = DaoUtils.getOperationTimerMapDao().getOperationIdsByTimerId(timerId);
  try {
    return this.getDao().queryBuilder().where().in(OperationTable.KEY_ID, ids).and()
        .eq(OperationTable.KEY_ENABLED, true).query();
  } catch (SQLException ex) {
    _logger.error("Exception,", ex);
    throw new McDatabaseException(ex);
  }
}

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

@Test(expected = IllegalStateException.class)
public void testMissingClause() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val = 1;
  where.and();
  where.eq(Foo.VAL_COLUMN_NAME, val);
  where.appendSql(null, new StringBuilder(), new ArrayList<ArgumentHolder>());
}

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

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

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

/**
 * {@inheritDoc}
 */
@Override
public int delete(DataColumns data) throws SQLException {
  DeleteBuilder<DataColumns, TableColumnKey> db = deleteBuilder();
  db.where().eq(DataColumns.COLUMN_TABLE_NAME, data.getTableName()).and()
      .eq(DataColumns.COLUMN_COLUMN_NAME, data.getColumnName());
  PreparedDelete<DataColumns> deleteQuery = db.prepare();
  int deleted = delete(deleteQuery);
  return deleted;
}

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

@Test
public void testMissingAndArg() throws Exception {
  Dao<Foo, String> fooDao = createDao(Foo.class, false);
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  try {
    qb.where().and();
    fail("expected exception");
  } catch (IllegalStateException e) {
    // expected
  }
}

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

@Test
public void testWherePrepare() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  List<Foo> results = fooDao.query(fooDao.queryBuilder()
      .where()
      .eq(Foo.ID_COLUMN_NAME, foo1.id)
      .and()
      .eq(Foo.VAL_COLUMN_NAME, foo1.val)
      .prepare());
  assertEquals(1, results.size());
  assertEquals(foo1, results.get(0));
}

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

@Test
public void testJeremyNull() throws Exception {
  Jeremy1 loop1 = new Jeremy1();
  Dao<Jeremy2, Long> dao = createDao(Jeremy2.class, true);
  List<Jeremy2> bars = dao.queryBuilder()
      .where()
      .eq(Jeremy2.LOOP1_COLUMN_NAME, loop1)
      .and()
      .eq(Jeremy2.OTHER_COLUMN_NAME, "someValue")
      .query();
  assertEquals(0, bars.size());
}

相关文章