From 6232ea6d2804b9488aa1c9c2dbeb99d32da130df Mon Sep 17 00:00:00 2001 From: Jeremy The SuperGeek Date: Tue, 20 Oct 2015 13:18:36 -0500 Subject: [PATCH] added convenience method for first() and all(). changed save() from final to overridable. Sometimes one might want to be able to wrap the save command with additional functionality, like logging, or creation of new relationship objects, etc. --- src/com/activeandroid/Model.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/com/activeandroid/Model.java b/src/com/activeandroid/Model.java index 421426ea3..dc256899a 100644 --- a/src/com/activeandroid/Model.java +++ b/src/com/activeandroid/Model.java @@ -71,7 +71,7 @@ public final void delete() { .notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null); } - public final Long save() { + public Long save() { final SQLiteDatabase db = Cache.openDatabase(); final ContentValues values = new ContentValues(); @@ -175,6 +175,14 @@ public static T load(Class type, long id) { return (T) new Select().from(type).where(tableInfo.getIdName()+"=?", id).executeSingle(); } + public static List all(Class type) { + return (List) new Select().from(type).execute(); + } + + public static T first(Class type) { + return (T) new Select().from(type).executeSingle(); + } + // Model population public final void loadFromCursor(Cursor cursor) {