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

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

本文整理了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

public Weather queryWeather(String cityId) throws SQLException {
  return TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), () -> {
    Weather weather = weatherDaoOperation.queryForId(cityId);
    if (weather != null) {
      weather.setAirQualityLive(apiDaoOperation.queryForId(cityId));
      weather.setWeatherForecasts(forecastDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
      weather.setLifeIndexes(lifeIndexesDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
      weather.setWeatherLive(realTimeDaoOperation.queryForId(cityId));
    }
    return weather;
  });
}

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

/**
 * 查询数据库中的所有已添加的城市
 *
 * @return 结果集中只包括城市信息,天气数据不在其中
 * @throws SQLException
 */
public List<Weather> queryAllSaveCity() throws SQLException {
  return TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), () -> {
    List<Weather> weatherList = weatherDaoOperation.queryForAll();
    for (Weather weather : weatherList) {
      String cityId = weather.getCityId();
      weather.setAirQualityLive(apiDaoOperation.queryForId(cityId));
      weather.setWeatherForecasts(forecastDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
      weather.setLifeIndexes(lifeIndexesDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
      weather.setWeatherLive(realTimeDaoOperation.queryForId(cityId));
    }
    return weatherList;
  });
}

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

/**
 * @see Dao#queryForEq(String, Object)
 */
@Override
public List<T> queryForEq(String fieldName, Object value) {
  try {
    return dao.queryForEq(fieldName, value);
  } catch (SQLException e) {
    logMessage(e, "queryForEq threw exception on: " + fieldName);
    throw new RuntimeException(e);
  }
}

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

/**
 * @see Dao#queryForEq(String, Object)
 */
@Override
public List<T> queryForEq(String fieldName, Object value) {
  try {
    return dao.queryForEq(fieldName, value);
  } catch (SQLException e) {
    logMessage(e, "queryForEq threw exception on: " + fieldName);
    throw new RuntimeException(e);
  }
}

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

@Override
public List<Sensor> getAllByNodeId(Integer nodeId) {
  try {
    if (nodeId == null) {
      return null;
    }
    return this.getDao().queryForEq(Sensor.KEY_NODE_ID, nodeId);
  } catch (SQLException ex) {
    _logger.error("unable to get all list with node id:{}", nodeId, ex);
    return null;
  }
}

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

@Override
public List<SensorVariable> getByVariableType(MESSAGE_TYPE_SET_REQ variableType) {
  try {
    if (variableType == null) {
      return null;
    }
    return this.getDao().queryForEq(SensorVariable.KEY_VARIABLE_TYPE, variableType);
  } catch (SQLException ex) {
    _logger.error("unable to get all list with variableType: {}", variableType, ex);
    return null;
  }
}

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

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

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

@Override
public List<SensorVariable> getAllBySensorId(Integer sensorRefId) {
  try {
    if (sensorRefId == null) {
      return new ArrayList<SensorVariable>();
    }
    return this.getDao().queryForEq(SensorVariable.KEY_SENSOR_DB_ID, sensorRefId);
  } catch (SQLException ex) {
    _logger.error("unable to get all list with sensorRefId:{}", sensorRefId, ex);
    return null;
  }
}

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

@Override
public User getByUsername(String userName) {
  try {
    List<User> users = this.getDao().queryForEq(User.KEY_USER_NAME, userName);
    if (users != null && !users.isEmpty()) {
      return users.get(0);
    }
  } catch (SQLException ex) {
    _logger.error("Error,", ex);
  }
  return null;
}

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

@Override
public List<Sensor> getAllByRoomId(Integer roomId) {
  try {
    if (roomId == null) {
      return null;
    }
    return this.getDao().queryForEq(Sensor.KEY_ROOM_ID, roomId);
  } catch (SQLException ex) {
    _logger.error("unable to get all list with room id:{}", roomId, ex);
    return null;
  }
}

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

@Override
public List<SensorsVariablesMap> getAll(MESSAGE_TYPE_PRESENTATION sensorType) {
  try {
    if (sensorType == null) {
      return null;
    }
    return this.getDao().queryForEq(SensorsVariablesMap.KEY_SENSOR_TYPE, sensorType);
  } catch (SQLException ex) {
    _logger.error("unable to get all list wit sensorType:{}", sensorType, ex);
    return null;
  }
}

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

@Override
public List<SensorVariable> getAllBySensorId(Integer sensorRefId) {
  try {
    if (sensorRefId == null) {
      return new ArrayList<SensorVariable>();
    }
    return this.getDao().queryForEq(SensorVariable.KEY_SENSOR_DB_ID, sensorRefId);
  } catch (SQLException ex) {
    _logger.error("unable to get all list with sensorRefId:{}", sensorRefId, ex);
    throw new McDatabaseException(ex);
  }
}

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

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

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

@Override
public List<Sensor> getAllByNodeId(Integer nodeId) {
  try {
    if (nodeId == null) {
      return null;
    }
    return this.getDao().queryForEq(Sensor.KEY_NODE_ID, nodeId);
  } catch (SQLException ex) {
    _logger.error("unable to get all list with node id:{}", nodeId, ex);
    throw new McDatabaseException(ex);
  }
}

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

@Override
public List<SensorsVariablesMap> getAll(MESSAGE_TYPE_PRESENTATION sensorType) {
  try {
    if (sensorType == null) {
      return null;
    }
    return this.getDao().queryForEq(SensorsVariablesMap.KEY_SENSOR_TYPE, sensorType);
  } catch (SQLException ex) {
    _logger.error("unable to get all list wit sensorType:{}", sensorType, ex);
    throw new McDatabaseException(ex);
  }
}

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

@Override
public List<Sensor> getByType(String typeString) {
  try {
    return this.getDao()
        .queryForEq("type", MESSAGE_TYPE_PRESENTATION.valueOf(typeString));
  } catch (SQLException ex) {
    _logger.error("unable to get all list with typeString: {}", typeString, ex);
    return null;
  }
}

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

@Override
public List<SensorVariable> getByVariableType(MESSAGE_TYPE_SET_REQ variableType) {
  try {
    if (variableType == null) {
      return null;
    }
    return this.getDao().queryForEq(SensorVariable.KEY_VARIABLE_TYPE, variableType);
  } catch (SQLException ex) {
    _logger.error("unable to get all list with variableType: {}", variableType, ex);
    throw new McDatabaseException(ex);
  }
}

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

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

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

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

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

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

相关文章