|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Target(value=METHOD) @Retention(value=RUNTIME) public @interface Select
The @Select
annotation is used to mark methods within a
Query
class that will return a DataSet
.
The Select
annotation contains the SQL query that will be
executed on the database, and whether the resulting DataSet
will
be a "connected" or "disconnected"
DataSet
to start with. Remember that a DataSet
may be cleanly disconnected
from the database.
Here is an example of how a @Select
is used:
public class User {
public Integer id;
public String username;
}
public interface UserQuery extends BaseQuery {
@Select("SELECT * FROM user WHERE id = ?1")
public DataSet<User> getUserById(int id);
}
Any method annotated with @Select
may return any one of the
following datatypes:
null
if no results where returned.
DataSet
- this is the preferred
way of returning mulitple results, as it can remain connected
to the database, or be disconnected
at any time.
Set
,
List
or Collection
-
these types have no connection to the database, the data is
loaded into them and the result is returned.
DataSet
inherits from List
,
and has all of it's read functionality.
Columns that cannot be mapped to fields are
ignored, as are fields that cannot be mapped to columns. @Select
SQL uses the exact same query parser as the Update
annotation, and
so can also accept complex types as it's parameters, and insert their
fields into the SQL query.
Update
Optional Element Summary | |
---|---|
boolean |
disconnected
Specify whether or not the DataSet resulting from a call to the
annotated method will be connected to the database or not. |
boolean |
rubberstamp
If rubberstamp is flagged as true , the annotated
method must return a DataIterator , otherwise it will be rejected by
the QueryTool . |
String |
sql
The SQL query to execute on the database. |
String |
value
The SQL query to execute on the database. |
public abstract String value
sql()
public abstract String sql
value()
, but is used when you wish
to specify values other than the SQL query.
public abstract boolean disconnected
DataSet
resulting from a call to the
annotated method will be connected to the database or not.
DataSet
,
DataSet.disconnect()
public abstract boolean rubberstamp
rubberstamp
is flagged as true
, the annotated
method must return a DataIterator
, otherwise it will be rejected by
the QueryTool
. Rubberstamping will cause the returned
DataIterator
to use a single instance of the data-object for all
of the rows returned, instead of initializing a new one for each row. This can
be used to save CPU time and memory, and is especially useful in display code.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |