From 6ecde85adc91754a60a64827fd978845cfe5259a Mon Sep 17 00:00:00 2001 From: Mats Date: Tue, 14 Jun 2022 13:57:51 +0200 Subject: [PATCH] Post save --- pom.xml | 2 +- src/main/java/com/craftmend/storm/Storm.java | 3 +++ src/main/java/com/craftmend/storm/api/StormModel.java | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6afaa75..a6724e1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.craftmend storm - 1.2.4 + 1.2.5 1.8 diff --git a/src/main/java/com/craftmend/storm/Storm.java b/src/main/java/com/craftmend/storm/Storm.java index eff7330..e14e663 100644 --- a/src/main/java/com/craftmend/storm/Storm.java +++ b/src/main/java/com/craftmend/storm/Storm.java @@ -238,6 +238,7 @@ public void delete(StormModel model) throws SQLException { if (parser == null) throw new IllegalArgumentException("The model " + model.getClass().getName() + " isn't loaded. Please call storm.migrate() with an empty instance"); if (model.getId() == null) throw new IllegalArgumentException("This model doesn't have an ID"); driver.executeUpdate("DELETE FROM " + parser.getTableName() + " WHERE id=" + model.getId()); + model.postDelete(); } public ModelParser getParsedModel(Class m, boolean loadIfNotFound) { @@ -317,8 +318,10 @@ public int save(StormModel model) throws SQLException { if (model.getId() == null) { int o = driver.executeUpdate(insertStatement, preparedValues); model.setId(o); + model.postSave(); return o; } else { + model.postSave(); return driver.executeUpdate(updateOrInsert, preparedValues); } } diff --git a/src/main/java/com/craftmend/storm/api/StormModel.java b/src/main/java/com/craftmend/storm/api/StormModel.java index dfa3d0a..f0a42a7 100644 --- a/src/main/java/com/craftmend/storm/api/StormModel.java +++ b/src/main/java/com/craftmend/storm/api/StormModel.java @@ -38,5 +38,7 @@ public StatementBuilder statements() { public void preSave() {} public void preDelete() {} + public void postSave() {} + public void postDelete() {} }