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

The following examples show how to use com.raizlabs.android.dbflow.sql.language.SQLite. 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: Meteorite   Source File: FlowQueryList.java    License: 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 Project: Meteorite   Source File: FlowCursorList.java    License: 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 3
Source Project: Stock-Hawk   Source File: DatabaseHelper.java    License: 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 4
Source Project: scroball   Source File: ScroballDB.java    License: 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 5
Source Project: android-notepad   Source File: FolderNoteDAO.java    License: 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 6
Source Project: incubator-taverna-mobile   Source File: DBHelper.java    License: 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 7
Source Project: Meteorite   Source File: RetrievalAdapter.java    License: 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 8
public static List<TagSensorReading> getForTag(String id) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.HOUR, -24);
    return SQLite.select()
            .from(TagSensorReading.class)
            .where(TagSensorReading_Table.ruuviTagId.eq(id))
            .and(TagSensorReading_Table.createdAt.greaterThan(cal.getTime()))
            .orderBy(TagSensorReading_Table.createdAt, true)
            .queryList();
}
 
Example 9
public static List<TagSensorReading> getLatestForTag(String id, int limit) {
    return SQLite.select()
            .from(TagSensorReading.class)
            .where(TagSensorReading_Table.ruuviTagId.eq(id))
            .orderBy(TagSensorReading_Table.id, false)
            .limit(limit)
            .queryList();
}
 
Example 10
public static void removeOlderThan(int hours) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.HOUR, -hours);
    SQLite.delete()
            .from(TagSensorReading.class)
            .where(TagSensorReading_Table.createdAt.lessThan(cal.getTime()))
            .async()
            .execute();
}
 
Example 11
public void deleteTagAndRelatives() {
    SQLite.delete()
            .from(Alarm.class)
            .where(Alarm_Table.ruuviTagId.eq(this.id))
            .execute();
    SQLite.delete()
            .from(TagSensorReading.class)
            .where(TagSensorReading_Table.ruuviTagId.eq(this.id))
            .execute();

    this.delete();
}
 
Example 12
public static HumidityCalibration get(RuuviTag tag) {
    if (cache.containsKey(tag.id)) {
        return cache.get(tag.id);
    }
    return SQLite.select()
            .from(HumidityCalibration.class)
            .where(HumidityCalibration_Table.mac.eq(tag.id))
            .querySingle();
}
 
Example 13
public static boolean Exists(String id) {
    long count = SQLite.selectCountOf()
            .from(RuuviTag.class)
            .where(RuuviTag_Table.id.eq(id))
            .count();
    return count > 0;
}
 
Example 14
Source Project: WeatherStream   Source File: WeatherData_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherData model, DatabaseWrapper wrapper) {
  return SQLite.selectCountOf()
  .from(WeatherData.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 15
Source Project: WeatherStream   Source File: Weather_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherData.Weather model, DatabaseWrapper wrapper) {
  return (model.getWId() != null && model.getWId() > 0 || model.getWId() == null)
  && SQLite.selectCountOf()
  .from(WeatherData.Weather.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 16
Source Project: WeatherStream   Source File: Sys_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherData.Sys model, DatabaseWrapper wrapper) {
  return (model.getSysId() != null && model.getSysId() > 0 || model.getSysId() == null)
  && SQLite.selectCountOf()
  .from(WeatherData.Sys.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 17
Source Project: WeatherStream   Source File: Main_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherData.Main model, DatabaseWrapper wrapper) {
  return (model.getId() != null && model.getId() > 0 || model.getId() == null)
  && SQLite.selectCountOf()
  .from(WeatherData.Main.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 18
Source Project: WeatherStream   Source File: WeatherForecastData_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherForecastData model, DatabaseWrapper wrapper) {
  return SQLite.selectCountOf()
  .from(WeatherForecastData.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 19
Source Project: WeatherStream   Source File: Rain_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherForecastData.Rain model, DatabaseWrapper wrapper) {
  return (model.getId() != null && model.getId() > 0 || model.getId() == null)
  && SQLite.selectCountOf()
  .from(WeatherForecastData.Rain.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 20
Source Project: WeatherStream   Source File: ForecastList_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherForecastData.ForecastList model, DatabaseWrapper wrapper) {
  return (model.getId() != null && model.getId() > 0 || model.getId() == null)
  && SQLite.selectCountOf()
  .from(WeatherForecastData.ForecastList.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 21
Source Project: WeatherStream   Source File: Wind_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherData.Wind model, DatabaseWrapper wrapper) {
  return (model.getId() != null && model.getId() > 0 || model.getId() == null)
  && SQLite.selectCountOf()
  .from(WeatherData.Wind.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 22
Source Project: WeatherStream   Source File: LocationSearchHistory_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(LocationSearchHistory model, DatabaseWrapper wrapper) {
  return SQLite.selectCountOf()
  .from(LocationSearchHistory.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 23
Source Project: WeatherStream   Source File: Clouds_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherData.Clouds model, DatabaseWrapper wrapper) {
  return (model.getId() != null && model.getId() > 0 || model.getId() == null)
  && SQLite.selectCountOf()
  .from(WeatherData.Clouds.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 24
Source Project: WeatherStream   Source File: Coord_Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean exists(WeatherData.Coord model, DatabaseWrapper wrapper) {
  return (model.getId() != null && model.getId() > 0 || model.getId() == null)
  && SQLite.selectCountOf()
  .from(WeatherData.Coord.class)
  .where(getPrimaryConditionClause(model))
  .hasData(wrapper);
}
 
Example 25
Source Project: JDAddressSelector   Source File: DefaultAddressProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void provideProvinces(final AddressReceiver<Province> addressReceiver) {
    final FlowQueryList<Province> provinceQueryList = SQLite.select()
            .from(Province.class)
            .flowQueryList();
    addressReceiver.send(new ArrayList<>(provinceQueryList));
}
 
Example 26
Source Project: JDAddressSelector   Source File: DefaultAddressProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void provideCitiesWith(int provinceId, final AddressReceiver<City> addressReceiver) {
    final FlowQueryList<City> cityQueryList = SQLite.select()
            .from(City.class)
            .where(City_Table.province_id.eq(provinceId))
            .flowQueryList();
    addressReceiver.send(new ArrayList<>(cityQueryList));
}
 
Example 27
Source Project: JDAddressSelector   Source File: DefaultAddressProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void provideCountiesWith(int cityId, final AddressReceiver<County> addressReceiver) {
    final FlowQueryList<County> countyQueryList = SQLite.select()
            .from(County.class)
            .where(County_Table.city_id.eq(cityId))
            .flowQueryList();
    addressReceiver.send(new ArrayList<>(countyQueryList));
}
 
Example 28
Source Project: JDAddressSelector   Source File: DefaultAddressProvider.java    License: MIT License 5 votes vote down vote up
@Override
public void provideStreetsWith(int countyId, final AddressReceiver<Street> addressReceiver) {
    final FlowQueryList<Street> streetQueryList = SQLite.select()
            .from(Street.class)
            .where(Street_Table.county_id.eq(countyId))
            .flowQueryList();
    addressReceiver.send(new ArrayList<>(streetQueryList));
}
 
Example 29
Source Project: scroball   Source File: ScroballDB.java    License: MIT License 5 votes vote down vote up
/** Returns a list of all pending and submitted {@link Scrobble}s. */
public List<Scrobble> readScrobbles() {
  List<ScrobbleLogEntry> entries =
      SQLite.select()
          .from(ScrobbleLogEntry.class)
          .orderBy(ScrobbleLogEntry_Table.timestamp, false)
          .queryList();
  return scrobbleEntriesToScrobbles(entries);
}
 
Example 30
Source Project: scroball   Source File: ScroballDB.java    License: MIT License 5 votes vote down vote up
/**
 * Returns a list of all pending {@link PlaybackItem}s which have been written to the database.
 */
public List<Scrobble> readPendingScrobbles() {
  List<ScrobbleLogEntry> entries =
      SQLite.select()
          .from(ScrobbleLogEntry.class)
          .where(ScrobbleLogEntry_Table.status.in(LastfmClient.TRANSIENT_ERROR_CODES))
          .orderBy(ScrobbleLogEntry_Table.timestamp, false)
          .queryList();
  return scrobbleEntriesToScrobbles(entries);
}