本文整理汇总了Java中com.activeandroid.query.From类的典型用法代码示例。如果您正苦于以下问题:Java From类的具体用法?Java From怎么用?Java From使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
From类属于com.activeandroid.query包,在下文中一共展示了From类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWhereWithArguments
import com.activeandroid.query.From; //导入依赖的package包/类
public void testWhereWithArguments() {
From query = from().where("Id = ?", 5);
assertArrayEquals(query.getArguments(), "5");
assertSqlEquals(SELECT_PREFIX + "WHERE Id = ?",
query);
query = from().where("Id > ? AND Id < ?", 5, 10);
assertArrayEquals(query.getArguments(), "5", "10");
assertSqlEquals(SELECT_PREFIX + "WHERE Id > ? AND Id < ?",
query);
// Chained
query = from()
.where("Id != ?", 10)
.where("Id IN (?, ?, ?)", 5, 10, 15)
.where("Id > ? AND Id < ?", 5, 10);
assertArrayEquals(query.getArguments(), "10", "5", "10", "15", "5", "10");
assertSqlEquals(SELECT_PREFIX + "WHERE Id != ? AND Id IN (?, ?, ?) AND Id > ? AND Id < ?",
query);
}
示例2: testCountOrderBy
import com.activeandroid.query.From; //导入依赖的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);
}
示例3: testCountGroupBy
import com.activeandroid.query.From; //导入依赖的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());
}
示例4: testCountOrderBy
import com.activeandroid.query.From; //导入依赖的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);
}
示例5: testCountGroupBy
import com.activeandroid.query.From; //导入依赖的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);
}
示例6: testCountGroupByEmpty
import com.activeandroid.query.From; //导入依赖的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);
}
示例7: fetchBoards
import com.activeandroid.query.From; //导入依赖的package包/类
public static Observable<List<Board>> fetchBoards(int orderBy) {
From query = new Select()
.all()
.from(Board.class)
.orderBy(Board.sortOrder(orderBy))
.and(Board.KEY_VISIBLE + "=?", true);
Log.d(LOG_TAG, "SQL=" + query.toSql());
BriteDatabase db = MimiApplication.getInstance().getBriteDatabase();
return db.createQuery(Board.TABLE_NAME, query.toSql(), query.getArguments())
.take(1)
.map(runQuery())
.flatMap(Board.mapper())
.onErrorReturn(new Func1<Throwable, List<Board>>() {
@Override
public List<Board> call(Throwable throwable) {
Log.e(LOG_TAG, "Error loading boards from the database", throwable);
return Collections.emptyList();
}
});
}
示例8: fetchHiddenThreads
import com.activeandroid.query.From; //导入依赖的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: addFilter
import com.activeandroid.query.From; //导入依赖的package包/类
/**
* Important, make sure that all previous complex SQL expressions are in braces!
*/
public static void addFilter(From sql, String[] columns, String filter) {
filter = prepareLikeFilter(filter);
if (org.apache.commons.lang3.StringUtils.isEmpty(filter)) {
return;
}
String whereExpression = new String();
String[] args = new String[columns.length * 2];
for (int i = 0; i < columns.length; i++) {
String column = columns[i];
if (whereExpression.length() > 0) {
whereExpression += " or ";
}
whereExpression += String.format(" %s like ? or %s like ? ", column, column);
args[i * 2] = filter + "%";
args[i * 2 + 1] = "% " + filter + "%";
}
sql.and("(" + whereExpression + ")", args);
}
示例10: reloadAnnotations
import com.activeandroid.query.From; //导入依赖的package包/类
private void reloadAnnotations(final String text) {
if (reloadingAsyncTask != null) {
reloadingAsyncTask.cancel(true);
}
String[] filterParts = text.split("\\s+");
final String filter = filterParts[filterParts.length - 1];
reloadingAsyncTask = new AsyncTask<Void, Void, From>() {
@Override
protected From doInBackground(Void... voids) {
return annotationService.getAnnotationsSelectByCollectionAndFilter(collectionId, filter);
}
@Override
protected void onPostExecute(From from) {
int size = annotationsAdapter.reloadAndGetSize(from);
binding.existingAnnotations.setVisibility(size > 0 ? View.VISIBLE : View.GONE);
}
};
reloadingAsyncTask.execute();
}
示例11: reloadAnnotations
import com.activeandroid.query.From; //导入依赖的package包/类
private void reloadAnnotations(final String text) {
if (reloadingAsyncTask != null) {
reloadingAsyncTask.cancel(true);
}
String[] filterParts = text.split("\\s+");
final String filter = filterParts.length > 0 ? filterParts[filterParts.length - 1] : "";
reloadingAsyncTask = new AsyncTask<Void, Void, From>() {
@Override
protected From doInBackground(Void... voids) {
return annotationService.getAnnotationsSelectBydFilter(filter, collectionId);
}
@Override
protected void onPostExecute(From from) {
annotationsAdapter.reloadAndGetSize(from);
}
};
reloadingAsyncTask.execute();
}
示例12: getAllAudits
import com.activeandroid.query.From; //导入依赖的package包/类
@Override
public List<Audit> getAllAudits(String name, SortCriteria sortCriteria) {
Timber.v("select all audits name=%s, sortCriteria=%s", name, sortCriteria);
long now = System.currentTimeMillis();
From from = new Select()
.all()
.from(Audit.class);
if (StringUtils.isNotBlank(name)) {
from = from.where(Audit.TABLE_NAME + "." + Audit.COLUMN_NAME + " LIKE ?", "%" + name + "%");
}
from = sortCriteria.upgrade(from);
List<Audit> audits = from.execute();
for (Audit audit : audits) {
updateAuditRuleSet(audit);
}
Timber.v("select all audits done in %d", System.currentTimeMillis() - now);
return audits;
}
示例13: checkAuditExistenceByNameAndVersion
import com.activeandroid.query.From; //导入依赖的package包/类
@Override
public boolean checkAuditExistenceByNameAndVersion(String name, Site site, int version) {
Timber.v("audit check existence : name %s version %d ", name, version);
From from = new Select().from(Audit.class)
.where(Audit.COLUMN_NAME + " = ?", name);
if (version != 0) {
from = from.and(Audit.COLUMN_VERSION + " = ?", version);
}
from = from.and(Audit.COLUMN_SITE + " = ?", site.getId());
boolean result = from.exists();
Timber.v("audit check existence retrieved : %b", result);
return result;
}
示例14: searchSites
import com.activeandroid.query.From; //导入依赖的package包/类
@Override
public List<Site> searchSites(String noImmo, String name) {
From from = new Select().from(Site.class);
if (StringUtils.isNotBlank(noImmo)) {
from = from.where(Site.COLUMN_NOIMMO + " LIKE ?", "" + noImmo + "%").orderBy(Site.COLUMN_NOIMMO + " ASC");
}
if (StringUtils.isNotBlank(name)) {
from = from.where(Site.COLUMN_NAME + " LIKE ?", "%" + name + "%").orderBy(Site.COLUMN_NAME + " ASC");
}
List<Site> sites = from.execute();
Timber.d("SQL Results : " + sites.size());
return sites;
}
示例15: isValid
import com.activeandroid.query.From; //导入依赖的package包/类
/**
* {@inheritDoc }
*/
@Override
public boolean isValid(IValueDescriptor<Object> value) {
Model model = value.getModel();
From from = new Select().from(model.getClass());
Model existing;
if (value.getValue() == null) {
existing = from.where(value.getColumnName() + " IS NULL").executeSingle();
} else {
existing = from.where(value.getColumnName() + " = ?", value.getValue()).executeSingle();
}
return existing == null || existing.getId().equals(value.getModel().getId());
}