当前位置: 首页>>代码示例>>Java>>正文


Java QueryBuilder.setCountOf方法代码示例

本文整理汇总了Java中com.j256.ormlite.stmt.QueryBuilder.setCountOf方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder.setCountOf方法的具体用法?Java QueryBuilder.setCountOf怎么用?Java QueryBuilder.setCountOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.j256.ormlite.stmt.QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder.setCountOf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:lujianzhao,项目名称:AndroidBase,代码行数:24,代码来源:OrmLiteDao.java

示例2: addNew

import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
public static void addNew(Manager manager,
    AlertPredicate alertType, DBProcessedAudit audit, DBIdentity userToAlert, long minTimestampMs) throws SQLException {
  // These must be unique on (secretId, userId, alertType)  
  // e.g. If I share, then unshare, then re-share something 
  // with a user, only one of these events should ever be added.
  
  QueryBuilder<DBFutureAlert,Integer> builder = manager.futureAlertDao.queryBuilder();
  builder.where().eq(INACTIVE, false)
      .and().eq(ALERT_TYPE, new SelectArg(alertType))
      .and().eq(USER_ID_TO_ALERT, userToAlert.getId());
  
  builder.setCountOf(true);
  if (manager.futureAlertDao.countOf(builder.prepare()) > 0) {
    logger.info("Trying to add new alert for {}, {}. Existing alert already exists. Ignoring",
        alertType, userToAlert.getId());
  } else {
    logger.info("Inserting future alert for {}, {}.",
        alertType, userToAlert.getId());
    DBFutureAlert a = new DBFutureAlert();
    a.userIdToAlert = userToAlert.getId();
    a.transactionId = audit.getTransactionId();
    a.enqueueTimestampMs = minTimestampMs;
    a.alertType = alertType;
    manager.futureAlertDao.create(a);
  }
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:27,代码来源:DBFutureAlert.java

示例3: internalProcess

import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
@Override
protected boolean internalProcess(AlerterContext context) throws SQLException {
  // get all actions that user did after joining.
  if (System.currentTimeMillis() < TIME_TO_WAIT_MS + context.dbAlertObject.enqueueTimestampMs) {
    context.dbAlertObject.nextCheckTimestampMs = context.dbAlertObject.enqueueTimestampMs + TIME_TO_WAIT_MS;
    return false;
  }
  QueryBuilder<DBProcessedAudit,Integer> builder = getBuilder(context, CANCEL_ALERT_ACTIONS, AlertUserType.ACTOR);

  // for some reason limit(int) is deprecated, WTF.
  builder.limit(1L);
  builder.setCountOf(true);
  
  if (context.manager.processedAuditDao.countOf(builder.prepare()) == 0) {
    // no such actions have happened. we should trigger the alert.
    logger.warn("should send unimplemented email for idle user");
    // TODO: send idle user email
  }
  return true;
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:21,代码来源:NewInactiveUserEmailer.java

示例4: enforceHistorySizeLimit

import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
private void enforceHistorySizeLimit() throws SQLException {
	for (SearchType searchType : SearchType.values()) {
		QueryBuilder<HistoryEntry, Integer> query = historyDao.queryBuilder();
		query.where().eq(DbSchemas.SearchHistory.SEARCH_TYPE, searchType);
		query.setCountOf(true);
		DbTransaction.performTransaction(historyDao, () -> {
			if (historyDao.countOf(query.prepare()) > HISTORY_SIZE) {
				historyDao.executeRaw(DELETE_OLDEST_ENTRY_STATEMENT, searchType.name());
			}
		});
	}
}
 
开发者ID:Microsoft,项目名称:EmbeddedSocial-Android-SDK,代码行数:13,代码来源:SearchHistory.java

示例5: internalProcess

import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
@Override
protected boolean internalProcess(AlerterContext context) throws SQLException {
  QueryBuilder<DBProcessedAudit,Integer> builder = getBuilder(context,
      ImmutableList.of(ActionType.CREATE_SECRET),
      AlertUserType.ACTOR);
  builder.setCountOf(true);
  if (context.manager.processedAuditDao.countOf(builder.prepare()) > 0) {
    enqueueEmail(context, Collections.<String,String>emptyMap(), DBEmailQueue.Type.MANDRILL_SAVE_FIRST_SECRET);
    return true;
  }
  return false;
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:13,代码来源:FirstSecretEmailer.java

示例6: exists

import com.j256.ormlite.stmt.QueryBuilder; //导入方法依赖的package包/类
/**
 * 判断是否存在
 * 
 * @return
 */
public boolean exists(Map<String, Object> map)
{
	if (map == null || map.isEmpty())
	{
		throw new NullPointerException("Map can not be null or empty!!!");
	}

	try
	{
		QueryBuilder<Model, ?> queryBuilder = mRuntimeDao.queryBuilder();
		queryBuilder.setCountOf(true);
		Where<Model, ?> where = null;

		Iterator<Entry<String, Object>> iterator = map.entrySet().iterator();
		Entry<String, Object> entry = null;
		boolean isFirst = true;
		while (iterator.hasNext())
		{
			entry = iterator.next();

			if (isFirst)
			{
				where = queryBuilder.where().eq(entry.getKey(), entry.getValue());
				isFirst = false;
			}
			else
			{
				where.and().eq(entry.getKey(), entry.getValue());
			}

			// 此法仅能保证一个
			// queryBuilder.where().eq(entry.getKey(), entry.getValue());
		}

		PreparedQuery<Model> preparedQuery = queryBuilder.prepare();
		long count = mRuntimeDao.countOf(preparedQuery);

		return count > 0 ? true : false;
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}

	return false;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:52,代码来源:CDKDao.java


注:本文中的com.j256.ormlite.stmt.QueryBuilder.setCountOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。