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

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

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

Where.like介绍

[英]Add a LIKE clause so the column must mach the value using '%' patterns.
[中]添加一个LIKE子句,以便列必须使用“%”模式处理值。

代码示例

代码示例来源: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

public Set<String> getCreatureNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    qb.where().like("types", new SelectArg('%' + CardType.CREATURE.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 creature names from DB : " + ex);
  }
  return names;
}

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

public Set<String> getArtifactNames() {
  Set<String> names = new TreeSet<>();
  try {
    QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
    qb.distinct().selectColumns("name");
    qb.where().like("types", new SelectArg('%' + CardType.ARTIFACT.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 artifact 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> 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

int clausesCount = 2;
if (name != null) {
  where.like("name", new SelectArg('%' + name + '%'));
  clausesCount++;
  where.like("name", new SelectArg(nameExact));
  clausesCount++;
  where.like("rules", new SelectArg('%' + rules + '%'));
  clausesCount++;
    where.like("types", new SelectArg('%' + type.name() + '%'));
  where.not().like("types", new SelectArg('%' + type.name() + '%'));
  clausesCount++;
  where.like("supertypes", new SelectArg('%' + superType + '%'));
  clausesCount++;
  where.not().like("supertypes", new SelectArg('%' + subType + '%'));
  clausesCount++;
  where.like("subtypes", new SelectArg('%' + subType + '%'));
  clausesCount++;

代码示例来源:origin: zulip/zulip-android

@Override
public Where<Message, Object> modWhere(Where<Message, Object> where)
    throws SQLException {
  where.like(Message.CONTENT_FIELD, name);
  return where;
}

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();
where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter);
where.or(3);

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();

where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter);
where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter);
where.or(3);

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();
where.or(where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter),
     where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter),
     where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter));

代码示例来源:origin: stackoverflow.com

Where where = queryBuilder.where();
where.like(Contacts.FIELD_NAME_FIRST_NAME, nameFilter);
where.or();
where.like(Contacts.FIELD_NAME_LAST_NAME, nameFilter);
where.or();
where.like(Contacts.FIELD_NAME_PHONE_NUMBER, nameFilter);

代码示例来源:origin: org.mycontroller.standalone/mycontroller-core

@Override
public List<UserSettings> getLike(User user, String key) {
  try {
    QueryBuilder<UserSettings, Integer> queryBuilder = getDao().queryBuilder();
    queryBuilder.where().like("key", key);
    return queryBuilder.orderBy("id", true).query();
  } catch (SQLException ex) {
    _logger.error("unable to get like:[{}]", key, ex);
    return null;
  }
}

代码示例来源:origin: mycontroller-org/mycontroller

@Override
public List<UserSettings> getLike(User user, String key) {
  try {
    QueryBuilder<UserSettings, Integer> queryBuilder = getDao().queryBuilder();
    queryBuilder.where().like("key", key);
    return queryBuilder.orderBy("id", true).query();
  } catch (SQLException ex) {
    _logger.error("unable to get like:[{}]", key, ex);
    throw new McDatabaseException(ex);
  }
}

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

@Test
public void testLike() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int val = 112;
  where.like(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(" 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 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: com.j256.ormlite/ormlite-jdbc

@Test
public void testLike() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  qb.where().like(Foo.ID_COLUMN_NAME, ID_PREFIX + "%");
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(2, results.size());
  assertEquals(foo1, results.get(0));
  assertEquals(foo2, results.get(1));
}

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

相关文章