Interface Dao<T>
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoidConnects this dao to aDatabaseinstance.voidCREATE TABLE IF NOT EXISTS ....voidDELETE ... WHERE id = ?.voidDROP TABLE IF EXISTS ....Free-form WHERE clause;whereis appended verbatim afterWHEREandparamsfills the?placeholders.findAll()SELECT * FROM ....SELECT ... WHERE id = ?.voidINSERT INTO ....The SQL table name.type()The entity class this dao handles.voidUPDATE ... WHERE id = ?.
-
Method Details
-
type
-
tableName
String tableName()The SQL table name. Defaults to the simple class name; an explicit@Entity(table="...")wins. -
attach
Connects this dao to aDatabaseinstance. Called byEntityManager.dao(Class); the same dao is reused for the lifetime of the entity manager. -
createTable
CREATE TABLE IF NOT EXISTS .... Idempotent.- Throws:
IOException
-
dropTable
-
insert
INSERT INTO .... When the entity has an auto-increment@Id, the generated id is written back into the instance viaSELECT last_insert_rowid().- Throws:
IOException
-
update
-
delete
-
findById
SELECT ... WHERE id = ?. Returnsnullwhen no row matches.- Throws:
IOException
-
findAll
SELECT * FROM .... Returns every row mapped to an instance of the entity class.- Throws:
IOException
-
find
Free-form WHERE clause;
whereis appended verbatim afterWHEREandparamsfills the?placeholders.users.find("age > ? AND city = ?", 18, "Berlin");- Throws:
IOException
-