1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchLayoutPrototypeException;
18  import com.liferay.portal.NoSuchModelException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.exception.SystemException;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.LayoutPrototype;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.model.impl.LayoutPrototypeImpl;
39  import com.liferay.portal.model.impl.LayoutPrototypeModelImpl;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import java.io.Serializable;
43  
44  import java.util.ArrayList;
45  import java.util.Collections;
46  import java.util.List;
47  
48  /**
49   * <a href="LayoutPrototypePersistenceImpl.java.html"><b><i>View Source</i></b></a>
50   *
51   * <p>
52   * ServiceBuilder generated this class. Modifications in this class will be
53   * overwritten the next time is generated.
54   * </p>
55   *
56   * @author    Brian Wing Shun Chan
57   * @see       LayoutPrototypePersistence
58   * @see       LayoutPrototypeUtil
59   * @generated
60   */
61  public class LayoutPrototypePersistenceImpl extends BasePersistenceImpl<LayoutPrototype>
62      implements LayoutPrototypePersistence {
63      public static final String FINDER_CLASS_NAME_ENTITY = LayoutPrototypeImpl.class.getName();
64      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
65          ".List";
66      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
67              LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
68              FINDER_CLASS_NAME_LIST, "findByCompanyId",
69              new String[] { Long.class.getName() });
70      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
71              LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
72              FINDER_CLASS_NAME_LIST, "findByCompanyId",
73              new String[] {
74                  Long.class.getName(),
75                  
76              "java.lang.Integer", "java.lang.Integer",
77                  "com.liferay.portal.kernel.util.OrderByComparator"
78              });
79      public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
80              LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
81              FINDER_CLASS_NAME_LIST, "countByCompanyId",
82              new String[] { Long.class.getName() });
83      public static final FinderPath FINDER_PATH_FIND_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
84              LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "findByC_A",
86              new String[] { Long.class.getName(), Boolean.class.getName() });
87      public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
88              LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
89              FINDER_CLASS_NAME_LIST, "findByC_A",
90              new String[] {
91                  Long.class.getName(), Boolean.class.getName(),
92                  
93              "java.lang.Integer", "java.lang.Integer",
94                  "com.liferay.portal.kernel.util.OrderByComparator"
95              });
96      public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
97              LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
98              FINDER_CLASS_NAME_LIST, "countByC_A",
99              new String[] { Long.class.getName(), Boolean.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
101             LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
103     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
104             LayoutPrototypeModelImpl.FINDER_CACHE_ENABLED,
105             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
106 
107     public void cacheResult(LayoutPrototype layoutPrototype) {
108         EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
109             LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
110             layoutPrototype);
111     }
112 
113     public void cacheResult(List<LayoutPrototype> layoutPrototypes) {
114         for (LayoutPrototype layoutPrototype : layoutPrototypes) {
115             if (EntityCacheUtil.getResult(
116                         LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
117                         LayoutPrototypeImpl.class,
118                         layoutPrototype.getPrimaryKey(), this) == null) {
119                 cacheResult(layoutPrototype);
120             }
121         }
122     }
123 
124     public void clearCache() {
125         CacheRegistry.clear(LayoutPrototypeImpl.class.getName());
126         EntityCacheUtil.clearCache(LayoutPrototypeImpl.class.getName());
127         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
128         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
129     }
130 
131     public LayoutPrototype create(long layoutPrototypeId) {
132         LayoutPrototype layoutPrototype = new LayoutPrototypeImpl();
133 
134         layoutPrototype.setNew(true);
135         layoutPrototype.setPrimaryKey(layoutPrototypeId);
136 
137         return layoutPrototype;
138     }
139 
140     public LayoutPrototype remove(Serializable primaryKey)
141         throws NoSuchModelException, SystemException {
142         return remove(((Long)primaryKey).longValue());
143     }
144 
145     public LayoutPrototype remove(long layoutPrototypeId)
146         throws NoSuchLayoutPrototypeException, SystemException {
147         Session session = null;
148 
149         try {
150             session = openSession();
151 
152             LayoutPrototype layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
153                     new Long(layoutPrototypeId));
154 
155             if (layoutPrototype == null) {
156                 if (_log.isWarnEnabled()) {
157                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
158                         layoutPrototypeId);
159                 }
160 
161                 throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
162                     layoutPrototypeId);
163             }
164 
165             return remove(layoutPrototype);
166         }
167         catch (NoSuchLayoutPrototypeException nsee) {
168             throw nsee;
169         }
170         catch (Exception e) {
171             throw processException(e);
172         }
173         finally {
174             closeSession(session);
175         }
176     }
177 
178     public LayoutPrototype remove(LayoutPrototype layoutPrototype)
179         throws SystemException {
180         for (ModelListener<LayoutPrototype> listener : listeners) {
181             listener.onBeforeRemove(layoutPrototype);
182         }
183 
184         layoutPrototype = removeImpl(layoutPrototype);
185 
186         for (ModelListener<LayoutPrototype> listener : listeners) {
187             listener.onAfterRemove(layoutPrototype);
188         }
189 
190         return layoutPrototype;
191     }
192 
193     protected LayoutPrototype removeImpl(LayoutPrototype layoutPrototype)
194         throws SystemException {
195         layoutPrototype = toUnwrappedModel(layoutPrototype);
196 
197         Session session = null;
198 
199         try {
200             session = openSession();
201 
202             if (layoutPrototype.isCachedModel() ||
203                     BatchSessionUtil.isEnabled()) {
204                 Object staleObject = session.get(LayoutPrototypeImpl.class,
205                         layoutPrototype.getPrimaryKeyObj());
206 
207                 if (staleObject != null) {
208                     session.evict(staleObject);
209                 }
210             }
211 
212             session.delete(layoutPrototype);
213 
214             session.flush();
215         }
216         catch (Exception e) {
217             throw processException(e);
218         }
219         finally {
220             closeSession(session);
221         }
222 
223         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
224 
225         EntityCacheUtil.removeResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
226             LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey());
227 
228         return layoutPrototype;
229     }
230 
231     public LayoutPrototype updateImpl(
232         com.liferay.portal.model.LayoutPrototype layoutPrototype, boolean merge)
233         throws SystemException {
234         layoutPrototype = toUnwrappedModel(layoutPrototype);
235 
236         Session session = null;
237 
238         try {
239             session = openSession();
240 
241             BatchSessionUtil.update(session, layoutPrototype, merge);
242 
243             layoutPrototype.setNew(false);
244         }
245         catch (Exception e) {
246             throw processException(e);
247         }
248         finally {
249             closeSession(session);
250         }
251 
252         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
253 
254         EntityCacheUtil.putResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
255             LayoutPrototypeImpl.class, layoutPrototype.getPrimaryKey(),
256             layoutPrototype);
257 
258         return layoutPrototype;
259     }
260 
261     protected LayoutPrototype toUnwrappedModel(LayoutPrototype layoutPrototype) {
262         if (layoutPrototype instanceof LayoutPrototypeImpl) {
263             return layoutPrototype;
264         }
265 
266         LayoutPrototypeImpl layoutPrototypeImpl = new LayoutPrototypeImpl();
267 
268         layoutPrototypeImpl.setNew(layoutPrototype.isNew());
269         layoutPrototypeImpl.setPrimaryKey(layoutPrototype.getPrimaryKey());
270 
271         layoutPrototypeImpl.setLayoutPrototypeId(layoutPrototype.getLayoutPrototypeId());
272         layoutPrototypeImpl.setCompanyId(layoutPrototype.getCompanyId());
273         layoutPrototypeImpl.setName(layoutPrototype.getName());
274         layoutPrototypeImpl.setDescription(layoutPrototype.getDescription());
275         layoutPrototypeImpl.setSettings(layoutPrototype.getSettings());
276         layoutPrototypeImpl.setActive(layoutPrototype.isActive());
277 
278         return layoutPrototypeImpl;
279     }
280 
281     public LayoutPrototype findByPrimaryKey(Serializable primaryKey)
282         throws NoSuchModelException, SystemException {
283         return findByPrimaryKey(((Long)primaryKey).longValue());
284     }
285 
286     public LayoutPrototype findByPrimaryKey(long layoutPrototypeId)
287         throws NoSuchLayoutPrototypeException, SystemException {
288         LayoutPrototype layoutPrototype = fetchByPrimaryKey(layoutPrototypeId);
289 
290         if (layoutPrototype == null) {
291             if (_log.isWarnEnabled()) {
292                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutPrototypeId);
293             }
294 
295             throw new NoSuchLayoutPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
296                 layoutPrototypeId);
297         }
298 
299         return layoutPrototype;
300     }
301 
302     public LayoutPrototype fetchByPrimaryKey(Serializable primaryKey)
303         throws SystemException {
304         return fetchByPrimaryKey(((Long)primaryKey).longValue());
305     }
306 
307     public LayoutPrototype fetchByPrimaryKey(long layoutPrototypeId)
308         throws SystemException {
309         LayoutPrototype layoutPrototype = (LayoutPrototype)EntityCacheUtil.getResult(LayoutPrototypeModelImpl.ENTITY_CACHE_ENABLED,
310                 LayoutPrototypeImpl.class, layoutPrototypeId, this);
311 
312         if (layoutPrototype == null) {
313             Session session = null;
314 
315             try {
316                 session = openSession();
317 
318                 layoutPrototype = (LayoutPrototype)session.get(LayoutPrototypeImpl.class,
319                         new Long(layoutPrototypeId));
320             }
321             catch (Exception e) {
322                 throw processException(e);
323             }
324             finally {
325                 if (layoutPrototype != null) {
326                     cacheResult(layoutPrototype);
327                 }
328 
329                 closeSession(session);
330             }
331         }
332 
333         return layoutPrototype;
334     }
335 
336     public List<LayoutPrototype> findByCompanyId(long companyId)
337         throws SystemException {
338         Object[] finderArgs = new Object[] { new Long(companyId) };
339 
340         List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
341                 finderArgs, this);
342 
343         if (list == null) {
344             Session session = null;
345 
346             try {
347                 session = openSession();
348 
349                 StringBundler query = new StringBundler(2);
350 
351                 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
352 
353                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
354 
355                 String sql = query.toString();
356 
357                 Query q = session.createQuery(sql);
358 
359                 QueryPos qPos = QueryPos.getInstance(q);
360 
361                 qPos.add(companyId);
362 
363                 list = q.list();
364             }
365             catch (Exception e) {
366                 throw processException(e);
367             }
368             finally {
369                 if (list == null) {
370                     list = new ArrayList<LayoutPrototype>();
371                 }
372 
373                 cacheResult(list);
374 
375                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
376                     finderArgs, list);
377 
378                 closeSession(session);
379             }
380         }
381 
382         return list;
383     }
384 
385     public List<LayoutPrototype> findByCompanyId(long companyId, int start,
386         int end) throws SystemException {
387         return findByCompanyId(companyId, start, end, null);
388     }
389 
390     public List<LayoutPrototype> findByCompanyId(long companyId, int start,
391         int end, OrderByComparator orderByComparator) throws SystemException {
392         Object[] finderArgs = new Object[] {
393                 new Long(companyId),
394                 
395                 String.valueOf(start), String.valueOf(end),
396                 String.valueOf(orderByComparator)
397             };
398 
399         List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
400                 finderArgs, this);
401 
402         if (list == null) {
403             Session session = null;
404 
405             try {
406                 session = openSession();
407 
408                 StringBundler query = null;
409 
410                 if (orderByComparator != null) {
411                     query = new StringBundler(3 +
412                             (orderByComparator.getOrderByFields().length * 3));
413                 }
414                 else {
415                     query = new StringBundler(2);
416                 }
417 
418                 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
419 
420                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
421 
422                 if (orderByComparator != null) {
423                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
424                         orderByComparator);
425                 }
426 
427                 String sql = query.toString();
428 
429                 Query q = session.createQuery(sql);
430 
431                 QueryPos qPos = QueryPos.getInstance(q);
432 
433                 qPos.add(companyId);
434 
435                 list = (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
436                         start, end);
437             }
438             catch (Exception e) {
439                 throw processException(e);
440             }
441             finally {
442                 if (list == null) {
443                     list = new ArrayList<LayoutPrototype>();
444                 }
445 
446                 cacheResult(list);
447 
448                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
449                     finderArgs, list);
450 
451                 closeSession(session);
452             }
453         }
454 
455         return list;
456     }
457 
458     public LayoutPrototype findByCompanyId_First(long companyId,
459         OrderByComparator orderByComparator)
460         throws NoSuchLayoutPrototypeException, SystemException {
461         List<LayoutPrototype> list = findByCompanyId(companyId, 0, 1,
462                 orderByComparator);
463 
464         if (list.isEmpty()) {
465             StringBundler msg = new StringBundler(4);
466 
467             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
468 
469             msg.append("companyId=");
470             msg.append(companyId);
471 
472             msg.append(StringPool.CLOSE_CURLY_BRACE);
473 
474             throw new NoSuchLayoutPrototypeException(msg.toString());
475         }
476         else {
477             return list.get(0);
478         }
479     }
480 
481     public LayoutPrototype findByCompanyId_Last(long companyId,
482         OrderByComparator orderByComparator)
483         throws NoSuchLayoutPrototypeException, SystemException {
484         int count = countByCompanyId(companyId);
485 
486         List<LayoutPrototype> list = findByCompanyId(companyId, count - 1,
487                 count, orderByComparator);
488 
489         if (list.isEmpty()) {
490             StringBundler msg = new StringBundler(4);
491 
492             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
493 
494             msg.append("companyId=");
495             msg.append(companyId);
496 
497             msg.append(StringPool.CLOSE_CURLY_BRACE);
498 
499             throw new NoSuchLayoutPrototypeException(msg.toString());
500         }
501         else {
502             return list.get(0);
503         }
504     }
505 
506     public LayoutPrototype[] findByCompanyId_PrevAndNext(
507         long layoutPrototypeId, long companyId,
508         OrderByComparator orderByComparator)
509         throws NoSuchLayoutPrototypeException, SystemException {
510         LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
511 
512         int count = countByCompanyId(companyId);
513 
514         Session session = null;
515 
516         try {
517             session = openSession();
518 
519             StringBundler query = null;
520 
521             if (orderByComparator != null) {
522                 query = new StringBundler(3 +
523                         (orderByComparator.getOrderByFields().length * 3));
524             }
525             else {
526                 query = new StringBundler(2);
527             }
528 
529             query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
530 
531             query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
532 
533             if (orderByComparator != null) {
534                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
535                     orderByComparator);
536             }
537 
538             String sql = query.toString();
539 
540             Query q = session.createQuery(sql);
541 
542             QueryPos qPos = QueryPos.getInstance(q);
543 
544             qPos.add(companyId);
545 
546             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
547                     orderByComparator, layoutPrototype);
548 
549             LayoutPrototype[] array = new LayoutPrototypeImpl[3];
550 
551             array[0] = (LayoutPrototype)objArray[0];
552             array[1] = (LayoutPrototype)objArray[1];
553             array[2] = (LayoutPrototype)objArray[2];
554 
555             return array;
556         }
557         catch (Exception e) {
558             throw processException(e);
559         }
560         finally {
561             closeSession(session);
562         }
563     }
564 
565     public List<LayoutPrototype> findByC_A(long companyId, boolean active)
566         throws SystemException {
567         Object[] finderArgs = new Object[] {
568                 new Long(companyId), Boolean.valueOf(active)
569             };
570 
571         List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_A,
572                 finderArgs, this);
573 
574         if (list == null) {
575             Session session = null;
576 
577             try {
578                 session = openSession();
579 
580                 StringBundler query = new StringBundler(3);
581 
582                 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
583 
584                 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
585 
586                 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
587 
588                 String sql = query.toString();
589 
590                 Query q = session.createQuery(sql);
591 
592                 QueryPos qPos = QueryPos.getInstance(q);
593 
594                 qPos.add(companyId);
595 
596                 qPos.add(active);
597 
598                 list = q.list();
599             }
600             catch (Exception e) {
601                 throw processException(e);
602             }
603             finally {
604                 if (list == null) {
605                     list = new ArrayList<LayoutPrototype>();
606                 }
607 
608                 cacheResult(list);
609 
610                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_A, finderArgs,
611                     list);
612 
613                 closeSession(session);
614             }
615         }
616 
617         return list;
618     }
619 
620     public List<LayoutPrototype> findByC_A(long companyId, boolean active,
621         int start, int end) throws SystemException {
622         return findByC_A(companyId, active, start, end, null);
623     }
624 
625     public List<LayoutPrototype> findByC_A(long companyId, boolean active,
626         int start, int end, OrderByComparator orderByComparator)
627         throws SystemException {
628         Object[] finderArgs = new Object[] {
629                 new Long(companyId), Boolean.valueOf(active),
630                 
631                 String.valueOf(start), String.valueOf(end),
632                 String.valueOf(orderByComparator)
633             };
634 
635         List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_A,
636                 finderArgs, this);
637 
638         if (list == null) {
639             Session session = null;
640 
641             try {
642                 session = openSession();
643 
644                 StringBundler query = null;
645 
646                 if (orderByComparator != null) {
647                     query = new StringBundler(4 +
648                             (orderByComparator.getOrderByFields().length * 3));
649                 }
650                 else {
651                     query = new StringBundler(3);
652                 }
653 
654                 query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
655 
656                 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
657 
658                 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
659 
660                 if (orderByComparator != null) {
661                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
662                         orderByComparator);
663                 }
664 
665                 String sql = query.toString();
666 
667                 Query q = session.createQuery(sql);
668 
669                 QueryPos qPos = QueryPos.getInstance(q);
670 
671                 qPos.add(companyId);
672 
673                 qPos.add(active);
674 
675                 list = (List<LayoutPrototype>)QueryUtil.list(q, getDialect(),
676                         start, end);
677             }
678             catch (Exception e) {
679                 throw processException(e);
680             }
681             finally {
682                 if (list == null) {
683                     list = new ArrayList<LayoutPrototype>();
684                 }
685 
686                 cacheResult(list);
687 
688                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_A,
689                     finderArgs, list);
690 
691                 closeSession(session);
692             }
693         }
694 
695         return list;
696     }
697 
698     public LayoutPrototype findByC_A_First(long companyId, boolean active,
699         OrderByComparator orderByComparator)
700         throws NoSuchLayoutPrototypeException, SystemException {
701         List<LayoutPrototype> list = findByC_A(companyId, active, 0, 1,
702                 orderByComparator);
703 
704         if (list.isEmpty()) {
705             StringBundler msg = new StringBundler(6);
706 
707             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
708 
709             msg.append("companyId=");
710             msg.append(companyId);
711 
712             msg.append(", active=");
713             msg.append(active);
714 
715             msg.append(StringPool.CLOSE_CURLY_BRACE);
716 
717             throw new NoSuchLayoutPrototypeException(msg.toString());
718         }
719         else {
720             return list.get(0);
721         }
722     }
723 
724     public LayoutPrototype findByC_A_Last(long companyId, boolean active,
725         OrderByComparator orderByComparator)
726         throws NoSuchLayoutPrototypeException, SystemException {
727         int count = countByC_A(companyId, active);
728 
729         List<LayoutPrototype> list = findByC_A(companyId, active, count - 1,
730                 count, orderByComparator);
731 
732         if (list.isEmpty()) {
733             StringBundler msg = new StringBundler(6);
734 
735             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
736 
737             msg.append("companyId=");
738             msg.append(companyId);
739 
740             msg.append(", active=");
741             msg.append(active);
742 
743             msg.append(StringPool.CLOSE_CURLY_BRACE);
744 
745             throw new NoSuchLayoutPrototypeException(msg.toString());
746         }
747         else {
748             return list.get(0);
749         }
750     }
751 
752     public LayoutPrototype[] findByC_A_PrevAndNext(long layoutPrototypeId,
753         long companyId, boolean active, OrderByComparator orderByComparator)
754         throws NoSuchLayoutPrototypeException, SystemException {
755         LayoutPrototype layoutPrototype = findByPrimaryKey(layoutPrototypeId);
756 
757         int count = countByC_A(companyId, active);
758 
759         Session session = null;
760 
761         try {
762             session = openSession();
763 
764             StringBundler query = null;
765 
766             if (orderByComparator != null) {
767                 query = new StringBundler(4 +
768                         (orderByComparator.getOrderByFields().length * 3));
769             }
770             else {
771                 query = new StringBundler(3);
772             }
773 
774             query.append(_SQL_SELECT_LAYOUTPROTOTYPE_WHERE);
775 
776             query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
777 
778             query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
779 
780             if (orderByComparator != null) {
781                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
782                     orderByComparator);
783             }
784 
785             String sql = query.toString();
786 
787             Query q = session.createQuery(sql);
788 
789             QueryPos qPos = QueryPos.getInstance(q);
790 
791             qPos.add(companyId);
792 
793             qPos.add(active);
794 
795             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
796                     orderByComparator, layoutPrototype);
797 
798             LayoutPrototype[] array = new LayoutPrototypeImpl[3];
799 
800             array[0] = (LayoutPrototype)objArray[0];
801             array[1] = (LayoutPrototype)objArray[1];
802             array[2] = (LayoutPrototype)objArray[2];
803 
804             return array;
805         }
806         catch (Exception e) {
807             throw processException(e);
808         }
809         finally {
810             closeSession(session);
811         }
812     }
813 
814     public List<LayoutPrototype> findAll() throws SystemException {
815         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
816     }
817 
818     public List<LayoutPrototype> findAll(int start, int end)
819         throws SystemException {
820         return findAll(start, end, null);
821     }
822 
823     public List<LayoutPrototype> findAll(int start, int end,
824         OrderByComparator orderByComparator) throws SystemException {
825         Object[] finderArgs = new Object[] {
826                 String.valueOf(start), String.valueOf(end),
827                 String.valueOf(orderByComparator)
828             };
829 
830         List<LayoutPrototype> list = (List<LayoutPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
831                 finderArgs, this);
832 
833         if (list == null) {
834             Session session = null;
835 
836             try {
837                 session = openSession();
838 
839                 StringBundler query = null;
840                 String sql = null;
841 
842                 if (orderByComparator != null) {
843                     query = new StringBundler(2 +
844                             (orderByComparator.getOrderByFields().length * 3));
845 
846                     query.append(_SQL_SELECT_LAYOUTPROTOTYPE);
847 
848                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
849                         orderByComparator);
850 
851                     sql = query.toString();
852                 }
853 
854                 sql = _SQL_SELECT_LAYOUTPROTOTYPE;
855 
856                 Query q = session.createQuery(sql);
857 
858                 if (orderByComparator == null) {
859                     list = (List<LayoutPrototype>)QueryUtil.list(q,
860                             getDialect(), start, end, false);
861 
862                     Collections.sort(list);
863                 }
864                 else {
865                     list = (List<LayoutPrototype>)QueryUtil.list(q,
866                             getDialect(), start, end);
867                 }
868             }
869             catch (Exception e) {
870                 throw processException(e);
871             }
872             finally {
873                 if (list == null) {
874                     list = new ArrayList<LayoutPrototype>();
875                 }
876 
877                 cacheResult(list);
878 
879                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
880 
881                 closeSession(session);
882             }
883         }
884 
885         return list;
886     }
887 
888     public void removeByCompanyId(long companyId) throws SystemException {
889         for (LayoutPrototype layoutPrototype : findByCompanyId(companyId)) {
890             remove(layoutPrototype);
891         }
892     }
893 
894     public void removeByC_A(long companyId, boolean active)
895         throws SystemException {
896         for (LayoutPrototype layoutPrototype : findByC_A(companyId, active)) {
897             remove(layoutPrototype);
898         }
899     }
900 
901     public void removeAll() throws SystemException {
902         for (LayoutPrototype layoutPrototype : findAll()) {
903             remove(layoutPrototype);
904         }
905     }
906 
907     public int countByCompanyId(long companyId) throws SystemException {
908         Object[] finderArgs = new Object[] { new Long(companyId) };
909 
910         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
911                 finderArgs, this);
912 
913         if (count == null) {
914             Session session = null;
915 
916             try {
917                 session = openSession();
918 
919                 StringBundler query = new StringBundler(2);
920 
921                 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
922 
923                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
924 
925                 String sql = query.toString();
926 
927                 Query q = session.createQuery(sql);
928 
929                 QueryPos qPos = QueryPos.getInstance(q);
930 
931                 qPos.add(companyId);
932 
933                 count = (Long)q.uniqueResult();
934             }
935             catch (Exception e) {
936                 throw processException(e);
937             }
938             finally {
939                 if (count == null) {
940                     count = Long.valueOf(0);
941                 }
942 
943                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
944                     finderArgs, count);
945 
946                 closeSession(session);
947             }
948         }
949 
950         return count.intValue();
951     }
952 
953     public int countByC_A(long companyId, boolean active)
954         throws SystemException {
955         Object[] finderArgs = new Object[] {
956                 new Long(companyId), Boolean.valueOf(active)
957             };
958 
959         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_A,
960                 finderArgs, this);
961 
962         if (count == null) {
963             Session session = null;
964 
965             try {
966                 session = openSession();
967 
968                 StringBundler query = new StringBundler(3);
969 
970                 query.append(_SQL_COUNT_LAYOUTPROTOTYPE_WHERE);
971 
972                 query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
973 
974                 query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
975 
976                 String sql = query.toString();
977 
978                 Query q = session.createQuery(sql);
979 
980                 QueryPos qPos = QueryPos.getInstance(q);
981 
982                 qPos.add(companyId);
983 
984                 qPos.add(active);
985 
986                 count = (Long)q.uniqueResult();
987             }
988             catch (Exception e) {
989                 throw processException(e);
990             }
991             finally {
992                 if (count == null) {
993                     count = Long.valueOf(0);
994                 }
995 
996                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_A, finderArgs,
997                     count);
998 
999                 closeSession(session);
1000            }
1001        }
1002
1003        return count.intValue();
1004    }
1005
1006    public int countAll() throws SystemException {
1007        Object[] finderArgs = new Object[0];
1008
1009        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1010                finderArgs, this);
1011
1012        if (count == null) {
1013            Session session = null;
1014
1015            try {
1016                session = openSession();
1017
1018                Query q = session.createQuery(_SQL_COUNT_LAYOUTPROTOTYPE);
1019
1020                count = (Long)q.uniqueResult();
1021            }
1022            catch (Exception e) {
1023                throw processException(e);
1024            }
1025            finally {
1026                if (count == null) {
1027                    count = Long.valueOf(0);
1028                }
1029
1030                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1031                    count);
1032
1033                closeSession(session);
1034            }
1035        }
1036
1037        return count.intValue();
1038    }
1039
1040    public void afterPropertiesSet() {
1041        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1042                    com.liferay.portal.util.PropsUtil.get(
1043                        "value.object.listener.com.liferay.portal.model.LayoutPrototype")));
1044
1045        if (listenerClassNames.length > 0) {
1046            try {
1047                List<ModelListener<LayoutPrototype>> listenersList = new ArrayList<ModelListener<LayoutPrototype>>();
1048
1049                for (String listenerClassName : listenerClassNames) {
1050                    listenersList.add((ModelListener<LayoutPrototype>)Class.forName(
1051                            listenerClassName).newInstance());
1052                }
1053
1054                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1055            }
1056            catch (Exception e) {
1057                _log.error(e);
1058            }
1059        }
1060    }
1061
1062    @BeanReference(type = AccountPersistence.class)
1063    protected AccountPersistence accountPersistence;
1064    @BeanReference(type = AddressPersistence.class)
1065    protected AddressPersistence addressPersistence;
1066    @BeanReference(type = BrowserTrackerPersistence.class)
1067    protected BrowserTrackerPersistence browserTrackerPersistence;
1068    @BeanReference(type = ClassNamePersistence.class)
1069    protected ClassNamePersistence classNamePersistence;
1070    @BeanReference(type = CompanyPersistence.class)
1071    protected CompanyPersistence companyPersistence;
1072    @BeanReference(type = ContactPersistence.class)
1073    protected ContactPersistence contactPersistence;
1074    @BeanReference(type = CountryPersistence.class)
1075    protected CountryPersistence countryPersistence;
1076    @BeanReference(type = EmailAddressPersistence.class)
1077    protected EmailAddressPersistence emailAddressPersistence;
1078    @BeanReference(type = GroupPersistence.class)
1079    protected GroupPersistence groupPersistence;
1080    @BeanReference(type = ImagePersistence.class)
1081    protected ImagePersistence imagePersistence;
1082    @BeanReference(type = LayoutPersistence.class)
1083    protected LayoutPersistence layoutPersistence;
1084    @BeanReference(type = LayoutPrototypePersistence.class)
1085    protected LayoutPrototypePersistence layoutPrototypePersistence;
1086    @BeanReference(type = LayoutSetPersistence.class)
1087    protected LayoutSetPersistence layoutSetPersistence;
1088    @BeanReference(type = LayoutSetPrototypePersistence.class)
1089    protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1090    @BeanReference(type = ListTypePersistence.class)
1091    protected ListTypePersistence listTypePersistence;
1092    @BeanReference(type = LockPersistence.class)
1093    protected LockPersistence lockPersistence;
1094    @BeanReference(type = MembershipRequestPersistence.class)
1095    protected MembershipRequestPersistence membershipRequestPersistence;
1096    @BeanReference(type = OrganizationPersistence.class)
1097    protected OrganizationPersistence organizationPersistence;
1098    @BeanReference(type = OrgGroupPermissionPersistence.class)
1099    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1100    @BeanReference(type = OrgGroupRolePersistence.class)
1101    protected OrgGroupRolePersistence orgGroupRolePersistence;
1102    @BeanReference(type = OrgLaborPersistence.class)
1103    protected OrgLaborPersistence orgLaborPersistence;
1104    @BeanReference(type = PasswordPolicyPersistence.class)
1105    protected PasswordPolicyPersistence passwordPolicyPersistence;
1106    @BeanReference(type = PasswordPolicyRelPersistence.class)
1107    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1108    @BeanReference(type = PasswordTrackerPersistence.class)
1109    protected PasswordTrackerPersistence passwordTrackerPersistence;
1110    @BeanReference(type = PermissionPersistence.class)
1111    protected PermissionPersistence permissionPersistence;
1112    @BeanReference(type = PhonePersistence.class)
1113    protected PhonePersistence phonePersistence;
1114    @BeanReference(type = PluginSettingPersistence.class)
1115    protected PluginSettingPersistence pluginSettingPersistence;
1116    @BeanReference(type = PortletPersistence.class)
1117    protected PortletPersistence portletPersistence;
1118    @BeanReference(type = PortletItemPersistence.class)
1119    protected PortletItemPersistence portletItemPersistence;
1120    @BeanReference(type = PortletPreferencesPersistence.class)
1121    protected PortletPreferencesPersistence portletPreferencesPersistence;
1122    @BeanReference(type = RegionPersistence.class)
1123    protected RegionPersistence regionPersistence;
1124    @BeanReference(type = ReleasePersistence.class)
1125    protected ReleasePersistence releasePersistence;
1126    @BeanReference(type = ResourcePersistence.class)
1127    protected ResourcePersistence resourcePersistence;
1128    @BeanReference(type = ResourceActionPersistence.class)
1129    protected ResourceActionPersistence resourceActionPersistence;
1130    @BeanReference(type = ResourceCodePersistence.class)
1131    protected ResourceCodePersistence resourceCodePersistence;
1132    @BeanReference(type = ResourcePermissionPersistence.class)
1133    protected ResourcePermissionPersistence resourcePermissionPersistence;
1134    @BeanReference(type = RolePersistence.class)
1135    protected RolePersistence rolePersistence;
1136    @BeanReference(type = ServiceComponentPersistence.class)
1137    protected ServiceComponentPersistence serviceComponentPersistence;
1138    @BeanReference(type = ShardPersistence.class)
1139    protected ShardPersistence shardPersistence;
1140    @BeanReference(type = SubscriptionPersistence.class)
1141    protected SubscriptionPersistence subscriptionPersistence;
1142    @BeanReference(type = TeamPersistence.class)
1143    protected TeamPersistence teamPersistence;
1144    @BeanReference(type = UserPersistence.class)
1145    protected UserPersistence userPersistence;
1146    @BeanReference(type = UserGroupPersistence.class)
1147    protected UserGroupPersistence userGroupPersistence;
1148    @BeanReference(type = UserGroupGroupRolePersistence.class)
1149    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1150    @BeanReference(type = UserGroupRolePersistence.class)
1151    protected UserGroupRolePersistence userGroupRolePersistence;
1152    @BeanReference(type = UserIdMapperPersistence.class)
1153    protected UserIdMapperPersistence userIdMapperPersistence;
1154    @BeanReference(type = UserTrackerPersistence.class)
1155    protected UserTrackerPersistence userTrackerPersistence;
1156    @BeanReference(type = UserTrackerPathPersistence.class)
1157    protected UserTrackerPathPersistence userTrackerPathPersistence;
1158    @BeanReference(type = WebDAVPropsPersistence.class)
1159    protected WebDAVPropsPersistence webDAVPropsPersistence;
1160    @BeanReference(type = WebsitePersistence.class)
1161    protected WebsitePersistence websitePersistence;
1162    @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1163    protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1164    @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1165    protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1166    private static final String _SQL_SELECT_LAYOUTPROTOTYPE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype";
1167    private static final String _SQL_SELECT_LAYOUTPROTOTYPE_WHERE = "SELECT layoutPrototype FROM LayoutPrototype layoutPrototype WHERE ";
1168    private static final String _SQL_COUNT_LAYOUTPROTOTYPE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype";
1169    private static final String _SQL_COUNT_LAYOUTPROTOTYPE_WHERE = "SELECT COUNT(layoutPrototype) FROM LayoutPrototype layoutPrototype WHERE ";
1170    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutPrototype.companyId = ?";
1171    private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "layoutPrototype.companyId = ? AND ";
1172    private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "layoutPrototype.active = ?";
1173    private static final String _ORDER_BY_ENTITY_ALIAS = "layoutPrototype.";
1174    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutPrototype exists with the primary key ";
1175    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutPrototype exists with the key {";
1176    private static Log _log = LogFactoryUtil.getLog(LayoutPrototypePersistenceImpl.class);
1177}