All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dk.apaq.crud.core.BaseCompleteCrud Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
/*
 * CrudContainer
 * Copyright (C) 2011 by Apaq
 *
 * 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 .
 */
package dk.apaq.crud.core;

import dk.apaq.crud.Crud;
import dk.apaq.crud.CrudEvent;
import dk.apaq.crud.CrudListener;
import dk.apaq.filter.Filter;
import dk.apaq.filter.limit.Limit;
import dk.apaq.filter.sort.Sorter;
import java.util.List;

/**
 * An abstract implementation of a Crud.Complete instance taking care
 * of CrudNotifer logic. An implementing class needs only to call the fire* methods(fx. fireOnRead)
 * and this class will make sure to fire events on the listeners.
 */
public abstract class BaseCompleteCrud extends BaseCrud implements Crud.Complete {
    /**
     * Tells listeners that a new entity is about to be created.
     */
    protected void fireOnBeforeCreate(BT entity) {
        CrudEvent.WithEntity e = createEventWithEntity(entity);

        for (CrudListener listener : getListeners()) {
            listener.onBeforeEntityCreate(e);
        }
    }

    /**
     * Tells listeners that an entity is about to be updated.
     * @param entity The entity that holds changes and is about to be persisted.
     */
    protected void fireOnBeforeUpdate(IDT id, BT entity) {
        CrudEvent.WithIdAndEntity e = createEventWithIdAndEntity(id, entity);

        for (CrudListener listener : getListeners()) {
            listener.onBeforeEntityUpdate(e);
        }
    }

    /**
     * Tells listeners that an eneity is about to be deleted.
     * @param id The id of the entity that is about to be deleted.
     */
    protected void fireOnBeforeDelete(IDT id) {
        CrudEvent.WithId e = createEventWithId(id);
        for (CrudListener listener : getListeners()) {
            listener.onBeforeEntityDelete(e);
        }
    }

    /**
     * Tells listeners that an entity has been created.
     * @param entity The entity that was created.
     */
    protected void fireOnCreate(IDT id, BT entity) {
        CrudEvent.WithIdAndEntity e = createEventWithIdAndEntity(id, entity);

        for (CrudListener listener : getListeners()) {
            listener.onEntityCreate(e);
        }
    }

    /**
     * Tells listeners that an entity was updated.
     * @param entity The entity that was updated.
     */
    protected void fireOnUpdate(IDT id, BT entity) {
        CrudEvent.WithIdAndEntity e = createEventWithIdAndEntity(id, entity);

        for (CrudListener listener : getListeners()) {
            listener.onEntityUpdate(e);
        }
    }

    /**
     * Tells listeners that an entity was deleted.
     * @param id The id of the entity that was deleted.
     */
    protected void fireOnDelete(IDT id) {
        CrudEvent.WithId e = createEventWithId(id);
        for (CrudListener listener : getListeners()) {
            listener.onEntityDelete(e);
        }
    }


    /**
     * {@inheritDoc}
     */
    public List listIds(Limit limit) {
        return listIds(null, null, limit);
    }

    /**
     * {@inheritDoc}
     */
    public List listIds(Filter filter, Sorter sorter) {
        return listIds(filter, sorter, null);
    }

    /**
     * {@inheritDoc}
     */
    public List list(Limit limit) {
        return list(null, null, limit);
    }

    /**
     * {@inheritDoc}
     */
    public List list(Filter filter, Sorter sorter) {
        return list(filter, sorter, null);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy