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

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

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

Dao.idExists介绍

[英]Returns true if an object exists that matches this ID otherwise false.
[中]如果存在与此ID匹配的对象,则返回true,否则返回false。

代码示例

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

  1. public void insertOrUpdateWeather(Weather weather) throws SQLException {
  2. TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), (Callable<Void>) () -> {
  3. if (weatherDaoOperation.idExists(weather.getCityId())) {
  4. updateWeather(weather);
  5. } else {
  6. insertWeather(weather);
  7. }
  8. return null;
  9. });
  10. }

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

  1. @Override
  2. public boolean exists(ID id) {
  3. try {
  4. return dao.idExists(id);
  5. } catch (SQLException e) {
  6. ErrorUtils.logError(e);
  7. }
  8. return false;
  9. }

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

  1. /**
  2. * @see Dao#idExists(Object)
  3. */
  4. @Override
  5. public boolean idExists(ID id) {
  6. try {
  7. return dao.idExists(id);
  8. } catch (SQLException e) {
  9. logMessage(e, "idExists threw exception on " + id);
  10. throw new RuntimeException(e);
  11. }
  12. }

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

  1. /**
  2. * @see Dao#idExists(Object)
  3. */
  4. @Override
  5. public boolean idExists(ID id) {
  6. try {
  7. return dao.idExists(id);
  8. } catch (SQLException e) {
  9. logMessage(e, "idExists threw exception on " + id);
  10. throw new RuntimeException(e);
  11. }
  12. }

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

  1. @Override
  2. public boolean exists(long id) {
  3. try {
  4. return dao.idExists(id);
  5. } catch (SQLException e) {
  6. ErrorUtils.logError(e);
  7. }
  8. return false;
  9. }

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

  1. @Test(expected = RuntimeException.class)
  2. public void testIdExists() 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. String id = "eopwjfpwejf";
  7. expect(dao.idExists(id)).andThrow(new SQLException("Testing catch"));
  8. replay(dao);
  9. rtDao.idExists(id);
  10. verify(dao);
  11. }
  12. }

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

  1. @Test
  2. public void testIfExists() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. Foo foo = new Foo();
  5. assertFalse(dao.idExists(1));
  6. assertEquals(1, dao.create(foo));
  7. assertTrue(dao.idExists(1));
  8. assertFalse(dao.idExists(2));
  9. }

相关文章