From 7ebf1479d7756bf1cd952166594e43c4ae46a34d Mon Sep 17 00:00:00 2001 From: zzss Date: Wed, 28 Jan 2015 23:21:56 +0100 Subject: [PATCH 1/3] Added lifecycle events: preInsert(), preUpdate(), preSave(), and their postXY counterparts --- src/com/activeandroid/Model.java | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/com/activeandroid/Model.java b/src/com/activeandroid/Model.java index 421426ea3..e8cd2f915 100644 --- a/src/com/activeandroid/Model.java +++ b/src/com/activeandroid/Model.java @@ -70,8 +70,37 @@ public final void delete() { Cache.getContext().getContentResolver() .notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null); } - + public final Long save() { + boolean isNew = (mId == null); + + if (isNew) { + preInsert(); + } else { + preUpdate(); + } + + preSave(); + Long result = doSave(); + postSave(); + + if (isNew) { + postInsert(); + } else { + postUpdate(); + } + + return result; + } + + protected void preInsert() {} + protected void preUpdate() {} + protected void preSave() {} + protected void postSave() {} + protected void postInsert() {} + protected void postUpdate() {} + + private final Long doSave() { final SQLiteDatabase db = Cache.openDatabase(); final ContentValues values = new ContentValues(); From ae855e9beb8b4e258f01efb5b67a3d75efffa21f Mon Sep 17 00:00:00 2001 From: zzss Date: Sat, 28 Feb 2015 14:17:44 +0100 Subject: [PATCH 2/3] Catch IncompatibleClassChangeError when scanning for model classes --- src/com/activeandroid/ModelInfo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/com/activeandroid/ModelInfo.java b/src/com/activeandroid/ModelInfo.java index 09e79117c..fb8ccc0ac 100644 --- a/src/com/activeandroid/ModelInfo.java +++ b/src/com/activeandroid/ModelInfo.java @@ -204,6 +204,9 @@ else if (ReflectionUtils.isTypeSerializer(discoveredClass)) { catch (IllegalAccessException e) { Log.e("IllegalAccessException", e); } + catch (IncompatibleClassChangeError e) { + Log.e("IncompatibleClassChangeError", e); + } } } } From 2ef6ff74c31251fb3abf50a63cf79a06f7f5125d Mon Sep 17 00:00:00 2001 From: zzss Date: Mon, 2 Mar 2015 19:33:14 +0100 Subject: [PATCH 3/3] Changed default id name to lowercase 'id' --- src/com/activeandroid/annotation/Table.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/activeandroid/annotation/Table.java b/src/com/activeandroid/annotation/Table.java index 541dfbe92..d0762bd3b 100644 --- a/src/com/activeandroid/annotation/Table.java +++ b/src/com/activeandroid/annotation/Table.java @@ -25,7 +25,7 @@ @Retention(RetentionPolicy.RUNTIME) public @interface Table { - public static final String DEFAULT_ID_NAME = "Id"; + public static final String DEFAULT_ID_NAME = "id"; public String name(); public String id() default DEFAULT_ID_NAME; }