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

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

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

Dao.queryForFieldValues介绍

[英]Query for the rows in the database that matches all of the field to value entries from the map passed in. If you are worried about SQL quote escaping, you should use #queryForFieldValuesArgs(Map).
[中]查询数据库中与传入映射中的所有字段值项相匹配的行。如果您担心SQL引号转义,那么应该使用#queryForFieldValuesArgs(Map)。

代码示例

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

/**
 * @see Dao#queryForFieldValues(Map)
 */
@Override
public List<T> queryForFieldValues(Map<String, Object> fieldValues) {
  try {
    return dao.queryForFieldValues(fieldValues);
  } catch (SQLException e) {
    logMessage(e, "queryForFieldValues threw exception");
    throw new RuntimeException(e);
  }
}

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

/**
 * @see Dao#queryForFieldValues(Map)
 */
@Override
public List<T> queryForFieldValues(Map<String, Object> fieldValues) {
  try {
    return dao.queryForFieldValues(fieldValues);
  } catch (SQLException e) {
    logMessage(e, "queryForFieldValues threw exception");
    throw new RuntimeException(e);
  }
}

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

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

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

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

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

@Test
public void testQueryForFieldValues() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  assertEquals(0, dao.countOf());
  Foo foo1 = new Foo();
  foo1.val = 1231231;
  assertEquals(1, dao.create(foo1));
  Foo foo2 = new Foo();
  foo2.val = foo1.val + 1;
  assertEquals(1, dao.create(foo2));
  Map<String, Object> fieldValues = new HashMap<String, Object>();
  fieldValues.put(Foo.VAL_COLUMN_NAME, foo1.val);
  List<Foo> results = dao.queryForFieldValues(fieldValues);
  assertEquals(1, results.size());
  assertEquals(foo1.id, results.get(0).id);
  fieldValues.put(Foo.ID_COLUMN_NAME, foo2.id);
  fieldValues.put(Foo.VAL_COLUMN_NAME, foo1.val);
  results = dao.queryForFieldValues(fieldValues);
  assertEquals(0, results.size());
}

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

@Test
public void testQueryForFieldValues() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  assertEquals(0, dao.countOf());
  Foo foo = new Foo();
  int id = 1;
  foo.id = id;
  int val = 1231231;
  foo.val = val;
  assertEquals(1, dao.create(foo));
  int notId = id + 1;
  foo.id = notId;
  foo.val = val + 1;
  assertEquals(1, dao.create(foo));
  Map<String, Object> fieldValues = new HashMap<String, Object>();
  fieldValues.put(Foo.VAL_FIELD_NAME, val);
  List<Foo> results = dao.queryForFieldValues(fieldValues);
  assertEquals(1, results.size());
  assertEquals(id, results.get(0).id);
  fieldValues.put(Foo.ID_FIELD_NAME, notId);
  fieldValues.put(Foo.VAL_FIELD_NAME, val);
  results = dao.queryForFieldValues(fieldValues);
  assertEquals(0, results.size());
}

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

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

相关文章