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

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

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

Dao.registerObserver介绍

[英]Register an observer that will be called when data changes for this DAO. You mustq make a call to #unregisterObserver(DaoObserver) to de-register the observer after you are done with it.
[中]注册一个观察者,当此DAO的数据更改时将调用该观察者。您必须调用#unregisterObserver(DAObserver),以便在完成操作后取消对该观察者的注册。

代码示例

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

@Override
public void registerObserver(DaoObserver observer) {
  dao.registerObserver(observer);
}

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

@Override
public void registerObserver(DaoObserver observer) {
  dao.registerObserver(observer);
}

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

/**
 * Starts an asynchronous load of the data. When the result is ready the callbacks will be called on the UI thread.
 * If a previous load has been completed and is still valid the result may be passed to the callbacks immediately.
 * 
 * <p>
 * Must be called from the UI thread.
 * </p>
 */
@Override
protected void onStartLoading() {
  // XXX: do we really return the cached results _before_ checking if the content has changed?
  if (cachedResults != null) {
    deliverResult(cachedResults);
  }
  if (takeContentChanged() || cachedResults == null) {
    forceLoad();
  }
  // watch for data changes
  dao.registerObserver(this);
}

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

@Override
protected void onStartLoading() {
  // start watching for dataset changes
  dao.registerObserver(this);
  if (cursor == null) {
    forceLoad();
  } else {
    deliverResult(cursor);
    if (takeContentChanged()) {
      forceLoad();
    }
  }
}

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

@Override
protected void onStartLoading() {
  // start watching for dataset changes
  dao.registerObserver(this);
  if (cursor == null) {
    forceLoad();
  } else {
    deliverResult(cursor);
    if (takeContentChanged()) {
      forceLoad();
    }
  }
}

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

@Test
public void testDaoObserver() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  final AtomicInteger changeCount = new AtomicInteger();
  DaoObserver obverver = new DaoObserver() {
    @Override
    public void onChange() {
      changeCount.incrementAndGet();
    }
  };
  dao.registerObserver(obverver);
  assertEquals(0, changeCount.get());
  Foo foo = new Foo();
  foo.val = 21312313;
  assertEquals(1, dao.create(foo));
  assertEquals(1, changeCount.get());
  foo.val = foo.val + 1;
  assertEquals(1, dao.create(foo));
  assertEquals(2, changeCount.get());
  // shouldn't change anything
  dao.queryForAll();
  assertEquals(2, changeCount.get());
  assertEquals(1, dao.delete(foo));
  assertEquals(3, changeCount.get());
  dao.unregisterObserver(obverver);
  assertEquals(1, dao.create(foo));
  // shouldn't change not that we have removed the observer
  assertEquals(3, changeCount.get());
}

相关文章