001    /**
002     * Copyright (c) 2000-2012 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 isVendorInformix() {
054                    return _instance._customSQL.isVendorInformix();
055            }
056    
057            public static boolean isVendorMySQL() {
058                    return _instance._customSQL.isVendorMySQL();
059            }
060    
061            public static boolean isVendorOracle() {
062                    return _instance._customSQL.isVendorOracle();
063            }
064    
065            public static boolean isVendorSybase() {
066                    return _instance._customSQL.isVendorSybase();
067            }
068    
069            public static String[] keywords(String keywords) {
070                    return _instance._customSQL.keywords(keywords);
071            }
072    
073            public static String[] keywords(String keywords, boolean lowerCase) {
074                    return _instance._customSQL.keywords(keywords, lowerCase);
075            }
076    
077            public static String[] keywords(String[] keywordsArray) {
078                    return _instance._customSQL.keywords(keywordsArray);
079            }
080    
081            public static String[] keywords(String[] keywordsArray, boolean lowerCase) {
082                    return _instance._customSQL.keywords(keywordsArray, lowerCase);
083            }
084    
085            public static void reloadCustomSQL() throws SQLException {
086                    _instance._customSQL.reloadCustomSQL();
087            }
088    
089            public static String removeGroupBy(String sql) {
090                    return _instance._customSQL.removeGroupBy(sql);
091            }
092    
093            public static String removeOrderBy(String sql) {
094                    return _instance._customSQL.removeOrderBy(sql);
095            }
096    
097            public static String replaceAndOperator(String sql, boolean andOperator) {
098                    return _instance._customSQL.replaceAndOperator(sql, andOperator);
099            }
100    
101            public static String replaceGroupBy(String sql, String groupBy) {
102                    return _instance._customSQL.replaceGroupBy(sql, groupBy);
103            }
104    
105            public static String replaceIsNull(String sql) {
106                    return _instance._customSQL.replaceIsNull(sql);
107            }
108    
109            public static String replaceKeywords(
110                    String sql, String field, boolean last, int[] values) {
111    
112                    return _instance._customSQL.replaceKeywords(sql, field, last, values);
113            }
114    
115            public static String replaceKeywords(
116                    String sql, String field, boolean last, long[] values) {
117    
118                    return _instance._customSQL.replaceKeywords(sql, field, last, values);
119            }
120    
121            public static String replaceKeywords(
122                    String sql, String field, String operator, boolean last,
123                    String[] values) {
124    
125                    return _instance._customSQL.replaceKeywords(
126                            sql, field, operator, last, values);
127            }
128    
129            public static String replaceOrderBy(String sql, OrderByComparator obc) {
130                    return _instance._customSQL.replaceOrderBy(sql, obc);
131            }
132    
133            private CustomSQLUtil() {
134                    try {
135                            _customSQL = new CustomSQL();
136                    }
137                    catch (Exception e) {
138                            _log.error(e, e);
139                    }
140            }
141    
142            private static Log _log = LogFactoryUtil.getLog(CustomSQLUtil.class);
143    
144            private static CustomSQLUtil _instance = new CustomSQLUtil();
145    
146            private CustomSQL _customSQL;
147    
148    }