API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.persistance. JOTSQLCondition View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

/*
------------------------------------
JavaOnTracks          Thibaut Colar
tcolar-jot AT colar DOT net
Artistic Licence 2.0
http://www.javaontracks.net
------------------------------------
 */
package net.jot.persistance;

import net.jot.db.JOTDBField;

/**
 * Defines a single DB condition, as used in an SQL 'where' closed <br>
 * ie: 'firstname' IS_EQUAL 'John'
 * 
 * @author Thibaut Colar http://jot.colar.net/
 *
 */
public class JOTSQLCondition {
	public static final int IS_EQUAL=0;
	public static final int IS_NOT_EQUAL=1;
	public static final int IS_GREATER=2;
	public static final int IS_LOWER=3;
	public static final int IS_GREATER_OR_EQUAL=5;
	public static final int IS_LOWER_OR_EQUAL=6;
	public static final int IS_LIKE=7;
	
	private String field;
	private int comparaison;
	private Object value;
	
	public int getComparaison() 
	{
		return comparaison;
	}

	public String getField() 
	{
		return field;
	}

	public Object getValue() 
	{
		return value;
	}

	/**
	 * Create an SQL condition(used in where statement)
	 * 
	 * @param field    ie: 'firstname'
	 * @param comparaison ie: IS_EQUAL
	 * @param value ie: 'John'
	 */
	public JOTSQLCondition(String field, int comparaison, Object value)
	{
                field=JOTDBField.getCleanFieldName(field);

		this.value=value;
		this.comparaison=comparaison;
		this.field=field;
	}
	
        /**
         * Return the comparator in SQL form
         * example: getSQLComparator() for IS_GREATER will return " > ? "
         * @return
         */
	public String getSQLComparator()
	{
		String s=" = ?";
		switch(comparaison)
		{
			case IS_GREATER: s=" > ?";break;
			case IS_GREATER_OR_EQUAL:s=" >= ?";break;
			case IS_LOWER:s=" < ?";break;
			case IS_LOWER_OR_EQUAL:s=" <= ?";break;
			case IS_LIKE:s=" like ?";break;
			case IS_NOT_EQUAL:s=" <> ?";break;
		}
		return s;
	}

        public String getSqlString()
        {
            return new StringBuffer(field).append(getSQLComparator()).toString();
        }
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar