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

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

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

Where.eq介绍

[英]Add a '=' clause so the column must be equal to the value.
[中]添加一个“=”子句,使该列必须等于该值。

代码示例

代码示例来源:origin: BaronZ88/MinimalistWeather

/**
 * 根据城市查询城市信息
 *
 * @param cityId 城市ID
 * @return city
 * @throws SQLException
 */
public City queryCityById(String cityId) throws SQLException {
  QueryBuilder<City, Integer> queryBuilder = cityDaoOperation.queryBuilder();
  queryBuilder.where().eq(City.CITY_ID_FIELD_NAME, cityId);
  return queryBuilder.queryForFirst();
}

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

public void buildQuery(QueryBuilder qb) throws SQLException {
  Where where = qb.where();
  where.eq("nightCard", false);
  where.eq("splitCardHalf", false);
  int clausesCount = 2;
  if (name != null) {
    where.eq("doubleFaced", doubleFaced);
    clausesCount++;
    where.eq("rarity", rarity);
    where.eq("setCode", setCode);
    where.eq("convertedManaCost", convertedManaCost);
    clausesCount++;
    int colorClauses = 0;
    if (black) {
      where.eq("black", true);
      colorClauses++;
      where.eq("blue", true);
      colorClauses++;
      where.eq("green", true);
      colorClauses++;
      where.eq("red", true);
      colorClauses++;

代码示例来源: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: j256/ormlite-core

@Override
public List<T> queryForEq(String fieldName, Object value) throws SQLException {
  return queryBuilder().where().eq(fieldName, value).query();
}

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

public UserStats getUser(String userName) {
  try {
    QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
    qb.limit(1L).where().eq("userName", userName);
    List<UserStats> users = dao.query(qb.prepare());
    if (!users.isEmpty()) {
      return users.get(0);
    }
  } catch (SQLException ex) {
    Logger.getLogger(UserStatsRepository.class).error("Error getting a user from DB - ", ex);
  }
  return null;
}

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

@Override
public List<T> queryForEq(String fieldName, Object value) throws SQLException {
  return queryBuilder().where().eq(fieldName, value).query();
}

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

public List<ExpansionInfo> getSetsFromBlock(String blockName) {
  List<ExpansionInfo> sets = new LinkedList<>();
  try {
    QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
    qb.where().eq("blockName", new SelectArg(blockName));
    return expansionDao.query(qb.prepare());
  } catch (SQLException ex) {
    logger.error(ex);
  }
  return sets;
}

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

public static List<Person> getAllPeople(ZulipApp app) throws SQLException {
  RuntimeExceptionDao<Person, Object> dao = app.getDao(Person.class);
  return dao.queryBuilder().where().eq(Person.ISBOT_FIELD, false).query();
}

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

public AuthorizedUser getByName(String userName) {
  try {
    QueryBuilder<AuthorizedUser, Object> qb = dao.queryBuilder();
    qb.where().eq("name", new SelectArg(userName));
    List<AuthorizedUser> results = dao.query(qb.prepare());
    if (results.size() == 1) {
      return results.get(0);
    }
    return null;
  } catch (SQLException ex) {
    Logger.getLogger(AuthorizedUserRepository.class).error("Error getting a authorized_user - ", ex);
  }
  return null;
}

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

public AuthorizedUser getByEmail(String userName) {
  try {
    QueryBuilder<AuthorizedUser, Object> qb = dao.queryBuilder();
    qb.where().eq("email", new SelectArg(userName));
    List<AuthorizedUser> results = dao.query(qb.prepare());
    if (results.size() == 1) {
      return results.get(0);
    }
    return null;
  } catch (SQLException ex) {
    Logger.getLogger(AuthorizedUserRepository.class).error("Error getting a authorized_user - ", ex);
  }
  return null;
}

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

public List<CardInfo> findCards(String name) {
  try {
    QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
    queryBuilder.where().eq("name", new SelectArg(name));
    return cardDao.query(queryBuilder.prepare());
  } catch (SQLException ex) {
  }
  return Collections.emptyList();
}

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

public List<ExpansionInfo> getSetsWithBasicLandsByReleaseDate() {
  List<ExpansionInfo> sets = new LinkedList<>();
  try {
    QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
    qb.orderBy("releaseDate", false);
    qb.where().eq("basicLands", new SelectArg(true));
    sets = expansionDao.query(qb.prepare());
  } catch (SQLException ex) {
    logger.error(ex);
  }
  return sets;
}

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

public ExpansionInfo getSetByName(String setName) {
  ExpansionInfo set = null;
  try {
    QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
    qb.limit(1L).where().eq("name", new SelectArg(setName));
    List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
    if (!expansions.isEmpty()) {
      set = expansions.get(0);
    }
  } catch (SQLException ex) {
    logger.error(ex);
  }
  return set;
}

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

public ExpansionInfo getSetByCode(String setCode) {
  ExpansionInfo set = null;
  try {
    QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
    qb.limit(1L).where().eq("code", new SelectArg(setCode));
    List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
    if (!expansions.isEmpty()) {
      set = expansions.get(0);
    }
  } catch (SQLException ex) {
    logger.error(ex);
  }
  return set;
}

代码示例来源:origin: tianshaojie/AndroidFine

return articleDaoOpe.queryBuilder().where().eq("user_id", userId)
      .query();
} catch (SQLException e)

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

public static long getDatabaseVersion(ConnectionSource connectionSource, String entityName) 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));
  List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
  if (dbVersions.isEmpty()) {
    return 0;
  } else {
    return dbVersions.get(0).getVersion();
  }
}

代码示例来源: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

public static void updateVersion(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));
  List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
  if (!dbVersions.isEmpty()) {
    DeleteBuilder<DatabaseVersion, Object> deleteBuilder = dbVersionDao.deleteBuilder();
    deleteBuilder.where().eq("entity", new SelectArg(entityName));
    deleteBuilder.delete();
  }
  DatabaseVersion databaseVersion = new DatabaseVersion();
  databaseVersion.setEntity(entityName);
  databaseVersion.setVersion(version);
  dbVersionDao.create(databaseVersion);
}

代码示例来源: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;
  }
}

相关文章