當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryBuilder.queryForFirst方法代碼示例

本文整理匯總了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;
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:22,代碼來源:GameRankingBiz.java

示例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;
}
 
開發者ID:lujianzhao,項目名稱:AndroidBase,代碼行數:22,代碼來源:OrmLiteDao.java

示例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;
}
 
開發者ID:lujianzhao,項目名稱:AndroidBase,代碼行數:25,代碼來源:OrmLiteDao.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:CityDao.java

示例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);
    }
}
 
開發者ID:remipassmoilesel,項目名稱:simple-hostel-management,代碼行數:21,代碼來源:UserService.java

示例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;
    }
}
 
開發者ID:willylatorre,項目名稱:restaurand,代碼行數:15,代碼來源:DatabaseHelper.java

示例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));
    }
}
 
開發者ID:zulip,項目名稱:zulip-android,代碼行數:31,代碼來源:MessageListFragment.java

示例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();
}
 
開發者ID:Microsoft,項目名稱:EmbeddedSocial-Android-SDK,代碼行數:6,代碼來源:ContentCache.java

示例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();
        }

    }



}
 
開發者ID:facetome,項目名稱:Interceptor,代碼行數:48,代碼來源:RegisterActivity.java


注:本文中的com.j256.ormlite.stmt.QueryBuilder.queryForFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。