/*
 * SportChef – Sports Competition Management Software
 * Copyright (C) 2016 Marcus Fihlon
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ch.sportchef.business.event.control;

import ch.sportchef.business.PersistenceManager;
import ch.sportchef.business.event.entity.Event;
import pl.setblack.airomem.core.SimpleController;

import javax.inject.Singleton;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Optional;

@Singleton
public class EventService {

    private final SimpleController<EventRepository> controller =
            PersistenceManager.createSimpleController(Event.class, EventRepository::new);

    public Event create(@NotNull final Event event) {
        return controller.executeAndQuery((mgr) -> mgr.create(event));
    }

    public Event update(@NotNull final Event event) {
        return controller.executeAndQuery((mgr) -> mgr.update(event));
    }

    public Optional<Event> findByEventId(@NotNull final Long eventId) {
        return controller.readOnly().findByEventId(eventId);
    }

    public List<Event> findAll() {
        return controller.readOnly().findAll();
    }

    public void delete(@NotNull final Long eventId) {
        controller.execute((mgr) -> mgr.delete(eventId));
    }
}

@@ -955,16 +955,52 @@
 oller;%0A%0A
+import javax.annotation.PreDestroy;%0A
 import j
@@ -1314,16 +1314,101 @@
 :new);%0A%0A
+    @PreDestroy%0A    private void takeSnapshot() %7B%0A        controller.close();%0A    %7D%0A%0A
     publ

Create a snopshot of the event repository on server shutdown