com.j256.ormlite.dao.Dao.queryForEq()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(147)

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

Dao.queryForEq介绍

[英]Query for the items in the object table that match a simple where with a single field = value type of WHERE clause. This is a convenience method for calling queryBuilder().where().eq(fieldName, value).query().
[中]查询对象表中与简单where匹配的项,并使用where子句的单字段=值类型。这是调用queryBuilder()的一个方便方法。where()。eq(字段名、值)。查询()。

代码示例

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

  1. public Weather queryWeather(String cityId) throws SQLException {
  2. return TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), () -> {
  3. Weather weather = weatherDaoOperation.queryForId(cityId);
  4. if (weather != null) {
  5. weather.setAirQualityLive(apiDaoOperation.queryForId(cityId));
  6. weather.setWeatherForecasts(forecastDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
  7. weather.setLifeIndexes(lifeIndexesDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
  8. weather.setWeatherLive(realTimeDaoOperation.queryForId(cityId));
  9. }
  10. return weather;
  11. });
  12. }

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

  1. /**
  2. * 查询数据库中的所有已添加的城市
  3. *
  4. * @return 结果集中只包括城市信息,天气数据不在其中
  5. * @throws SQLException
  6. */
  7. public List<Weather> queryAllSaveCity() throws SQLException {
  8. return TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), () -> {
  9. List<Weather> weatherList = weatherDaoOperation.queryForAll();
  10. for (Weather weather : weatherList) {
  11. String cityId = weather.getCityId();
  12. weather.setAirQualityLive(apiDaoOperation.queryForId(cityId));
  13. weather.setWeatherForecasts(forecastDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
  14. weather.setLifeIndexes(lifeIndexesDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
  15. weather.setWeatherLive(realTimeDaoOperation.queryForId(cityId));
  16. }
  17. return weatherList;
  18. });
  19. }

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

  1. /**
  2. * @see Dao#queryForEq(String, Object)
  3. */
  4. @Override
  5. public List<T> queryForEq(String fieldName, Object value) {
  6. try {
  7. return dao.queryForEq(fieldName, value);
  8. } catch (SQLException e) {
  9. logMessage(e, "queryForEq threw exception on: " + fieldName);
  10. throw new RuntimeException(e);
  11. }
  12. }

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

  1. /**
  2. * @see Dao#queryForEq(String, Object)
  3. */
  4. @Override
  5. public List<T> queryForEq(String fieldName, Object value) {
  6. try {
  7. return dao.queryForEq(fieldName, value);
  8. } catch (SQLException e) {
  9. logMessage(e, "queryForEq threw exception on: " + fieldName);
  10. throw new RuntimeException(e);
  11. }
  12. }

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

  1. @Override
  2. public List<Sensor> getAllByNodeId(Integer nodeId) {
  3. try {
  4. if (nodeId == null) {
  5. return null;
  6. }
  7. return this.getDao().queryForEq(Sensor.KEY_NODE_ID, nodeId);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list with node id:{}", nodeId, ex);
  10. return null;
  11. }
  12. }

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

  1. @Override
  2. public List<SensorVariable> getByVariableType(MESSAGE_TYPE_SET_REQ variableType) {
  3. try {
  4. if (variableType == null) {
  5. return null;
  6. }
  7. return this.getDao().queryForEq(SensorVariable.KEY_VARIABLE_TYPE, variableType);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list with variableType: {}", variableType, ex);
  10. return null;
  11. }
  12. }

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

  1. @Override
  2. public List<ForwardPayload> getAll(Integer sensorVariableId) {
  3. try {
  4. return this.getDao().queryForEq(ForwardPayload.KEY_SOURCE_ID, sensorVariableId);
  5. } catch (SQLException ex) {
  6. _logger.error("unable to featch getAll for selected id, ", ex);
  7. }
  8. return null;
  9. }

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

  1. @Override
  2. public List<SensorVariable> getAllBySensorId(Integer sensorRefId) {
  3. try {
  4. if (sensorRefId == null) {
  5. return new ArrayList<SensorVariable>();
  6. }
  7. return this.getDao().queryForEq(SensorVariable.KEY_SENSOR_DB_ID, sensorRefId);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list with sensorRefId:{}", sensorRefId, ex);
  10. return null;
  11. }
  12. }

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

  1. @Override
  2. public User getByUsername(String userName) {
  3. try {
  4. List<User> users = this.getDao().queryForEq(User.KEY_USER_NAME, userName);
  5. if (users != null && !users.isEmpty()) {
  6. return users.get(0);
  7. }
  8. } catch (SQLException ex) {
  9. _logger.error("Error,", ex);
  10. }
  11. return null;
  12. }

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

  1. @Override
  2. public List<Sensor> getAllByRoomId(Integer roomId) {
  3. try {
  4. if (roomId == null) {
  5. return null;
  6. }
  7. return this.getDao().queryForEq(Sensor.KEY_ROOM_ID, roomId);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list with room id:{}", roomId, ex);
  10. return null;
  11. }
  12. }

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

  1. @Override
  2. public List<SensorsVariablesMap> getAll(MESSAGE_TYPE_PRESENTATION sensorType) {
  3. try {
  4. if (sensorType == null) {
  5. return null;
  6. }
  7. return this.getDao().queryForEq(SensorsVariablesMap.KEY_SENSOR_TYPE, sensorType);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list wit sensorType:{}", sensorType, ex);
  10. return null;
  11. }
  12. }

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

  1. @Override
  2. public List<SensorVariable> getAllBySensorId(Integer sensorRefId) {
  3. try {
  4. if (sensorRefId == null) {
  5. return new ArrayList<SensorVariable>();
  6. }
  7. return this.getDao().queryForEq(SensorVariable.KEY_SENSOR_DB_ID, sensorRefId);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list with sensorRefId:{}", sensorRefId, ex);
  10. throw new McDatabaseException(ex);
  11. }
  12. }

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

  1. @Override
  2. public List<ForwardPayload> getAll(Integer sensorVariableId) {
  3. try {
  4. return this.getDao().queryForEq(ForwardPayload.KEY_SOURCE_ID, sensorVariableId);
  5. } catch (SQLException ex) {
  6. _logger.error("unable to featch getAll for selected id, ", ex);
  7. throw new McDatabaseException(ex);
  8. }
  9. }

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

  1. @Override
  2. public List<Sensor> getAllByNodeId(Integer nodeId) {
  3. try {
  4. if (nodeId == null) {
  5. return null;
  6. }
  7. return this.getDao().queryForEq(Sensor.KEY_NODE_ID, nodeId);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list with node id:{}", nodeId, ex);
  10. throw new McDatabaseException(ex);
  11. }
  12. }

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

  1. @Override
  2. public List<SensorsVariablesMap> getAll(MESSAGE_TYPE_PRESENTATION sensorType) {
  3. try {
  4. if (sensorType == null) {
  5. return null;
  6. }
  7. return this.getDao().queryForEq(SensorsVariablesMap.KEY_SENSOR_TYPE, sensorType);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list wit sensorType:{}", sensorType, ex);
  10. throw new McDatabaseException(ex);
  11. }
  12. }

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

  1. @Override
  2. public List<Sensor> getByType(String typeString) {
  3. try {
  4. return this.getDao()
  5. .queryForEq("type", MESSAGE_TYPE_PRESENTATION.valueOf(typeString));
  6. } catch (SQLException ex) {
  7. _logger.error("unable to get all list with typeString: {}", typeString, ex);
  8. return null;
  9. }
  10. }

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

  1. @Override
  2. public List<SensorVariable> getByVariableType(MESSAGE_TYPE_SET_REQ variableType) {
  3. try {
  4. if (variableType == null) {
  5. return null;
  6. }
  7. return this.getDao().queryForEq(SensorVariable.KEY_VARIABLE_TYPE, variableType);
  8. } catch (SQLException ex) {
  9. _logger.error("unable to get all list with variableType: {}", variableType, ex);
  10. throw new McDatabaseException(ex);
  11. }
  12. }

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

  1. @Override
  2. public List<Sensor> getByType(String typeString) {
  3. try {
  4. return this.getDao()
  5. .queryForEq("type", MESSAGE_TYPE_PRESENTATION.valueOf(typeString));
  6. } catch (SQLException ex) {
  7. _logger.error("unable to get all list with typeString: {}", typeString, ex);
  8. throw new McDatabaseException(ex);
  9. }
  10. }

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

  1. @Test(expected = RuntimeException.class)
  2. public void testQueryForEqThrow() throws Exception {
  3. @SuppressWarnings("unchecked")
  4. Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  5. RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  6. expect(dao.queryForEq(null, null)).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.queryForEq(null, null);
  9. verify(dao);
  10. }

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

  1. @Test
  2. public void testComparisonOfForeignCollection() throws Exception {
  3. Dao<ForeignCollectionComparison, Long> dao = createDao(ForeignCollectionComparison.class, true);
  4. try {
  5. // we can't do a query on a foreign collection field
  6. dao.queryForEq("foos", "someValue");
  7. } catch (NullPointerException e) {
  8. fail("Should not get a NPE here");
  9. } catch (SQLException e) {
  10. // this is what we should get
  11. }
  12. }

相关文章