View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.services.search.criterias;
18  
19  /**
20   * Criteria for the like pattern.
21   *
22   * @svnLink $Revision: 3880 $;$Date: 2009-08-04 15:17:52 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/services/search/criterias/LikeCriteria.java $
23   *
24   * @author Martin Zeltner (MZE)
25   */
26  public class LikeCriteria extends AbstractCriteria {
27  	/**
28  	 * Marks whether the pattern is case sensitive.
29  	 */
30  	private Boolean m_caseSensitive;
31  	
32  	/**
33  	 * Default constructor for remoting protocols like hessian added.
34  	 */
35  	protected LikeCriteria() { }
36  	
37  	/**
38  	 * Hidden constructor.
39  	 *
40  	 * @param field Is the field the criteria is made for.
41  	 * @param value Is the value of this criteria.
42  	 * @param caseSensitive Marks if the pattern is case sensitive.
43  	 */
44  	protected LikeCriteria(String field, String value,
45  		boolean caseSensitive) {
46  		super(field, value);
47  		m_caseSensitive = Boolean.valueOf(caseSensitive);
48  	}
49  
50  	/**
51  	 * @param field Is the field the criteria is made for.
52  	 * @param value Is the value of this criteria.
53  	 * @return Returns a case insensitive pattern criteria.
54  	 */
55  	public static LikeCriteria caseInsensitive(String field, String value) {
56  		return new LikeCriteria(field, value, false);
57  	}
58  
59  	/**
60  	 * @param field Is the field the criteria is made for.
61  	 * @param value Is the value of this criteria.
62  	 * @return Returns a case sensitive pattern criteria.
63  	 */
64  	public static LikeCriteria caseSensitive(String field, String value) {
65  		return new LikeCriteria(field, value, true);
66  	}
67  
68  	/**
69  	 * @return Returns <code>true</code> if it is case sensitive.
70  	 */
71  	public final Boolean isCaseSensitive() {
72  		return m_caseSensitive;
73  	}
74  
75  	/**
76  	 * {@inheritDoc}
77  	 */
78  	public String getType() {
79  		return "like";
80  	}
81  
82  	/**
83  	 * {@inheritDoc}
84  	 */
85  	public String getSqlWhereCondition() {
86  		// TODO: consider also case sensitivity
87  		return " ( "+getField()+" LIKE "+getValue()+ " ) ";
88  	}
89  	
90  }