Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
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
Method details
type
public abstract Class<T> type()tableName
public abstract String tableName()@Entity(table="...") wins.attach
public abstract void attach(Database db)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
save
public abstract T save(T entity)
throws IOExceptionStores entity and answers the instance that holds what the database
decided: inserted when its auto-increment key is still unassigned or no
row has its key, updated otherwise.
For an ordinary entity the answer is entity itself. A record cannot
have its generated key written into it, so for one the answer is a copy
that carries the key – the instance to keep.
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");