本文整理了Java中com.j256.ormlite.dao.Dao.queryForMatching()
方法的一些代码示例,展示了Dao.queryForMatching()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.queryForMatching()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:queryForMatching
[英]Query for the rows in the database that match the object passed in as a parameter. Any fields in the matching object that are not the default value (null, false, 0, 0.0, etc.) are used as the matching parameters with AND. If you are worried about SQL quote escaping, you should use #queryForMatchingArgs(Object).
[中]查询数据库中与作为参数传入的对象匹配的行。匹配对象中不是默认值(null、false、0、0.0等)的任何字段都将用作与和的匹配参数。如果您担心SQL引号转义,那么应该使用#queryForMatchingArgs(Object)。
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#queryForMatching(Object)
*/
@Override
public List<T> queryForMatching(T matchObj) {
try {
return dao.queryForMatching(matchObj);
} catch (SQLException e) {
logMessage(e, "queryForMatching threw exception on: " + matchObj);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
&& dataType != DataType.FLOAT_OBJ) {
list = dao.queryForMatching(foo);
assertEquals(1, list.size());
assertTrue(dao.objectsEqual(foo, list.get(0)));
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#queryForMatching(Object)
*/
@Override
public List<T> queryForMatching(T matchObj) {
try {
return dao.queryForMatching(matchObj);
} catch (SQLException e) {
logMessage(e, "queryForMatching threw exception on: " + matchObj);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testQueryForMatchingThrow() 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.queryForMatching(null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.queryForMatching(null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testQueryForMatching() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
assertEquals(0, dao.countOf());
Foo foo1 = new Foo();
int val = 1231231;
foo1.val = val;
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
foo2.val = val + 1;
assertEquals(1, dao.create(foo2));
Foo match = new Foo();
match.val = val;
List<Foo> results = dao.queryForMatching(match);
assertEquals(1, results.size());
assertEquals(foo1.id, results.get(0).id);
match = new Foo();
match.id = foo2.id;
match.val = val;
results = dao.queryForMatching(match);
assertEquals(0, results.size());
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testQueryForMatchingNoFields() 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));
Foo match = new Foo();
List<Foo> results = dao.queryForMatching(match);
assertEquals(0, results.size());
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testQueryForMatching() 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));
Foo match = new Foo();
match.val = val;
List<Foo> results = dao.queryForMatching(match);
assertEquals(1, results.size());
assertEquals(id, results.get(0).id);
match = new Foo();
match.id = notId;
match.val = val;
results = dao.queryForMatching(match);
assertEquals(0, results.size());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testQueryForMatchingQuotes() 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));
Foo match = new Foo();
match.stringField = "this id has a quote '";
dao.queryForMatching(match);
}
内容来源于网络,如有侵权,请联系作者删除!