|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.j256.ormlite.stmt.Where
public class Where
Manages the various clauses that make up the WHERE part of a SQL statement. You get one of these when you call
QueryBuilder.where or you can set the where clause by calling QueryBuilder.setWhere(com.j256.ormlite.stmt.Where).
Here's a page with a good tutorial of SQL commands.
To create a query which looks up an account by name and password you would do the following:
QueryBuilder<Account, String> qb = accountDao.queryBuilder(); Where where = qb.where(); // the name field must be equal to "foo" where.eq(Account.NAME_FIELD_NAME, "foo"); // and where.and(); // the password field must be equal to "_secret" where.eq(Account.PASSWORD_FIELD_NAME, "_secret"); PreparedQuery<Account, String> preparedQuery = qb.prepareQuery();
In this example, the SQL query that will be generated will be approximately:
SELECT * FROM account WHERE (name = 'foo' AND passwd = '_secret')
If you'd rather chain the methods onto one line (like StringBuilder), this can also be written as:
queryBuilder.where().eq(Account.NAME_FIELD_NAME, "foo").and().eq(Account.PASSWORD_FIELD_NAME, "_secret");
If you'd rather use parens and the like then you can call:
Where where = queryBuilder.where(); where.and(where.eq(Account.NAME_FIELD_NAME, "foo"), where.eq(Account.PASSWORD_FIELD_NAME, "_secret"));
All three of the above call formats produce the same SQL. For complex queries that mix ANDs and ORs, the last format will be necessary to get the grouping correct. For example, here's a complex query:
Where where = queryBuilder.where();
where.or(where.and(where.eq(Account.NAME_FIELD_NAME, "foo"), where.eq(Account.PASSWORD_FIELD_NAME, "_secret")),
where.and(where.eq(Account.NAME_FIELD_NAME, "bar"), where.eq(Account.PASSWORD_FIELD_NAME, "qwerty")));
This produces the following approximate SQL:
SELECT * FROM account WHERE ((name = 'foo' AND passwd = '_secret') OR (name = 'bar' AND passwd = 'qwerty'))
| Method Summary | |
|---|---|
Where |
and()
AND operation which takes the previous clause and the next clause and AND's them together. |
Where |
and(Where left,
Where right)
AND operation which takes 2 arguments and AND's them together. |
Where |
between(String columnName,
Object low,
Object high)
Add a BETWEEN clause so the column must be between the low and high parameters. |
Where |
eq(String columnName,
Object value)
Add a '=' clause so the column must be equal to the value. |
Where |
ge(String columnName,
Object value)
Add a '>=' clause so the column must be greater-than or equals-to the value. |
Where |
gt(String columnName,
Object value)
Add a '>' clause so the column must be greater-than the value. |
Where |
in(String columnName,
Iterable<?> objects)
Add a IN clause so the column must be equal-to one of the objects from the list passed in. |
Where |
in(String columnName,
Object... objects)
Add a IN clause so the column must be equal-to one of the objects passed in. |
Where |
isNotNull(String columnName)
Add a 'IS NOT NULL' clause so the column must not be null. |
Where |
isNull(String columnName)
Add a 'IS NULL' clause so the column must be null. |
Where |
le(String columnName,
Object value)
Add a '<=' clause so the column must be less-than or equals-to the value. |
Where |
like(String columnName,
Object value)
Add a LIKE clause so the column must be like the value (where you can specify '%' patterns. |
Where |
lt(String columnName,
Object value)
Add a '<' clause so the column must be less-than the value. |
Where |
ne(String columnName,
Object value)
Add a '<>' clause so the column must be not-equal-to the value. |
Where |
not()
Used to NOT the next clause specified. |
Where |
not(Where comparison)
Used to NOT the argument clause specified. |
Where |
or()
OR operation which takes the previous clause and the next clause and OR's them together. |
Where |
or(Where left,
Where right)
OR operation which takes 2 arguments and OR's them together. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public Where and()
public Where and(Where left,
Where right)
public Where between(String columnName,
Object low,
Object high)
throws SQLException
SQLException
public Where eq(String columnName,
Object value)
throws SQLException
SQLException
public Where ge(String columnName,
Object value)
throws SQLException
SQLException
public Where gt(String columnName,
Object value)
throws SQLException
SQLException
public Where in(String columnName,
Iterable<?> objects)
throws SQLException
SQLException
public Where in(String columnName,
Object... objects)
throws SQLException
SQLException
public Where isNull(String columnName)
throws SQLException
SQLException
public Where isNotNull(String columnName)
throws SQLException
SQLException
public Where le(String columnName,
Object value)
throws SQLException
SQLException
public Where lt(String columnName,
Object value)
throws SQLException
SQLException
public Where like(String columnName,
Object value)
throws SQLException
SQLException
public Where ne(String columnName,
Object value)
throws SQLException
SQLExceptionpublic Where not()
public Where not(Where comparison)
public Where or()
public Where or(Where left,
Where right)
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||