本文整理了Java中com.j256.ormlite.dao.Dao.countOf()
方法的一些代码示例,展示了Dao.countOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.countOf()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:countOf
[英]Returns the number of rows in the table associated with the data class. Depending on the size of the table and the database type, this may be expensive and take a while.
[中]返回表中与数据类关联的行数。根据表的大小和数据库类型,这可能会很昂贵,并且需要一段时间。
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#countOf()
*/
@Override
public long countOf() {
try {
return dao.countOf();
} catch (SQLException e) {
logMessage(e, "countOf threw exception");
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#countOf(PreparedQuery)
*/
@Override
public long countOf(PreparedQuery<T> preparedQuery) {
try {
return dao.countOf(preparedQuery);
} catch (SQLException e) {
logMessage(e, "countOf threw exception on " + preparedQuery);
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#countOf()
*/
@Override
public long countOf() {
try {
return dao.countOf();
} catch (SQLException e) {
logMessage(e, "countOf threw exception");
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#countOf(PreparedQuery)
*/
@Override
public long countOf(PreparedQuery<T> preparedQuery) {
try {
return dao.countOf(preparedQuery);
} catch (SQLException e) {
logMessage(e, "countOf threw exception on " + preparedQuery);
throw new RuntimeException(e);
}
}
代码示例来源:origin: QuickBlox/q-municate-android
public long getAllCount() {
long numRows = 0;
try {
numRows = dao.countOf();
} catch (SQLException e) {
ErrorUtils.logError(e);
}
return numRows;
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public Long countOf() {
try {
return this.getDao().countOf();
} catch (SQLException ex) {
_logger.error("unable to get count,", ex);
}
return null;
}
代码示例来源:origin: mycontroller-org/mycontroller
public Long countOf() {
try {
return this.getDao().countOf();
} catch (SQLException ex) {
_logger.error("unable to get count,", ex);
throw new McDatabaseException(ex);
}
}
代码示例来源: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
@Test(expected = RuntimeException.class)
public void testCountOfPreparedThrow() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
@SuppressWarnings("unchecked")
PreparedQuery<Foo> prepared = (PreparedQuery<Foo>) createMock(PreparedQuery.class);
expect(dao.countOf(prepared)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.countOf(prepared);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testCountOfThrow() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
expect(dao.countOf()).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.countOf();
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testClearTable() throws Exception {
Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, true);
assertEquals(0, fooDao.countOf());
LocalFoo foo = new LocalFoo();
assertEquals(1, fooDao.create(foo));
assertEquals(1, fooDao.countOf());
TableUtils.clearTable(connectionSource, LocalFoo.class);
assertEquals(0, fooDao.countOf());
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testCountOf() 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.countOf());
assertEquals(1, dao.create(foo));
assertEquals(2, dao.countOf());
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testCountOf() throws Exception {
Dao<Foo, String> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
foo.id = 1;
assertEquals(1, dao.create(foo));
assertEquals(1, dao.countOf());
foo.id = 2;
assertEquals(1, dao.create(foo));
assertEquals(2, dao.countOf());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = IllegalArgumentException.class)
public void testCountOfPreparedNoCountOf() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
dao.countOf(qb.prepare());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testQueryForFieldValuesQuotes() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo1 = new Foo();
foo1.val = 1231231;
assertEquals(1, dao.create(foo1));
Map<String, Object> fieldValues = new HashMap<String, Object>();
fieldValues.put(Foo.ID_COLUMN_NAME, "this id has a quote '");
dao.queryForFieldValues(fieldValues);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testQueryForFieldValuesEmpty() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
foo.val = 1231231;
assertEquals(1, dao.create(foo));
Map<String, Object> fieldValues = new HashMap<String, Object>();
List<Foo> results = dao.queryForFieldValues(fieldValues);
assertEquals(0, results.size());
}
代码示例来源: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 testCountOfPreparedNoCountOf() throws Exception {
Dao<Foo, String> dao = createDao(Foo.class, true);
QueryBuilder<Foo, String> qb = dao.queryBuilder();
try {
dao.countOf(qb.prepare());
fail("Should have thrown");
} catch (IllegalArgumentException e) {
// expected
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testQueryForMatchingNoFields() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
foo.val = 1231231;
assertEquals(1, dao.create(foo));
Foo match = new Foo();
List<Foo> results = dao.queryForMatching(match);
assertEquals(0, results.size());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testQueryForMatchingQuotes() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo = new Foo();
foo.val = 1231231;
assertEquals(1, dao.create(foo));
Foo match = new Foo();
match.stringField = "this id has a quote '";
dao.queryForMatching(match);
}
内容来源于网络,如有侵权,请联系作者删除!