本文整理了Java中com.j256.ormlite.stmt.Where.in()
方法的一些代码示例,展示了Where.in()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Where.in()
方法的具体详情如下:
包路径:com.j256.ormlite.stmt.Where
类名称:Where
方法名:in
[英]Add a IN clause which makes sure the column is in one of the columns returned from a sub-query inside of parenthesis. The QueryBuilder must return 1 and only one column which can be set with the QueryBuilder#selectColumns(String...) method calls. That 1 argument must match the SQL type of the column-name passed to this method.
NOTE: The sub-query will be prepared at the same time that the outside query is.
[中]添加一个IN子句,确保该列位于从括号内的子查询返回的一列中。QueryBuilder必须返回1,并且只能返回一列,可以使用QueryBuilder#selectColumns(String…)设置该列方法调用。该1参数必须与传递给此方法的列名的SQL类型匹配。
注意:子查询将与外部查询同时准备。
代码示例来源: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
/**
* Same as {@link #in(String, Object...)} except with a NOT IN clause.
*/
public Where<T, ID> notIn(String columnName, Object... objects) throws SQLException {
return in(false, columnName, objects);
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* Same as {@link #in(String, QueryBuilder)} except with a NOT IN clause.
*/
public Where<T, ID> notIn(String columnName, QueryBuilder<?, ?> subQueryBuilder) throws SQLException {
return in(false, columnName, subQueryBuilder);
}
代码示例来源:origin: j256/ormlite-core
/**
* Same as {@link #in(String, QueryBuilder)} except with a NOT IN clause.
*/
public Where<T, ID> notIn(String columnName, QueryBuilder<?, ?> subQueryBuilder) throws SQLException {
return in(false, columnName, subQueryBuilder);
}
代码示例来源:origin: j256/ormlite-core
/**
* Add a IN clause so the column must be equal-to one of the objects passed in.
*/
public Where<T, ID> in(String columnName, Object... objects) throws SQLException {
return in(true, columnName, objects);
}
代码示例来源:origin: stackoverflow.com
List<String> ids = new ArrayList<String>();
for(Order r : LoginActivity.orders) {
ids.add(r.getProcess_status().getProccessStatusId());
}
QueryBuilder<ProcessStatus, Integer> qb = dao.queryBuilder();
Where where = qb.where();
where.in(ProcessStatus.STATUS_ID, ids);
qb.selectColumns(ProcessStatus.STATUS_TITLE);
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public List<Tdao> getAll(String key, List<Tid> ids) {
try {
if (ids != null && !ids.isEmpty()) {
return this.getDao().queryBuilder().where().in(key, ids).query();
}
return new ArrayList<Tdao>();
} catch (SQLException ex) {
_logger.error("unable to get all items ids:{}", ids, ex);
return null;
}
}
代码示例来源:origin: PaNaVTEC/Clean-Contacts
private void internalDeleteContacts(List<String> deleteMd5s) throws SQLException {
DeleteBuilder<BddContact, Integer> deleteBuilder = daoContacts.deleteBuilder();
deleteBuilder.where().in(BddContact.FIELD_MD5, deleteMd5s);
deleteBuilder.delete();
}
}
代码示例来源:origin: QuickBlox/q-municate-android
public List<Friend> getAllByIds(List<Integer> idsList) {
List<Friend> friendsList = Collections.emptyList();
try {
QueryBuilder<Friend, Long> queryBuilder = dao.queryBuilder();
queryBuilder.where().in(QMUserColumns.ID, idsList);
PreparedQuery<Friend> preparedQuery = queryBuilder.prepare();
friendsList = dao.query(preparedQuery);
} catch (SQLException e) {
ErrorUtils.logError(e);
}
return friendsList;
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testIn() throws Exception {
Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
int val = 112;
where.in(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(" IN (");
sb.append(val).append(" ) ");
assertEquals(sb.toString(), whereSb.toString());
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public List<OperationTable> getByRuleDefinitionIdEnabled(Integer ruleDefinitionId) {
List<Integer> ids = DaoUtils.getOperationRuleDefinitionMapDao().getOperationIdsByRuleDefinitionId(
ruleDefinitionId);
try {
return this.getDao().queryBuilder().where().in(OperationTable.KEY_ID, ids).and()
.eq(OperationTable.KEY_ENABLED, true).query();
} catch (SQLException ex) {
_logger.error("Exception,", ex);
}
return null;
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public List<OperationTable> getByRuleDefinitionIdEnabled(Integer ruleDefinitionId) {
List<Integer> ids = DaoUtils.getOperationRuleDefinitionMapDao().getOperationIdsByRuleDefinitionId(
ruleDefinitionId);
try {
return this.getDao().queryBuilder().where().in(OperationTable.KEY_ID, ids).and()
.eq(OperationTable.KEY_ENABLED, true).query();
} catch (SQLException ex) {
_logger.error("Exception,", ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = IllegalArgumentException.class)
public void testInArrayWithinArray() throws Exception {
Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
// NOTE: we can't pass in vals here
where.in(Foo.VAL_COLUMN_NAME, new int[] { 112 });
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testInIterable() throws Exception {
Dao<Foo, String> fooDao = createTestData();
QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
qb.where().in(Foo.ID_COLUMN_NAME, Arrays.asList(foo1.id, foo2.id));
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 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: j256/ormlite-core
@Test(expected = SQLException.class)
public void testInSubQueryToManySubColumns() 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();
qb.selectColumns(ID_COLUMN_NAME, FOREIGN_COLUMN_NAME);
where.in(ID_COLUMN_NAME, qb);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testResultColumnNoMatchWhere() throws Exception {
BaseDaoImpl<ForeignFoo, Integer> foreignDao =
new BaseDaoImpl<ForeignFoo, Integer>(connectionSource, ForeignFoo.class) {
};
QueryBuilder<ForeignFoo, Integer> qbInner = foreignDao.queryBuilder();
qbInner.selectColumns(STRING_COLUMN_NAME);
QueryBuilder<ForeignFoo, Integer> qbOuter = foreignDao.queryBuilder();
Where<ForeignFoo, Integer> where = qbOuter.where();
where.in(ID_COLUMN_NAME, qbInner);
where.prepare();
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testTwoResultsInSubQuery() throws Exception {
BaseDaoImpl<ForeignFoo, Integer> foreignDao =
new BaseDaoImpl<ForeignFoo, Integer>(connectionSource, ForeignFoo.class) {
};
QueryBuilder<ForeignFoo, Integer> qbInner = foreignDao.queryBuilder();
qbInner.selectColumns(ID_COLUMN_NAME);
QueryBuilder<ForeignFoo, Integer> qbOuter = foreignDao.queryBuilder();
qbInner.selectColumns(FOREIGN_COLUMN_NAME);
Where<ForeignFoo, Integer> where = qbOuter.where();
where.in(ID_COLUMN_NAME, qbInner);
where.prepare();
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = IllegalArgumentException.class)
public void testInnerQuerySubQueryPrepared() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
fooDao.queryBuilder()
.where()
.in(Foo.ID_COLUMN_NAME,
// this is a problem because prepare() returns a PreparedStmt not a QueryBuilder
fooDao.queryBuilder().selectColumns(Foo.ID_COLUMN_NAME).prepare())
.query();
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = IllegalArgumentException.class)
public void testInnerQuerySubQueryWhere() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
fooDao.queryBuilder()
.where()
.in(Foo.ID_COLUMN_NAME,
// this is a problem because eq() returns a Where not a QueryBuilder
fooDao.queryBuilder().selectColumns(Foo.ID_COLUMN_NAME).where().eq(Foo.ID_COLUMN_NAME, 1))
.query();
}
内容来源于网络,如有侵权,请联系作者删除!