com.raizlabs.android.dbflow.sql.language.SQLite Java Examples

The following examples show how to use com.raizlabs.android.dbflow.sql.language.SQLite. 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: FlowQueryList.java    From Meteorite with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes all items from the table. Be careful as this will clear data!
 */
@Override
public void clear() {
    Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
        .beginTransactionAsync(new QueryTransaction.Builder<>(
            SQLite.delete().from(internalCursorList.table())).build())
        .error(internalErrorCallback)
        .success(internalSuccessCallback)
        .build();

    if (transact) {
        transaction.execute();
    } else {
        transaction.executeSync();
    }
}
 
Example #2
Source File: FolderNoteDAO.java    From android-notepad with MIT License 6 votes vote down vote up
public static List<Note> getLatestNotes(Folder folder){
	List<FolderNoteRelation> folderNoteRelations = SQLite
			.select()
			.from(FolderNoteRelation.class)
			.where(FolderNoteRelation_Table.folder_id.is(folder.getId()))
			.queryList();
	List<Note> notes = new ArrayList<>(folderNoteRelations.size());
	for (FolderNoteRelation folderNoteRelation : folderNoteRelations){
		folderNoteRelation.load();
		notes.add(folderNoteRelation.getNote());
	}
	Collections.sort(notes, new Comparator<Note>(){
		@Override public int compare(Note lhs, Note rhs){
			return lhs.getCreatedAt().compareTo(rhs.getCreatedAt());
		}
	});
	return notes;
}
 
Example #3
Source File: DBHelper.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
public Observable<Boolean> getFavouriteWorkflow(final String id) {
    return Observable.defer(new Callable<ObservableSource<? extends Boolean>>() {
        @Override
        public ObservableSource<? extends Boolean> call() throws Exception {
            Workflow workflow = SQLite.select()
                    .from(Workflow.class)
                    .where(Workflow_Table.id.eq(id))
                    .querySingle();
            if (workflow != null) {
                return Observable.just(workflow.isFavourite());
            } else {
                return Observable.just(null);
            }
        }
    });
}
 
Example #4
Source File: DatabaseHelper.java    From Stock-Hawk with Apache License 2.0 6 votes vote down vote up
public Observable<Stocks> getStocks() {
    return Observable.defer(new Func0<Observable<Stocks>>() {
        @Override
        public Observable<Stocks> call() {

            List<Quote> quotes = SQLite.select()
                    .from(Quote.class)
                    .queryList();

            Stocks stock = new Stocks();
            stock.getQuery().getResult().setQuote(quotes);

            return Observable.just(stock);
        }
    });
}
 
Example #5
Source File: FlowCursorList.java    From Meteorite with Apache License 2.0 6 votes vote down vote up
private FlowCursorList(final Builder<TModel> builder) {
    table = builder.modelClass;
    modelQueriable = builder.modelQueriable;
    if (builder.modelQueriable == null) {
        cursor = builder.cursor;
        // no cursor or queriable, we formulate query from table data.
        if (cursor == null) {
            modelQueriable = SQLite.select().from(table);
            cursor = modelQueriable.query();
        }
    } else {
        cursor = builder.modelQueriable.query();
    }
    cacheModels = builder.cacheModels;
    if (cacheModels) {
        modelCache = builder.modelCache;
        if (modelCache == null) {
            // new cache with default size
            modelCache = ModelLruCache.newInstance(0);
        }
    }
    instanceAdapter = FlowManager.getInstanceAdapter(builder.modelClass);

    setCacheModels(cacheModels);
}
 
Example #6
Source File: ScroballDB.java    From scroball with MIT License 6 votes vote down vote up
/** Prunes old submitted {@link Scrobble}s from the database, limiting to {@code MAX_ROWS}. */
public void prune() {
  long rowCount =
      SQLite.selectCountOf()
          .from(ScrobbleLogEntry.class)
          .where(ScrobbleLogEntry_Table.status.lessThan(0))
          .count();
  long toRemove = MAX_ROWS - rowCount;

  if (toRemove > 0) {
    SQLite.delete(ScrobbleLogEntry_Table.class)
        .where(ScrobbleLogEntry_Table.status.lessThan(0))
        .orderBy(ScrobbleLogEntry_Table.id, true)
        .limit((int) toRemove)
        .async()
        .execute();
  }
}
 
Example #7
Source File: RecordModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static List<RecordModel> getAllUnSync() {
    // Status <> STATUS_DELETE
    return SQLite.select()
            .from(RecordModel.class)
            .where(RecordModel_Table.Status.isNot(STATUS_UPLOADED))
            .queryList();
}
 
Example #8
Source File: DebugActivity.java    From android-notepad with MIT License 5 votes vote down vote up
@OnClick(R.id.assign_to_folders) void assignToFolders(){
	Note note = SQLite.select().from(Note.class).orderBy(Note_Table.createdAt, false).querySingle();
	List<Folder> folders = FoldersDAO.getLatestFolders();
	for (Folder folder : folders){
		FolderNoteRelation fnr = new FolderNoteRelation();
		fnr.setFolder(folder);
		fnr.setNote(note);
		fnr.save();
	}
}
 
Example #9
Source File: NoteActivity.java    From android-notepad with MIT License 5 votes vote down vote up
@Override public boolean onOptionsItemSelected(MenuItem item){
	if (item.getItemId() == R.id.delete_note){
		SQLite.delete().from(Note.class).where(Note_Table.id.is(note.getId())).execute();
		shouldFireDeleteEvent = true;
		onBackPressed();
	}
	return super.onOptionsItemSelected(item);
}
 
Example #10
Source File: PerfTestDbFlow.java    From android-database-performance with Apache License 2.0 5 votes vote down vote up
private void indexedStringEntityQueriesRun(int count) {
    // create entities
    List<IndexedStringEntity> entities = new ArrayList<>(count);
    String[] fixedRandomStrings = StringGenerator.createFixedRandomStrings(count);
    for (int i = 0; i < count; i++) {
        IndexedStringEntity entity = new IndexedStringEntity();
        entity._id = (long) i;
        entity.indexedString = fixedRandomStrings[i];
        entities.add(entity);
    }
    log("Built entities.");

    // insert entities
    FlowManager.getDatabase(FlowDatabase.class).executeTransaction(insertTransaction(entities, IndexedStringEntity.class));

    log("Inserted entities.");

    // query for entities by indexed string at random
    int[] randomIndices = StringGenerator.getFixedRandomIndices(getQueryCount(), count - 1);

    startClock();
    for (int i = 0; i < getQueryCount(); i++) {
        int nextIndex = randomIndices[i];

        //noinspection unused
        IndexedStringEntity indexedStringEntity = SQLite.select()
                .from(IndexedStringEntity.class)
                .where(IndexedStringEntity_Table.indexedString.eq(
                        fixedRandomStrings[nextIndex]))
                .querySingle();
    }
    stopClock(Benchmark.Type.QUERY_INDEXED);

    // delete all entities
    Delete.table(IndexedStringEntity.class);
    log("Deleted all entities.");
}
 
Example #11
Source File: DBHelper.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
public boolean updateFavouriteWorkflow(String id) {

        Workflow workflow1 = SQLite.select()
                .from(Workflow.class)
                .where(Workflow_Table.id.eq(id))
                .querySingle();

        if (workflow1 != null) {
            workflow1.setFavourite(!workflow1.isFavourite());
            workflow1.save();
            return true;
        }

        return false;
    }
 
Example #12
Source File: DBHelper.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
public Observable<List<Workflow>> getFavouriteWorkflow() {
    return Observable.defer(new Callable<ObservableSource<? extends List<Workflow>>>() {
        @Override
        public ObservableSource<? extends List<Workflow>> call() throws Exception {
            return Observable.just(SQLite.select()
                    .from(Workflow.class)
                    .where(Workflow_Table.favourite.eq(true))
                    .queryList());
        }
    });
}
 
Example #13
Source File: DBHelper.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
public Observable<Workflow> getFavouriteWorkflowDetail(final String id) {
    return Observable.defer(new Callable<ObservableSource<? extends Workflow>>() {
        @Override
        public ObservableSource<? extends Workflow> call() throws Exception {
            return Observable.just(SQLite.select()
                            .from(Workflow.class)
                            .where(Workflow_Table.id.eq(id))
                            .querySingle());
        }
    });
}
 
Example #14
Source File: DBHelper.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
public void clearFavouriteWorkflow() {
    List<Workflow> workflowList = SQLite.select()
            .from(Workflow.class)
            .where(Workflow_Table.favourite.eq(true))
            .queryList();

    for (Workflow workflow : workflowList) {
        workflow.setFavourite(!workflow.isFavourite());
        workflow.save();
    }

}
 
Example #15
Source File: UserManager.java    From jianshi with Apache License 2.0 5 votes vote down vote up
private void doLogout(final @NonNull Context context) {
  userPrefs.clear();
  SQLite.delete().from(PushData.class).execute();
  SQLite.delete().from(EventLog.class).execute();
  SQLite.delete().from(Diary.class).execute();
  context.startActivity(SignupActivity.createIntent(context));
}
 
Example #16
Source File: RetrievalAdapter.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * Force loads the model from the DB. Even if caching is enabled it will requery the object.
 */
public void load(@NonNull TModel model, DatabaseWrapper databaseWrapper) {
    getNonCacheableSingleModelLoader().load(databaseWrapper,
        SQLite.select()
            .from(getModelClass())
            .where(getPrimaryConditionClause(model)).getQuery(),
        model);
}
 
Example #17
Source File: CostRepositoryImpl.java    From android-clean-sample-app with MIT License 5 votes vote down vote up
@Override
public List<Cost> getAllUnsyncedCosts() {

    List<com.kodelabs.mycosts.storage.model.Cost> costs = SQLite
            .select()
            .from(com.kodelabs.mycosts.storage.model.Cost.class)
            .where(Cost_Table.synced.eq(false))
            .queryList();

    return StorageModelConverter.convertListToDomainModel(costs);
}
 
Example #18
Source File: RecordModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static RecordModel get(long id) {
    // Id = ?
    return SQLite.select()
            .from(RecordModel.class)
            .where(RecordModel_Table.Id.is(id))
            .querySingle();
}
 
Example #19
Source File: RecordModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static RecordModel get(UUID id) {
    // Mark = ?
    return SQLite.select()
            .from(RecordModel.class)
            .where(RecordModel_Table.Mark.is(id))
            .querySingle();
}
 
Example #20
Source File: RecordModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static List<RecordModel> getAllChanged(long date) {
    // ChangedTime > date
    return SQLite.select()
            .from(RecordModel.class)
            .where(RecordModel_Table.ChangedTime.greaterThan(date))
            .queryList();
}
 
Example #21
Source File: ScroballDB.java    From scroball with MIT License 5 votes vote down vote up
public boolean isLoved(Track track) {
  return SQLite.select()
          .from(LovedTracksEntry.class)
          .where(LovedTracksEntry_Table.artist.eq(track.artist().toLowerCase()))
          .and(LovedTracksEntry_Table.track.eq(track.track().toLowerCase()))
          .querySingle()
      != null;
}
 
Example #22
Source File: RecordModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static List<RecordModel> getAll() {
    // Status <> STATUS_DELETE
    return SQLite.select()
            .from(RecordModel.class)
            .where(RecordModel_Table.Status.isNot(STATUS_DELETE))
            .queryList();
}
 
Example #23
Source File: ContactModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
@OneToMany(methods = {OneToMany.Method.ALL}, variableName = "recordModels")
public List<RecordModel> records() {
    // get recordModels is this.Id
    if (recordModels == null || recordModels.isEmpty()) {
        recordModels = SQLite.select()
                .from(RecordModel.class)
                .where(RecordModel_Table.contact_Id.eq(id))
                .and(RecordModel_Table.Status.isNot(STATUS_DELETE))
                .queryList();
    }
    return recordModels;
}
 
Example #24
Source File: ContactModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static List<ContactModel> getAllChanged(long date) {
    // Changed > ?
    return SQLite.select()
            .from(ContactModel.class)
            .where(ContactModel_Table.ChangedTime.greaterThan(date))
            .queryList();
}
 
Example #25
Source File: ContactModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static List<ContactModel> getAllUnSync() {
    // Status <> ?
    return SQLite.select()
            .from(ContactModel.class)
            .where(ContactModel_Table.Status.isNot(STATUS_UPLOADED))
            .queryList();
}
 
Example #26
Source File: ContactModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static List<ContactModel> getAll() {
    // Status <> ?
    return SQLite.select()
            .from(ContactModel.class)
            .where(ContactModel_Table.Status.isNot(STATUS_DELETE))
            .queryList();
}
 
Example #27
Source File: ContactModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static ContactModel get(long id) {
    //Id = ?
    return SQLite.select()
            .from(ContactModel.class)
            .where(ContactModel_Table.Id.is(id))
            .querySingle();
}
 
Example #28
Source File: ContactModel.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
public static ContactModel get(UUID id) {
    // Mark = ?
    return SQLite.select()
            .from(ContactModel.class)
            .where(ContactModel_Table.Mark.is(id))
            .querySingle();
}
 
Example #29
Source File: DiaryService.java    From jianshi with Apache License 2.0 5 votes vote down vote up
public Observable<Diary> getDiaryByUuid(final String uuid) {
  return Observable.defer(new Func0<Observable<Diary>>() {
    @Override
    public Observable<Diary> call() {
      Diary diary = SQLite
          .select()
          .from(Diary.class)
          .where(Diary_Table.uuid.is(uuid))
          .querySingle();
      return Observable.just(diary);
    }
  });
}
 
Example #30
Source File: MainActivity.java    From DBFlowManager with Apache License 2.0 5 votes vote down vote up
public void updateCountText()
{
    if (radioGroup.getCheckedRadioButtonId() == R.id.radioUser)
    {
        txtRecordsCount.setText(SQLite.select().from(UserModel.class).queryList().size() + "");
    }
    else if (radioGroup.getCheckedRadioButtonId() == R.id.radioCompany)
    {
        txtRecordsCount.setText(SQLite.select().from(CompanyModel.class).queryList().size() + "");
    }
}