Skip to content

Commit

Permalink
Feat: Do not delete the Questions and Answers from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
UO283615 committed Apr 19, 2024
1 parent 97945e9 commit 45517e1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 27 deletions.
3 changes: 0 additions & 3 deletions questiongenerator/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
public class Main {

public static void main(String[] args) {
// Deletes all questions and answers from the DB
GeneralRepositoryStorer.clearAllQA();

//Edit constraints of the DB
GeneralRepositoryStorer.editConstraints();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,6 @@
*/
public class GeneralRepositoryStorer {

/**
* Removes all questions and answers from the DB using SQL queries on cascade.
*/
public static void clearAllQA() {
try{
EntityManagerFactory emf = Jpa.getEntityManagerFactory();
EntityManager entityManager = emf.createEntityManager();

entityManager.getTransaction().begin();

entityManager.createNativeQuery("DELETE FROM games_questions").executeUpdate();
entityManager.createNativeQuery("DELETE FROM questions_answers").executeUpdate();
entityManager.createNativeQuery("DELETE FROM questions").executeUpdate();
entityManager.createNativeQuery("DELETE FROM answers").executeUpdate();

entityManager.getTransaction().commit();

entityManager.close();
Jpa.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public void saveAll(List<Storable> storableList) {
EntityManagerFactory emf = Jpa.getEntityManagerFactory();
EntityManager entityManager = emf.createEntityManager();
Expand Down

0 comments on commit 45517e1

Please sign in to comment.