KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > PMParams


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

17 package org.apache.ws.jaxme;
18
19 import java.io.Serializable JavaDoc;
20 import java.sql.Types JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Calendar JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26
27 /** <p>Implementation of a parameter object for use in
28  * {@link PM#select(Observer, String, PMParams)}.</p>
29  *
30  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
31  */

32 public class PMParams implements Serializable JavaDoc {
33   /** <p>A single parameter.</p>
34    */

35   public static class Param {
36     private int type;
37     private Object JavaDoc value;
38     /** <p>Creates a new parameter with the given type and value.</p>
39      */

40     public Param(int pType, Object JavaDoc pValue) {
41       type = pType;
42       value = pValue;
43     }
44     public int getType() { return type; }
45     public Object JavaDoc getValue() { return value; }
46   }
47
48   private List JavaDoc params;
49   private int max, start;
50   private boolean distinct;
51
52   /** <p>Adds a new parameter.</p>
53    */

54   public void addParam(Param pParam) {
55     if (params == null) { params = new ArrayList JavaDoc(); }
56     params.add(pParam);
57   }
58
59   /** <p>Adds a String parameter.</p>
60    */

61   public void addParam(String JavaDoc pParam) {
62     addParam(new Param(Types.VARCHAR, pParam));
63   }
64
65   /** <p>Adds a Long parameter.</p>
66    */

67   public void addParam(Long JavaDoc pParam) {
68     addParam(new Param(Types.BIGINT, pParam));
69   }
70
71   /** <p>Adds a long parameter.</p>
72    */

73   public void addParam(long pParam) {
74     addParam(new Param(Types.BIGINT, new Long JavaDoc(pParam)));
75   }
76
77   /** <p>Adds an Integer parameter.</p>
78    */

79   public void addParam(Integer JavaDoc pParam) {
80     addParam(new Param(Types.INTEGER, pParam));
81   }
82
83   /** <p>Adds an int parameter.</p>
84    */

85   public void addParam(int pParam) {
86     addParam(new Param(Types.INTEGER, new Integer JavaDoc(pParam)));
87   }
88
89   /** <p>Adds a Short parameter.</p>
90    */

91   public void addParam(Short JavaDoc pParam) {
92     addParam(new Param(Types.SMALLINT, pParam));
93   }
94
95   /** <p>Adds a short parameter.</p>
96    */

97   public void addParam(short pParam) {
98     addParam(new Param(Types.SMALLINT, new Short JavaDoc(pParam)));
99   }
100
101   /** <p>Adds a Byte parameter.</p>
102    */

103   public void addParam(Byte JavaDoc pParam) {
104     addParam(new Param(Types.TINYINT, pParam));
105   }
106
107   /** <p>Adds a byte parameter.</p>
108    */

109   public void addParam(byte pParam) {
110     addParam(new Param(Types.TINYINT, new Byte JavaDoc(pParam)));
111   }
112
113   /** <p>Adds a DateTime parameter.</p>
114    */

115   public void addDateTimeParam(Calendar JavaDoc pParam) {
116     addParam(new Param(Types.TIMESTAMP, pParam));
117   }
118
119   /** <p>Adds a VARBINARY parameter.</p>
120    */

121   public void addParam(byte[] pParam) {
122     addParam(new Param(Types.VARBINARY, pParam));
123   }
124
125   /** <p>Adds a Date parameter.</p>
126    */

127   public void addDateParam(Calendar JavaDoc pParam) {
128     addParam(new Param(Types.DATE, pParam));
129   }
130
131   /** <p>Adds a Time parameter.</p>
132    */

133   public void addTimeParam(Calendar JavaDoc pParam) {
134     addParam(new Param(Types.TIME, pParam));
135   }
136
137   /** <p>Sets the maximum number of result documents.</p>
138    */

139   public void setMaxResultDocuments(int pMax) {
140     max = pMax;
141   }
142
143   /** <p>Returns the maximum number of result documents
144    * or 0 (default) for an unlimited number.</p>
145    */

146   public int getMaxResultDocuments() {
147     return max;
148   }
149
150   /** <p>Sets the maximum number of documents to skip
151    * at the beginning (soft cursoring).</p>
152    */

153   public void setSkippedResultDocuments(int pStart) {
154     start = pStart;
155   }
156
157   /** <p>Sets the maximum number of documents to skip
158    * at the beginning or 0 (default) to skip no documents.</p>
159    */

160   public int getSkippedResultDocuments() {
161     return start;
162   }
163
164   /** <p>Returns the number of parameters added with
165    * <code>addParam()</code>.</p>
166    */

167   public int getNumParams() {
168     return (params == null) ? 0 : params.size()/2;
169   }
170
171   /** <p>Returns an {@link Iterator} to the list of parameters. Any
172    * element in the list is an instance of {@link PMParams.Param}.</p>
173    */

174   public Iterator JavaDoc getParams() {
175     return params.iterator();
176   }
177
178   /** <p>Sets whether the query should guarantee to return only
179    * distinct objects by activating the DISTINCT clause.</p>
180    */

181   public void setDistinct(boolean pDistinct) {
182     distinct = pDistinct;
183   }
184
185   /** <p>Returns whether the query should guarantee to return only
186    * distinct objects by activating the DISTINCT clause.</p>
187    */

188   public boolean isDistinct() {
189     return distinct;
190   }
191 }
192
Popular Tags