本文整理了Java中com.j256.ormlite.stmt.QueryBuilder.setCountOf
方法的一些代码示例,展示了QueryBuilder.setCountOf
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryBuilder.setCountOf
方法的具体详情如下:
包路径:com.j256.ormlite.stmt.QueryBuilder
类名称:QueryBuilder
方法名:setCountOf
[英]Set the field that we are counting from the database. For example, you can qb.setCountOf("DISTINCT(fieldname)"). This query can then be used by Dao#countOf(PreparedQuery). To get the count-of directly, use #countOf(String).
[中]设置我们从数据库中计数的字段。例如,你可以使用qb。setCountOf(“不同的(字段名)”。然后,Dao#countOf(PreparedQuery)可以使用这个查询。要直接获取的计数,请使用#countOf(String)。
代码示例来源:origin: j256/ormlite-core
/**
* Set whether or not we should only return the count of the results. This query can then be used by
* {@link Dao#countOf(PreparedQuery)}.
*
* To get the count-of directly, use {@link #countOf()}.
*/
public QueryBuilder<T, ID> setCountOf(boolean countOf) {
return setCountOf("*");
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* Set whether or not we should only return the count of the results. This query can then be used by
* {@link Dao#countOf(PreparedQuery)}.
*
* To get the count-of directly, use {@link #countOf()}.
*/
public QueryBuilder<T, ID> setCountOf(boolean countOf) {
return setCountOf("*");
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* Returns the count of the number of rows in the table. This uses {@link #setCountOf(boolean)} to true and then
* calls {@link Dao#countOf(PreparedQuery)}. It restores the previous count-of value before returning.
*/
public long countOf() throws SQLException {
String countOfQuerySave = this.countOfQuery;
try {
setCountOf(true);
return dao.countOf(prepare());
} finally {
setCountOf(countOfQuerySave);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* Returns the count of the number of rows in the table. This uses {@link #setCountOf(boolean)} to true and then
* calls {@link Dao#countOf(PreparedQuery)}. It restores the previous count-of value before returning.
*/
public long countOf() throws SQLException {
String countOfQuerySave = this.countOfQuery;
try {
setCountOf(true);
return dao.countOf(prepare());
} finally {
setCountOf(countOfQuerySave);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* Returns the count of the number of rows that match a field so you can do
* {@code qb.countOf("DISTINCT(fieldname)")}. This uses {@link #setCountOf(String)} and then calls
* {@link Dao#countOf(PreparedQuery)}. It restores the previous count-of value before returning.
*/
public long countOf(String countOfQuery) throws SQLException {
String countOfQuerySave = this.countOfQuery;
try {
setCountOf(countOfQuery);
return dao.countOf(prepare());
} finally {
setCountOf(countOfQuerySave);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* Returns the count of the number of rows that match a field so you can do
* {@code qb.countOf("DISTINCT(fieldname)")}. This uses {@link #setCountOf(String)} and then calls
* {@link Dao#countOf(PreparedQuery)}. It restores the previous count-of value before returning.
*/
public long countOf(String countOfQuery) throws SQLException {
String countOfQuerySave = this.countOfQuery;
try {
setCountOf(countOfQuery);
return dao.countOf(prepare());
} finally {
setCountOf(countOfQuerySave);
}
}
代码示例来源:origin: stackoverflow.com
dao = getHelper().getUsuarioDao();
QueryBuilder queryBuilder = dao.queryBuilder();
queryBuilder.setCountOf(true);
queryBuilder.setWhere(queryBuilder.where().eq("name", "Joe Smith" ));
Long usuarios = dao.countOf(queryBuilder.prepare());
Log.d(TAG, "How much name by "Joe Smith" are:" + usuarios);
代码示例来源:origin: QuickBlox/q-municate-android
public long getCountUnreadDialogNotifications(List<Long> dialogOccupantsIdsList, int currentUserId) {
long count = 0;
try {
QueryBuilder<DialogNotification, Long> queryBuilder = dao.queryBuilder();
queryBuilder.setCountOf(true);
QueryBuilder<DialogOccupant, Long> dialogOccupantQueryBuilder = dialogOccupantDao.queryBuilder();
dialogOccupantQueryBuilder.where().ne(QMUserColumns.ID, currentUserId);
queryBuilder.join(dialogOccupantQueryBuilder);
Where<DialogNotification, Long> where = queryBuilder.where();
where.and(
where.in(DialogOccupant.Column.ID, dialogOccupantsIdsList),
where.or(
where.eq(DialogNotification.Column.STATE, State.DELIVERED),
where.eq(DialogNotification.Column.STATE, State.TEMP_LOCAL_UNREAD)
)
);
PreparedQuery<DialogNotification> preparedQuery = queryBuilder.prepare();
count = dao.countOf(preparedQuery);
} catch (SQLException e) {
ErrorUtils.logError(e);
}
return count;
}
代码示例来源:origin: QuickBlox/q-municate-android
public long getCountUnreadMessages(List<Long> dialogOccupantsIdsList, int currentUserId) {
long count = 0;
try {
QueryBuilder<Message, Long> queryBuilder = dao.queryBuilder();
queryBuilder.setCountOf(true);
QueryBuilder<DialogOccupant, Long> dialogOccupantQueryBuilder = dialogOccupantDao.queryBuilder();
dialogOccupantQueryBuilder.where().ne(QMUserColumns.ID, currentUserId);
queryBuilder.join(dialogOccupantQueryBuilder);
Where<Message, Long> where = queryBuilder.where();
where.and(
where.in(DialogOccupant.Column.ID, dialogOccupantsIdsList),
where.or(
where.eq(Message.Column.STATE, State.DELIVERED),
where.eq(Message.Column.STATE, State.TEMP_LOCAL_UNREAD)
)
);
PreparedQuery<Message> preparedQuery = queryBuilder.prepare();
count = dao.countOf(preparedQuery);
} catch (SQLException e) {
ErrorUtils.logError(e);
}
return count;
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testCountOf() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
assertEquals(0, qb.countOf());
Foo foo1 = new Foo();
int val = 123213;
foo1.val = val;
assertEquals(1, dao.create(foo1));
assertEquals(1, qb.countOf());
Foo foo2 = new Foo();
foo2.val = val;
assertEquals(1, dao.create(foo2));
assertEquals(2, qb.countOf());
String distinct = "DISTINCT(" + Foo.VAL_COLUMN_NAME + ")";
assertEquals(1, qb.countOf(distinct));
qb.setCountOf(distinct);
assertEquals(1, dao.countOf(qb.prepare()));
distinct = "DISTINCT(" + Foo.ID_COLUMN_NAME + ")";
assertEquals(2, qb.countOf(distinct));
qb.setCountOf(distinct);
assertEquals(2, dao.countOf(qb.prepare()));
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testCountOfPrepared() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
assertEquals(1, dao.create(foo));
assertEquals(2, dao.countOf());
QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
qb.setCountOf(true).where().eq(Foo.ID_COLUMN_NAME, foo.id);
assertEquals(1, dao.countOf(qb.prepare()));
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testCountOfPrepared() throws Exception {
Dao<Foo, String> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
int id1 = 1;
foo.id = id1;
assertEquals(1, dao.create(foo));
foo.id = 2;
assertEquals(1, dao.create(foo));
assertEquals(2, dao.countOf());
QueryBuilder<Foo, String> qb = dao.queryBuilder();
qb.setCountOf(true).where().eq(Foo.ID_FIELD_NAME, id1);
assertEquals(1, dao.countOf(qb.prepare()));
}
代码示例来源:origin: j256/ormlite-core
fooQb.where().in(Foo.ID_COLUMN_NAME, idList).and().in(Foo.VAL_COLUMN_NAME, barQb);
fooQb.setCountOf(true);
assertEquals(1, fooQb.getSelectColumnCount());
assertEquals("COUNT(*)", fooQb.getSelectColumnsAsString());
代码示例来源:origin: j256/ormlite-core
assertNull(dao.findForeignFieldType(Void.class));
assertEquals(1, dao.countOf());
assertEquals(1, dao.countOf(dao.queryBuilder().setCountOf(true).prepare()));
PreparedQuery<Foo> prepared = dao.queryBuilder().prepare();
DatabaseConnection conn = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
内容来源于网络,如有侵权,请联系作者删除!