metagloss 0.0.2

net.sf.metagloss.db
Annotation Type Query


@Target(value=METHOD)
@Retention(value=SOURCE)
public @interface Query

Annotation specifies an SQL query. Annotated methods are required to pass an instance of SQLiteDatabase as the first parameter. Subsequent parameters are bound to ?s in the SELECT.

Info:

Requires that the annotation processor is properly configured.

Valid return types

The first two options require a matching ITable enum class and that the data class is annotated with CursorBind.

Interfaces annotated with @Query must implement the QueryProvider marker interface.

Conformant interface

public interface DatabaseExample extends QueryProvider
{
    @Query(sql="SELECT * FROM books", table=BookTable.class)
    ArrayList<AnnotatedBook> getBooks(SQLiteDatabase database);
    
    @Query(sql="SELECT * FROM books WHERE id = ?", table=BookTable.class)
    AnnotatedBook getBook(SQLiteDatabase database, int id);
    
    @Query("SELECT * FROM books WHERE id = ?") // no table class required
    Cursor getBookCursor(SQLiteDatabase database, int id);
    
    @Query("SELECT * FROM books WHERE id = ?") // table class given by AssistCursor
    AssistCursor<BookTable> getBookAssistCursor(SQLiteDatabase database, int id);
}

See Also:
QueryProvider, QueryManager.getImplementation(Class)

Optional Element Summary
 java.lang.String sql
          Same as value().
 java.lang.Class<? extends ITable> table
          A single SQLite table.
 java.lang.String value
          SQL select.
 

value

public abstract java.lang.String value
SQL select. All ?s must have a corresponding parameter in the method signature.

Returns:
SQL Select.
Default:
""

sql

public abstract java.lang.String sql
Same as value(). Only one must be given.

Returns:
SQL Select
Default:
""

table

public abstract java.lang.Class<? extends ITable> table
A single SQLite table. Only required for operations where setter injection is performed.

Returns:
Class representing a single SQLite table.
Default:
net.sf.metagloss.db.ITable.class