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.util.dao.orm;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.util.OrderByComparator;
021    
022    import java.sql.SQLException;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     * @author Bruno Farache
027     * @author Raymond Aug??
028     */
029    public class CustomSQLUtil {
030    
031            public static String appendCriteria(String sql, String criteria) {
032                    return _instance._customSQL.appendCriteria(sql, criteria);
033            }
034    
035            public static String get(String id) {
036                    return _instance._customSQL.get(id);
037            }
038    
039            public static String get(String id, QueryDefinition queryDefinition) {
040                    return _instance._customSQL.get(id, queryDefinition);
041            }
042    
043            public static String get(
044                    String id, QueryDefinition queryDefinition, String tableName) {
045    
046                    return _instance._customSQL.get(id, queryDefinition, tableName);
047            }
048    
049            public static boolean isVendorDB2() {
050                    return _instance._customSQL.isVendorDB2();
051            }
052    
053            public static boolean isVendorHSQL() {
054                    return _instance._customSQL.isVendorHSQL();
055            }
056    
057            public static boolean isVendorInformix() {
058                    return _instance._customSQL.isVendorInformix();
059            }
060    
061            public static boolean isVendorMySQL() {
062                    return _instance._customSQL.isVendorMySQL();
063            }
064    
065            public static boolean isVendorOracle() {
066                    return _instance._customSQL.isVendorOracle();
067            }
068    
069            public static boolean isVendorSybase() {
070                    return _instance._customSQL.isVendorSybase();
071            }
072    
073            public static String[] keywords(String keywords) {
074                    return _instance._customSQL.keywords(keywords);
075            }
076    
077            public static String[] keywords(String keywords, boolean lowerCase) {
078                    return _instance._customSQL.keywords(keywords, lowerCase);
079            }
080    
081            public static String[] keywords(String[] keywordsArray) {
082                    return _instance._customSQL.keywords(keywordsArray);
083            }
084    
085            public static String[] keywords(String[] keywordsArray, boolean lowerCase) {
086                    return _instance._customSQL.keywords(keywordsArray, lowerCase);
087            }
088    
089            public static void reloadCustomSQL() throws SQLException {
090                    _instance._customSQL.reloadCustomSQL();
091            }
092    
093            public static String removeGroupBy(String sql) {
094                    return _instance._customSQL.removeGroupBy(sql);
095            }
096    
097            public static String removeOrderBy(String sql) {
098                    return _instance._customSQL.removeOrderBy(sql);
099            }
100    
101            public static String replaceAndOperator(String sql, boolean andOperator) {
102                    return _instance._customSQL.replaceAndOperator(sql, andOperator);
103            }
104    
105            public static String replaceGroupBy(String sql, String groupBy) {
106                    return _instance._customSQL.replaceGroupBy(sql, groupBy);
107            }
108    
109            public static String replaceIsNull(String sql) {
110                    return _instance._customSQL.replaceIsNull(sql);
111            }
112    
113            public static String replaceKeywords(
114                    String sql, String field, boolean last, int[] values) {
115    
116                    return _instance._customSQL.replaceKeywords(sql, field, last, values);
117            }
118    
119            public static String replaceKeywords(
120                    String sql, String field, boolean last, long[] values) {
121    
122                    return _instance._customSQL.replaceKeywords(sql, field, last, values);
123            }
124    
125            public static String replaceKeywords(
126                    String sql, String field, String operator, boolean last,
127                    String[] values) {
128    
129                    return _instance._customSQL.replaceKeywords(
130                            sql, field, operator, last, values);
131            }
132    
133            public static String replaceOrderBy(String sql, OrderByComparator obc) {
134                    return _instance._customSQL.replaceOrderBy(sql, obc);
135            }
136    
137            private CustomSQLUtil() {
138                    try {
139                            _customSQL = new CustomSQL();
140                    }
141                    catch (Exception e) {
142                            _log.error(e, e);
143                    }
144            }
145    
146            private static Log _log = LogFactoryUtil.getLog(CustomSQLUtil.class);
147    
148            private static CustomSQLUtil _instance = new CustomSQLUtil();
149    
150            private CustomSQL _customSQL;
151    
152    }