com.j256.ormlite.stmt.Where.exists()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(169)

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

Where.exists介绍

[英]Add a EXISTS clause with a sub-query inside of parenthesis.

NOTE: The sub-query will be prepared at the same time that the outside query is.
[中]添加一个EXISTS子句,并在括号内添加一个子查询。
注意:子查询将与外部查询同时准备。

代码示例

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

@Test
public void testExistsSubQuery() throws Exception {
  TableInfo<ForeignFoo, Integer> tableInfo = new TableInfo<ForeignFoo, Integer>(databaseType, ForeignFoo.class);
  Where<ForeignFoo, Integer> where = new Where<ForeignFoo, Integer>(tableInfo, null, databaseType);
  BaseDaoImpl<ForeignFoo, Integer> foreignDao =
      new BaseDaoImpl<ForeignFoo, Integer>(connectionSource, ForeignFoo.class) {
      };
  QueryBuilder<ForeignFoo, Integer> qb = foreignDao.queryBuilder();
  where.exists(qb);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  sb.append("EXISTS (");
  sb.append("SELECT * FROM ");
  databaseType.appendEscapedEntityName(sb, tableInfo.getTableName());
  sb.append(" ) ");
  assertEquals(sb.toString(), whereSb.toString());
}

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

@Test
public void testNotExistsSubQuery() throws Exception {
  TableInfo<ForeignFoo, Integer> tableInfo = new TableInfo<ForeignFoo, Integer>(databaseType, ForeignFoo.class);
  Where<ForeignFoo, Integer> where = new Where<ForeignFoo, Integer>(tableInfo, null, databaseType);
  BaseDaoImpl<ForeignFoo, Integer> foreignDao =
      new BaseDaoImpl<ForeignFoo, Integer>(connectionSource, ForeignFoo.class) {
      };
  QueryBuilder<ForeignFoo, Integer> qb = foreignDao.queryBuilder();
  where.not().exists(qb);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  sb.append("(NOT EXISTS (");
  sb.append("SELECT * FROM ");
  databaseType.appendEscapedEntityName(sb, tableInfo.getTableName());
  sb.append(" ) ) ");
  assertEquals(sb.toString(), whereSb.toString());
}

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

@Test
public void testExists() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> innerQb = fooDao.queryBuilder();
  innerQb.where().idEq(foo1.id);
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  qb.where().exists(innerQb);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(2, results.size());
  assertEquals(foo1, results.get(0));
  assertEquals(foo2, results.get(1));
}

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

@Test
public void testExistsNoEntries() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> innerQb = fooDao.queryBuilder();
  innerQb.where().idEq("no id by this name");
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  qb.where().exists(innerQb);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(0, results.size());
}

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

@Test
public void testNotExists() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> innerQb = fooDao.queryBuilder();
  innerQb.where().idEq(foo1.id);
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  qb.where().not().exists(innerQb);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(0, results.size());
}

相关文章