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

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

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

Dao.queryRawValue介绍

[英]Perform a raw query that returns a single value (usually an aggregate function like MAX or COUNT). If the query does not return a single long value then it will throw a SQLException.
[中]执行返回单个值的原始查询(通常是一个聚合函数,如MAX或COUNT)。如果查询没有返回单个长值,那么它将抛出SQLException。

代码示例

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

/**
 * @see Dao#queryRawValue(String, String...)
 */
@Override
public long queryRawValue(String query, String... arguments) {
  try {
    return dao.queryRawValue(query, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRawValue threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

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

/**
 * @see Dao#queryRawValue(String, String...)
 */
@Override
public long queryRawValue(String query, String... arguments) {
  try {
    return dao.queryRawValue(query, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRawValue threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

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

@Test
public void testQueryRawValue() throws Exception {
  @SuppressWarnings("unchecked")
  Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  String query = "fkeowjfkewfewf";
  expect(dao.queryRawValue(query, new String[0])).andReturn(0L);
  replay(dao);
  rtDao.queryRawValue(query);
  verify(dao);
}

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

@Test(expected = RuntimeException.class)
public void testQueryRawValueThrow() 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.queryRawValue(null)).andThrow(new SQLException("Testing catch"));
  replay(dao);
  rtDao.queryRawValue(null);
  verify(dao);
}

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

@Test
public void testQueryRawValue() throws Exception {
  Dao<Foo, Object> dao = createDao(Foo.class, true);
  assertEquals(1, dao.create(new Foo()));
  assertEquals(1, dao.queryRawValue("select max(" + Foo.ID_COLUMN_NAME + ") from foo"));
  assertEquals(1, dao.create(new Foo()));
  assertEquals(2, dao.queryRawValue("select max(" + Foo.ID_COLUMN_NAME + ") from foo"));
  assertEquals(1, dao.create(new Foo()));
  assertEquals(3, dao.queryRawValue("select max(" + Foo.ID_COLUMN_NAME + ") from foo"));
}

相关文章