com.j256.ormlite.dao.Dao.countOf()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(260)

本文整理了Java中com.j256.ormlite.dao.Dao.countOf()方法的一些代码示例,展示了Dao.countOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.countOf()方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:countOf

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

  1. /**
  2. * @see Dao#countOf()
  3. */
  4. @Override
  5. public long countOf() {
  6. try {
  7. return dao.countOf();
  8. } catch (SQLException e) {
  9. logMessage(e, "countOf threw exception");
  10. throw new RuntimeException(e);
  11. }
  12. }

代码示例来源:origin: j256/ormlite-core

  1. /**
  2. * @see Dao#countOf(PreparedQuery)
  3. */
  4. @Override
  5. public long countOf(PreparedQuery<T> preparedQuery) {
  6. try {
  7. return dao.countOf(preparedQuery);
  8. } catch (SQLException e) {
  9. logMessage(e, "countOf threw exception on " + preparedQuery);
  10. throw new RuntimeException(e);
  11. }
  12. }

代码示例来源:origin: com.j256.ormlite/ormlite-core

  1. /**
  2. * @see Dao#countOf()
  3. */
  4. @Override
  5. public long countOf() {
  6. try {
  7. return dao.countOf();
  8. } catch (SQLException e) {
  9. logMessage(e, "countOf threw exception");
  10. throw new RuntimeException(e);
  11. }
  12. }

代码示例来源:origin: com.j256.ormlite/ormlite-core

  1. /**
  2. * @see Dao#countOf(PreparedQuery)
  3. */
  4. @Override
  5. public long countOf(PreparedQuery<T> preparedQuery) {
  6. try {
  7. return dao.countOf(preparedQuery);
  8. } catch (SQLException e) {
  9. logMessage(e, "countOf threw exception on " + preparedQuery);
  10. throw new RuntimeException(e);
  11. }
  12. }

代码示例来源:origin: QuickBlox/q-municate-android

  1. public long getAllCount() {
  2. long numRows = 0;
  3. try {
  4. numRows = dao.countOf();
  5. } catch (SQLException e) {
  6. ErrorUtils.logError(e);
  7. }
  8. return numRows;
  9. }

代码示例来源:origin: org.mycontroller.standalone/mycontroller-core

  1. public Long countOf() {
  2. try {
  3. return this.getDao().countOf();
  4. } catch (SQLException ex) {
  5. _logger.error("unable to get count,", ex);
  6. }
  7. return null;
  8. }

代码示例来源:origin: mycontroller-org/mycontroller

  1. public Long countOf() {
  2. try {
  3. return this.getDao().countOf();
  4. } catch (SQLException ex) {
  5. _logger.error("unable to get count,", ex);
  6. throw new McDatabaseException(ex);
  7. }
  8. }

代码示例来源:origin: j256/ormlite-core

  1. /**
  2. * Returns the count of the number of rows in the table. This uses {@link #setCountOf(boolean)} to true and then
  3. * calls {@link Dao#countOf(PreparedQuery)}. It restores the previous count-of value before returning.
  4. */
  5. public long countOf() throws SQLException {
  6. String countOfQuerySave = this.countOfQuery;
  7. try {
  8. setCountOf(true);
  9. return dao.countOf(prepare());
  10. } finally {
  11. setCountOf(countOfQuerySave);
  12. }
  13. }

代码示例来源:origin: j256/ormlite-core

  1. @Test(expected = RuntimeException.class)
  2. public void testCountOfPreparedThrow() throws Exception {
  3. @SuppressWarnings("unchecked")
  4. Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  5. RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  6. @SuppressWarnings("unchecked")
  7. PreparedQuery<Foo> prepared = (PreparedQuery<Foo>) createMock(PreparedQuery.class);
  8. expect(dao.countOf(prepared)).andThrow(new SQLException("Testing catch"));
  9. replay(dao);
  10. rtDao.countOf(prepared);
  11. verify(dao);
  12. }

代码示例来源:origin: j256/ormlite-core

  1. @Test(expected = RuntimeException.class)
  2. public void testCountOfThrow() throws Exception {
  3. @SuppressWarnings("unchecked")
  4. Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  5. RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  6. expect(dao.countOf()).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.countOf();
  9. verify(dao);
  10. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testClearTable() throws Exception {
  3. Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, true);
  4. assertEquals(0, fooDao.countOf());
  5. LocalFoo foo = new LocalFoo();
  6. assertEquals(1, fooDao.create(foo));
  7. assertEquals(1, fooDao.countOf());
  8. TableUtils.clearTable(connectionSource, LocalFoo.class);
  9. assertEquals(0, fooDao.countOf());
  10. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testCountOf() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo = new Foo();
  6. assertEquals(1, dao.create(foo));
  7. assertEquals(1, dao.countOf());
  8. assertEquals(1, dao.create(foo));
  9. assertEquals(2, dao.countOf());
  10. }

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

  1. @Test
  2. public void testCountOf() throws Exception {
  3. Dao<Foo, String> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo = new Foo();
  6. foo.id = 1;
  7. assertEquals(1, dao.create(foo));
  8. assertEquals(1, dao.countOf());
  9. foo.id = 2;
  10. assertEquals(1, dao.create(foo));
  11. assertEquals(2, dao.countOf());
  12. }

代码示例来源:origin: j256/ormlite-core

  1. @Test(expected = IllegalArgumentException.class)
  2. public void testCountOfPreparedNoCountOf() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
  5. dao.countOf(qb.prepare());
  6. }

代码示例来源:origin: j256/ormlite-core

  1. @Test(expected = SQLException.class)
  2. public void testQueryForFieldValuesQuotes() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo1 = new Foo();
  6. foo1.val = 1231231;
  7. assertEquals(1, dao.create(foo1));
  8. Map<String, Object> fieldValues = new HashMap<String, Object>();
  9. fieldValues.put(Foo.ID_COLUMN_NAME, "this id has a quote '");
  10. dao.queryForFieldValues(fieldValues);
  11. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testQueryForFieldValuesEmpty() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo = new Foo();
  6. foo.val = 1231231;
  7. assertEquals(1, dao.create(foo));
  8. Map<String, Object> fieldValues = new HashMap<String, Object>();
  9. List<Foo> results = dao.queryForFieldValues(fieldValues);
  10. assertEquals(0, results.size());
  11. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testCountOfPrepared() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo = new Foo();
  6. assertEquals(1, dao.create(foo));
  7. assertEquals(1, dao.create(foo));
  8. assertEquals(2, dao.countOf());
  9. QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
  10. qb.setCountOf(true).where().eq(Foo.ID_COLUMN_NAME, foo.id);
  11. assertEquals(1, dao.countOf(qb.prepare()));
  12. }

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

  1. @Test
  2. public void testCountOfPreparedNoCountOf() throws Exception {
  3. Dao<Foo, String> dao = createDao(Foo.class, true);
  4. QueryBuilder<Foo, String> qb = dao.queryBuilder();
  5. try {
  6. dao.countOf(qb.prepare());
  7. fail("Should have thrown");
  8. } catch (IllegalArgumentException e) {
  9. // expected
  10. }
  11. }

代码示例来源:origin: j256/ormlite-core

  1. @Test
  2. public void testQueryForMatchingNoFields() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo = new Foo();
  6. foo.val = 1231231;
  7. assertEquals(1, dao.create(foo));
  8. Foo match = new Foo();
  9. List<Foo> results = dao.queryForMatching(match);
  10. assertEquals(0, results.size());
  11. }

代码示例来源:origin: j256/ormlite-core

  1. @Test(expected = SQLException.class)
  2. public void testQueryForMatchingQuotes() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo = new Foo();
  6. foo.val = 1231231;
  7. assertEquals(1, dao.create(foo));
  8. Foo match = new Foo();
  9. match.stringField = "this id has a quote '";
  10. dao.queryForMatching(match);
  11. }

相关文章