Skip to content
Snippets Groups Projects
Commit e310324e authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add playout log delete function

parent c53097bd
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@ public class PlayoutLogPlugin implements PlayPadPluginStub, PluginArtifact {
try {
LogSeasons.getStorageHandler().close();
} catch (RuntimeException e) {
} catch (Exception e) {
Logger.log(LogLevel.ERROR, "Cannot close LogSeasonStorageHandler (" + e.getLocalizedMessage() + ")");
}
}
......
......@@ -41,6 +41,10 @@ public class LogSeasons {
return getStorageHandler().getAllLogSeasonsLazy();
}
public static void deleteSession(int id) {
getStorageHandler().deleteSession(id);
};
public static LogSeason getLogSeason(int id) {
return getStorageHandler().getLogSeason(id);
}
......
......@@ -6,7 +6,8 @@ import de.tobias.playpad.plugin.playout.log.PlayOutItem;
import java.util.List;
public interface LogSeasonStorageHandler {
public interface LogSeasonStorageHandler extends AutoCloseable {
void addLogSeason(LogSeason season);
void addLogItem(LogItem item);
......@@ -17,10 +18,5 @@ public interface LogSeasonStorageHandler {
List<LogSeason> getAllLogSeasonsLazy();
/**
* Close the storage handler.
*
* @throws RuntimeException fail to close handler (e.g. sql error)
*/
void close();
void deleteSession(int id);
}
package de.tobias.playpad.plugin.playout.storage;
import de.thecodelabs.logger.LogLevel;
import de.thecodelabs.logger.Logger;
import de.tobias.playpad.plugin.playout.log.LogItem;
import de.tobias.playpad.plugin.playout.log.LogSeason;
......@@ -51,7 +50,7 @@ public class SqlLiteLogSeasonStorageHandler implements LogSeasonStorageHandler {
}
}
} catch (SQLException e) {
Logger.log(LogLevel.ERROR, e.getLocalizedMessage());
Logger.error(e);
}
}
......@@ -124,7 +123,7 @@ public class SqlLiteLogSeasonStorageHandler implements LogSeasonStorageHandler {
}
}
} catch (SQLException e) {
Logger.log(LogLevel.ERROR, e.getLocalizedMessage());
Logger.error(e);
}
return null;
}
......@@ -149,7 +148,7 @@ public class SqlLiteLogSeasonStorageHandler implements LogSeasonStorageHandler {
}
}
} catch (SQLException e) {
Logger.log(LogLevel.ERROR, e.getLocalizedMessage());
Logger.error(e);
}
return logItems;
}
......@@ -172,11 +171,31 @@ public class SqlLiteLogSeasonStorageHandler implements LogSeasonStorageHandler {
}
}
} catch (SQLException e) {
Logger.log(LogLevel.ERROR, e.getLocalizedMessage());
Logger.error(e);
}
return playOutItems;
}
@Override
public void deleteSession(int id) {
try (PreparedStatement deletePlayoutItems = connection.prepareStatement("DELETE FROM PlayOutItem WHERE uuid IN (SELECT uuid FROM LogItem l WHERE l.logSeason = ?)")) {
deletePlayoutItems.setInt(1, id);
deletePlayoutItems.execute();
try (PreparedStatement deleteLogItems = connection.prepareStatement("DELETE FROM LogItem WHERE logSeason = ?")) {
deleteLogItems.setInt(1, id);
deleteLogItems.execute();
}
try (PreparedStatement deleteLogSeason = connection.prepareStatement("DELETE FROM LogSeason WHERE id = ?")) {
deleteLogSeason.setInt(1, id);
deleteLogSeason.execute();
}
} catch (SQLException e) {
Logger.error(e);
}
}
@Override
public void close() throws RuntimeException {
if (connection != null) {
......
......@@ -140,7 +140,10 @@ public class PlayoutLogViewController extends NVC {
@FXML
private void deleteButtonHandler(ActionEvent event) {
getSelectedLogSeason().ifPresent(season -> { // Lazy Season
LogSeasons.deleteSession(season.getId());
logList.getItems().remove(season);
});
}
@FXML
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment