CriteriaSearchParameter.java

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by hibernate/HibernateSearchParameter.vsl in andromda-spring-cartridge. Do not modify by hand!.
//
package org.andromda.samples.animalquiz;

import java.util.regex.Pattern;
import org.hibernate.criterion.MatchMode;

/**
 * A <code>CriteriaSearchParameter</code> represents a parameter for a <code>CriteriaSearch</code>.
 * <br>
 * <br>
 * The <code>parameterValue</code> is the actual value to be searched for.
 * <br>
 * <br>
 * The <code>parameterPattern</code> describes the actual parameter which shall be considered for
 * the search. It contains the dot-separated path and the name of the parameter starting at the
 * rootEntity of the actual <code>CriteriaSearch</code>. The pattern of a the street of an address
 * of a person would look like <i>address.street </i> (assuming the entity structure to be
 * <code>aPerson.getAddress().getStreet()</code>).
 * <br>
 * <br>
 * Usually, if a parameter is <code>null</code> (or if the parameter is of type <code>String</code>
 * and empty), it is not considered for a search. If <code>searchIfNull</code> is <code>true</code>
 * it is explicitly searched for the parameter to be null (or empty if the parameter is of type
 * <code>String</code>).<br>
 * <br>
 * The <code>comparator</code> defines the comparator for the parameter. For parameters of type
 * <code>String</code> the default comparator is the <code>LIKE_COMPARATOR</code>. The
 * <code>EQUAL_COMPARATOR</code> is default for other parameters.
 *
 * @author Stefan Reichert
 * @author Peter Friese
 * @author Chad Brandon
 */
public class CriteriaSearchParameter
    extends SearchParameter
{
    /** Compiled pattern \\. */
    public static final Pattern PATTERN = Pattern.compile("\\.");

    /** Order relevance not set */
    public static final int RELEVANCE_UNSET = -1;

    private Object parameterValue;
    private String parameterPattern;
    private MatchMode matchMode = null;
    private int orderDirection = ORDER_UNSET;
    private int orderRelevance = RELEVANCE_UNSET;

    /**
     * Constructor for CriteriaSearchParameter. Sets <code>searchIfNull</code> to
     * <code>false</code> and uses the <code>EQUAL_COMPARATOR</code>.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     */
    public CriteriaSearchParameter(Object parameterValueIn, String parameterPatternIn)
    {
        this(parameterValueIn, parameterPatternIn, false, EQUAL_COMPARATOR);
    }

    /**
     * Constructor for CriteriaSearchParameter for a <code>String</code> parameter.
     * Sets <code>searchIfNull</code> to <code>false</code> and uses the
     * <code>LIKE_COMPARATOR</code>.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     */
    public CriteriaSearchParameter(String parameterValueIn, String parameterPatternIn)
    {
        this(parameterValueIn, parameterPatternIn, false, LIKE_COMPARATOR);
    }

    /**
     * Constructor for CriteriaSearchParameter for a <code>String[]</code> parameter.
     * Sets <code>searchIfNull</code> to <code>false</code> and uses the
     * <code>LIKE_COMPARATOR</code>.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     */
    public CriteriaSearchParameter(String[] parameterValueIn, String parameterPatternIn)
    {
        this(parameterValueIn, parameterPatternIn, false, LIKE_COMPARATOR);
    }

    /**
     * Constructor for CriteriaSearchParameter. Sets <code>searchIfNull</code> to <code>false</code>.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param comparatorIn
     */
    public CriteriaSearchParameter(Object parameterValueIn, String parameterPatternIn, int comparatorIn)
    {
        this(parameterValueIn, parameterPatternIn, false, comparatorIn);
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     */
    public CriteriaSearchParameter(
        Object parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull)
    {
        this(parameterValueIn, parameterPatternIn, searchIfNull, EQUAL_COMPARATOR);
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     */
    public CriteriaSearchParameter(
        String parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull)
    {
        this(parameterValueIn, parameterPatternIn, searchIfNull, LIKE_COMPARATOR);
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     */
    public CriteriaSearchParameter(
        String[] parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull)
    {
        this(parameterValueIn, parameterPatternIn, searchIfNull, LIKE_COMPARATOR);
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...).
     */
    public CriteriaSearchParameter(
        Object parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull,
        int comparatorIn)
    {
        super(parameterPatternIn, parameterValueIn);
        this.parameterValue = parameterValueIn;
        this.parameterPattern = parameterPatternIn;
        super.setSearchIfNull(searchIfNull);
        this.setComparator(comparatorIn);
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        Object parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull,
        MatchMode matchModeIn)
    {
         this(parameterValueIn, parameterPatternIn, searchIfNull);
         this.matchMode = matchModeIn;
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        String parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull,
        MatchMode matchModeIn)
    {
        this(parameterValueIn, parameterPatternIn, searchIfNull);
        this.matchMode = matchModeIn;
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        String[] parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull,
        MatchMode matchModeIn)
    {
        this(parameterValueIn, parameterPatternIn, searchIfNull);
        this.matchMode = matchModeIn;
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param searchIfNull Indicates whether the query should contain an
     *     <code>IS NULL</code> if the parameter is <code>null</code>.
     * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...).
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        String parameterValueIn,
        String parameterPatternIn,
        boolean searchIfNull,
        int comparatorIn,
        MatchMode matchModeIn)
    {
        this(parameterValueIn, parameterPatternIn, searchIfNull, comparatorIn);
        this.matchMode = matchModeIn;
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...).
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        Object parameterValueIn,
        String parameterPatternIn,
        int comparatorIn,
        MatchMode matchModeIn)
    {
        this(parameterValueIn, parameterPatternIn, comparatorIn);
        this.matchMode = matchModeIn;
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        Object parameterValueIn,
        String parameterPatternIn,
        MatchMode matchModeIn)
    {
        this(parameterValueIn, parameterPatternIn);
        this.matchMode = matchModeIn;
    }

    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        String parameterValueIn,
        String parameterPatternIn,
        MatchMode matchModeIn)
    {
        this(parameterValueIn, parameterPatternIn);
        this.matchMode = matchModeIn;
    }


    /**
     * Constructor for CriteriaSearchParameter.
     *
     * @param parameterValueIn The actual value of the parameter.
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     * @param matchModeIn The hibernate matchmode to be used in string comparisons.
     */
    public CriteriaSearchParameter(
        String[] parameterValueIn,
        String parameterPatternIn,
        MatchMode matchModeIn)
    {
        this(parameterValueIn, parameterPatternIn);
        this.matchMode = matchModeIn;
    }

    /**
     * @return The pattern of this parameter (dot-separated path e.g. person.address.street).
     */
    public String getParameterPattern()
    {
        return this.parameterPattern;
    }

    /**
     * Sets the pattern of this parameter.
     *
     * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
     */
    public void setParameterPattern(String parameterPatternIn)
    {
        this.parameterPattern = parameterPatternIn;
    }

    /**
     * Parse the parameter pattern and return the last part of the name.
     *
     * @param parameterPatternIn The parameter pattern.
     * @return The last part of the parameter pattern, i.e. the attribute name.
     */
    private String parseParameterName(String parameterPatternIn)
    {
        // parsing the pattern of the parameter
        String[] path = CriteriaSearchParameter.PATTERN.split(parameterPatternIn);
        return path[path.length - 1];
    }

    /**
     * @return The last part of the parameter pattern, i.e. the attribute name.
     */
    public String getParameterName()
    {
        return parseParameterName(this.parameterPattern);
    }

    /**
     * @return The value of this parameter.
     */
    public Object getParameterValue()
    {
        return this.parameterValue;
    }

    /**
     * Sets the value of this parameter.
     *
     * @param parameterValueIn The value of this parameter.
     */
    public void setParameterValue(Object parameterValueIn)
    {
        this.parameterValue = parameterValueIn;
    }

    /**
     * @return The hibernate matchmode of this parameter.
     */
    public MatchMode getMatchMode()
    {
        return this.matchMode;
    }

    /**
     * Sets the hibernate matchmode of this parameter.
     *
     * @param matchModeIn The hibernate matchmode.
     */
    public void setMatchMode(MatchMode matchModeIn)
    {
        this.matchMode = matchModeIn;
    }

    /**
     * @return The order (ascending or descending) for this parameter.
     * @see SearchParameter#ORDER_ASC
     * @see SearchParameter#ORDER_DESC
     * @see SearchParameter#ORDER_UNSET
     */
    public int getOrderDirection()
    {
        return this.orderDirection;
    }

    /**
     * Sets the ordering for this parameter.
     *
     * @param orderDirectionIn The ordering for this parameter.
     */
    public void setOrderDirection(int orderDirectionIn)
    {
        this.orderDirection = orderDirectionIn;
    }

    /**
     * @return The relevance for this parameter.
     * @see SearchParameter#ORDER_UNSET
     */
    public int getOrderRelevance()
    {
        return this.orderRelevance;
    }

    /**
     * Sets the ordering relevance for this parameter.
     *
     * @param relevanceIn The ordering relevance for this parameter.
     */
    public void setOrderRelevance(int relevanceIn)
    {
        this.orderRelevance = relevanceIn;
    }

    private static final long serialVersionUID = 1L;
}