当前位置: 首页>>代码示例>>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;未经允许,请勿转载。