Skip to content

Commit

Permalink
Post save
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Jun 14, 2022
1 parent 6f2df02 commit 6ecde85
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.craftmend</groupId>
<artifactId>storm</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/craftmend/storm/Storm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends StormModel> ModelParser<T> getParsedModel(Class<T> m, boolean loadIfNotFound) {
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/craftmend/storm/api/StormModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public StatementBuilder statements() {

public void preSave() {}
public void preDelete() {}
public void postSave() {}
public void postDelete() {}

}

0 comments on commit 6ecde85

Please sign in to comment.