KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > query > QueryArgs


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.amber.query;
30
31 import com.caucho.amber.type.*;
32
33 /**
34  * Represents the arguments to a query.
35  */

36 public class QueryArgs {
37   private Type []_argTypes;
38   private Object JavaDoc []_argValues;
39
40   public QueryArgs(int length)
41   {
42     _argTypes = new Type[length];
43     _argValues = new Object JavaDoc[length];
44   }
45
46   /**
47    * Returns the arg type array.
48    */

49   Type []getArgTypes()
50   {
51     return _argTypes;
52   }
53
54   /**
55    * Returns the arg values
56    */

57   Object JavaDoc []getArgValues()
58   {
59     return _argValues;
60   }
61
62   /**
63    * Sets the argument with a string
64    */

65   public void setString(int index, String JavaDoc v)
66   {
67     _argTypes[index - 1] = StringType.create();
68     _argValues[index - 1] = v;
69   }
70
71   /**
72    * Sets the argument with a byte
73    */

74   public void setByte(int index, byte v)
75   {
76     _argTypes[index - 1] = ByteType.create();
77     _argValues[index - 1] = new Integer JavaDoc(v);
78   }
79
80   /**
81    * Sets the argument with a short
82    */

83   public void setShort(int index, short v)
84   {
85     _argTypes[index - 1] = ShortType.create();
86     _argValues[index - 1] = new Integer JavaDoc(v);
87   }
88
89   /**
90    * Sets the argument with an int
91    */

92   public void setInt(int index, int v)
93   {
94     _argTypes[index - 1] = IntegerType.create();
95     _argValues[index - 1] = new Integer JavaDoc(v);
96   }
97
98   /**
99    * Sets the argument with a string
100    */

101   public void setLong(int index, long v)
102   {
103     _argTypes[index - 1] = LongType.create();
104     _argValues[index - 1] = new Long JavaDoc(v);
105   }
106
107   /**
108    * Sets the argument with a double
109    */

110   public void setDouble(int index, double v)
111   {
112     _argTypes[index - 1] = DoubleType.create();
113     _argValues[index - 1] = new Double JavaDoc(v);
114   }
115
116   /**
117    * Sets the argument with a timestamp
118    */

119   public void setTimestamp(int index, java.sql.Timestamp JavaDoc v)
120   {
121     _argTypes[index - 1] = SqlTimestampType.create();
122     _argValues[index - 1] = v;
123   }
124
125   /**
126    * Sets the argument with a date
127    */

128   public void setDate(int index, java.sql.Date JavaDoc v)
129   {
130     _argTypes[index - 1] = SqlDateType.create();
131     _argValues[index - 1] = v;
132   }
133
134   /**
135    * Sets the argument with a null
136    */

137   public void setNull(int index, int v)
138   {
139     _argTypes[index - 1] = StringType.create();
140     _argValues[index - 1] = null;
141   }
142
143   /**
144    * Returns a hash code.
145    */

146   public int hashCode()
147   {
148     int hash = 37;
149
150     for (int i = _argValues.length - 1; i >= 0; i--) {
151       Object JavaDoc v = _argValues[i];
152
153       if (v != null)
154     hash = 31 * hash + v.hashCode();
155       else
156     hash = 31 * hash + 17;
157     }
158
159     return hash;
160   }
161
162   /**
163    * Returns true if equals.
164    */

165   public boolean equals(Object JavaDoc o)
166   {
167     if (! (o instanceof QueryArgs))
168       return false;
169
170     QueryArgs args = (QueryArgs) o;
171
172     if (_argValues.length != args._argValues.length)
173       return false;
174
175     for (int i = _argValues.length - 1; i >= 0; i--) {
176       Object JavaDoc a = args._argValues[i];
177       Object JavaDoc b = _argValues[i];
178       
179       if (a != b && (a == null || ! a.equals(b)))
180     return false;
181     }
182
183     return true;
184   }
185
186   public String JavaDoc toString()
187   {
188     return "QueryArgs[]";
189   }
190 }
191
Popular Tags