本文整理汇总了Java中io.requery.Persistable类的典型用法代码示例。如果您正苦于以下问题:Java Persistable类的具体用法?Java Persistable怎么用?Java Persistable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Persistable类属于io.requery包,在下文中一共展示了Persistable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRunInTransactionFromBlocking
import io.requery.Persistable; //导入依赖的package包/类
@Test
public void testRunInTransactionFromBlocking() {
final BlockingEntityStore<Persistable> blocking = data.toBlocking();
Completable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
blocking.runInTransaction(new Callable<Object>() {
@Override
public Object call() throws Exception {
final Person person = randomPerson();
blocking.insert(person);
blocking.update(person);
return null;
}
});
return null;
}
}).subscribe();
assertEquals(1, data.count(Person.class).get().value().intValue());
}
示例2: provideDatabaseSource
import io.requery.Persistable; //导入依赖的package包/类
@Singleton
@Provides
public EntityDataStore<Persistable> provideDatabaseSource() {
Observable.<Void>just(null).observeOn(Schedulers.io()).subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
raw2data(app, DB_NAME, R.raw.books);
}
});
DatabaseSource source = new DatabaseSource(app, Models.DEFAULT, DB_NAME, DB_VERSION);
source.setLoggingEnabled(BuildConfig.DEBUG);
Configuration configuration = source.getConfiguration();
return new EntityDataStore<>(configuration);
}
示例3: shouldSaveNoExistingStripInBatch
import io.requery.Persistable; //导入依赖的package包/类
@Test
public void shouldSaveNoExistingStripInBatch() throws Exception {
StripDto strip = SampleStrip.generateSampleDto();
TestSubscriber testSubscriber = new TestSubscriber<>();
Flowable<StripDto> strips = Flowable.just(strip);
SaveStripBatchTask underTest = new SaveStripBatchTask(getStripRepository());
underTest.execute(strips).blockingSubscribe(testSubscriber);
testSubscriber.assertNoErrors();
testSubscriber.assertComplete();
testSubscriber.assertValueCount(1);
testSubscriber.assertValue(strip);
ReactiveEntityStore<Persistable> database = mRobolectricRepositoryRule.getLocalDatabase();
Integer numberRow = database.count()
.from(StripDaoEntity.class)
.where(StripDaoEntity.ID.eq(1L))
.get().call();
Assert.assertTrue ("Should have one strip saved on database : ", numberRow == 1);
}
示例4: saveInBatchExistingStripShouldReturnZeroStrip
import io.requery.Persistable; //导入依赖的package包/类
@Test
public void saveInBatchExistingStripShouldReturnZeroStrip() throws Exception {
StripDaoEntity strip = SampleStrip.generateSampleDao();
mRobolectricRepositoryRule.getLocalDatabase().insert(strip).blockingGet();
TestSubscriber testSubscriber = new TestSubscriber<>();
Flowable<StripDto> strips = Flowable.just(SampleStrip.generateSampleDto());
SaveStripBatchTask underTest = new SaveStripBatchTask(getStripRepository());
underTest.execute(strips).blockingSubscribe(testSubscriber);
testSubscriber.assertNoErrors();
testSubscriber.assertComplete();
ReactiveEntityStore<Persistable> database = mRobolectricRepositoryRule.getLocalDatabase();
Integer numberRow = database
.count()
.from(StripDaoEntity.class)
.get()
.call();
Assert.assertTrue ("Should have one strip saved on database : ", numberRow == 1);
}
示例5: setup
import io.requery.Persistable; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
Platform platform = new HSQL();
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = io.requery.test.model.Models.DEFAULT;
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setWriteExecutor(Executors.newSingleThreadExecutor())
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.useSerializableCache(true)
.useCacheManager(cacheManager)
.build())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
data = new ReactorEntityStore<>(new EntityDataStore<Persistable>(configuration));
}
示例6: setup
import io.requery.Persistable; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
Platform platform = new HSQL();
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = io.requery.test.model.Models.DEFAULT;
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setWriteExecutor(Executors.newSingleThreadExecutor())
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.useSerializableCache(true)
.useCacheManager(cacheManager)
.build())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
data = ReactiveSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
示例7: setup
import io.requery.Persistable; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
Platform platform = new HSQL();
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = io.requery.test.model.Models.DEFAULT;
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setWriteExecutor(Executors.newSingleThreadExecutor())
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.useSerializableCache(true)
.useCacheManager(cacheManager)
.build())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
data = RxSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
示例8: getData
import io.requery.Persistable; //导入依赖的package包/类
@NonNull
public ReactiveEntityStore<Persistable> getData() throws RuntimeException {
if (dataStore == null) {
// override onUpgrade to handle migrating to a new version
DatabaseSource source = new DatabaseSource(getReflectedContext(), Models.DEFAULT, 1);
if (BuildConfig.DEBUG) {
// use this in development mode to drop and recreate the tables on every upgrade
source.setTableCreationMode(TableCreationMode.DROP_CREATE);
}
Configuration configuration = source.getConfiguration();
dataStore = ReactiveSupport.toReactiveStore(
new EntityDataStore<Persistable>(configuration));
}
return dataStore;
}
示例9: getAll
import io.requery.Persistable; //导入依赖的package包/类
public <T extends Persistable> Observable<T> getAll(Class<T> clazz) {
EntityInfo info = EntityInfos.infoFor(clazz);
if (info.single()) {
//noinspection unchecked
return getObject(info.endpoint(), clazz)
.toObservable();
} else {
return getAll(info.endpoint(), clazz);
}
}
示例10: getMany
import io.requery.Persistable; //导入依赖的package包/类
private <T extends Persistable> List<T> getMany(Class<T> clazz, int count) {
return database
.getAll(clazz)
.take(count)
.toList()
.blockingGet();
}
示例11: sendNotificationClicked
import io.requery.Persistable; //导入依赖的package包/类
public void sendNotificationClicked(Class<? extends Persistable> clazz, int count) {
if (clazz.isAssignableFrom(LuckyNumber.class)) {
notificationService.addLuckyNumber(getMany(LuckyNumber.class, count));
widgetUpdater.updateLuckyNumber();
} else if (clazz.isAssignableFrom(Event.class)) {
notificationService.addEvents(getMany(Event.class, count));
} else if (clazz.isAssignableFrom(Grade.class)) {
notificationService.addGrades(getMany(Grade.class, count));
} else if (clazz.isAssignableFrom(Announcement.class)) {
notificationService.addAnnouncements(getMany(Announcement.class, count));
}
}
示例12: getAll
import io.requery.Persistable; //导入依赖的package包/类
public <T extends Persistable> Observable<T> getAll(Class<T> clazz) {
EntityInfo info = EntityInfos.infoFor(clazz);
return getAll(info.endpoint(), clazz)
.onErrorResumeNext(e -> {
if(e instanceof NotActiveException){
return Observable.empty();
} else {
return Observable.error(e);
}
});
}
示例13: getById
import io.requery.Persistable; //导入依赖的package包/类
@Override
public <T extends Persistable & Identifiable> Single<T> getById(Class<T> clazz, String id) {
EntityInfo info = EntityInfos.infoFor(clazz);
return makeRequest(info.endpoint(id))
.map(s -> EntityParser.parseObject(s, clazz))
.map(o -> {
if (o.isPresent()) {
return o.get();
} else {
throw new EntityMissingException("server", clazz, id);
}
});
}
示例14: getAll
import io.requery.Persistable; //导入依赖的package包/类
@Override
public <T extends Persistable> Observable<T> getAll(Class<T> clazz) {
return dataStore.select(clazz)
.get()
.observable()
.subscribeOn(Schedulers.io());
}
示例15: getById
import io.requery.Persistable; //导入依赖的package包/类
@Override
public <T extends Persistable & Identifiable> Single<T> getById(Class<T> clazz, String id) {
return dataStore.findByKey(clazz, id)
.toSingle()
.onErrorResumeNext(Single.error(new EntityMissingException("database", clazz, id)))
.subscribeOn(Schedulers.io());
}