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

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

本文整理了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

/**
 * @see Dao#getEmptyForeignCollection(String)
 */
@Override
public <FT> ForeignCollection<FT> getEmptyForeignCollection(String fieldName) {
  try {
    return dao.getEmptyForeignCollection(fieldName);
  } catch (SQLException e) {
    logMessage(e, "getEmptyForeignCollection threw exception on " + fieldName);
    throw new RuntimeException(e);
  }
}

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

/**
 * @see Dao#getEmptyForeignCollection(String)
 */
@Override
public <FT> ForeignCollection<FT> getEmptyForeignCollection(String fieldName) {
  try {
    return dao.getEmptyForeignCollection(fieldName);
  } catch (SQLException e) {
    logMessage(e, "getEmptyForeignCollection threw exception on " + fieldName);
    throw new RuntimeException(e);
  }
}

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

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

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

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

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

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

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

@Test
public void testEmptyCollection() throws Exception {
  Dao<Account, Object> accountDao = createDao(Account.class, true);
  createTable(Order.class, true);
  Account account = new Account();
  String name = "another name";
  account.name = name;
  account.orders = accountDao.getEmptyForeignCollection(Account.ORDERS_FIELD_NAME);
  assertEquals(1, accountDao.create(account));
  Order order = new Order();
  int val3 = 17097;
  order.val = val3;
  order.account = account;
  account.orders.add(order);
  assertEquals(1, account.orders.size());
  Account accountResult = accountDao.queryForId(account.id);
  assertNotNull(accountResult.orders);
  assertEquals(1, accountResult.orders.size());
  CloseableIterator<Order> iterator = accountResult.orders.closeableIterator();
  assertTrue(iterator.hasNext());
  Order orderResult = iterator.next();
  assertNotNull(orderResult);
  assertEquals(order.id, orderResult.id);
  assertFalse(iterator.hasNext());
  iterator.close();
}

相关文章