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

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

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

Dao.getEmptyForeignCollection介绍

[英]Like #assignEmptyForeignCollection(Object,String) but it returns the empty collection that you assign to the appropriate field.

NOTE: May be deprecated in the future.
[中]类似于#assignEmptyForeignCollection(对象,字符串),但它返回分配给相应字段的空集合。
注意:将来可能会被弃用。

代码示例

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

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

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

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

代码示例来源:origin: com.octo.android.robospice/robospice-ormlite

  1. public <T, FT> ForeignCollection<FT> getNewEmptyForeignCollection(String foreignKeyColumnName, Class<T> modelObjectClass, Class<FT> foreignObjectClass) throws SQLException {
  2. Dao<T, ?> dao = getDao(modelObjectClass);
  3. return dao.getEmptyForeignCollection(foreignKeyColumnName);
  4. }

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

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

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

  1. @Test(expected = IllegalArgumentException.class)
  2. public void testUnknownEmptyCollection() throws Exception {
  3. Dao<Account, Object> dao = createDao(Account.class, true);
  4. dao.getEmptyForeignCollection("unknown field name");
  5. }

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

  1. @Test
  2. public void testEmptyCollection() throws Exception {
  3. Dao<Account, Object> accountDao = createDao(Account.class, true);
  4. createTable(Order.class, true);
  5. Account account = new Account();
  6. String name = "another name";
  7. account.name = name;
  8. account.orders = accountDao.getEmptyForeignCollection(Account.ORDERS_FIELD_NAME);
  9. assertEquals(1, accountDao.create(account));
  10. Order order = new Order();
  11. int val3 = 17097;
  12. order.val = val3;
  13. order.account = account;
  14. account.orders.add(order);
  15. assertEquals(1, account.orders.size());
  16. Account accountResult = accountDao.queryForId(account.id);
  17. assertNotNull(accountResult.orders);
  18. assertEquals(1, accountResult.orders.size());
  19. CloseableIterator<Order> iterator = accountResult.orders.closeableIterator();
  20. assertTrue(iterator.hasNext());
  21. Order orderResult = iterator.next();
  22. assertNotNull(orderResult);
  23. assertEquals(order.id, orderResult.id);
  24. assertFalse(iterator.hasNext());
  25. iterator.close();
  26. }

相关文章