当前位置: 首页>>代码示例>>Java>>正文


Java BriteDatabase类代码示例

本文整理汇总了Java中com.squareup.sqlbrite.BriteDatabase的典型用法代码示例。如果您正苦于以下问题:Java BriteDatabase类的具体用法?Java BriteDatabase怎么用?Java BriteDatabase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BriteDatabase类属于com.squareup.sqlbrite包,在下文中一共展示了BriteDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateTaskBundle

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
/**
 * 更新TaskBundle
 */
public void updateTaskBundle(TaskBundle taskBundle) {

  //更新 有可能是
  if (taskBundle.getTaskList() == null || taskBundle.getTaskList().size() == 0) {
    db.update(TaskBundle.TASK_BUNDLE_TABLE_NAME, getTaskBundleValues(taskBundle),
        TaskBundle.COLUMN_KEY + "=?", taskBundle.getKey());
  } else {
    if (!isExistTaskEntity(taskBundle.getBundleId())) {
      BriteDatabase.Transaction transaction = db.newTransaction();
      db.update(TaskBundle.TASK_BUNDLE_TABLE_NAME, getTaskBundleValues(taskBundle),
          TaskBundle.COLUMN_KEY + "=?", taskBundle.getKey());
      int nextTaskId = getNextID(db, TaskEntity.TASK_TABLE_NAME, TaskEntity.COLUMN_TASK_ID);
      for (TaskEntity taskEntity : taskBundle.getTaskList()) {
        taskEntity.setTaskBundleId(taskBundle.getBundleId());
        taskEntity.setTaskId(nextTaskId);
        db.insert(TaskEntity.TASK_TABLE_NAME, getTaskEntity(taskEntity));
        nextTaskId++;
      }
      transaction.markSuccessful();
      transaction.end();
    }
    db.update(TaskBundle.TASK_BUNDLE_TABLE_NAME, getTaskBundleValues(taskBundle),
        TaskBundle.COLUMN_KEY + "=?", taskBundle.getKey());
  }
}
 
开发者ID:MaYunFei,项目名称:RxJavaDownLoadMultipleFile,代码行数:29,代码来源:DownloadDao.java

示例2: getNextID

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
private int getNextID(BriteDatabase db, String tableName, String idName) {
  StringBuilder sqlB = new StringBuilder();
  sqlB.append("SELECT max(").append(idName).append(") AS maxId ");
  sqlB.append("FROM ").append(tableName);
  L.i("max id " + sqlB.toString());
  int maxId = 1;
  Cursor cursor = db.query(sqlB.toString());
  if (cursor.moveToFirst()) {
    maxId = DBHelper.getInt(cursor, "maxId");

    if (maxId >= 0) {
      return maxId + 1;
    }
  }
  cursor.close();
  return maxId;
}
 
开发者ID:MaYunFei,项目名称:RxJavaDownLoadMultipleFile,代码行数:18,代码来源:DownloadDao.java

示例3: insert

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public long insert(BriteDatabase db, Library library) {
  synchronized (this) {
    insertLibrary.bind(
        library.id(),
        library.packageName(),
        library.sourceDir(),
        library.title(),
        library.subtitle(),
        library.description(),
        library.websiteUrl(),
        library.type(),
        library.createdAt(),
        library.updatedAt());

    return db.executeInsert(insertLibrary.table, insertLibrary.program);
  }
}
 
开发者ID:philipphager,项目名称:disclosure-android-app,代码行数:18,代码来源:LibraryRepository.java

示例4: update

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public int update(BriteDatabase db, Library library) {
  synchronized (this) {
    updateLibrary.bind(
        library.packageName(),
        library.sourceDir(),
        library.title(),
        library.subtitle(),
        library.description(),
        library.websiteUrl(),
        library.type(),
        library.createdAt(),
        library.updatedAt(),
        library.id());

    return db.executeUpdateDelete(updateLibrary.table, updateLibrary.program);
  }
}
 
开发者ID:philipphager,项目名称:disclosure-android-app,代码行数:18,代码来源:LibraryRepository.java

示例5: Repository

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public Repository(Context context) {
    SchedulerProvider schedulerProvider = DefaultSchedulerProvider.getInstance();
    DbHelper openHelper = new DbHelper(context);
    SqlBrite sqlBrite = new SqlBrite.Builder().build();
    // TODO: switch to the rxjava2 scheduler when new sqlbrite will be released
    BriteDatabase briteDatabase = sqlBrite.wrapDatabaseHelper(openHelper, Schedulers.io());

    if (BuildConfig.DEBUG) {
        briteDatabase.setLoggingEnabled(true);
    }

    briteDatabaseHelper = new BriteDatabaseHelper(briteDatabase);

    Dependencies dependencies = new Dependencies(context, this, briteDatabaseHelper,
            schedulerProvider);

    artistRepository = new ArtistRepository(dependencies);
    locationRepository = new LocationRepository(dependencies);
    concertRepository = new ConcertRepository(dependencies);
    syncStateRepository = new SyncStateRepository(dependencies);
    syncRepository = new SyncRepository(dependencies);
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:23,代码来源:Repository.java

示例6: deleteArtists

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public Completable deleteArtists(List<Artist> artists) {
    return Completable.fromAction(() -> {
        try (BriteDatabase.Transaction transaction =
                     dbHelper.getBriteDatabase().newTransaction()) {
            Observable.fromIterable(artists).blockingForEach(artist -> {
                dbHelper.blockingDeleteByValue(entityRegistry.artist.getTableName(),
                        entityRegistry.artist.getIdColumn(),
                        artist.getId());
                dbHelper.blockingDeleteByValue(entityRegistry.concert.getTableName(),
                        Contract.ConcertsTable.COLUMN_ARTIST_ID, artist.getId());
                dbHelper.blockingDeleteByValue(entityRegistry.syncState.getTableName(),
                        Contract.SyncStatesTable.COLUMN_ARTIST_ID, artist.getId());
            });
            transaction.markSuccessful();
        }
    })
            .subscribeOn(schedulerProvider.io());
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:19,代码来源:ArtistRepository.java

示例7: addPackages

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public void addPackages(List<PackageInfo> packageInfos) {
  BriteDatabase db = databaseManager.get();
  try (BriteDatabase.Transaction transaction = db.newTransaction()) {

    for (PackageInfo packageInfo : packageInfos) {
      App app = toAppMapper.map(packageInfo.applicationInfo);
      long appId = appRepository.insertOrUpdate(db, app);

      Version version = new ToVersionMapper(clock, appId).map(packageInfo);
      versionRepository.insert(db, version);

      String thread = Thread.currentThread().getName();
      Timber.d("%s : inserted app %s, %s", thread, app.packageName(), version.versionName());
    }

    transaction.markSuccessful();
  }
}
 
开发者ID:philipphager,项目名称:disclosure-android-app,代码行数:19,代码来源:AppService.java

示例8: insertOrUpdate

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public void insertOrUpdate(List<Permission> permissions) {
  BriteDatabase db = databaseManager.get();
  try (BriteDatabase.Transaction transaction = db.newTransaction()) {
    for (Permission permission : permissions) {
      PermissionGroup group = getGroup(permission.permissionGroup());

      if (group != null) {
        insertOrUpdate(group);
      }

      int updatedRows = permissionRepository.update(db, permission);

      if (updatedRows == 0) {
        permissionRepository.insert(db, permission);
      }
    }
    transaction.markSuccessful();
  }
}
 
开发者ID:philipphager,项目名称:disclosure-android-app,代码行数:20,代码来源:PermissionService.java

示例9: setRibots

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public Observable<Ribot> setRibots(final Collection<Ribot> newRibots) {
    return Observable.create(new Observable.OnSubscribe<Ribot>() {
        @Override
        public void call(Subscriber<? super Ribot> subscriber) {
            if (subscriber.isUnsubscribed()) return;
            BriteDatabase.Transaction transaction = mDb.newTransaction();
            try {
                mDb.delete(Db.RibotProfileTable.TABLE_NAME, null);
                for (Ribot ribot : newRibots) {
                    long result = mDb.insert(Db.RibotProfileTable.TABLE_NAME,
                            Db.RibotProfileTable.toContentValues(ribot.profile()),
                            SQLiteDatabase.CONFLICT_REPLACE);
                    if (result >= 0) subscriber.onNext(ribot);
                }
                transaction.markSuccessful();
                subscriber.onCompleted();
            } finally {
                transaction.end();
            }
        }
    });
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:23,代码来源:DatabaseHelper.java

示例10: setProducts

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public Observable<ProductListResponse> setProducts(final ProductListResponse productListResponse) {
    return Observable.create(new Observable.OnSubscribe<ProductListResponse>() {
        @Override
        public void call(Subscriber<? super ProductListResponse> subscriber) {
            if (subscriber.isUnsubscribed()) return;
            BriteDatabase.Transaction transaction = mDb.newTransaction();
            try {
                mDb.delete(Db.ProductProfileTable.TABLE_NAME, null);
                for (ProductListResponse.Product product : productListResponse.getList()) {
                    long result = mDb.insert(Db.ProductProfileTable.TABLE_NAME,
                            Db.ProductProfileTable.toContentValues(product),
                            SQLiteDatabase.CONFLICT_REPLACE);
                    if (result >= 0) subscriber.onNext(productListResponse);
                }
                transaction.markSuccessful();
                subscriber.onCompleted();
            } finally {
                transaction.end();
            }
        }
    });
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:23,代码来源:DatabaseHelper.java

示例11: saveLocations

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public Completable saveLocations(List<Location> locations) {
    return Completable.fromAction(() -> {
        try (BriteDatabase.Transaction transaction =
                     dbHelper.getBriteDatabase().newTransaction()) {
            List<Artist> artists = dbHelper.selectAll(entityRegistry.artist,
                    entityRegistry.artist.getIdColumn());
            Observable<Artist> artistObservable = Observable.fromIterable(artists);

            Observable.fromIterable(locations).blockingForEach(location -> {
                dbHelper.getBriteDatabase().insert(
                        entityRegistry.location.getTableName(),
                        entityRegistry.location.toContentValues(location));
                syncStateRepository.resetSyncStates(artistObservable, location);
            });

            transaction.markSuccessful();
        }
    })
            .doOnComplete(() -> SyncManager.requestSync(context))
            .subscribeOn(schedulerProvider.io());
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:22,代码来源:LocationRepository.java

示例12: deleteLocation

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public Completable deleteLocation(Location location) {
    return Completable.fromAction(() -> {
        try (BriteDatabase.Transaction transaction =
                     dbHelper.getBriteDatabase().newTransaction()) {
            dbHelper.blockingDeleteByValue(entityRegistry.location.getTableName(),
                    entityRegistry.location.getIdColumn(), location.getId());
            dbHelper.blockingDeleteByValue(entityRegistry.concert.getTableName(),
                    Contract.ConcertsTable.COLUMN_LOCATION_ID, location.getId());
            dbHelper.blockingDeleteByValue(entityRegistry.syncState.getTableName(),
                    Contract.SyncStatesTable.COLUMN_LOCATION_ID, location.getId());

            transaction.markSuccessful();
        }
    })
            .subscribeOn(schedulerProvider.io());
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:17,代码来源:LocationRepository.java

示例13: provideDatabase

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
@Provides
@Singleton
BriteDatabase provideDatabase(SqlBrite sqlBrite, SQLiteOpenHelper helper) {
    BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
    db.setLoggingEnabled(true);
    return db;
}
 
开发者ID:geralt-encore,项目名称:Delightful-SQLBrite,代码行数:8,代码来源:DbModule.java

示例14: insertOrUpdateInTransaction

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
public int insertOrUpdateInTransaction(final String table, final List<ContentValues> batch) {
    final BriteDatabase.Transaction transaction = briteDatabase.newTransaction();
    int updatedRows = 0;
    try {
        for (final ContentValues cv : batch) {
            updatedRows += (insertOrUpdate(table, cv) >= 0 ? 1 : 0);
        }
        transaction.markSuccessful();
    } finally {
        transaction.end();
    }
    return updatedRows;
}
 
开发者ID:dmitrikudrenko,项目名称:MDRXL,代码行数:14,代码来源:Database.java

示例15: insertTaskBundle

import com.squareup.sqlbrite.BriteDatabase; //导入依赖的package包/类
/**
 * 插入TaskBundle
 */
public void insertTaskBundle(TaskBundle taskBundle) {
  if (!isExistTaskBundle(taskBundle.getKey())) {
    BriteDatabase.Transaction transaction = db.newTransaction();
    try {
      int nextBundleId =
          getNextID(db, TaskBundle.TASK_BUNDLE_TABLE_NAME, TaskBundle.COLUMN_BUNDLE_ID);
      db.insert(TaskBundle.TASK_BUNDLE_TABLE_NAME, getTaskBundleValues(taskBundle));
      List<TaskEntity> taskList = taskBundle.getTaskList();

      taskBundle.setBundleId(nextBundleId);

      if (taskList != null && taskList.size() > 0) {
        int nextTaskId = getNextID(db, TaskEntity.TASK_TABLE_NAME, TaskEntity.COLUMN_TASK_ID);
        for (TaskEntity taskEntity : taskList) {
          taskEntity.setTaskBundleId(nextBundleId);
          taskEntity.setTaskId(nextTaskId);
          db.insert(TaskEntity.TASK_TABLE_NAME, getTaskEntity(taskEntity));
          nextTaskId++;
        }
      }
      transaction.markSuccessful();
    } finally {
      transaction.end();
    }
  } else {
    TaskBundle bundleByKey = getBundleByKey(taskBundle.getKey());
    taskBundle.init(bundleByKey);
  }
}
 
开发者ID:MaYunFei,项目名称:RxJavaDownLoadMultipleFile,代码行数:33,代码来源:DownloadDao.java


注:本文中的com.squareup.sqlbrite.BriteDatabase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。