本文整理汇总了Java中com.activeandroid.query.Select类的典型用法代码示例。如果您正苦于以下问题:Java Select类的具体用法?Java Select怎么用?Java Select使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Select类属于com.activeandroid.query包,在下文中一共展示了Select类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCountOrderBy
import com.activeandroid.query.Select; //导入依赖的package包/类
/**
* Should not change the result if order by is used.
*/
public void testCountOrderBy() {
cleanTable();
populateTable();
From from = new Select()
.from(MockModel.class)
.where("intField = ?", 1)
.orderBy("intField ASC");
final List<MockModel> list = from.execute();
final int count = from.count();
assertEquals(2, count);
assertEquals(list.size(), count);
}
示例2: testCountGroupBy
import com.activeandroid.query.Select; //导入依赖的package包/类
/**
* Should return the total number of rows, even if the rows are grouped. May seem weird, just
* test it in an SQL explorer.
*/
public void testCountGroupBy() {
cleanTable();
populateTable();
From from = new Select()
.from(MockModel.class)
.groupBy("intField")
.having("intField = 1");
final List<MockModel> list = from.execute();
final int count = from.count();
assertEquals(2, count);
assertEquals(1, list.size());
}
示例3: testCountOrderBy
import com.activeandroid.query.Select; //导入依赖的package包/类
/**
* Should not change the result if order by is used.
*/
public void testCountOrderBy() {
cleanTable();
populateTable();
From from = new Select()
.from(MockModel.class)
.where("intField = ?", 1)
.orderBy("intField ASC");
final List<MockModel> list = from.execute();
final boolean exists = from.exists();
assertTrue(exists);
assertTrue(list.size() > 0);
}
示例4: testCountGroupBy
import com.activeandroid.query.Select; //导入依赖的package包/类
/**
* Should not change the result if group by is used.
*/
public void testCountGroupBy() {
cleanTable();
populateTable();
From from = new Select()
.from(MockModel.class)
.groupBy("intField")
.having("intField = 1");
final List<MockModel> list = from.execute();
final boolean exists = from.exists();
assertTrue(exists);
assertTrue(list.size() > 0);
}
示例5: testCountGroupByEmpty
import com.activeandroid.query.Select; //导入依赖的package包/类
/**
* Should not exist if group by eliminates all rows.
*/
public void testCountGroupByEmpty() {
cleanTable();
populateTable();
From from = new Select()
.from(MockModel.class)
.groupBy("intField")
.having("intField = 3");
final List<MockModel> list = from.execute();
final boolean exists = from.exists();
assertFalse(exists);
assertFalse(list.size() > 0);
}
示例6: testBooleanColumnType
import com.activeandroid.query.Select; //导入依赖的package包/类
/**
* Boolean should handle integer (0/1) and boolean (false/true) values.
*/
public void testBooleanColumnType() {
MockModel mockModel = new MockModel();
mockModel.booleanField = false;
Long id = mockModel.save();
boolean databaseBooleanValue = MockModel.load( MockModel.class, id ).booleanField;
assertEquals( false, databaseBooleanValue );
// Test passing both a integer and a boolean into the where conditional.
assertEquals(
mockModel,
new Select().from(MockModel.class).where("booleanField = ?", 0).executeSingle() );
assertEquals(
mockModel,
new Select().from(MockModel.class).where("booleanField = ?", false).executeSingle() );
assertNull( new Select().from(MockModel.class).where("booleanField = ?", 1).executeSingle() );
assertNull( new Select().from(MockModel.class).where("booleanField = ?", true).executeSingle() );
}
示例7: updateLatestForumPosts
import com.activeandroid.query.Select; //导入依赖的package包/类
private void updateLatestForumPosts() {
ArrayList<String>forumids;
List<Forum> forums = new Select().all().from(Forum.class).execute(); // gets a list of all the forums
ArrayList<Forum>news_forums = new ArrayList<>();
if(forums != null && forums.size() > 0) { // checks if there are no forums
for(int i = 0; i < forums.size(); i++) {
if (forums.get(i).getName().toUpperCase().contains("NEWS FORUM")) // checks if it is a news forum
news_forums.add(forums.get(i));
}
forumids = new ArrayList<>();
if(news_forums.size() > 0) {
for (int i = 0; i < news_forums.size(); i++)
forumids.add(news_forums.get(i).getForumid() + ""); // adds all the forums ids of the news forums to list
}
DiscussionSync dsync = new DiscussionSync(token, super.getContext());
boolean sync = dsync.syncDiscussions(forumids); // syncs all forum discussions
if(sync && first_update == 404)
sharedPrefs.edit().putInt(MoodleConstants.FIRST_UPDATE, 200); // update first update flag
}
}
示例8: fetchHiddenThreads
import com.activeandroid.query.Select; //导入依赖的package包/类
public static Observable<List<HiddenThread>> fetchHiddenThreads(String boardName) {
From query = new Select()
.all()
.from(HiddenThread.class)
.where(HiddenThread.BOARD_NAME + "=?", boardName);
BriteDatabase db = MimiApplication.getInstance().getBriteDatabase();
return db.createQuery(HiddenThread.TABLE_NAME, query.toSql(), query.getArguments())
.take(1)
.map(runQuery())
.flatMap(HiddenThread.mapper())
.onErrorReturn(new Func1<Throwable, List<HiddenThread>>() {
@Override
public List<HiddenThread> call(Throwable throwable) {
Log.e(LOG_TAG, "Error loading hidden threads from the database", throwable);
return Collections.emptyList();
}
});
}
示例9: latest
import com.activeandroid.query.Select; //导入依赖的package包/类
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")
.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")
.orderBy("timestamp desc")
.limit(number)
.execute();
}
}
示例10: min_recent
import com.activeandroid.query.Select; //导入依赖的package包/类
public static double min_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 asc")
.executeSingle();
if (calibration != null) {
return calibration.bg;
} else {
return 100;
}
}
示例11: toSettings
import com.activeandroid.query.Select; //导入依赖的package包/类
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;
}
示例12: noReadingsBelowRange
import com.activeandroid.query.Select; //导入依赖的package包/类
public static int noReadingsBelowRange(Context context) {
Bounds bounds = new Bounds().invoke();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));
double low = Double.parseDouble(settings.getString("lowValue", "70"));
if (!mgdl) {
low *= Constants.MMOLL_TO_MGDL;
}
int count = new Select()
.from(BgReading.class)
.where("timestamp >= " + bounds.start)
.where("timestamp <= " + bounds.stop)
.where("calculated_value > " + CUTOFF)
.where("calculated_value < " + low)
.where("snyced == 0")
.count();
Log.d("DrawStats", "Low count: " + count);
return count;
}
示例13: clearResponses
import com.activeandroid.query.Select; //导入依赖的package包/类
public static void clearResponses() {
List<GeoStatResponse> list = new Select().from(GeoStatResponse.class).execute();
for (GeoStatResponse response : list) {
GeoStat max = response.getMax();
GeoStat min = response.getMin();
GeoStat totals = response.getTotals();
List<GeoStat> items = response.getGeoStats();
for (GeoStat item : items) {
item.delete();
}
response.delete();
if (max != null) {
max.delete();
}
if (min != null) {
min.delete();
}
if (totals != null) {
totals.delete();
}
}
}
示例14: getForTimestamp
import com.activeandroid.query.Select; //导入依赖的package包/类
public static BgReading getForTimestamp(double timestamp) {
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
BgReading bgReading = new Select()
.from(BgReading.class)
.where("Sensor = ? ", sensor.getId())
.where("timestamp <= ?", (timestamp + (60 * 1000))) // 1 minute padding (should never be that far off, but why not)
.where("calculated_value = 0")
.where("raw_calculated = 0")
.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;
}
}
Log.d(TAG, "getForTimestamp: No luck finding a BG timestamp match");
return null;
}
示例15: removeResponseFromCache
import com.activeandroid.query.Select; //导入依赖的package包/类
@Override
protected void removeResponseFromCache() {
PageTitleStatResponse response = new Select().from(PageTitleStatResponse.class).where("startDate='" + mStartDate.getTime() + "'").and("endDate='" + mEndDate.getTime() + "'").executeSingle();
if (response == null) return;
PageTitleStat max = response.getMax();
PageTitleStat min = response.getMin();
PageTitleStat totals = response.getTotals();
List<PageTitleStat> items = response.getStats();
for (PageTitleStat item : items) {
item.delete();
}
response.delete();
if (max != null) {
max.delete();
}
if (min != null) {
min.delete();
}
if (totals != null) {
totals.delete();
}
}