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

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

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

Dao.extractId介绍

[英]Returns the ID from the data parameter passed in. This is used by some of the internal queries to be able to search by id.
[中]从传入的数据参数返回ID。这被一些内部查询用来按id进行搜索。

代码示例

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

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

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

  1. /**
  2. * A call through to the {@link Dao#extractId(Object)}.
  3. */
  4. public ID extractId() throws SQLException {
  5. checkForDao();
  6. @SuppressWarnings("unchecked")
  7. T t = (T) this;
  8. return dao.extractId(t);
  9. }

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

  1. /**
  2. * A call through to the {@link Dao#extractId(Object)}.
  3. */
  4. public ID extractId() throws SQLException {
  5. checkForDao();
  6. @SuppressWarnings("unchecked")
  7. T t = (T) this;
  8. return dao.extractId(t);
  9. }

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

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

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

  1. /**
  2. * Add a clause where the ID is from an existing object.
  3. */
  4. public <OD> Where<T, ID> idEq(Dao<OD, ?> dataDao, OD data) throws SQLException {
  5. if (idColumnName == null) {
  6. throw new SQLException("Object has no id column specified");
  7. }
  8. addClause(new SimpleComparison(idColumnName, idFieldType, dataDao.extractId(data),
  9. SimpleComparison.EQUAL_TO_OPERATION));
  10. return this;
  11. }

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

  1. /**
  2. * Add a clause where the ID is from an existing object.
  3. */
  4. public <OD> Where<T, ID> idEq(Dao<OD, ?> dataDao, OD data) throws SQLException {
  5. if (idColumnName == null) {
  6. throw new SQLException("Object has no id column specified");
  7. }
  8. addClause(new SimpleComparison(idColumnName, idFieldType, dataDao.extractId(data),
  9. SimpleComparison.EQUAL_TO_OPERATION));
  10. return this;
  11. }

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

  1. @Test(expected = RuntimeException.class)
  2. public void testExtractIdThrow() 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.extractId(null)).andThrow(new SQLException("Testing catch"));
  7. replay(dao);
  8. rtDao.extractId(null);
  9. verify(dao);
  10. }

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

  1. @Test(expected = SQLException.class)
  2. public void testExtractIdBadClass() throws Exception {
  3. Dao<NoId, Void> dao = createDao(NoId.class, true);
  4. NoId foo = new NoId();
  5. String stuff = "stuff1";
  6. foo.stuff = stuff;
  7. dao.extractId(foo);
  8. }

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

  1. @Test
  2. public void testExtractId() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. Foo foo = new Foo();
  5. assertEquals((Integer) foo.id, dao.extractId(foo));
  6. }

相关文章