
package org.jbromo.service.crud;

import java.io.Serializable;

import org.jbromo.common.invocation.InvocationUtil;
import org.jbromo.common.invocation.ParameterizedTypeUtil;

/**
 * The class for implementation of CRUD services.
 * 
 * @author qjafcunuas
 * @param <M>
 *            the model type.
 * @param <P>
 *            the primary key type.
 */
public abstract class AbstractCrudService<M extends Serializable, P extends Serializable>
        implements ICRUDService<M, P> {

    /**
     * Serial version UID for class.
     */
    private static final long serialVersionUID = -4053211327121284550L;

    /**
     * The model class.
     */
    private Class<M> modelClass;

    /**
     * Default constructor.
     */
    public AbstractCrudService() {
        super();
    }

    /**
     * Return the model class.
     *
     * @return the model class.
     */
    protected Class<M> getModelClass() {
        if (this.modelClass == null) {
            this.modelClass = ParameterizedTypeUtil.getGenericType(
                    InvocationUtil.getField(getClass(), "modelClass"), 0);
        }
        return this.modelClass;
    }

}
