Java Code Examples for com.squareup.sqlbrite.SqlBrite

The following examples show how to use com.squareup.sqlbrite.SqlBrite. These examples are extracted from open source projects. 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 Project: TodoFluxArchitecture   Source File: StorageModule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 提供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 2
Source Project: MaterialHome   Source File: BookshelfModelImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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 3
Source Project: RxJavaExplained   Source File: SqlbriteDemoActivity.java    License: Apache License 2.0 5 votes vote down vote up
@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 4
Source Project: android   Source File: ElifutDataStore.java    License: Apache License 2.0 5 votes vote down vote up
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 5
Source Project: moVirt   Source File: ProviderFacade.java    License: Apache License 2.0 5 votes vote down vote up
@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 6
Source Project: StatusSaver-for-Whatsapp   Source File: DatabaseHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Inject
public DatabaseHelper(DbOpenHelper dbOpenHelper) {
    SqlBrite.Builder builder = new SqlBrite.Builder();
    mDb = builder.build().wrapDatabaseHelper(dbOpenHelper, Schedulers.immediate());
}
 
Example 7
Source Project: ReadMark   Source File: BookshelfModelImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 取出表中所有条目
 * @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 8
Source Project: droidconat-2016   Source File: DatabaseModule.java    License: Apache License 2.0 4 votes vote down vote up
@Provides @Singleton SqlBrite provideSqlBrite() {
    return SqlBrite.create(Timber.tag(TAG)::v);
}
 
Example 9
Source Project: droidconat-2016   Source File: DatabaseModule.java    License: Apache License 2.0 4 votes vote down vote up
@Provides @Singleton BriteDatabase provideBriteDatabase(SqlBrite sqlBrite, SQLiteOpenHelper helper) {
    return sqlBrite.wrapDatabaseHelper(helper, Schedulers.immediate());
}
 
Example 10
Source Project: FriendlyDemo   Source File: ApplicationModule.java    License: Apache License 2.0 4 votes vote down vote up
@Provides
@NonNull
@Singleton
public SqlBrite provideSqlBrite() {
    return SqlBrite.create(message -> Timber.tag("Database").v(message));
}
 
Example 11
Source Project: FriendlyDemo   Source File: ApplicationModule.java    License: Apache License 2.0 4 votes vote down vote up
@Provides
@NonNull
@Singleton
public BriteDatabase provideDatabase(SqlBrite sqlBrite, Database helper) {
    return sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
}
 
Example 12
Source Project: ReadMark   Source File: BookshelfModelImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 取出表中所有条目
 * @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 13
Source Project: sqlbrite-dao   Source File: DaoManager.java    License: Apache License 2.0 4 votes vote down vote up
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 14
Source Project: Fishing   Source File: DataCleaner.java    License: GNU General Public License v3.0 4 votes vote down vote up
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 15
Source Project: Fishing   Source File: PlaceModel.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onAppCreate(Context ctx) {
    SqlBrite mSqlBrite = SqlBrite.create(s -> JUtils.Log("DB",s));
    mDbBrite = mSqlBrite.wrapDatabaseHelper(new DBHelper(ctx));
}
 
Example 16
Source Project: android   Source File: DataModule.java    License: Apache License 2.0 4 votes vote down vote up
@Provides @Singleton ElifutDataStore provideDataStore(List<Persistable.Converter<?>> converters) {
  return new ElifutDataStore(context, SqlBrite.create(), converters);
}
 
Example 17
Source Project: ribot-app-android   Source File: DatabaseHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Inject
public DatabaseHelper(DbOpenHelper dbOpenHelper) {
    mDb = SqlBrite.create().wrapDatabaseHelper(dbOpenHelper);
}