當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。