本文整理匯總了Java中com.squareup.sqlbrite.SqlBrite.Query方法的典型用法代碼示例。如果您正苦於以下問題:Java SqlBrite.Query方法的具體用法?Java SqlBrite.Query怎麽用?Java SqlBrite.Query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.sqlbrite.SqlBrite
的用法示例。
在下文中一共展示了SqlBrite.Query方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: call
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
@Override public List<Vocabulary> call(SqlBrite.Query query) {
Cursor cursor = query.run();
try {
List<Vocabulary> values = new ArrayList<>(cursor.getCount());
while (cursor.moveToNext()) {
values.add(new AutoParcel_Vocabulary(
DbUtils.getLong(cursor, ID),
DbUtils.getString(cursor, ORIGINAL),
DbUtils.getString(cursor, TRANSLATED),
DbUtils.getString(cursor, LANG_ORIGINAL),
DbUtils.getString(cursor, LANG_TRANSLATED)
));
}
return values;
} finally {
cursor.close();
}
}
示例2: runQuery
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
public static Func1<SqlBrite.Query, Cursor> runQuery() {
return new Func1<SqlBrite.Query, Cursor>() {
@Override
public Cursor call(SqlBrite.Query query) {
return query.run();
}
};
}
示例3: loadBookshelf
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
@Override
public void loadBookshelf(ApiCompleteListener listener) {
if (db != null) {
Observable<SqlBrite.Query> bookshelf = db.createQuery("bookshelf", "SELECT * FROM bookshelf order by orders DESC");
subscribe = bookshelf.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<SqlBrite.Query>() {
@Override
public void call(SqlBrite.Query query) {
Cursor cursor = query.run();
if (cursor == null || cursor.getCount() < 0) {
return;
}
List<Bookshelf> bookshelfs = new ArrayList<>();
while (cursor.moveToNext()) {
Bookshelf bookshelfBean = new Bookshelf();
bookshelfBean.setId(cursor.getInt(cursor.getColumnIndex("id")));
bookshelfBean.setBookCount(cursor.getInt(cursor.getColumnIndex("bookCount")));
bookshelfBean.setTitle(cursor.getString(cursor.getColumnIndex("title")));
bookshelfBean.setRemark(cursor.getString(cursor.getColumnIndex("remark")));
bookshelfBean.setOrder(cursor.getInt(cursor.getColumnIndex("orders")));
bookshelfBean.setCreateTime(cursor.getString(cursor.getColumnIndex("create_at")));
bookshelfs.add(bookshelfBean);
}
listener.onComplected(bookshelfs);
}
});
} else {
listener.onFailed(new BaseResponse(500, "db error : init"));
}
}
示例4: loadDataFromDatabase
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
private void loadDataFromDatabase() {
Observable<SqlBrite.Query> observable = db.createQuery(FavSQLiteHelper.Fav.TABLE_NAME,
QuerySQL.selectFavorite(PreferenceManager.getValue(getContext(), TOKEN),
PreferenceManager.getValue(getContext(), ID)));
observable
.observeOn(AndroidSchedulers.mainThread())
.subscribe(query -> {
Cursor cursor = query.run();
if (refreshLayout.isRefreshing())
refreshLayout.setRefreshing(false);
if (cursor == null) {
loadData(true);
} else {
List<Card> cards = new ArrayList<>();
while (cursor.moveToNext()) {
cards.add(CardConverter.createCard(cursor));
}
if (cards.size() > 0) {
Iterator<Object> iterator = items.iterator();
while (iterator.hasNext()) {
if (!(iterator.next() instanceof SendingCard)) {
iterator.remove();
}
}
addData(adapter, cards);
if (appBarCallback != null) {
appBarCallback.setExpanded(cards.size() == 0, false);
}
} else
loadData(true);
cursor.close();
}
}, throwable -> {
if (refreshLayout.isRefreshing())
refreshLayout.setRefreshing(false);
throwable.printStackTrace();
ToastUtils.shorts(getContext(), throwable.getMessage());
});
}
示例5: getStationsObservables
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
public Observable<List<Station>> getStationsObservables() {
Observable<SqlBrite.Query> stations = mBrite.createQuery(PisaBikeDbHelper.STATION_TABLE, "SELECT * " +
"FROM Station");
return stations.map(q -> {
Cursor cursor = q.run();
List<Station> s = new ArrayList<>(cursor.getCount());
while (cursor.moveToNext()) {
Station station = new Station(cursor);
s.add(station);
}
cursor.close();
return s;
});
}
示例6: call
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
@Override public List<Language> call(SqlBrite.Query query) {
try (Cursor cursor = query.run()) {
List<Language> values = new ArrayList<>(cursor.getCount());
while (cursor.moveToNext()) {
values.add(new AutoParcel_Language(DbUtils.getLong(cursor, ID), DbUtils.getString(cursor, LANGUAGE)));
}
return values;
}
}
示例7: loadBookshelf
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
/**
* 取出表中所有條目
* @param listener 回調
*/
@Override
public void loadBookshelf(final ApiCompleteListener listener) {
if(db != null){
final Observable<SqlBrite.Query> bookshelf = db
.createQuery("bookshelf", "SELECT * FROM bookshelf order by id DESC");
subscribe = bookshelf.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<SqlBrite.Query>() {
@Override
public void call(SqlBrite.Query query) {
Cursor cursor = query.run();
if(cursor == null || cursor.getCount() < 0){
return;
}
List<Bookshelf> bookshelfs = new ArrayList<Bookshelf>();
while(cursor.moveToNext()){
Bookshelf bookshelfBean = new Bookshelf();
bookshelfBean.setId(cursor.getInt(cursor.getColumnIndex("id")));
bookshelfBean.setTitle(cursor.getString(cursor.getColumnIndex("title")));
bookshelfBean.setRemark(cursor.getString(cursor.getColumnIndex("remark")));
bookshelfBean.setCreateTime(cursor.getString(cursor.getColumnIndex("create_at")));
bookshelfBean.setColor(cursor.getInt(cursor.getColumnIndex("color")));
bookshelfBean.setFinished(cursor.getInt(cursor.getColumnIndex("finished")));
bookshelfBean.setProgress(cursor.getFloat(cursor.getColumnIndex("progress")));
bookshelfBean.setWaveratio(cursor.getFloat(cursor.getColumnIndex("waveratio")));
bookshelfBean.setAmpratio(cursor.getFloat(cursor.getColumnIndex("ampratio")));
bookshelfBean.setTotalpage(cursor.getInt(cursor.getColumnIndex("totalpage")));
bookshelfBean.setCurrentpage(cursor.getInt(cursor.getColumnIndex("currentpage")));
bookshelfBean.setRed(cursor.getInt(cursor.getColumnIndex("red")));
bookshelfBean.setGreen(cursor.getInt(cursor.getColumnIndex("green")));
bookshelfBean.setBlue(cursor.getInt(cursor.getColumnIndex("blue")));
bookshelfs.add(bookshelfBean);
}
listener.onCompleted(bookshelfs);
}
});
}else{
listener.onFailed(new BaseResponse(500, "db error : not init"));
}
}
示例8: createQueryForUnsentMessages
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
public static Observable<SqlBrite.Query> createQueryForUnsentMessages(SqlBrite brite, long userId, long rootMessageId) {
return brite.createQuery(TABLE,
"SELECT * FROM " + TABLE + " WHERE " + USER_ID + " = ? AND " + ROOT_MESSAGE_ID + " = ?",
String.valueOf(userId),
String.valueOf(rootMessageId));
}
示例9: executeNext
import com.squareup.sqlbrite.SqlBrite; //導入方法依賴的package包/類
private void executeNext() {
// FIXME We can only process one item at time.
if (running) return;
// We're running, baby!
running = true;
// TODO Prioritize current user's messages? :D
Observable<SqlBrite.Query> query = brite.createQuery(
LocalMessage.TABLE,
QUERY_FIRST_MESSAGE_BY_STATUS,
LocalMessage.valueOf(LocalMessage.Status.QUEUE));
LocalMessage message = query.map(SqlBrite.Query::run)
.map(LocalMessage.READ_SINGLE)
.filter(m -> m != null)
.toBlocking()
.firstOrDefault(null);
if (message == null) {
Timber.d("Stopping service...");
stopSelf();
return;
}
// TODO FIXME When the task fails, if the user keeps retrying, it'll be executing this line N+1 times for every retry.
AddMessageTask task = new AddMessageTask(message);
EDMApplication.get(this).getObjectGraph().inject(task);
subscription = Schedulers.newThread().createWorker().schedule(() -> {
try {
task.execute();
} catch (Throwable t) {
task.onError(t);
}
running = false;
executeNext();
});
}