com.activeandroid.query.Select Java Examples
The following examples show how to use
com.activeandroid.query.Select.
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: AlertType.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static boolean toSettings(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); List<AlertType> alerts = new Select() .from(AlertType.class) .execute(); Gson gson = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .registerTypeAdapter(Date.class, new DateTypeAdapter()) .serializeSpecialFloatingPointValues() .create(); String output = gson.toJson(alerts); Log.e(TAG, "Created the string " + output); prefs.edit().putString("saved_alerts", output).commit(); // always leave this as commit return true; }
Example #2
Source File: Calibration.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static double max_recent() { Sensor sensor = Sensor.currentSensor(); Calibration calibration = new Select() .from(Calibration.class) .where("Sensor = ? ", sensor.getId()) .where("slope_confidence != 0") .where("sensor_confidence != 0") .where("timestamp > ?", (new Date().getTime() - (60000 * 60 * 24 * 4))) .orderBy("bg desc") .executeSingle(); if (calibration != null) { return calibration.bg; } else { return 120; } }
Example #3
Source File: BgReading.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static BgReading getForPreciseTimestamp(long timestamp, long precision, boolean lock_to_sensor) { final Sensor sensor = Sensor.currentSensor(); if ((sensor != null) || !lock_to_sensor) { final BgReading bgReading = new Select() .from(BgReading.class) .where(lock_to_sensor ? "Sensor = ?" : "timestamp > ?", (lock_to_sensor ? sensor.getId() : 0)) .where("timestamp <= ?", (timestamp + precision)) .where("timestamp >= ?", (timestamp - precision)) .orderBy("abs(timestamp - " + timestamp + ") asc") .executeSingle(); if (bgReading != null && Math.abs(bgReading.timestamp - timestamp) < precision) { //cool, so was it actually within precision of that bg reading? //Log.d(TAG, "getForPreciseTimestamp: Found a BG timestamp match"); return bgReading; } } Log.d(TAG, "getForPreciseTimestamp: No luck finding a BG timestamp match: " + JoH.dateTimeText((long) timestamp) + " precision:" + precision + " Sensor: " + ((sensor == null) ? "null" : sensor.getId())); return null; }
Example #4
Source File: UploaderQueue.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private static int getLegacyCount(Class which, Boolean rest, Boolean mongo, Boolean and) { try { String where = ""; if (rest != null) where += " success = " + (rest ? "1 " : "0 "); if (and != null) where += (and ? " and " : " or "); if (mongo != null) where += " mongo_success = " + (mongo ? "1 " : "0 "); final String query = new Select("COUNT(*) as total").from(which).toSql(); final Cursor resultCursor = Cache.openDatabase().rawQuery(query + ((where.length() > 0) ? " where " + where : ""), null); if (resultCursor.moveToNext()) { final int total = resultCursor.getInt(0); resultCursor.close(); return total; } else { return 0; } } catch (Exception e) { Log.d(TAG, "Got exception getting count: " + e); return -1; } }
Example #5
Source File: AlertType.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static boolean toSettings(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); List<AlertType> alerts = new Select() .from(AlertType.class) .execute(); Gson gson = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .registerTypeAdapter(Date.class, new DateTypeAdapter()) .serializeSpecialFloatingPointValues() .create(); String output = gson.toJson(alerts); Log.e(TAG, "Created the string " + output); prefs.edit().putString("saved_alerts", output).commit(); return true; }
Example #6
Source File: UserNotification.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static UserNotification GetNotificationByType(String type) { if (legacy_types.contains(type)) { type = type + " = ?"; return new Select() .from(UserNotification.class) .where(type, true) .orderBy("_ID desc") .executeSingle(); } else { final String timestamp = PersistentStore.getString("UserNotification:timestamp:" + type); if (timestamp.equals("")) return null; final String message = PersistentStore.getString("UserNotification:message:" + type); if (message.equals("")) return null; UserNotification userNotification = new UserNotification(); userNotification.timestamp = JoH.tolerantParseDouble(timestamp, -1); if (userNotification.timestamp == -1) return null; // bad data userNotification.message = message; Log.d(TAG, "Workaround for: " + type + " " + userNotification.message + " timestamp: " + userNotification.timestamp); return userNotification; } }
Example #7
Source File: Reminder.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static Reminder getNextActiveReminder() { fixUpTable(schema); final boolean onHomeWifi = !HomeWifi.isSet() || HomeWifi.isConnected(); final long now = JoH.tsl(); final Reminder reminder = new Select() .from(Reminder.class) .where("enabled = ?", true) .where("next_due < ?", now) .where("snoozed_till < ?", now) .where("last_fired < (? - (600000 * alerted_times))", now) // if on home wifi or not set then anything otherwise only home only = false .where(onHomeWifi ? "homeonly > -1 " : "homeonly = 0") .orderBy("enabled desc, priority desc, next_due asc") .executeSingle(); return reminder; }
Example #8
Source File: TransmitterData.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static TransmitterData getForTimestamp(double timestamp) {//KS try { Sensor sensor = Sensor.currentSensor(); if (sensor != null) { TransmitterData bgReading = new Select() .from(TransmitterData.class) .where("timestamp <= ?", (timestamp + (60 * 1000))) // 1 minute padding (should never be that far off, but why not) .orderBy("timestamp desc") .executeSingle(); if (bgReading != null && Math.abs(bgReading.timestamp - timestamp) < (3 * 60 * 1000)) { //cool, so was it actually within 4 minutes of that bg reading? Log.i(TAG, "getForTimestamp: Found a BG timestamp match"); return bgReading; } } } catch (Exception e) { Log.e(TAG,"getForTimestamp() Got exception on Select : "+e.toString()); return null; } Log.d(TAG, "getForTimestamp: No luck finding a BG timestamp match"); return null; }
Example #9
Source File: Calibration.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static List<Calibration> latestValid(int number, long until) { Sensor sensor = Sensor.currentSensor(); if (sensor == null) { return null; } // we don't filter invalid intercepts here as they will be filtered in the plugin itself return new Select() .from(Calibration.class) .where("Sensor = ? ", sensor.getId()) .where("slope_confidence != 0") .where("sensor_confidence != 0") .where("slope != 0") .where("timestamp <= ?", until) .orderBy("timestamp desc") .limit(number) .execute(); }
Example #10
Source File: NotificationActivity.java From MagicPrint-ECommerce-App-Android with MIT License | 5 votes |
private List<Notification> getAll() { //Getting all items stored in Inventory table return new Select() .from(Notification.class) .limit(10) .execute(); }
Example #11
Source File: NotificationActivity.java From MagicPrint-ECommerce-App-Android with MIT License | 5 votes |
public void markAsRead(View view) { List<Notification> listtodel= new Select() .from(Notification.class) .limit(10) .execute(); for (int i=listtodel.size()-1;i>=0;i--){ Notification.delete(Notification.class,i); } Intent refresh = new Intent(this, NotificationActivity.class); startActivity(refresh);//Start the same Activity finish(); //finish Activity. }
Example #12
Source File: UserError.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static void cleanup(long timestamp) { patched = fixUpTable(schema, patched); List<UserError> userErrors = new Select() .from(UserError.class) .where("timestamp < ?", timestamp) .orderBy("timestamp desc") .execute(); if (userErrors != null) Log.d(TAG, "cleanup UserError size=" + userErrors.size()); new Cleanup().execute(userErrors); }
Example #13
Source File: BgReading.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static List<BgReading> latestForGraphAsc(int number, long startTime, long endTime) {//KS return new Select() .from(BgReading.class) .where("timestamp >= " + Math.max(startTime, 0)) .where("timestamp <= " + endTime) .where("calculated_value != 0") .where("raw_data != 0") .orderBy("timestamp asc") .limit(number) .execute(); }
Example #14
Source File: AlertType.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static List<AlertType> getAll(boolean above) { String order; if (above) { order = "threshold asc"; } else { order = "threshold desc"; } List<AlertType> alerts = new Select() .from(AlertType.class) .where("above = ?", above) .orderBy(order) .execute(); return alerts; }
Example #15
Source File: Calibration.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static Calibration lastValid() { Sensor sensor = Sensor.currentSensor(); if (sensor == null) { return null; } return new Select() .from(Calibration.class) .where("Sensor = ? ", sensor.getId()) .where("slope_confidence != 0") .where("sensor_confidence != 0") .where("slope != 0") .orderBy("timestamp desc") .executeSingle(); }
Example #16
Source File: LibreBlock.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static LibreBlock getForTimestamp(long timestamp) { final long margin = (3 * 1000); return new Select() .from(LibreBlock.class) .where("timestamp >= ?", (timestamp - margin)) .where("timestamp <= ?", (timestamp + margin)) .executeSingle(); }
Example #17
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<BgReading> latest(int number, boolean is_follower) { if (is_follower) { // exclude sensor information when working as a follower return new Select() .from(BgReading.class) .where("calculated_value != 0") .where("raw_data != 0") // .where("timestamp <= ?", JoH.tsl()) .orderBy("timestamp desc") .limit(number) .execute(); } else { Sensor sensor = Sensor.currentSensor(); if (sensor == null) { return null; } return new Select() .from(BgReading.class) .where("Sensor = ? ", sensor.getId()) .where("calculated_value != 0") .where("raw_data != 0") // .where("timestamp <= ?", JoH.tsl()) .orderBy("timestamp desc") .limit(number) .execute(); } }
Example #18
Source File: AlertType.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static void remove_all() { List<AlertType> Alerts = new Select() .from(AlertType.class) .execute(); for (AlertType alert : Alerts) { alert.delete(); } ActiveBgAlert.ClearData(); }
Example #19
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static BgReading byUUID(String uuid) { if (uuid == null) return null; return new Select() .from(BgReading.class) .where("uuid = ?", uuid) .executeSingle(); }
Example #20
Source File: Treatments.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<Treatments> latest(int num) { try { return new Select() .from(Treatments.class) .orderBy("timestamp desc") .limit(num) .execute(); } catch (android.database.sqlite.SQLiteException e) { fixUpTable(); return null; } }
Example #21
Source File: Reminder.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<Reminder> getAllReminders() { fixUpTable(schema); final List<Reminder> reminders = new Select() .from(Reminder.class) .orderBy("enabled desc, priority desc, next_due asc") .execute(); return reminders; }
Example #22
Source File: UserError.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<UserError> bySeverity(Integer[] levels) { String levelsString = " "; for (int level : levels) { levelsString += level + ","; } Log.d("UserError", "severity in ("+levelsString.substring(0,levelsString.length() - 1)+")"); return new Select() .from(UserError.class) .where("severity in ("+levelsString.substring(0,levelsString.length() - 1)+")") .orderBy("timestamp desc") .limit(10000)//too many data can kill akp .execute(); }
Example #23
Source File: DailyGankData.java From GankLock with GNU General Public License v3.0 | 5 votes |
public List<GankDaily> getDailyDataFromDB(Observer<List<GankDaily>> observer) { Observable.create(new ObservableOnSubscribe<List<GankDaily>>() { @Override public void subscribe(ObservableEmitter<List<GankDaily>> emitter) throws Exception { List<GankDaily> list = new Select().from(GankDaily.class) .orderBy("publishedAt DESC")//DESC ASC .execute(); emitter.onNext(list); } }).subscribeOn(Schedulers.io()) .subscribe(observer); return mList; }
Example #24
Source File: SensorSendQueue.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<SensorSendQueue> queue() { return new Select() .from(SensorSendQueue.class) .where("success = ?", false) .orderBy("_ID desc") .execute(); }
Example #25
Source File: BgReading.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static List<BgReading> futureReadings() { double timestamp = new Date().getTime(); return new Select() .from(BgReading.class) .where("timestamp > " + timestamp) .orderBy("timestamp desc") .execute(); }
Example #26
Source File: Sensor.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static Sensor currentSensor() { try {//KS Sensor sensor = new Select() .from(Sensor.class) .where("started_at != 0") .where("stopped_at = 0") .orderBy("_ID desc") .limit(1) .executeSingle(); return sensor; } catch (Exception e) { return null; } }
Example #27
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<BgReading> latestForGraphSensor(int number, long startTime, long endTime) { Sensor sensor = Sensor.currentSensor(); if (sensor == null) { return null; } return new Select() .from(BgReading.class) .where("Sensor = ? ", sensor.getId()) .where("timestamp >= " + Math.max(startTime, 0)) .where("timestamp <= " + endTime) .where("calculated_value != 0") .where("raw_data != 0") .where("calibration_uuid != \"\"") .orderBy("timestamp desc") .limit(number) .execute(); }
Example #28
Source File: UploaderQueue.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private static List<String> getClasses() { fixUpTable(); final ArrayList<String> results = new ArrayList<>(); final String query = new Select("distinct otype as otypes").from(UploaderQueue.class).toSql(); final Cursor resultCursor = Cache.openDatabase().rawQuery(query, null); while (resultCursor.moveToNext()) { results.add(resultCursor.getString(0)); } resultCursor.close(); return results; }
Example #29
Source File: BloodTest.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<BloodTest> last(int num) { try { return new Select() .from(BloodTest.class) .orderBy("timestamp desc") .limit(num) .execute(); } catch (android.database.sqlite.SQLiteException e) { fixUpTable(); return null; } }
Example #30
Source File: UserError.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<UserError> bySeverity(Integer[] levels) { String levelsString = " "; for (int level : levels) { levelsString += level + ","; } Log.d("UserError", "severity in ("+levelsString.substring(0,levelsString.length() - 1)+")"); return new Select() .from(UserError.class) .where("severity in ("+levelsString.substring(0,levelsString.length() - 1)+")") .orderBy("timestamp desc") .execute(); }