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