1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.util.dao.orm.hibernate;
16  
17  import java.sql.Timestamp;
18  
19  import org.hibernate.Query;
20  
21  /**
22   * <a href="QueryPos.java.html"><b><i>View Source</i></b></a>
23   *
24   * @author     Brian Wing Shun Chan
25   * @deprecated This class has been repackaged at
26   *             <code>com.liferay.portal.kernel.dao.orm</code>.
27   */
28  public class QueryPos {
29  
30      public static QueryPos getInstance(Query query) {
31          return new QueryPos(query);
32      }
33  
34      public int getPos() {
35          return _pos;
36      }
37  
38      public void add(boolean value) {
39          _query.setBoolean(_pos++, value);
40      }
41  
42      public void add(Boolean value) {
43          if (value != null) {
44              _query.setBoolean(_pos++, value.booleanValue());
45          }
46          else {
47              addNull();
48          }
49      }
50  
51      public void add(double value) {
52          _query.setDouble(_pos++, value);
53      }
54  
55      public void add(Double value) {
56          if (value != null) {
57              _query.setDouble(_pos++, value.doubleValue());
58          }
59          else {
60              addNull();
61          }
62      }
63  
64      public void add(float value) {
65          _query.setFloat(_pos++, value);
66      }
67  
68      public void add(Float value) {
69          if (value != null) {
70              _query.setFloat(_pos++, value.intValue());
71          }
72          else {
73              addNull();
74          }
75      }
76  
77      public void add(int value) {
78          _query.setInteger(_pos++, value);
79      }
80  
81      public void add(Integer value) {
82          if (value != null) {
83              _query.setInteger(_pos++, value.intValue());
84          }
85          else {
86              addNull();
87          }
88      }
89  
90      public void add(long value) {
91          _query.setLong(_pos++, value);
92      }
93  
94      public void add(Long value) {
95          if (value != null) {
96              _query.setLong(_pos++, value.longValue());
97          }
98          else {
99              addNull();
100         }
101     }
102 
103     public void add(short value) {
104         _query.setShort(_pos++, value);
105     }
106 
107     public void add(Short value) {
108         if (value != null) {
109             _query.setShort(_pos++, value.shortValue());
110         }
111         else {
112             addNull();
113         }
114     }
115 
116     public void add(String value) {
117         _query.setString(_pos++, value);
118     }
119 
120     public void add(String[] values) {
121         add(values, 1);
122     }
123 
124     public void add(String[] values, int count) {
125         for (int i = 0; i < values.length; i++) {
126             for (int j = 0; j < count; j++) {
127                 add(values[i]);
128             }
129         }
130     }
131 
132     public void add(Timestamp value) {
133         _query.setTimestamp(_pos++, value);
134     }
135 
136     private QueryPos(Query query) {
137         _query = query;
138     }
139 
140     private void addNull() {
141         _query.setSerializable(_pos++, null);
142     }
143 
144     private Query _query;
145     private int _pos;
146 
147 }