public interface Dao<T>
Runtime contract a build-time-generated @Entity data access object
implements. Application code rarely references Dao by name – the typed
dao is reached through EntityManager.dao(EntityClass.class).
All methods throw IOException for the same reasons com.codename1.db
does: the underlying SQLite driver propagates IO failures, locking
failures, and constraint violations through IOException.
Methods
public abstract Class<T> type() | The entity class this dao handles. |
public abstract String tableName() | The SQL table name. |
public abstract void attach(Database db) | Connects this dao to a Database instance. |
public abstract void createTable()
throws IOException | CREATE TABLE IF NOT EXISTS .... |
public abstract void dropTable()
throws IOException | DROP TABLE IF EXISTS .... |
public abstract void insert(T entity)
throws IOException | INSERT INTO .... |
public abstract void update(T entity)
throws IOException | UPDATE ... WHERE id = ?. |
public abstract void delete(T entity)
throws IOException | DELETE ... WHERE id = ?. |
public abstract T findById(Object id)
throws IOException | SELECT ... WHERE id = ?. |
public abstract List<T> findAll()
throws IOException | SELECT * FROM .... |
public abstract List<T> find(String where, Object... params)
throws IOException | Free-form WHERE clause; where is appended verbatim after WHERE and params fills the ? placeholders. |
Method details
type
public abstract Class<T> type()The entity class this dao handles.
tableName
public abstract String tableName()The SQL table name. Defaults to the simple class name; an explicit
@Entity(table="...") wins.attach
public abstract void attach(Database db)Connects this dao to a
Database instance. Called by
EntityManager.dao(Class); the same dao is reused for the lifetime of
the entity manager.createTable
public abstract void createTable()
throws IOExceptionCREATE TABLE IF NOT EXISTS .... Idempotent.Throws
dropTable
public abstract void dropTable()
throws IOExceptionDROP TABLE IF EXISTS ....Throws
insert
public abstract void insert(T entity)
throws IOExceptionINSERT INTO .... When the entity has an auto-increment @Id, the
generated id is written back into the instance via
SELECT last_insert_rowid().Throws
update
public abstract void update(T entity)
throws IOExceptionUPDATE ... WHERE id = ?.Throws
delete
public abstract void delete(T entity)
throws IOExceptionDELETE ... WHERE id = ?.Throws
findById
public abstract T findById(Object id)
throws IOExceptionSELECT ... WHERE id = ?. Returns null when no row matches.Throws
findAll
public abstract List<T> findAll()
throws IOExceptionSELECT * FROM .... Returns every row mapped to an instance of the
entity class.Throws
find
public abstract List<T> find(String where, Object... params)
throws IOExceptionFree-form WHERE clause; where is appended verbatim after WHERE
and params fills the ? placeholders.
users.find("age > ? AND city = ?", 18, "Berlin");