com.squareup.sqlbrite.SqlBrite Java Examples
The following examples show how to use
com.squareup.sqlbrite.SqlBrite.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProviderFacade.java From moVirt with Apache License 2.0 | 5 votes |
@AfterInject void initContentProviderClient() { final ContentResolver contentResolver = context.getContentResolver(); contentClient = contentResolver.acquireContentProviderClient(OVirtContract.BASE_CONTENT_URI); SqlBrite sqlBrite = new SqlBrite.Builder().build(); // TODO possibly refactor to use sqlBrite.wrapDatabaseHelper(), but all queries must use SqlBrite briteResolver = sqlBrite.wrapContentProvider(contentResolver, Schedulers.io()); }
Example #2
Source File: StorageModule.java From TodoFluxArchitecture with Apache License 2.0 | 5 votes |
/** * 提供BriteDatabase注入. * * @return BriteDatabase */ @Provides BriteDatabase briteDatabase() { SqlBrite sqlBrite = SqlBrite.create(message -> LogTool.debug("Database", message)); SQLiteOpenHelper sqLiteOpenHelper = new DatabaseOpenHelper(application, userId); BriteDatabase db = sqlBrite.wrapDatabaseHelper(sqLiteOpenHelper); db.setLoggingEnabled(BuildConfig.DEBUG); return db; }
Example #3
Source File: ElifutDataStore.java From android with Apache License 2.0 | 5 votes |
public ElifutDataStore(Context context, SqlBrite sqlBrite, List<Persistable.Converter<?>> converters) { super(context, "ElifutDB", null, 1); // TODO: Change to io() or computation() scheduler but needs to fix failing test db = sqlBrite.wrapDatabaseHelper(this, AndroidSchedulers.mainThread()); for (Persistable.Converter<?> converter : converters) { converterMap.put(converter.targetType(), converter); } }
Example #4
Source File: SqlbriteDemoActivity.java From RxJavaExplained with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_of_kittens_layout); listOfKittens = (RecyclerView) findViewById(R.id.list_of_kittens); floatingActionButton = (FloatingActionButton) findViewById(R.id.fab); floatingActionButton.setOnClickListener(this::addRandomKitten); sqlBrite = SqlBrite.create(); kittenAdapter = new KittenAdapter(this); listOfKittens.setLayoutManager(new LinearLayoutManager(this)); listOfKittens.setAdapter(kittenAdapter); }
Example #5
Source File: BookshelfModelImpl.java From MaterialHome with Apache License 2.0 | 5 votes |
@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")); } }
Example #6
Source File: BookshelfModelImpl.java From ReadMark with Apache License 2.0 | 4 votes |
/** * 取出表中所有条目 * @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")); } }
Example #7
Source File: DatabaseHelper.java From ribot-app-android with Apache License 2.0 | 4 votes |
@Inject public DatabaseHelper(DbOpenHelper dbOpenHelper) { mDb = SqlBrite.create().wrapDatabaseHelper(dbOpenHelper); }
Example #8
Source File: DataModule.java From android with Apache License 2.0 | 4 votes |
@Provides @Singleton ElifutDataStore provideDataStore(List<Persistable.Converter<?>> converters) { return new ElifutDataStore(context, SqlBrite.create(), converters); }
Example #9
Source File: PlaceModel.java From Fishing with GNU General Public License v3.0 | 4 votes |
@Override protected void onAppCreate(Context ctx) { SqlBrite mSqlBrite = SqlBrite.create(s -> JUtils.Log("DB",s)); mDbBrite = mSqlBrite.wrapDatabaseHelper(new DBHelper(ctx)); }
Example #10
Source File: DataCleaner.java From Fishing with GNU General Public License v3.0 | 4 votes |
public static void Clean(Context ctx){ JUtils.getSharedPreference().edit().clear().apply(); JFileManager.getInstance().clearAllData(); SqlBrite.create().wrapDatabaseHelper(new DBHelper(ctx)).delete(PlaceDBTable.TABLE_NAME,""); }
Example #11
Source File: DaoManager.java From sqlbrite-dao with Apache License 2.0 | 4 votes |
private DaoManager(Builder builder) { if (builder.name == null) { throw new IllegalArgumentException( "Database name not set. Use Builder.databaseName() to specify a database name"); } if (builder.version == -1) { throw new IllegalArgumentException( "Database version not set. Use Builder.version() to specify the database version"); } if (builder.daos.isEmpty()) { throw new IllegalArgumentException( "No DAO added. Use Builder.add() to register at least one DAO"); } this.name = builder.name; this.version = builder.version; this.createdListener = builder.createdListener; this.upgradedListener = builder.upgradedListener; this.daos = builder.daos; OpenHelper openHelper; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { openHelper = new OpenHelper(builder.context, name, builder.cursorFactory, version, builder.errorHandler, builder.foreignKeyConstraints); } else { openHelper = new OpenHelperApi16(builder.context, name, builder.cursorFactory, version, builder.errorHandler, builder.foreignKeyConstraints); } SqlBrite brite; if (builder.logger != null) { brite = SqlBrite.create(builder.logger); } else { brite = SqlBrite.create(); } db = brite.wrapDatabaseHelper(openHelper, builder.scheduler == null ? Schedulers.io() : builder.scheduler); db.setLoggingEnabled(builder.logging); for (Dao dao : builder.daos) { dao.setSqlBriteDb(db); } }
Example #12
Source File: DatabaseHelper.java From StatusSaver-for-Whatsapp with Apache License 2.0 | 4 votes |
@Inject public DatabaseHelper(DbOpenHelper dbOpenHelper) { SqlBrite.Builder builder = new SqlBrite.Builder(); mDb = builder.build().wrapDatabaseHelper(dbOpenHelper, Schedulers.immediate()); }
Example #13
Source File: ApplicationModule.java From FriendlyDemo with Apache License 2.0 | 4 votes |
@Provides @NonNull @Singleton public BriteDatabase provideDatabase(SqlBrite sqlBrite, Database helper) { return sqlBrite.wrapDatabaseHelper(helper, Schedulers.io()); }
Example #14
Source File: ApplicationModule.java From FriendlyDemo with Apache License 2.0 | 4 votes |
@Provides @NonNull @Singleton public SqlBrite provideSqlBrite() { return SqlBrite.create(message -> Timber.tag("Database").v(message)); }
Example #15
Source File: DatabaseModule.java From droidconat-2016 with Apache License 2.0 | 4 votes |
@Provides @Singleton BriteDatabase provideBriteDatabase(SqlBrite sqlBrite, SQLiteOpenHelper helper) { return sqlBrite.wrapDatabaseHelper(helper, Schedulers.immediate()); }
Example #16
Source File: DatabaseModule.java From droidconat-2016 with Apache License 2.0 | 4 votes |
@Provides @Singleton SqlBrite provideSqlBrite() { return SqlBrite.create(Timber.tag(TAG)::v); }
Example #17
Source File: BookshelfModelImpl.java From ReadMark with Apache License 2.0 | 4 votes |
/** * 取出表中所有条目 * @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")); } }