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.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  }