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.portlet.dynamicdatamapping.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryPos;
018    import com.liferay.portal.kernel.dao.orm.QueryUtil;
019    import com.liferay.portal.kernel.dao.orm.SQLQuery;
020    import com.liferay.portal.kernel.dao.orm.Session;
021    import com.liferay.portal.kernel.dao.orm.Type;
022    import com.liferay.portal.kernel.exception.SystemException;
023    import com.liferay.portal.kernel.util.OrderByComparator;
024    import com.liferay.portal.kernel.util.StringPool;
025    import com.liferay.portal.kernel.util.StringUtil;
026    import com.liferay.portal.kernel.util.Validator;
027    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
028    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
029    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
030    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateImpl;
031    import com.liferay.util.dao.orm.CustomSQLUtil;
032    
033    import java.util.Iterator;
034    import java.util.List;
035    
036    /**
037     * @author Eduardo Lundgren
038     * @author Connor McKay
039     * @author Marcellus Tavares
040     * @author Juan Fernández
041     */
042    public class DDMTemplateFinderImpl
043            extends BasePersistenceImpl<DDMTemplate> implements DDMTemplateFinder {
044    
045            public static final String COUNT_BY_C_G_C_C_N_D_T_M_L =
046                    DDMTemplateFinder.class.getName() + ".countByC_G_C_C_N_D_T_M_L";
047    
048            public static final String FIND_BY_G_SC =
049                    DDMTemplateFinder.class.getName() + ".findByG_SC";
050    
051            public static final String FIND_BY_C_G_C_C_N_D_T_M_L =
052                    DDMTemplateFinder.class.getName() + ".findByC_G_C_C_N_D_T_M_L";
053    
054            public int countByKeywords(
055                            long companyId, long groupId, long classNameId, long classPK,
056                            String keywords, String type, String mode)
057                    throws SystemException {
058    
059                    String[] names = null;
060                    String[] descriptions = null;
061                    String[] types = CustomSQLUtil.keywords(type, false);
062                    String[] modes = CustomSQLUtil.keywords(mode, false);
063                    String[] languages = null;
064                    boolean andOperator = false;
065    
066                    if (Validator.isNotNull(keywords)) {
067                            names = CustomSQLUtil.keywords(keywords);
068                            descriptions = CustomSQLUtil.keywords(keywords, false);
069                            languages = CustomSQLUtil.keywords(keywords, false);
070                    }
071                    else {
072                            andOperator = true;
073                    }
074    
075                    return countByC_G_C_C_N_D_T_M_L(
076                            companyId, groupId, classNameId, classPK, names, descriptions,
077                            types, modes, languages, andOperator);
078            }
079    
080            public int countByKeywords(
081                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
082                            String keywords, String type, String mode)
083                    throws SystemException {
084    
085                    String[] names = null;
086                    String[] descriptions = null;
087                    String[] types = CustomSQLUtil.keywords(type, false);
088                    String[] modes = CustomSQLUtil.keywords(mode, false);
089                    String[] languages = null;
090                    boolean andOperator = false;
091    
092                    if (Validator.isNotNull(keywords)) {
093                            names = CustomSQLUtil.keywords(keywords);
094                            descriptions = CustomSQLUtil.keywords(keywords, false);
095                            languages = CustomSQLUtil.keywords(keywords, false);
096                    }
097                    else {
098                            andOperator = true;
099                    }
100    
101                    return countByC_G_C_C_N_D_T_M_L(
102                            companyId, groupIds, classNameIds, classPK, names, descriptions,
103                            types, modes, languages, andOperator);
104            }
105    
106            public int countByC_G_C_C_N_D_T_M_L(
107                            long companyId, long groupId, long classNameId, long classPK,
108                            String name, String description, String type, String mode,
109                            String language, boolean andOperator)
110                    throws SystemException {
111    
112                    String[] names = CustomSQLUtil.keywords(name);
113                    String[] descriptions = CustomSQLUtil.keywords(description, false);
114                    String[] types = CustomSQLUtil.keywords(type, false);
115                    String[] modes = CustomSQLUtil.keywords(mode, false);
116                    String[] languages = CustomSQLUtil.keywords(language, false);
117    
118                    return countByC_G_C_C_N_D_T_M_L(
119                            companyId, groupId, classNameId, classPK, names, descriptions,
120                            types, modes, languages, andOperator);
121            }
122    
123            public int countByC_G_C_C_N_D_T_M_L(
124                            long companyId, long groupId, long classNameId, long classPK,
125                            String[] names, String[] descriptions, String[] types,
126                            String[] modes, String[] languages, boolean andOperator)
127                    throws SystemException {
128    
129                    long[] groupIds = new long[] {groupId};
130                    long[] classNameIds = new long[] {classNameId};
131    
132                    return doCountByC_G_C_C_N_D_T_M_L(
133                            companyId, groupIds, classNameIds, classPK, names, descriptions,
134                            types, modes, languages, andOperator, false);
135            }
136    
137            public int countByC_G_C_C_N_D_T_M_L(
138                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
139                            String name, String description, String type, String mode,
140                            String language, boolean andOperator)
141                    throws SystemException {
142    
143                    String[] names = CustomSQLUtil.keywords(name);
144                    String[] descriptions = CustomSQLUtil.keywords(description, false);
145                    String[] types = CustomSQLUtil.keywords(type, false);
146                    String[] modes = CustomSQLUtil.keywords(mode, false);
147                    String[] languages = CustomSQLUtil.keywords(language, false);
148    
149                    return countByC_G_C_C_N_D_T_M_L(
150                            companyId, groupIds, classNameIds, classPK, names, descriptions,
151                            types, modes, languages, andOperator);
152            }
153    
154            public int countByC_G_C_C_N_D_T_M_L(
155                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
156                            String[] names, String[] descriptions, String[] types,
157                            String[] modes, String[] languages, boolean andOperator)
158                    throws SystemException {
159    
160                    return doCountByC_G_C_C_N_D_T_M_L(
161                            companyId, groupIds, classNameIds, classPK, names, descriptions,
162                            types, modes, languages, andOperator, false);
163            }
164    
165            public int filterCountByKeywords(
166                            long companyId, long groupId, long classNameId, long classPK,
167                            String keywords, String type, String mode)
168                    throws SystemException {
169    
170                    String[] names = null;
171                    String[] descriptions = null;
172                    String[] types = CustomSQLUtil.keywords(type, false);
173                    String[] modes = CustomSQLUtil.keywords(mode, false);
174                    String[] languages = null;
175                    boolean andOperator = false;
176    
177                    if (Validator.isNotNull(keywords)) {
178                            names = CustomSQLUtil.keywords(keywords);
179                            descriptions = CustomSQLUtil.keywords(keywords, false);
180                            languages = CustomSQLUtil.keywords(keywords, false);
181                    }
182                    else {
183                            andOperator = true;
184                    }
185    
186                    return filterCountByC_G_C_C_N_D_T_M_L(
187                            companyId, groupId, classNameId, classPK, names, descriptions,
188                            types, modes, languages, andOperator);
189            }
190    
191            public int filterCountByKeywords(
192                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
193                            String keywords, String type, String mode)
194                    throws SystemException {
195    
196                    String[] names = null;
197                    String[] descriptions = null;
198                    String[] types = CustomSQLUtil.keywords(type, false);
199                    String[] modes = CustomSQLUtil.keywords(mode, false);
200                    String[] languages = null;
201                    boolean andOperator = false;
202    
203                    if (Validator.isNotNull(keywords)) {
204                            names = CustomSQLUtil.keywords(keywords);
205                            descriptions = CustomSQLUtil.keywords(keywords, false);
206                            languages = CustomSQLUtil.keywords(keywords, false);
207                    }
208                    else {
209                            andOperator = true;
210                    }
211    
212                    return filterCountByC_G_C_C_N_D_T_M_L(
213                            companyId, groupIds, classNameIds, classPK, names, descriptions,
214                            types, modes, languages, andOperator);
215            }
216    
217            public int filterCountByC_G_C_C_N_D_T_M_L(
218                            long companyId, long groupId, long classNameId, long classPK,
219                            String name, String description, String type, String mode,
220                            String language, boolean andOperator)
221                    throws SystemException {
222    
223                    String[] names = CustomSQLUtil.keywords(name);
224                    String[] descriptions = CustomSQLUtil.keywords(description, false);
225                    String[] types = CustomSQLUtil.keywords(type, false);
226                    String[] modes = CustomSQLUtil.keywords(mode, false);
227                    String[] languages = CustomSQLUtil.keywords(language, false);
228    
229                    return filterCountByC_G_C_C_N_D_T_M_L(
230                            companyId, groupId, classNameId, classPK, names, descriptions,
231                            types, modes, languages, andOperator);
232            }
233    
234            public int filterCountByC_G_C_C_N_D_T_M_L(
235                            long companyId, long groupId, long classNameId, long classPK,
236                            String[] names, String[] descriptions, String[] types,
237                            String[] modes, String[] languages, boolean andOperator)
238                    throws SystemException {
239    
240                    long[] groupIds = new long[] {groupId};
241                    long[] classNameIds = new long[] {classNameId};
242    
243                    return filterCountByC_G_C_C_N_D_T_M_L(
244                            companyId, groupIds, classNameIds, classPK, names, descriptions,
245                            types, modes, languages, andOperator);
246            }
247    
248            public int filterCountByC_G_C_C_N_D_T_M_L(
249                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
250                            String name, String description, String type, String mode,
251                            String language, boolean andOperator)
252                    throws SystemException {
253    
254                    String[] names = CustomSQLUtil.keywords(name);
255                    String[] descriptions = CustomSQLUtil.keywords(description, false);
256                    String[] types = CustomSQLUtil.keywords(type, false);
257                    String[] modes = CustomSQLUtil.keywords(mode, false);
258                    String[] languages = CustomSQLUtil.keywords(language, false);
259    
260                    return filterCountByC_G_C_C_N_D_T_M_L(
261                            companyId, groupIds, classNameIds, classPK, names, descriptions,
262                            types, modes, languages, andOperator);
263            }
264    
265            public int filterCountByC_G_C_C_N_D_T_M_L(
266                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
267                            String[] names, String[] descriptions, String[] types,
268                            String[] modes, String[] languages, boolean andOperator)
269                    throws SystemException {
270    
271                    return doCountByC_G_C_C_N_D_T_M_L(
272                            companyId, groupIds, classNameIds, classPK, names, descriptions,
273                            types, modes, languages, andOperator, true);
274            }
275    
276            public List<DDMTemplate> filterFindByKeywords(
277                            long companyId, long groupId, long classNameId, long classPK,
278                            String keywords, String type, String mode, int start, int end,
279                            OrderByComparator orderByComparator)
280                    throws SystemException {
281    
282                    String[] names = null;
283                    String[] descriptions = null;
284                    String[] types = CustomSQLUtil.keywords(type, false);
285                    String[] modes = CustomSQLUtil.keywords(mode, false);
286                    String[] languages = null;
287                    boolean andOperator = false;
288    
289                    if (Validator.isNotNull(keywords)) {
290                            names = CustomSQLUtil.keywords(keywords);
291                            descriptions = CustomSQLUtil.keywords(keywords, false);
292                            languages = CustomSQLUtil.keywords(keywords, false);
293                    }
294                    else {
295                            andOperator = true;
296                    }
297    
298                    return filterFindByC_G_C_C_N_D_T_M_L(
299                            companyId, groupId, classNameId, classPK, names, descriptions,
300                            types, modes, languages, andOperator, start, end,
301                            orderByComparator);
302            }
303    
304            public List<DDMTemplate> filterFindByKeywords(
305                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
306                            String keywords, String type, String mode, int start, int end,
307                            OrderByComparator orderByComparator)
308                    throws SystemException {
309    
310                    String[] names = null;
311                    String[] descriptions = null;
312                    String[] types = CustomSQLUtil.keywords(type, false);
313                    String[] modes = CustomSQLUtil.keywords(mode, false);
314                    String[] languages = null;
315                    boolean andOperator = false;
316    
317                    if (Validator.isNotNull(keywords)) {
318                            names = CustomSQLUtil.keywords(keywords);
319                            descriptions = CustomSQLUtil.keywords(keywords, false);
320                            languages = CustomSQLUtil.keywords(languages, false);
321                    }
322                    else {
323                            andOperator = true;
324                    }
325    
326                    return filterFindByC_G_C_C_N_D_T_M_L(
327                            companyId, groupIds, classNameIds, classPK, names, descriptions,
328                            types, modes, languages, andOperator, start, end,
329                            orderByComparator);
330            }
331    
332            public List<DDMTemplate> filterFindByG_SC(
333                            long groupId, long structureClassNameId, int start, int end,
334                            OrderByComparator orderByComparator)
335                    throws SystemException {
336    
337                    return doFindByG_SC(
338                            groupId, structureClassNameId, start, end, orderByComparator, true);
339            }
340    
341            public List<DDMTemplate> filterFindByC_G_C_C_N_D_T_M_L(
342                            long companyId, long groupId, long classNameId, long classPK,
343                            String name, String description, String type, String mode,
344                            String language, boolean andOperator, int start, int end,
345                            OrderByComparator orderByComparator)
346                    throws SystemException {
347    
348                    String[] names = CustomSQLUtil.keywords(name);
349                    String[] descriptions = CustomSQLUtil.keywords(description, false);
350                    String[] types = CustomSQLUtil.keywords(type, false);
351                    String[] modes = CustomSQLUtil.keywords(mode, false);
352                    String[] languages = CustomSQLUtil.keywords(language, false);
353    
354                    return filterFindByC_G_C_C_N_D_T_M_L(
355                            companyId, groupId, classNameId, classPK, names, descriptions,
356                            types, modes, languages, andOperator, start, end,
357                            orderByComparator);
358            }
359    
360            public List<DDMTemplate> filterFindByC_G_C_C_N_D_T_M_L(
361                            long companyId, long groupId, long classNameId, long classPK,
362                            String[] names, String[] descriptions, String[] types,
363                            String[] modes, String[] languages, boolean andOperator, int start,
364                            int end, OrderByComparator orderByComparator)
365                    throws SystemException {
366    
367                    long[] groupIds = new long[] {groupId};
368                    long[] classNameIds = new long[] {classNameId};
369    
370                    return filterFindByC_G_C_C_N_D_T_M_L(
371                            companyId, groupIds, classNameIds, classPK, names, descriptions,
372                            types, modes, languages, andOperator, start, end,
373                            orderByComparator);
374            }
375    
376            public List<DDMTemplate> filterFindByC_G_C_C_N_D_T_M_L(
377                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
378                            String name, String description, String type, String mode,
379                            String language, boolean andOperator, int start, int end,
380                            OrderByComparator orderByComparator)
381                    throws SystemException {
382    
383                    String[] names = CustomSQLUtil.keywords(name);
384                    String[] descriptions = CustomSQLUtil.keywords(description, false);
385                    String[] types = CustomSQLUtil.keywords(type, false);
386                    String[] modes = CustomSQLUtil.keywords(mode, false);
387                    String[] languages = CustomSQLUtil.keywords(language, false);
388    
389                    return filterFindByC_G_C_C_N_D_T_M_L(
390                            companyId, groupIds, classNameIds, classPK, names, descriptions,
391                            types, modes, languages, andOperator, start, end,
392                            orderByComparator);
393            }
394    
395            public List<DDMTemplate> filterFindByC_G_C_C_N_D_T_M_L(
396                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
397                            String[] names, String[] descriptions, String[] types,
398                            String[] modes, String[] languages, boolean andOperator, int start,
399                            int end, OrderByComparator orderByComparator)
400                    throws SystemException {
401    
402                    return doFindByC_G_C_C_N_D_T_M_L(
403                            companyId, groupIds, classNameIds, classPK, names, descriptions,
404                            types, modes, languages, andOperator, start, end, orderByComparator,
405                            true);
406            }
407    
408            public List<DDMTemplate> findByKeywords(
409                            long companyId, long groupId, long classNameId, long classPK,
410                            String keywords, String type, String mode, int start, int end,
411                            OrderByComparator orderByComparator)
412                    throws SystemException {
413    
414                    String[] names = null;
415                    String[] descriptions = null;
416                    String[] types = CustomSQLUtil.keywords(type, false);
417                    String[] modes = CustomSQLUtil.keywords(mode, false);
418                    String[] languages = null;
419                    boolean andOperator = false;
420    
421                    if (Validator.isNotNull(keywords)) {
422                            names = CustomSQLUtil.keywords(keywords);
423                            descriptions = CustomSQLUtil.keywords(keywords, false);
424                            languages = CustomSQLUtil.keywords(keywords, false);
425                    }
426                    else {
427                            andOperator = true;
428                    }
429    
430                    return findByC_G_C_C_N_D_T_M_L(
431                            companyId, groupId, classNameId, classPK, names, descriptions,
432                            types, modes, languages, andOperator, start, end,
433                            orderByComparator);
434            }
435    
436            public List<DDMTemplate> findByKeywords(
437                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
438                            String keywords, String type, String mode, int start, int end,
439                            OrderByComparator orderByComparator)
440                    throws SystemException {
441    
442                    String[] names = null;
443                    String[] descriptions = null;
444                    String[] types = CustomSQLUtil.keywords(type, false);
445                    String[] modes = CustomSQLUtil.keywords(mode, false);
446                    String[] languages = null;
447                    boolean andOperator = false;
448    
449                    if (Validator.isNotNull(keywords)) {
450                            names = CustomSQLUtil.keywords(keywords);
451                            descriptions = CustomSQLUtil.keywords(keywords, false);
452                            languages = CustomSQLUtil.keywords(languages, false);
453                    }
454                    else {
455                            andOperator = true;
456                    }
457    
458                    return findByC_G_C_C_N_D_T_M_L(
459                            companyId, groupIds, classNameIds, classPK, names, descriptions,
460                            types, modes, languages, andOperator, start, end,
461                            orderByComparator);
462            }
463    
464            public List<DDMTemplate> findByG_SC(
465                            long groupId, long structureClassNameId, int start, int end,
466                            OrderByComparator orderByComparator)
467                    throws SystemException {
468    
469                    return doFindByG_SC(
470                            groupId, structureClassNameId, start, end, orderByComparator,
471                            false);
472            }
473    
474            public List<DDMTemplate> findByC_G_C_C_N_D_T_M_L(
475                            long companyId, long groupId, long classNameId, long classPK,
476                            String name, String description, String type, String mode,
477                            String language, boolean andOperator, int start, int end,
478                            OrderByComparator orderByComparator)
479                    throws SystemException {
480    
481                    String[] names = CustomSQLUtil.keywords(name);
482                    String[] descriptions = CustomSQLUtil.keywords(description, false);
483                    String[] types = CustomSQLUtil.keywords(type, false);
484                    String[] modes = CustomSQLUtil.keywords(mode, false);
485                    String[] languages = CustomSQLUtil.keywords(language, false);
486    
487                    return findByC_G_C_C_N_D_T_M_L(
488                            companyId, groupId, classNameId, classPK, names, descriptions,
489                            types, modes, languages, andOperator, start, end,
490                            orderByComparator);
491            }
492    
493            public List<DDMTemplate> findByC_G_C_C_N_D_T_M_L(
494                            long companyId, long groupId, long classNameId, long classPK,
495                            String[] names, String[] descriptions, String[] types,
496                            String[] modes, String[] languages, boolean andOperator, int start,
497                            int end, OrderByComparator orderByComparator)
498                    throws SystemException {
499    
500                    long[] groupIds = new long[] {groupId};
501                    long[] classNameIds = new long[] {classNameId};
502    
503                    return doFindByC_G_C_C_N_D_T_M_L(
504                            companyId, groupIds, classNameIds, classPK, names, descriptions,
505                            types, modes, languages, andOperator, start, end, orderByComparator,
506                            false);
507            }
508    
509            public List<DDMTemplate> findByC_G_C_C_N_D_T_M_L(
510                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
511                            String name, String description, String type, String mode,
512                            String language, boolean andOperator, int start, int end,
513                            OrderByComparator orderByComparator)
514                    throws SystemException {
515    
516                    String[] names = CustomSQLUtil.keywords(name);
517                    String[] descriptions = CustomSQLUtil.keywords(description, false);
518                    String[] types = CustomSQLUtil.keywords(type, false);
519                    String[] modes = CustomSQLUtil.keywords(mode, false);
520                    String[] languages = CustomSQLUtil.keywords(language, false);
521    
522                    return findByC_G_C_C_N_D_T_M_L(
523                            companyId, groupIds, classNameIds, classPK, names, descriptions,
524                            types, modes, languages, andOperator, start, end,
525                            orderByComparator);
526            }
527    
528            public List<DDMTemplate> findByC_G_C_C_N_D_T_M_L(
529                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
530                            String[] names, String[] descriptions, String[] types,
531                            String[] modes, String[] languages, boolean andOperator, int start,
532                            int end, OrderByComparator orderByComparator)
533                    throws SystemException {
534    
535                    return doFindByC_G_C_C_N_D_T_M_L(
536                            companyId, groupIds, classNameIds, classPK, names, descriptions,
537                            types, modes, languages, andOperator, start, end, orderByComparator,
538                            false);
539            }
540    
541            protected int doCountByC_G_C_C_N_D_T_M_L(
542                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
543                            String[] names, String[] descriptions, String[] types,
544                            String[] modes, String[] languages, boolean andOperator,
545                            boolean inlineSQLHelper)
546                    throws SystemException {
547    
548                    names = CustomSQLUtil.keywords(names);
549                    descriptions = CustomSQLUtil.keywords(descriptions, false);
550                    types = CustomSQLUtil.keywords(types, false);
551                    modes = CustomSQLUtil.keywords(modes, false);
552                    languages = CustomSQLUtil.keywords(languages, false);
553    
554                    Session session = null;
555    
556                    try {
557                            session = openSession();
558    
559                            String sql = CustomSQLUtil.get(COUNT_BY_C_G_C_C_N_D_T_M_L);
560    
561                            if (inlineSQLHelper) {
562                                    sql = InlineSQLHelperUtil.replacePermissionCheck(
563                                            sql, DDMTemplate.class.getName(), "DDMTemplate.templateId",
564                                            groupIds);
565                            }
566    
567                            if (groupIds.length <= 0) {
568                                    sql = StringUtil.replace(
569                                            sql, "(groupId IN ([$GROUP_ID$])) AND", StringPool.BLANK);
570                            }
571                            else {
572                                    sql = StringUtil.replace(
573                                            sql, "[$GROUP_ID$]", StringUtil.merge(groupIds));
574                            }
575    
576                            if (classNameIds.length == 0) {
577                                    sql = StringUtil.replace(
578                                            sql, "(classNameId IN ([$CLASSNAME_ID$])) AND", "");
579                            }
580                            else {
581                                    sql = StringUtil.replace(
582                                            sql, "[$CLASSNAME_ID$]", StringUtil.merge(classNameIds));
583                            }
584    
585                            if (classPK < 0) {
586                                    sql = StringUtil.replace(sql, "(classPK = ?) AND", "");
587                            }
588    
589                            sql = CustomSQLUtil.replaceKeywords(
590                                    sql, "lower(name)", StringPool.LIKE, false, names);
591                            sql = CustomSQLUtil.replaceKeywords(
592                                    sql, "description", StringPool.LIKE, false, descriptions);
593                            sql = CustomSQLUtil.replaceKeywords(
594                                    sql, "type", StringPool.LIKE, false, types);
595                            sql = CustomSQLUtil.replaceKeywords(
596                                    sql, "mode", StringPool.LIKE, false, modes);
597                            sql = CustomSQLUtil.replaceKeywords(
598                                    sql, "language", StringPool.LIKE, true, languages);
599                            sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
600    
601                            SQLQuery q = session.createSQLQuery(sql);
602    
603                            q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
604    
605                            QueryPos qPos = QueryPos.getInstance(q);
606    
607                            qPos.add(companyId);
608    
609                            if (classPK >= 0) {
610                                    qPos.add(classPK);
611                            }
612    
613                            qPos.add(names, 2);
614                            qPos.add(descriptions, 2);
615                            qPos.add(types, 2);
616                            qPos.add(modes, 2);
617                            qPos.add(languages, 2);
618    
619                            Iterator<Long> itr = q.iterate();
620    
621                            if (itr.hasNext()) {
622                                    Long count = itr.next();
623    
624                                    if (count != null) {
625                                            return count.intValue();
626                                    }
627                            }
628    
629                            return 0;
630                    }
631                    catch (Exception e) {
632                            throw new SystemException(e);
633                    }
634                    finally {
635                            closeSession(session);
636                    }
637            }
638    
639            protected List<DDMTemplate> doFindByG_SC(
640                            long groupId, long structureClassNameId, int start, int end,
641                            OrderByComparator orderByComparator, boolean inlineSQLHelper)
642                    throws SystemException {
643    
644                    Session session = null;
645    
646                    try {
647                            session = openSession();
648    
649                            String sql = CustomSQLUtil.get(FIND_BY_G_SC);
650    
651                            if (inlineSQLHelper) {
652                                    sql = InlineSQLHelperUtil.replacePermissionCheck(
653                                            sql, DDMTemplate.class.getName(), "DDMTemplate.templateId",
654                                            groupId);
655                            }
656    
657                            if (orderByComparator != null) {
658                                    sql = CustomSQLUtil.replaceOrderBy(sql, orderByComparator);
659                            }
660    
661                            SQLQuery q = session.createSQLQuery(sql);
662    
663                            q.addEntity("DDMTemplate", DDMTemplateImpl.class);
664    
665                            QueryPos qPos = QueryPos.getInstance(q);
666    
667                            qPos.add(groupId);
668                            qPos.add(structureClassNameId);
669    
670                            return (List<DDMTemplate>)QueryUtil.list(
671                                    q, getDialect(), start, end);
672                    }
673                    catch (Exception e) {
674                            throw new SystemException(e);
675                    }
676                    finally {
677                            closeSession(session);
678                    }
679            }
680    
681            protected List<DDMTemplate> doFindByC_G_C_C_N_D_T_M_L(
682                            long companyId, long[] groupIds, long[] classNameIds, long classPK,
683                            String[] names, String[] descriptions, String[] types,
684                            String[] modes, String[] languages, boolean andOperator, int start,
685                            int end, OrderByComparator orderByComparator,
686                            boolean inlineSQLHelper)
687                    throws SystemException {
688    
689                    names = CustomSQLUtil.keywords(names);
690                    descriptions = CustomSQLUtil.keywords(descriptions, false);
691                    types = CustomSQLUtil.keywords(types, false);
692                    modes = CustomSQLUtil.keywords(modes, false);
693                    languages = CustomSQLUtil.keywords(languages, false);
694    
695                    Session session = null;
696    
697                    try {
698                            session = openSession();
699    
700                            String sql = CustomSQLUtil.get(FIND_BY_C_G_C_C_N_D_T_M_L);
701    
702                            if (inlineSQLHelper) {
703                                    sql = InlineSQLHelperUtil.replacePermissionCheck(
704                                            sql, DDMTemplate.class.getName(), "DDMTemplate.templateId",
705                                            groupIds);
706                            }
707    
708                            if (groupIds.length <= 0) {
709                                    sql = StringUtil.replace(
710                                            sql, "(groupId IN ([$GROUP_ID$])) AND", StringPool.BLANK);
711                            }
712                            else {
713                                    sql = StringUtil.replace(
714                                            sql, "[$GROUP_ID$]", StringUtil.merge(groupIds));
715                            }
716    
717                            if (classNameIds.length == 0) {
718                                    sql = StringUtil.replace(
719                                            sql, "(classNameId IN ([$CLASSNAME_ID$])) AND", "");
720                            }
721                            else {
722                                    sql = StringUtil.replace(
723                                            sql, "[$CLASSNAME_ID$]", StringUtil.merge(classNameIds));
724                            }
725    
726                            if (classPK < 0) {
727                                    sql = StringUtil.replace(sql, "(classPK = ?) AND", "");
728                            }
729    
730                            sql = CustomSQLUtil.replaceKeywords(
731                                    sql, "lower(name)", StringPool.LIKE, false, names);
732                            sql = CustomSQLUtil.replaceKeywords(
733                                    sql, "description", StringPool.LIKE, false, descriptions);
734                            sql = CustomSQLUtil.replaceKeywords(
735                                    sql, "type", StringPool.LIKE, false, types);
736                            sql = CustomSQLUtil.replaceKeywords(
737                                    sql, "mode", StringPool.LIKE, false, modes);
738                            sql = CustomSQLUtil.replaceKeywords(
739                                    sql, "language", StringPool.LIKE, true, languages);
740                            sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
741    
742                            if (orderByComparator != null) {
743                                    sql = CustomSQLUtil.replaceOrderBy(sql, orderByComparator);
744                            }
745    
746                            SQLQuery q = session.createSQLQuery(sql);
747    
748                            q.addEntity("DDMTemplate", DDMTemplateImpl.class);
749    
750                            QueryPos qPos = QueryPos.getInstance(q);
751    
752                            qPos.add(companyId);
753    
754                            if (classPK >= 0) {
755                                    qPos.add(classPK);
756                            }
757    
758                            qPos.add(names, 2);
759                            qPos.add(descriptions, 2);
760                            qPos.add(types, 2);
761                            qPos.add(modes, 2);
762                            qPos.add(languages, 2);
763    
764                            return (List<DDMTemplate>)QueryUtil.list(
765                                    q, getDialect(), start, end);
766                    }
767                    catch (Exception e) {
768                            throw new SystemException(e);
769                    }
770                    finally {
771                            closeSession(session);
772                    }
773            }
774    
775    }