Skip to content

Commit

Permalink
Add pre save/delete handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Jun 10, 2022
1 parent 77d6011 commit 6f2df02
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 1 deletion.
Binary file modified memory
Binary file not shown.
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.3</version>
<version>1.2.4</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/craftmend/storm/Storm.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public <T extends StormModel> CompletableFuture<Collection<T>> findAll(Class<T>
*/
public void delete(StormModel model) throws SQLException {
catchState();
model.preDelete();
ModelParser parser = registeredModels.get(model.getClass());
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");
Expand Down Expand Up @@ -264,6 +265,7 @@ public <T extends StormModel> ModelParser<T> getParsedModel(Class<T> m, boolean
*/
public int save(StormModel model) throws SQLException {
catchState();
model.preSave();
String updateOrInsert = "update %tableName set %psUpdateValues where id=%id";
String insertStatement = "insert into %tableName(%insertVars) values(%insertValues);";

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/craftmend/storm/api/StormModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ public StatementBuilder statements() {
return statementBuilder;
}

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

}
Binary file modified test-data/mass-test.db
Binary file not shown.
Binary file removed test-data/mass-test.db-journal
Binary file not shown.
Binary file modified test-data/relation-test.db
Binary file not shown.

0 comments on commit 6f2df02

Please sign in to comment.