本文整理汇总了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();
}
}
}