001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.dao.orm;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public class CustomSQLParam {
023    
024            public CustomSQLParam(String sql, Object value) {
025                    _sql = sql;
026                    _value = value;
027            }
028    
029            public String getSQL() {
030                    return _sql;
031            }
032    
033            public void process(QueryPos qPos) {
034                    if (_value instanceof Long) {
035                            Long valueLong = (Long)_value;
036    
037                            if (valueLong != null) {
038                                    qPos.add(valueLong);
039                            }
040                    }
041                    else if (_value instanceof Long[]) {
042                            Long[] valueArray = (Long[])_value;
043    
044                            for (int i = 0; i < valueArray.length; i++) {
045                                    if (valueArray[i] != null) {
046                                            qPos.add(valueArray[i]);
047                                    }
048                            }
049                    }
050                    else if (_value instanceof String) {
051                            String valueString = (String)_value;
052    
053                            if (Validator.isNotNull(valueString)) {
054                                    qPos.add(valueString);
055                            }
056                    }
057                    else if (_value instanceof String[]) {
058                            String[] valueArray = (String[])_value;
059    
060                            for (int i = 0; i < valueArray.length; i++) {
061                                    if (Validator.isNotNull(valueArray[i])) {
062                                            qPos.add(valueArray[i]);
063                                    }
064                            }
065                    }
066            }
067    
068            private String _sql;
069            private Object _value;
070    
071    }