universe@34: /* universe@34: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@34: * universe@34: * Copyright 2018 Mike Becker. All rights reserved. universe@34: * universe@34: * Redistribution and use in source and binary forms, with or without universe@34: * modification, are permitted provided that the following conditions are met: universe@34: * universe@34: * 1. Redistributions of source code must retain the above copyright universe@34: * notice, this list of conditions and the following disclaimer. universe@34: * universe@34: * 2. Redistributions in binary form must reproduce the above copyright universe@34: * notice, this list of conditions and the following disclaimer in the universe@34: * documentation and/or other materials provided with the distribution. universe@34: * universe@34: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@34: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@34: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@34: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@34: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@34: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@34: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@34: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@34: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@34: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@34: * POSSIBILITY OF SUCH DAMAGE. universe@34: * universe@34: */ universe@34: package de.uapcore.lightpit.dao; universe@34: universe@34: import java.sql.SQLException; universe@128: import java.util.List; universe@34: universe@128: public interface RootEntityDao { universe@128: universe@128: /** universe@128: * Lists all entities. universe@128: * @return a list of all entities universe@128: * @throws SQLException on any kind of SQL errors universe@128: */ universe@128: List list() throws SQLException; universe@38: universe@38: /** universe@47: * Finds an entity by its integer ID. universe@75: * It is not guaranteed that referenced entities are automatically joined. universe@47: * universe@47: * @param id the id universe@47: * @return the enity or null if there is no such entity universe@47: * @throws SQLException on any kind of SQL errors universe@47: */ universe@47: T find(int id) throws SQLException; universe@47: universe@47: /** universe@38: * Inserts an instance into database. universe@75: * It is not guaranteed that generated fields will be updated in the instance. universe@38: * universe@38: * @param instance the instance to insert universe@38: * @throws SQLException on any kind of SQL errors universe@38: */ universe@38: void save(T instance) throws SQLException; universe@38: universe@38: /** universe@38: * Updates an instance in the database. universe@38: * universe@38: * @param instance the instance to insert universe@38: * @return true if an instance has been updated, false if no instance with the specified ID was found universe@38: * @throws SQLException on any kind of SQL errors universe@38: */ universe@38: boolean update(T instance) throws SQLException; universe@38: universe@38: /** universe@38: * Inserts or updates an instance in the database. universe@38: * Tries an update first and if that fails, performs a save. universe@38: * universe@38: * @param instance the instance to insert or update universe@38: * @throws SQLException on any kind of SQL errors universe@38: * @see #update(Object) universe@38: * @see #save(Object) universe@38: */ universe@38: default void saveOrUpdate(T instance) throws SQLException { universe@38: if (!update(instance)) save(instance); universe@38: } universe@34: }