1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.util.dao.orm.hibernate;
24  
25  import java.sql.Timestamp;
26  
27  import org.hibernate.Query;
28  
29  /**
30   * <a href="QueryPos.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   * @deprecated This class has been repackaged at
35   * <code>com.liferay.portal.kernel.dao.orm</code>.
36   *
37   */
38  public class QueryPos {
39  
40      public static QueryPos getInstance(Query query) {
41          return new QueryPos(query);
42      }
43  
44      public int getPos() {
45          return _pos;
46      }
47  
48      public void add(boolean value) {
49          _query.setBoolean(_pos++, value);
50      }
51  
52      public void add(Boolean value) {
53          if (value != null) {
54              _query.setBoolean(_pos++, value.booleanValue());
55          }
56          else {
57              addNull();
58          }
59      }
60  
61      public void add(double value) {
62          _query.setDouble(_pos++, value);
63      }
64  
65      public void add(Double value) {
66          if (value != null) {
67              _query.setDouble(_pos++, value.doubleValue());
68          }
69          else {
70              addNull();
71          }
72      }
73  
74      public void add(float value) {
75          _query.setFloat(_pos++, value);
76      }
77  
78      public void add(Float value) {
79          if (value != null) {
80              _query.setFloat(_pos++, value.intValue());
81          }
82          else {
83              addNull();
84          }
85      }
86  
87      public void add(int value) {
88          _query.setInteger(_pos++, value);
89      }
90  
91      public void add(Integer value) {
92          if (value != null) {
93              _query.setInteger(_pos++, value.intValue());
94          }
95          else {
96              addNull();
97          }
98      }
99  
100     public void add(long value) {
101         _query.setLong(_pos++, value);
102     }
103 
104     public void add(Long value) {
105         if (value != null) {
106             _query.setLong(_pos++, value.longValue());
107         }
108         else {
109             addNull();
110         }
111     }
112 
113     public void add(short value) {
114         _query.setShort(_pos++, value);
115     }
116 
117     public void add(Short value) {
118         if (value != null) {
119             _query.setShort(_pos++, value.shortValue());
120         }
121         else {
122             addNull();
123         }
124     }
125 
126     public void add(String value) {
127         _query.setString(_pos++, value);
128     }
129 
130     public void add(String[] values) {
131         add(values, 1);
132     }
133 
134     public void add(String[] values, int count) {
135         for (int i = 0; i < values.length; i++) {
136             for (int j = 0; j < count; j++) {
137                 add(values[i]);
138             }
139         }
140     }
141 
142     public void add(Timestamp value) {
143         _query.setTimestamp(_pos++, value);
144     }
145 
146     private QueryPos(Query query) {
147         _query = query;
148     }
149 
150     private void addNull() {
151         _query.setSerializable(_pos++, null);
152     }
153 
154     private Query _query;
155     private int _pos;
156 
157 }