本文整理匯總了Java中com.j256.ormlite.stmt.QueryBuilder.queryForFirst方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryBuilder.queryForFirst方法的具體用法?Java QueryBuilder.queryForFirst怎麽用?Java QueryBuilder.queryForFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.j256.ormlite.stmt.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.queryForFirst方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTopScore
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
/**
* 返回最高得分
*
* @return
*/
public GameRanking getTopScore()
{
QueryBuilder<GameRanking, ?> qb = getDao().queryBuilder();
try
{
// qb.where().eq("user_name", userName);
qb.orderBy("score", false);
return qb.queryForFirst();
}
catch (SQLException e)
{
e.printStackTrace();
}
return null;
}
示例2: queryForFirst
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
/**
* 通過表列名查詢第一條記錄
*
* @param map
* @return
*/
public T queryForFirst(Map<String, Object> map) {
T t = null;
QueryBuilder<T, Integer> queryBuilder = ormLiteDao.queryBuilder();
Where where = queryBuilder.where();
try {
where.isNotNull("id");
for (Map.Entry<String, Object> entry : map.entrySet()) {
where.and().eq(entry.getKey(), entry.getValue());
}
t = queryBuilder.queryForFirst();
} catch (SQLException e) {
LogUtils.e(e);
}
return t;
}
示例3: queryForFirstByOrder
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
/**
* 排序查詢
*
* @param map 查詢條件鍵值組合
* @param orderColumn 排序的列
* @param ascending 是否升序
* @return
*/
public T queryForFirstByOrder(Map<String, Object> map, String orderColumn, boolean ascending) {
T t = null;
QueryBuilder<T, Integer> queryBuilder = ormLiteDao.queryBuilder();
Where where = queryBuilder.where();
try {
queryBuilder.orderBy(orderColumn, ascending);
where.isNotNull("id");
for (Map.Entry<String, Object> entry : map.entrySet()) {
where.and().eq(entry.getKey(), entry.getValue());
}
t = queryBuilder.queryForFirst();
} catch (SQLException e) {
LogUtils.e(e);
}
return t;
}
示例4: queryCityById
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
/**
* 根據城市查詢城市信息
*
* @param cityId 城市ID
* @return city
* @throws SQLException
*/
public City queryCityById(String cityId) throws SQLException {
QueryBuilder<City, Integer> queryBuilder = cityDaoOperation.queryBuilder();
queryBuilder.where().eq(City.CITY_ID_FIELD_NAME, cityId);
return queryBuilder.queryForFirst();
}
示例5: getByUsername
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
/**
* Return a user with specified username or null if nothing is found
*
* @param username
* @return
* @throws IOException
*/
public User getByUsername(String username) throws IOException {
try {
username = username.trim().toLowerCase();
QueryBuilder builder = dao.queryBuilder();
builder.where().eq(User.USERNAME_FIELD_NAME, username);
return (User) builder.queryForFirst();
} catch (SQLException e) {
throw new IOException(e);
}
}
示例6: searchRestaurantById
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
@Override
public Restaurand searchRestaurantById(int id) {
final Restaurand rest;
QueryBuilder<Restaurand, Integer> qb = restauREDao.queryBuilder();
try {
qb.where().eq("id", id);
rest = qb.queryForFirst();
return rest;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
示例7: selectPointer
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
private void selectPointer() {
if (filter != null) {
Where<Message, Object> filteredWhere;
try {
filteredWhere = filter.modWhere(app.getDao(Message.class)
.queryBuilder().where());
filteredWhere.and().le(Message.ID_FIELD, app.getPointer());
QueryBuilder<Message, Object> closestQuery = app.getDao(
Message.class).queryBuilder();
closestQuery.orderBy(Message.TIMESTAMP_FIELD, false).setWhere(
filteredWhere);
Message closestMessage = closestQuery.queryForFirst();
// use anchor message id if message was narrowed
if (anchorId != -1) {
selectMessage(getMessageById(anchorId));
} else {
recyclerView.scrollToPosition(adapter.getItemIndex(closestMessage));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
} else {
int anc = app.getPointer();
selectMessage(getMessageById(anc));
}
}
示例8: findEditedTopicByHandle
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
private EditedTopic findEditedTopicByHandle(String topicHandle) throws SQLException {
QueryBuilder<EditedTopic, Integer> queryBuilder = editedTopicDao.queryBuilder();
queryBuilder.where().eq(DbSchemas.Topics.TOPIC_HANDLE, topicHandle);
return queryBuilder.queryForFirst();
}
示例9: register
import com.j256.ormlite.stmt.QueryBuilder; //導入方法依賴的package包/類
private void register(){
String username = mUsername.getEditableText().toString();
String password = mPassword.getEditableText().toString();
String confirmPassword = mConfirmPassword.getEditableText().toString();
boolean isReady = true;
if(TextUtils.isEmpty(username)){
Toast.makeText(this, getString(R.string.message_no_username), Toast.LENGTH_SHORT);
isReady = false;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this, getString(R.string.message_no_password), Toast.LENGTH_SHORT).show();
isReady = false;
}
if(TextUtils.isEmpty(confirmPassword)){
Toast.makeText(this, getString(R.string.message_password_no_confirm), Toast
.LENGTH_SHORT).show();
isReady = false;
}
if(isReady && password.equals(confirmPassword)){
//先查詢數據庫中是否已經有了這樣的一個賬號.
RuntimeExceptionDao<User, Integer> userDao = getDBHelper().getUserDao();
QueryBuilder<User, Integer> builder = userDao.queryBuilder();
Where where =builder.where();
try {
where.eq(User.KEY_USERNAME, username);
User exsitUser = builder.queryForFirst();
if(exsitUser == null){
User user = new User();
user.setTimeStamp(System.currentTimeMillis());
user.setPassword(password);
user.setUserName(username);
getDBHelper().getUserDao().create(user);
finish();
} else {
Toast.makeText(this, getString(R.string.message_account_exsit), Toast
.LENGTH_SHORT).show();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}