本文整理汇总了Java中com.j256.ormlite.stmt.QueryBuilder.prepare方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder.prepare方法的具体用法?Java QueryBuilder.prepare怎么用?Java QueryBuilder.prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.stmt.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTag
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public Tag getTag(final String aTag) {
try {
QueryBuilder<Tag, Long> queryBuilder = dbHelper.getTagDao().queryBuilder();
Where<Tag, Long> where = queryBuilder.where();
SelectArg selectArg = new SelectArg();
// define our query as 'name = ?'
where.eq(Tag.COLUMN_NAME_TITLE, selectArg);
// prepare it so it is ready for later query or iterator calls
PreparedQuery<Tag> preparedQuery = queryBuilder.prepare();
// later we can set the select argument and issue the query
selectArg.setValue(aTag);
List<Tag> tgs = dbHelper.getTagDao().query(preparedQuery);
if (!tgs.isEmpty()) {
return tgs.get(0);
}
} catch (java.sql.SQLException pE) {
pE.printStackTrace();
}
return null;
}
示例2: updateDanaRHistoryRecordId
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public void updateDanaRHistoryRecordId(JSONObject trJson) {
try {
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = getDaoDanaRHistory().queryBuilder();
Where where = queryBuilder.where();
where.ge("bytes", trJson.get(DanaRNSHistorySync.DANARSIGNATURE));
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
List<DanaRHistoryRecord> list = getDaoDanaRHistory().query(preparedQuery);
if (list.size() == 0) {
// Record does not exists. Ignore
} else if (list.size() == 1) {
DanaRHistoryRecord record = list.get(0);
if (record._id == null || !record._id.equals(trJson.getString("_id"))) {
if (Config.logIncommingData)
log.debug("Updating _id in DanaR history database: " + trJson.getString("_id"));
record._id = trJson.getString("_id");
getDaoDanaRHistory().update(record);
} else {
// already set
}
}
} catch (SQLException | JSONException e) {
log.error("Unhandled exception", e);
}
}
示例3: lookupTagsForEBook
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
private List<Tag> lookupTagsForEBook(EBook ebk) throws SQLException {
if (tagsForEBookQuery == null) {
QueryBuilder<EBookTags, Long> dbQryBld = dbHelper.getEBookTagsDao().queryBuilder();
// this time selecting for the user-id field
dbQryBld.selectColumns(EBookTags.COLUMN_NAME_TAG_ID);
SelectArg postSelectArg = new SelectArg();
dbQryBld.where().eq(EBookTags.COLUMN_NAME_BOOK_ID, postSelectArg);
// build our outer query
QueryBuilder<Tag, Long> userQb = dbHelper.getTagDao().queryBuilder();
// where the user-id matches the inner query's user-id field
userQb.where().in(Tag.COLUMN_NAME_ID, dbQryBld);
tagsForEBookQuery = userQb.prepare();
}
tagsForEBookQuery.setArgumentHolderValue(0, ebk);
return dbHelper.getTagDao().query(tagsForEBookQuery);
}
示例4: getFileType
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public FileType getFileType(final String aFileType) {
try {
QueryBuilder<FileType, Long> queryBuilder = dbHelper.getFileTypeDao().queryBuilder();
Where<FileType, Long> where = queryBuilder.where();
SelectArg selectArg = new SelectArg();
// define our query as 'name = ?'
where.eq(FileType.COLUMN_NAME_TITLE, selectArg);
// prepare it so it is ready for later query or iterator calls
PreparedQuery<FileType> preparedQuery = queryBuilder.prepare();
// later we can set the select argument and issue the query
selectArg.setValue(aFileType);
List<FileType> tgs = dbHelper.getFileTypeDao().query(preparedQuery);
if (!tgs.isEmpty()) {
return tgs.get(0);
}
} catch (java.sql.SQLException pE) {
pE.printStackTrace();
}
return null;
}
示例5: findTempTargetById
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public TempTarget findTempTargetById(String _id) {
try {
QueryBuilder<TempTarget, Long> queryBuilder = getDaoTempTargets().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", _id);
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
List<TempTarget> list = getDaoTempTargets().query(preparedQuery);
if (list.size() == 1) {
return list.get(0);
} else {
return null;
}
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return null;
}
示例6: lookupEBooksForTag
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
private List<EBook> lookupEBooksForTag(Tag pTag) throws SQLException {
if (ebooksForTagQuery == null) {
// build our inner query for UserPost objects
QueryBuilder<EBookTags, Long> dbQryBld = dbHelper.getEBookTagsDao().queryBuilder();
// just select the post-id field
dbQryBld.selectColumns(EBookTags.COLUMN_NAME_BOOK_ID);
SelectArg userSelectArg = new SelectArg();
dbQryBld.where().eq(EBookTags.COLUMN_NAME_TAG_ID, userSelectArg);
// build our outer query for Post objects
QueryBuilder<EBook, Long> postQb = dbHelper.getEBookDao().queryBuilder()
.orderByRaw("book_title COLLATE NOCASE");
// where the id matches in the post-id from the inner query
postQb.where().in(EBook.COLUMN_NAME_ID, dbQryBld);
ebooksForTagQuery = postQb.prepare();
}
if (pTag != null) {
ebooksForTagQuery.setArgumentHolderValue(0, pTag);
return dbHelper.getEBookDao().query(ebooksForTagQuery);
}
return new ArrayList<>();
}
示例7: searchBooksMatching
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public List<EBook> searchBooksMatching(final String searchStr) {
List<EBook> result = new ArrayList<>();
try {
QueryBuilder<EBook, Long> queryBuilder = dbHelper.getEBookDao().queryBuilder();
Where<EBook, Long> where = queryBuilder.where();
SelectArg selectArg2 = new SelectArg();
selectArg2.setValue("%" + searchStr + "%");
SelectArg selectArg1 = new SelectArg();
selectArg1.setValue("%" + searchStr + "%");
// define our query as 'name = ?'
where.like(EBook.COLUMN_FULL_FILE_NAME, selectArg1).or()
.like(EBook.COLUMN_BOOK_TITLE, selectArg2);
// prepare it so it is ready for later query or iterator calls
PreparedQuery<EBook> preparedQuery = queryBuilder.prepare();
// later we can set the select argument and issue the query
result = dbHelper.getEBookDao().query(preparedQuery);
} catch (SQLException pE) {
pE.printStackTrace();
}
return result;
}
示例8: getTreatmentDataFromTime
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public List<Treatment> getTreatmentDataFromTime(long mills, boolean ascending) {
try {
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
List<Treatment> treatments;
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where();
where.ge("date", mills);
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
treatments = daoTreatments.query(preparedQuery);
return treatments;
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<Treatment>();
}
示例9: findExtendedBolusById
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public ExtendedBolus findExtendedBolusById(String _id) {
try {
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
queryBuilder = getDaoExtendedBolus().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", _id);
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
List<ExtendedBolus> list = getDaoExtendedBolus().query(preparedQuery);
if (list.size() == 1) {
return list.get(0);
} else {
return null;
}
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return null;
}
示例10: getCount
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
/**
* 获取满足指定条件的记录数
*
* @param map 查询条件键值组合
* @return
*/
public long getCount(Map<String, Object> map) {
long count = 0;
QueryBuilder queryBuilder = ormLiteDao.queryBuilder();
queryBuilder.setCountOf(true);
Where where = queryBuilder.where();
try {
where.isNotNull("id");
for (Map.Entry<String, Object> entry : map.entrySet()) {
where.and().eq(entry.getKey(), entry.getValue());
}
PreparedQuery<T> preparedQuery = queryBuilder.prepare();
count = ormLiteDao.countOf(preparedQuery);
} catch (SQLException e) {
LogUtils.e(e);
}
return count;
}
示例11: deleteCareportalEventById
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public void deleteCareportalEventById(String _id) {
try {
QueryBuilder<CareportalEvent, Long> queryBuilder = null;
queryBuilder = getDaoCareportalEvents().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", _id);
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
List<CareportalEvent> list = getDaoCareportalEvents().query(preparedQuery);
if (list.size() == 1) {
CareportalEvent record = list.get(0);
if (Config.logIncommingData)
log.debug("Removing CareportalEvent record from database: " + record.log());
delete(record);
} else {
if (Config.logIncommingData)
log.debug("CareportalEvent not found database: " + _id);
}
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
}
示例12: bucketOps
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public static void bucketOps(String path, Boolean bucket, Context mContext) {
final OrmHandler ormHandler = OpenHelperManager.getHelper(mContext, OrmHandler.class);
try {
Dao<Track, String> dbTrack = ormHandler.getDao(Track.class);
QueryBuilder<Track, String> queryBuilder = dbTrack.queryBuilder();
SelectArg selectArg = new SelectArg();
queryBuilder.where().eq("path", selectArg);
PreparedQuery<Track> preparedQuery = queryBuilder.prepare();
selectArg.setValue(path);
List<Track> lister = dbTrack.query(preparedQuery);
Track temp_track = lister.get(0);
temp_track.setBucket(bucket);
dbTrack.update(temp_track);
BUCKET_OPS = true;
} catch (SQLException | IndexOutOfBoundsException e) {
e.printStackTrace();
}
}
示例13: lastBg
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
@Nullable
public static BgReading lastBg() {
List<BgReading> bgList = null;
try {
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
queryBuilder.orderBy("date", false);
queryBuilder.limit(1L);
queryBuilder.where().gt("value", 38);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgList = daoBgReadings.query(preparedQuery);
} catch (SQLException e) {
log.debug(e.getMessage(), e);
}
if (bgList != null && bgList.size() > 0)
return bgList.get(0);
else
return null;
}
示例14: getLastCareportalEvent
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
@Nullable
public CareportalEvent getLastCareportalEvent(String event) {
try {
List<CareportalEvent> careportalEvents;
QueryBuilder<CareportalEvent, Long> queryBuilder = getDaoCareportalEvents().queryBuilder();
queryBuilder.orderBy("date", false);
Where where = queryBuilder.where();
where.eq("eventType", event);
queryBuilder.limit(1L);
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
if (careportalEvents.size() == 1)
return careportalEvents.get(0);
else
return null;
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return null;
}
示例15: deleteDbRequestbyMongoId
import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public int deleteDbRequestbyMongoId(String action, String id) {
try {
QueryBuilder<DbRequest, String> queryBuilder = getDaoDbRequest().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", id).and().eq("action", action);
queryBuilder.limit(10L);
PreparedQuery<DbRequest> preparedQuery = queryBuilder.prepare();
List<DbRequest> dbList = getDaoDbRequest().query(preparedQuery);
if (dbList.size() != 1) {
log.error("deleteDbRequestbyMongoId query size: " + dbList.size());
} else {
//log.debug("Treatment findTreatmentById found: " + trList.get(0).log());
return delete(dbList.get(0));
}
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return 0;
}