#22 story/medikamente-modul-grundimplementierung #34
1 changed files with 25 additions and 2 deletions
|
@ -3,7 +3,11 @@ package de.hitec.nhplus.medication.database;
|
|||
import de.hitec.nhplus.datastorage.Dao;
|
||||
import de.hitec.nhplus.medication.Ingredient;
|
||||
import de.hitec.nhplus.medication.Medication;
|
||||
import java.sql.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -118,6 +122,25 @@ public class MedicationDao implements Dao<Medication> {
|
|||
preparedStatement.setInt(5, medication.getCurrentStock());
|
||||
preparedStatement.setInt(6, medication.getId());
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
final String ingredientDeleteSQL = """
|
||||
DELETE FROM medication_ingredient WHERE id = ?
|
||||
""";
|
||||
PreparedStatement ingredientStatement = this.connection.prepareStatement(ingredientDeleteSQL);
|
||||
ingredientStatement.setInt(1, medication.getId());
|
||||
ingredientStatement.executeUpdate();
|
||||
|
||||
final String ingredientCreateSQL = """
|
||||
INSERT INTO medication_ingredient
|
||||
(id, name)
|
||||
VALUES (?, ?);
|
||||
""";
|
||||
for (Ingredient ingredient : medication.getIngredients()) {
|
||||
PreparedStatement statement = this.connection.prepareStatement(ingredientCreateSQL);
|
||||
statement.setInt(1, medication.getId());
|
||||
statement.setString(2, ingredient.getName());
|
||||
statement.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue