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

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

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

Where.reset介绍

[英]Reset the Where object so it can be re-used.
[中]重置Where对象,使其可以重复使用。

代码示例

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

@Test
public void testClear() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val = 112;
  where.eq(Foo.VAL_COLUMN_NAME, val);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" = ");
  sb.append(val).append(' ');
  assertEquals(sb.toString(), whereSb.toString());
  where.reset();
  whereSb.setLength(0);
  where.eq(Foo.VAL_COLUMN_NAME, val + 1);
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  sb.setLength(0);
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" = ");
  sb.append(val + 1).append(' ');
  assertEquals(sb.toString(), whereSb.toString());
}

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

assertEquals(sb.toString(), whereSb.toString());
where.reset();
where.eq(Foo.VAL_COLUMN_NAME, val1);
where.eq(Foo.VAL_COLUMN_NAME, val2);

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

@Test
public void testDateBetween() throws Exception {
  Dao<DateBetween, Object> dao = createDao(DateBetween.class, true);
  DateBetween dateBetween = new DateBetween();
  long now = System.currentTimeMillis();
  Date date = new Date(now);
  dateBetween.date = date;
  assertEquals(1, dao.create(dateBetween));
  QueryBuilder<DateBetween, Object> qb = dao.queryBuilder();
  qb.where().between(DateBetween.DATE_COLUMN_NAME, new Date(now - 1), new Date(now + 1));
  List<DateBetween> results = qb.query();
  assertEquals(1, results.size());
  qb.where().reset();
  qb.where().between(DateBetween.DATE_COLUMN_NAME, new Date(now), new Date(now + 1));
  results = qb.query();
  assertEquals(1, results.size());
  qb.where().reset();
  qb.where().between(DateBetween.DATE_COLUMN_NAME, new Date(now), new Date(now));
  results = qb.query();
  assertEquals(1, results.size());
}

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

@SuppressWarnings("unchecked")
@Test
public void testUseOfAndMany() 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));
  Where<Foo, Integer> where = dao.queryBuilder().where();
  where.and(where.eq(Foo.VAL_COLUMN_NAME, foo1.val), where.eq(Foo.ID_COLUMN_NAME, foo1.id));
  List<Foo> results = where.query();
  assertEquals(1, results.size());
  assertEquals(foo1.id, results.get(0).id);
  // this should match none
  where.reset();
  where.and(where.eq(Foo.ID_COLUMN_NAME, foo1.id), where.eq(Foo.ID_COLUMN_NAME, foo2.id),
      where.eq(Foo.VAL_COLUMN_NAME, foo1.val), where.eq(Foo.VAL_COLUMN_NAME, foo2.val));
  results = where.query();
  assertEquals(0, results.size());
}

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

@SuppressWarnings("unchecked")
@Test
public void testUseOfAndMany() 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));
  Where<Foo, Integer> where = dao.queryBuilder().where();
  where.and(where.eq(Foo.VAL_FIELD_NAME, val), where.eq(Foo.ID_FIELD_NAME, id));
  List<Foo> results = where.query();
  assertEquals(1, results.size());
  assertEquals(id, results.get(0).id);
  // this should match none
  where.reset();
  where.and(where.eq(Foo.VAL_FIELD_NAME, val), where.eq(Foo.ID_FIELD_NAME, id),
      where.eq(Foo.ID_FIELD_NAME, notId));
  results = where.query();
  assertEquals(0, results.size());
}

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

@Test
@SuppressWarnings("unchecked")
public void testUseOfAndInt() 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));
  Where<Foo, Integer> where = dao.queryBuilder().where();
  where.and(where.eq(Foo.VAL_FIELD_NAME, val), where.eq(Foo.ID_FIELD_NAME, id));
  List<Foo> results = where.query();
  assertEquals(1, results.size());
  assertEquals(id, results.get(0).id);
  // this should match none
  where.reset();
  where.eq(Foo.VAL_FIELD_NAME, val);
  where.eq(Foo.ID_FIELD_NAME, id);
  where.eq(Foo.ID_FIELD_NAME, notId);
  where.and(3);
  results = where.query();
  assertEquals(0, results.size());
}

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

@Test
public void testUseOfAndInt() 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(foo1));
  Where<Foo, Integer> where = dao.queryBuilder().where();
  where.eq(Foo.VAL_COLUMN_NAME, foo1.val);
  where.eq(Foo.ID_COLUMN_NAME, foo1.id);
  where.and(2);
  List<Foo> results = where.query();
  assertEquals(1, results.size());
  assertEquals(foo1.id, results.get(0).id);
  // this should match none
  where.reset();
  where.eq(Foo.ID_COLUMN_NAME, foo1.id);
  where.eq(Foo.ID_COLUMN_NAME, foo2.id);
  where.eq(Foo.VAL_COLUMN_NAME, foo1.val);
  where.eq(Foo.VAL_COLUMN_NAME, foo2.val);
  where.and(4);
  results = where.query();
  assertEquals(0, results.size());
}

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

@Test
  public void testDeleteMethod() throws Exception {
    Dao<Foo, Integer> dao = createDao(Foo.class, true);
    Foo foo = new Foo();
    foo.val = 123123;
    assertEquals(1, dao.create(foo));

    assertNotNull(dao.queryForId(foo.id));
    DeleteBuilder<Foo, Integer> db = dao.deleteBuilder();
    // no match
    db.where().eq(Foo.VAL_COLUMN_NAME, foo.val + 1);
    assertEquals(0, db.delete());
    assertNotNull(dao.queryForId(foo.id));

    db.where().reset();
    db.where().eq(Foo.VAL_COLUMN_NAME, foo.val);
    assertEquals(1, db.delete());
    assertNull(dao.queryForId(foo.id));
  }
}

相关文章