KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > util > SqlEnum


1 package org.apache.torque.util;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */

21
22 /**
23  * A typesafe enum of SQL string fragments. Used by Criteria and SqlExpression
24  * to build queries. Criteria also makes most of the constants available
25  * in order to specify a criterion.
26  *
27  * @author <a HREF="mailto:jmcnally@collab.net"></a>
28  * @author <a HREF="mailto:fischer@seitenbau.de">Thomas Fischer</a>
29  * @version $Id: SqlEnum.java 473821 2006-11-11 22:37:25Z tv $
30  * @since 3.0
31  */

32 public class SqlEnum implements java.io.Serializable JavaDoc
33 {
34     /**
35      * Serial version
36      */

37     private static final long serialVersionUID = 5963149836513364800L;
38
39     private final String JavaDoc s;
40
41     private SqlEnum(String JavaDoc s)
42     {
43         this.s = s;
44     }
45
46     public final String JavaDoc toString()
47     {
48         return s;
49     }
50
51     public static final SqlEnum EQUAL =
52         new SqlEnum("=");
53     public static final SqlEnum NOT_EQUAL =
54             new SqlEnum("<>");
55     public static final SqlEnum ALT_NOT_EQUAL =
56         new SqlEnum("!=");
57     public static final SqlEnum GREATER_THAN =
58         new SqlEnum(">");
59     public static final SqlEnum LESS_THAN =
60         new SqlEnum("<");
61     public static final SqlEnum GREATER_EQUAL =
62         new SqlEnum(">=");
63     public static final SqlEnum LESS_EQUAL =
64         new SqlEnum("<=");
65     public static final SqlEnum LIKE =
66         new SqlEnum(" LIKE ");
67     public static final SqlEnum NOT_LIKE =
68         new SqlEnum(" NOT LIKE ");
69     public static final SqlEnum ILIKE =
70         new SqlEnum(" ILIKE ");
71     public static final SqlEnum NOT_ILIKE =
72         new SqlEnum(" NOT ILIKE ");
73     public static final SqlEnum IN =
74         new SqlEnum(" IN ");
75     public static final SqlEnum NOT_IN =
76         new SqlEnum(" NOT IN ");
77     public static final SqlEnum CUSTOM =
78         new SqlEnum("CUSTOM");
79     public static final SqlEnum JOIN =
80         new SqlEnum("JOIN");
81     public static final SqlEnum DISTINCT =
82         new SqlEnum("DISTINCT ");
83     public static final SqlEnum ALL =
84         new SqlEnum("ALL ");
85     public static final SqlEnum ASC =
86         new SqlEnum("ASC");
87     public static final SqlEnum DESC =
88         new SqlEnum("DESC");
89     public static final SqlEnum ISNULL =
90         new SqlEnum(" IS NULL ");
91     public static final SqlEnum ISNOTNULL =
92         new SqlEnum(" IS NOT NULL ");
93     public static final SqlEnum CURRENT_DATE =
94         new SqlEnum("CURRENT_DATE");
95     public static final SqlEnum CURRENT_TIME =
96         new SqlEnum("CURRENT_TIME");
97     public static final SqlEnum LEFT_JOIN =
98         new SqlEnum(" LEFT JOIN ");
99     public static final SqlEnum RIGHT_JOIN =
100         new SqlEnum(" RIGHT JOIN ");
101     public static final SqlEnum INNER_JOIN =
102         new SqlEnum(" INNER JOIN ");
103     public static final SqlEnum ON =
104         new SqlEnum(" ON ");
105     public static final SqlEnum AS =
106         new SqlEnum(" AS ");
107     public static final SqlEnum ESCAPE =
108         new SqlEnum(" ESCAPE ");
109
110     /**
111      * returns whether o is the same SqlEnum as this object.
112      * Two SqlEnums are considered equal if they contain the same String.
113      * @param o the object to compare the SqlEnum with.
114      */

115     public boolean equals(Object JavaDoc o)
116     {
117         if (o == null)
118         {
119             return false;
120         }
121
122         if (!(o instanceof SqlEnum))
123         {
124             return false;
125         }
126
127         SqlEnum otherEnum = (SqlEnum) o;
128
129
130         // both null: true
131
// other null, this not null: false
132
// else compare
133
return (otherEnum.s == null)
134                 ? (s == null)
135                 : otherEnum.s.equals(s);
136     }
137
138     /**
139      * returns a hashcode for this object which is consistent with equals()
140      */

141     public int hashCode()
142     {
143         return (s == null)
144                 ? 0
145                 : s.hashCode();
146     }
147 }
148
Popular Tags