Skip to content
EntitiesContainer.java 2.19 KiB
Newer Older
package it.inaf.oats.ia2.tapschemamanager.api.contract;

import java.sql.SQLException;
import java.util.List;

/**
 * Objects of this class contain zero or more {@link ChildEntity} objects.
 *
 * @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
 */
public interface EntitiesContainer<T extends ChildEntity> {

    /**
     * Returns a specific child of the container, selecting it by name and
     * filtering it by a set of possible status: if the child doesn't have one
     * of the status specified, this method returns null.<br>
     * <strong>If no status is specified it is assumed that all status are
     * valid.</strong>
     */
    T getChild(String childName, Status... status);

    /**
     * Add a {@link ChildEntity} specifying its name. If the child entity has
     * never been read from the database it is loaded when this method is
     * called. If the entity was marked as removed, it will marked as added
     * again.
     */
    T addChild(String childName) throws SQLException;

    /**
     * Remove a {@link ChildEntity} specifying its name.<br>
     * The child isn't really removed but only marked as removed (the removal
     * will happen when the {@link TapSchema#save()} method will be called).
     */
    void removeChild(String childName);

    /**
     * Retrieve a list of names of child entities that can be added.<br> The
     * list contains only names of entities that have never been added: entities
     * which instance don't exist yet or entities having
     * {@link Status} {@code LOADED}.
     */
    List<String> getAddableChildrenNames();

    /**
     * Retrieve a list of children filtering them by a set of possible
     * status.<br>
     * <strong>If no status is specified it is assumed that all status are
     * valid.</strong>
     */
    List<T> getChildren(Status... statuses);

    /**
     * Retrieve all children having {@link Status} {@code ADDED_PERSISTED} or
     * {@code ADDED_NOT_PERSISTED}.
     */
    List<T> getAddedChildren();

    /**
     * Retrieve all children having {@link Status} {@code ADDED_PERSISTED},
     * {@code ADDED_NOT_PERSISTED}, {@code TO_REMOVE} or
     * {@code REMOVED_NOT_PERSISTED}.
     */
    List<T> getAddedOrRemovedChildren();
}