Long startDate; @Nullable public Long getStartDate() { return startDate; } public void setStartDate(final long startDate) { this.startDate = startDate; } }
childColumns = "book_id"), @ForeignKey(entity = User.class, parentColumns = "id", childColumns = "user_id")}) @TypeConverters(DateConverter.class) public class Loan { public @PrimaryKey String id; public Date startTime; public Date endTime; @ColumnInfo(name="book_id") public String bookId; @ColumnInfo(name="user_id") public String userId; } Foreign Key
public final int id; @SerializedName("name") public final String name; @SerializedName("full_name") public final String fullName; ... @SerializedName("owner") @Embedded(prefix = "owner_") public final Owner owner; ... } Nested Objects public class Owner { @SerializedName("login") public final String login; @SerializedName("url") public final String url; ... }
= _cursor.getColumnIndexOrThrow("id"); final int _cursorIndexOfName = _cursor.getColumnIndexOrThrow("name"); final int _cursorIndexOfLastName = _cursor.getColumnIndexOrThrow("lastName"); final int _cursorIndexOfAge = _cursor.getColumnIndexOrThrow("age"); final List<User> _result = new ArrayList<User>(_cursor.getCount()); while(_cursor.moveToNext()) { final User _item; _item = new User(); _item.id = _cursor.getString(_cursorIndexOfId); _item.name = _cursor.getString(_cursorIndexOfName); _item.lastName = _cursor.getString(_cursorIndexOfLastName); _item.age = _cursor.getInt(_cursorIndexOfAge); _result.add(_item); } return _result; UserDao_Impl implements UserDao (2/3)
= 1) public abstract class AppDatabase extends RoomDatabase { public abstract UserDao userModel(); public abstract BookDao bookModel(); public abstract LoanDao loanModel(); ... } Database
table_id) where version is an auto-increment primary key and a table_id (hardcoded int from initialization). ObservedTableTracker tracks list of tables we should be watching (e.g. adding triggers for). Before each beginTransaction, RoomDatabase invokes InvalidationTracker to sync trigger states. After each endTransaction, RoomDatabase invokes InvalidationTracker to refresh invalidated tables. Each update on one of the observed tables triggers an insertion into this table, hence a new version. Unfortunately, we cannot override the previous row because sqlite uses the conflict resolution of the outer query (the thing that triggered us) so we do a cleanup as we sync instead of letting SQLite override the rows. https://sqlite.org/lang_createtrigger.html: An ON CONFLICT clause may be specified as part of an UPDATE or INSERT action within the body of the trigger. However if an ON CONFLICT clause is specified as part of the statement causing the trigger to fire, then conflict handling policy of the outer statement is used instead.
collection of arguments Querying multiple tables Indices and uniqueness @Query Observable queries type converters Relationships Passing parameters into the query RxJava Nested objects Returning subsets of columns Direct cursor access