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