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(); 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); + } } } } 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; }