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

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

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

Where.not介绍

[英]Used to NOT the next clause specified.
[中]用于不指定下一个子句。

代码示例

代码示例来源:origin: magefree/mage

public List<CardInfo> getMissingCards(List<String> classNames) {
  try {
    QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
    queryBuilder.where().not().in("className", classNames);
    return cardDao.query(queryBuilder.prepare());
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting missing cards from DB : " + ex);
  }
  return Collections.emptyList();
}

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

@Test
public void testNotIn() throws Exception {
  Dao<Foo, String> dao = createDao(Foo.class, true);
  Foo foo1 = new Foo();
  foo1.val = 63465365;
  assertEquals(1, dao.create(foo1));
  Foo foo2 = new Foo();
  foo2 = new Foo();
  foo2.val = 163123;
  assertEquals(1, dao.create(foo2));
  List<Foo> results = dao.queryBuilder().where().in(Foo.ID_COLUMN_NAME, foo2.id).query();
  assertEquals(1, results.size());
  assertEquals(foo2.val, results.get(0).val);
  // support not with in
  results = dao.queryBuilder().where().not().in(Foo.ID_COLUMN_NAME, foo2.id).query();
  assertEquals(1, results.size());
  assertEquals(foo1.val, results.get(0).val);
  // support not in
  results = dao.queryBuilder().where().notIn(Foo.ID_COLUMN_NAME, foo2.id).query();
  assertEquals(1, results.size());
  assertEquals(foo1.val, results.get(0).val);
}

代码示例来源:origin: magefree/mage

public Set<String> getNonLandAndNonCreatureNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    Where where = qb.where();
    where.and(
        where.not().like("types", '%' + CardType.CREATURE.name() + '%'),
        where.not().like("types", '%' + CardType.LAND.name() + '%')
    );
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-land and non-creature names from DB : " + ex);
  }
  return names;
}

代码示例来源:origin: magefree/mage

public Set<String> getNonArtifactAndNonLandNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    Where where = qb.where();
    where.and(
        where.not().like("types", '%' + CardType.ARTIFACT.name() + '%'),
        where.not().like("types", '%' + CardType.LAND.name() + '%')
    );
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-artifact non-land names from DB : " + ex);
  }
  return names;
}

代码示例来源:origin: magefree/mage

public Set<String> getNonLandNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    qb.where().not().like("types", new SelectArg('%' + CardType.LAND.name() + '%'));
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-land names from DB : " + ex);
  }
  return names;
}

代码示例来源:origin: magefree/mage

public Set<String> getNotBasicLandNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    qb.where().not().like("supertypes", new SelectArg('%' + SuperType.BASIC.name() + '%'));
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-land names from DB : " + ex);
  }
  return names;
}

代码示例来源:origin: magefree/mage

public Set<String> getNonbasicLandNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    Where where = qb.where();
    where.and(
        where.not().like("supertypes", '%' + SuperType.BASIC.name() + '%'),
        where.like("types", '%' + CardType.LAND.name() + '%')
    );
    List<CardInfo> results = cardDao.query(qb.prepare());
    for (CardInfo card : results) {
      int result = card.getName().indexOf(" // ");
      if (result > 0) {
        names.add(card.getName().substring(0, result));
        names.add(card.getName().substring(result + 4));
      } else {
        names.add(card.getName());
      }
    }
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error getting non-land names from DB : " + ex);
  }
  return names;
}

代码示例来源:origin: magefree/mage

where.not().like("types", new SelectArg('%' + type.name() + '%'));
clausesCount++;
where.not().like("supertypes", new SelectArg('%' + subType + '%'));
clausesCount++;

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

@Test
public void testNotFuture() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val = 112;
  where.not();
  where.like(Foo.VAL_COLUMN_NAME, val);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  sb.append("(NOT ");
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" LIKE ");
  sb.append(val).append(" ) ");
  assertEquals(sb.toString(), whereSb.toString());
}

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

@Test
public void testNotAbsorb() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val = 112;
  where.like(Foo.VAL_COLUMN_NAME, val);
  where.not(where);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  sb.append("(NOT ");
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" LIKE ");
  sb.append(val).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 testSelectNot() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  qb.where().not().eq(Foo.ID_COLUMN_NAME, foo1.id);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertEquals(foo2, results.get(0));
}

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

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

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

@Test
public void testNotArg() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  Where<Foo, String> where = qb.where();
  where.not(where.eq(Foo.ID_COLUMN_NAME, foo1.id));
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertEquals(foo2, results.get(0));
}

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

@Test
public void testNotBad() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  qb.where().not();
  try {
    fooDao.query(qb.prepare());
    fail("expected exception");
  } catch (IllegalStateException e) {
    // expected
  }
}

代码示例来源: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());
}

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

@Test
public void testMultipleFuture() throws Exception {
  Dao<Foo, String> dao = createDao(Foo.class, true);
  Foo foo1 = new Foo();
  foo1.val = 123;
  foo1.stringField = "fjewpjfew";
  dao.create(foo1);
  QueryBuilder<Foo, String> qb = dao.queryBuilder();
  Where<Foo, String> where = qb.where();
  where.eq(Foo.VAL_COLUMN_NAME, foo1.val);
  where.and();
  where.not();
  where.like(Foo.STRING_COLUMN_NAME, "hello");
  List<Foo> results = where.query();
  assertNotNull(results);
  assertEquals(1, results.size());
  assertEquals(foo1.id, results.get(0).id);
}

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

@Test
@SuppressWarnings("unchecked")
public void testNotNotComparison() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  Where<Foo, String> where = qb.where();
  try {
    where.not(where.and(where.eq(Foo.ID_COLUMN_NAME, foo1.id), where.eq(Foo.ID_COLUMN_NAME, foo1.id)));
    fail("expected exception");
  } catch (IllegalArgumentException e) {
    // expected
  }
}

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

results = fooDao.query(fooDao.queryBuilder().where().not().in(Foo.STUFF_FIELD_NAME, bqb).prepare());
assertEquals(num1 + num3, results.size());

相关文章