1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.dao.orm;
16  
17  import com.liferay.portal.kernel.util.Validator;
18  
19  /**
20   * <a href="CustomSQLParam.java.html"><b><i>View Source</i></b></a>
21   *
22   * @author Brian Wing Shun Chan
23   */
24  public class CustomSQLParam {
25  
26      public CustomSQLParam(String sql, Object value) {
27          _sql = sql;
28          _value = value;
29      }
30  
31      public String getSQL() {
32          return _sql;
33      }
34  
35      public void process(QueryPos qPos) {
36          if (_value instanceof Long) {
37              Long valueLong = (Long)_value;
38  
39              if (Validator.isNotNull(valueLong)) {
40                  qPos.add(valueLong);
41              }
42          }
43          else if (_value instanceof Long[]) {
44              Long[] valueArray = (Long[])_value;
45  
46              for (int i = 0; i < valueArray.length; i++) {
47                  if (Validator.isNotNull(valueArray[i])) {
48                      qPos.add(valueArray[i]);
49                  }
50              }
51          }
52          else if (_value instanceof String) {
53              String valueString = (String)_value;
54  
55              if (Validator.isNotNull(valueString)) {
56                  qPos.add(valueString);
57              }
58          }
59          else if (_value instanceof String[]) {
60              String[] valueArray = (String[])_value;
61  
62              for (int i = 0; i < valueArray.length; i++) {
63                  if (Validator.isNotNull(valueArray[i])) {
64                      qPos.add(valueArray[i]);
65                  }
66              }
67          }
68      }
69  
70      private String _sql;
71      private Object _value;
72  
73  }