Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/de/igslandstuhl/database/api/SchoolClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public List<Student> getStudents() {

public void delete() throws SQLException {
Server.getInstance().getConnection().executeVoidProcessSecure(SQLHelper.getDeleteObjectProcess("class", String.valueOf(id)));
getStudents().forEach((s) -> {
try {
s.delete();
} catch (SQLException e) {
e.printStackTrace();
throw new IllegalStateException(e);
}
});
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/igslandstuhl/database/api/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ public void clearSubjectRequest(int subjectId) {
currentRequests.remove(subjectId);
}

public void delete() throws SQLException {
Server.getInstance().getConnection().executeVoidProcessSecure(SQLHelper.getDeleteObjectProcess("student", String.valueOf(id)));
students.remove(id);
}

@Override
public String toString() {
return toJSON();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/de/igslandstuhl/database/api/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -236,6 +237,22 @@ public void delete() throws SQLException {
SQLHelper.getDeleteObjectProcess("subject", String.valueOf(id))
);
subjects.remove(id);
try {
Arrays.stream(getGrades()).mapToObj(this::getTopics).forEach((l) -> l.forEach((t) -> {
try {
t.delete();
} catch (SQLException e) {
e.printStackTrace();
throw new IllegalStateException(e);
}
}));
} catch (IllegalStateException e) {
if (e.getCause() != null && e.getCause() instanceof SQLException ex) {
throw ex;
} else {
throw e;
}
}
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/igslandstuhl/database/api/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public void removeFromCache() {
tasks.remove(id);
}

public void delete() throws SQLException {
Server.getInstance().getConnection().executeVoidProcessSecure(SQLHelper.getDeleteObjectProcess("task", String.valueOf(id)));
removeFromCache();
}

/**
* Creates a Task object from SQL query result fields.
*
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/de/igslandstuhl/database/api/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ public static Topic addTopic(String name, Subject subject, int ratio, int grade,
public void delete() throws SQLException {
Server.getInstance().getConnection().executeVoidProcessSecure(SQLHelper.getDeleteObjectProcess("topic", String.valueOf(id)));
topics.remove(id);
tasks.forEach(Task::removeFromCache);
tasks.forEach(t -> {
try {
t.delete();
} catch (SQLException e) {
throw new IllegalStateException(e);
}
});
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/sql/pushes/delete_student.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DELETE FROM students
WHERE id = {0}
2 changes: 2 additions & 0 deletions src/main/resources/sql/pushes/delete_task.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DELETE FROM tasks
WHERE id = {0}
Loading