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

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

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

Dao.queryForMatchingArgs介绍

[英]Same as #queryForMatching(Object) but this uses SelectArg and SQL ? arguments. This is slightly more expensive but you don't have to worry about SQL quote escaping.
[中]与#queryForMatching(Object)相同,但它使用SelectArg和SQL?论据。这稍微贵一点,但您不必担心SQL引号转义。

代码示例

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

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

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

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

代码示例来源:origin: kamax-matrix/mxisd

  1. @Override
  2. public Optional<IThreePidSessionDao> findThreePidSession(ThreePid tpid, String secret) {
  3. return withCatcher(() -> {
  4. List<ThreePidSessionDao> daoList = sessionDao.queryForMatchingArgs(new ThreePidSessionDao(tpid, secret));
  5. if (daoList.size() > 1) {
  6. throw new InternalServerError("Lookup for 3PID Session " +
  7. tpid + " returned more than one result");
  8. }
  9. if (daoList.isEmpty()) {
  10. return Optional.empty();
  11. }
  12. return Optional.of(daoList.get(0));
  13. });
  14. }

代码示例来源:origin: kamax-matrix/mxisd

  1. @Override
  2. public Optional<ASTransactionDao> getTransactionResult(String localpart, String txnId) {
  3. return withCatcher(() -> {
  4. ASTransactionDao dao = new ASTransactionDao();
  5. dao.setLocalpart(localpart);
  6. dao.setTransactionId(txnId);
  7. List<ASTransactionDao> daoList = asTxnDao.queryForMatchingArgs(dao);
  8. if (daoList.size() > 1) {
  9. throw new InternalServerError("Lookup for Transaction " +
  10. txnId + " for localpart " + localpart + " returned more than one result");
  11. }
  12. if (daoList.isEmpty()) {
  13. return Optional.empty();
  14. }
  15. return Optional.of(daoList.get(0));
  16. });
  17. }

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

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

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

  1. @Test
  2. public void testQueryForMatchingArgs() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. assertEquals(0, dao.countOf());
  5. Foo foo1 = new Foo();
  6. int val = 1231231;
  7. foo1.val = val;
  8. assertEquals(1, dao.create(foo1));
  9. Foo foo2 = new Foo();
  10. foo2.val = val + 1;
  11. assertEquals(1, dao.create(foo2));
  12. Foo match = new Foo();
  13. match.stringField = "this id has a quote '";
  14. List<Foo> results = dao.queryForMatchingArgs(match);
  15. assertEquals(0, results.size());
  16. }

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

  1. assertTrue(dao.objectsEqual(foo, list.get(0)));
  2. list = dao.queryForMatchingArgs(foo);
  3. assertEquals(1, list.size());
  4. assertTrue(dao.objectsEqual(foo, list.get(0)));

相关文章