package com.acme.structure;


import com.acme.structure.util.ObjectUtil;
import com.acme.structure.util.StringUtility;

import java.io.Serializable;

import javax.persistence.EntityManager;
import javax.persistence.Query;


public abstract class BaseFilter implements Serializable
{
    protected Object object;

    protected BaseFilter(Object object)
    {
        this.object = object;
    }

    protected boolean isNull(Object object)
    {
        return ObjectUtil.isNull(object);
    }

    protected boolean isNullOrEmpty(String stringValue)
    {
        return StringUtility.isNullOrEmpty(stringValue);
    }

    // method to check mandatory fields are supplied

    public void checkSearchFields() throws Exception
    {
        if (object == null)
            throw new Exception("MissingCriteriaException");
    }

    // default query excecution method

    abstract public Query createQuery(EntityManager manager);

    public Object getObject()
    {
        return this.object;
    }

}
