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.portlet.bookmarks.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderPath;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.QueryPos;
25  import com.liferay.portal.kernel.dao.orm.QueryUtil;
26  import com.liferay.portal.kernel.dao.orm.Session;
27  import com.liferay.portal.kernel.exception.SystemException;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.OrderByComparator;
32  import com.liferay.portal.kernel.util.StringBundler;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.kernel.util.StringUtil;
35  import com.liferay.portal.kernel.util.Validator;
36  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.service.persistence.BatchSessionUtil;
39  import com.liferay.portal.service.persistence.GroupPersistence;
40  import com.liferay.portal.service.persistence.ResourcePersistence;
41  import com.liferay.portal.service.persistence.UserPersistence;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import com.liferay.portlet.bookmarks.NoSuchFolderException;
45  import com.liferay.portlet.bookmarks.model.BookmarksFolder;
46  import com.liferay.portlet.bookmarks.model.impl.BookmarksFolderImpl;
47  import com.liferay.portlet.bookmarks.model.impl.BookmarksFolderModelImpl;
48  import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
49  
50  import java.io.Serializable;
51  
52  import java.util.ArrayList;
53  import java.util.Collections;
54  import java.util.List;
55  
56  /**
57   * <a href="BookmarksFolderPersistenceImpl.java.html"><b><i>View Source</i></b></a>
58   *
59   * <p>
60   * ServiceBuilder generated this class. Modifications in this class will be
61   * overwritten the next time is generated.
62   * </p>
63   *
64   * @author    Brian Wing Shun Chan
65   * @see       BookmarksFolderPersistence
66   * @see       BookmarksFolderUtil
67   * @generated
68   */
69  public class BookmarksFolderPersistenceImpl extends BasePersistenceImpl<BookmarksFolder>
70      implements BookmarksFolderPersistence {
71      public static final String FINDER_CLASS_NAME_ENTITY = BookmarksFolderImpl.class.getName();
72      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
73          ".List";
74      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
75              BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
76              FINDER_CLASS_NAME_LIST, "findByUuid",
77              new String[] { String.class.getName() });
78      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
79              BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
80              FINDER_CLASS_NAME_LIST, "findByUuid",
81              new String[] {
82                  String.class.getName(),
83                  
84              "java.lang.Integer", "java.lang.Integer",
85                  "com.liferay.portal.kernel.util.OrderByComparator"
86              });
87      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
88              BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
89              FINDER_CLASS_NAME_LIST, "countByUuid",
90              new String[] { String.class.getName() });
91      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
92              BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
93              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
94              new String[] { String.class.getName(), Long.class.getName() });
95      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
96              BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
97              FINDER_CLASS_NAME_LIST, "countByUUID_G",
98              new String[] { String.class.getName(), Long.class.getName() });
99      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
100             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
101             FINDER_CLASS_NAME_LIST, "findByGroupId",
102             new String[] { Long.class.getName() });
103     public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
104             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
105             FINDER_CLASS_NAME_LIST, "findByGroupId",
106             new String[] {
107                 Long.class.getName(),
108                 
109             "java.lang.Integer", "java.lang.Integer",
110                 "com.liferay.portal.kernel.util.OrderByComparator"
111             });
112     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
113             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
114             FINDER_CLASS_NAME_LIST, "countByGroupId",
115             new String[] { Long.class.getName() });
116     public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
117             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
118             FINDER_CLASS_NAME_LIST, "findByCompanyId",
119             new String[] { Long.class.getName() });
120     public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
121             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
122             FINDER_CLASS_NAME_LIST, "findByCompanyId",
123             new String[] {
124                 Long.class.getName(),
125                 
126             "java.lang.Integer", "java.lang.Integer",
127                 "com.liferay.portal.kernel.util.OrderByComparator"
128             });
129     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
130             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
131             FINDER_CLASS_NAME_LIST, "countByCompanyId",
132             new String[] { Long.class.getName() });
133     public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
134             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
135             FINDER_CLASS_NAME_LIST, "findByG_P",
136             new String[] { Long.class.getName(), Long.class.getName() });
137     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_P = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
138             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
139             FINDER_CLASS_NAME_LIST, "findByG_P",
140             new String[] {
141                 Long.class.getName(), Long.class.getName(),
142                 
143             "java.lang.Integer", "java.lang.Integer",
144                 "com.liferay.portal.kernel.util.OrderByComparator"
145             });
146     public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
147             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
148             FINDER_CLASS_NAME_LIST, "countByG_P",
149             new String[] { Long.class.getName(), Long.class.getName() });
150     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
151             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
152             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
153     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
154             BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
155             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
156 
157     public void cacheResult(BookmarksFolder bookmarksFolder) {
158         EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
159             BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
160             bookmarksFolder);
161 
162         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
163             new Object[] {
164                 bookmarksFolder.getUuid(),
165                 new Long(bookmarksFolder.getGroupId())
166             }, bookmarksFolder);
167     }
168 
169     public void cacheResult(List<BookmarksFolder> bookmarksFolders) {
170         for (BookmarksFolder bookmarksFolder : bookmarksFolders) {
171             if (EntityCacheUtil.getResult(
172                         BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
173                         BookmarksFolderImpl.class,
174                         bookmarksFolder.getPrimaryKey(), this) == null) {
175                 cacheResult(bookmarksFolder);
176             }
177         }
178     }
179 
180     public void clearCache() {
181         CacheRegistry.clear(BookmarksFolderImpl.class.getName());
182         EntityCacheUtil.clearCache(BookmarksFolderImpl.class.getName());
183         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
184         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
185     }
186 
187     public BookmarksFolder create(long folderId) {
188         BookmarksFolder bookmarksFolder = new BookmarksFolderImpl();
189 
190         bookmarksFolder.setNew(true);
191         bookmarksFolder.setPrimaryKey(folderId);
192 
193         String uuid = PortalUUIDUtil.generate();
194 
195         bookmarksFolder.setUuid(uuid);
196 
197         return bookmarksFolder;
198     }
199 
200     public BookmarksFolder remove(Serializable primaryKey)
201         throws NoSuchModelException, SystemException {
202         return remove(((Long)primaryKey).longValue());
203     }
204 
205     public BookmarksFolder remove(long folderId)
206         throws NoSuchFolderException, SystemException {
207         Session session = null;
208 
209         try {
210             session = openSession();
211 
212             BookmarksFolder bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
213                     new Long(folderId));
214 
215             if (bookmarksFolder == null) {
216                 if (_log.isWarnEnabled()) {
217                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
218                 }
219 
220                 throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
221                     folderId);
222             }
223 
224             return remove(bookmarksFolder);
225         }
226         catch (NoSuchFolderException nsee) {
227             throw nsee;
228         }
229         catch (Exception e) {
230             throw processException(e);
231         }
232         finally {
233             closeSession(session);
234         }
235     }
236 
237     public BookmarksFolder remove(BookmarksFolder bookmarksFolder)
238         throws SystemException {
239         for (ModelListener<BookmarksFolder> listener : listeners) {
240             listener.onBeforeRemove(bookmarksFolder);
241         }
242 
243         bookmarksFolder = removeImpl(bookmarksFolder);
244 
245         for (ModelListener<BookmarksFolder> listener : listeners) {
246             listener.onAfterRemove(bookmarksFolder);
247         }
248 
249         return bookmarksFolder;
250     }
251 
252     protected BookmarksFolder removeImpl(BookmarksFolder bookmarksFolder)
253         throws SystemException {
254         bookmarksFolder = toUnwrappedModel(bookmarksFolder);
255 
256         Session session = null;
257 
258         try {
259             session = openSession();
260 
261             if (bookmarksFolder.isCachedModel() ||
262                     BatchSessionUtil.isEnabled()) {
263                 Object staleObject = session.get(BookmarksFolderImpl.class,
264                         bookmarksFolder.getPrimaryKeyObj());
265 
266                 if (staleObject != null) {
267                     session.evict(staleObject);
268                 }
269             }
270 
271             session.delete(bookmarksFolder);
272 
273             session.flush();
274         }
275         catch (Exception e) {
276             throw processException(e);
277         }
278         finally {
279             closeSession(session);
280         }
281 
282         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
283 
284         BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
285 
286         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
287             new Object[] {
288                 bookmarksFolderModelImpl.getOriginalUuid(),
289                 new Long(bookmarksFolderModelImpl.getOriginalGroupId())
290             });
291 
292         EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
293             BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey());
294 
295         return bookmarksFolder;
296     }
297 
298     public BookmarksFolder updateImpl(
299         com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder,
300         boolean merge) throws SystemException {
301         bookmarksFolder = toUnwrappedModel(bookmarksFolder);
302 
303         boolean isNew = bookmarksFolder.isNew();
304 
305         BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
306 
307         if (Validator.isNull(bookmarksFolder.getUuid())) {
308             String uuid = PortalUUIDUtil.generate();
309 
310             bookmarksFolder.setUuid(uuid);
311         }
312 
313         Session session = null;
314 
315         try {
316             session = openSession();
317 
318             BatchSessionUtil.update(session, bookmarksFolder, merge);
319 
320             bookmarksFolder.setNew(false);
321         }
322         catch (Exception e) {
323             throw processException(e);
324         }
325         finally {
326             closeSession(session);
327         }
328 
329         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
330 
331         EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
332             BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
333             bookmarksFolder);
334 
335         if (!isNew &&
336                 (!Validator.equals(bookmarksFolder.getUuid(),
337                     bookmarksFolderModelImpl.getOriginalUuid()) ||
338                 (bookmarksFolder.getGroupId() != bookmarksFolderModelImpl.getOriginalGroupId()))) {
339             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
340                 new Object[] {
341                     bookmarksFolderModelImpl.getOriginalUuid(),
342                     new Long(bookmarksFolderModelImpl.getOriginalGroupId())
343                 });
344         }
345 
346         if (isNew ||
347                 (!Validator.equals(bookmarksFolder.getUuid(),
348                     bookmarksFolderModelImpl.getOriginalUuid()) ||
349                 (bookmarksFolder.getGroupId() != bookmarksFolderModelImpl.getOriginalGroupId()))) {
350             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
351                 new Object[] {
352                     bookmarksFolder.getUuid(),
353                     new Long(bookmarksFolder.getGroupId())
354                 }, bookmarksFolder);
355         }
356 
357         return bookmarksFolder;
358     }
359 
360     protected BookmarksFolder toUnwrappedModel(BookmarksFolder bookmarksFolder) {
361         if (bookmarksFolder instanceof BookmarksFolderImpl) {
362             return bookmarksFolder;
363         }
364 
365         BookmarksFolderImpl bookmarksFolderImpl = new BookmarksFolderImpl();
366 
367         bookmarksFolderImpl.setNew(bookmarksFolder.isNew());
368         bookmarksFolderImpl.setPrimaryKey(bookmarksFolder.getPrimaryKey());
369 
370         bookmarksFolderImpl.setUuid(bookmarksFolder.getUuid());
371         bookmarksFolderImpl.setFolderId(bookmarksFolder.getFolderId());
372         bookmarksFolderImpl.setGroupId(bookmarksFolder.getGroupId());
373         bookmarksFolderImpl.setCompanyId(bookmarksFolder.getCompanyId());
374         bookmarksFolderImpl.setUserId(bookmarksFolder.getUserId());
375         bookmarksFolderImpl.setCreateDate(bookmarksFolder.getCreateDate());
376         bookmarksFolderImpl.setModifiedDate(bookmarksFolder.getModifiedDate());
377         bookmarksFolderImpl.setParentFolderId(bookmarksFolder.getParentFolderId());
378         bookmarksFolderImpl.setName(bookmarksFolder.getName());
379         bookmarksFolderImpl.setDescription(bookmarksFolder.getDescription());
380 
381         return bookmarksFolderImpl;
382     }
383 
384     public BookmarksFolder findByPrimaryKey(Serializable primaryKey)
385         throws NoSuchModelException, SystemException {
386         return findByPrimaryKey(((Long)primaryKey).longValue());
387     }
388 
389     public BookmarksFolder findByPrimaryKey(long folderId)
390         throws NoSuchFolderException, SystemException {
391         BookmarksFolder bookmarksFolder = fetchByPrimaryKey(folderId);
392 
393         if (bookmarksFolder == null) {
394             if (_log.isWarnEnabled()) {
395                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
396             }
397 
398             throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
399                 folderId);
400         }
401 
402         return bookmarksFolder;
403     }
404 
405     public BookmarksFolder fetchByPrimaryKey(Serializable primaryKey)
406         throws SystemException {
407         return fetchByPrimaryKey(((Long)primaryKey).longValue());
408     }
409 
410     public BookmarksFolder fetchByPrimaryKey(long folderId)
411         throws SystemException {
412         BookmarksFolder bookmarksFolder = (BookmarksFolder)EntityCacheUtil.getResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
413                 BookmarksFolderImpl.class, folderId, this);
414 
415         if (bookmarksFolder == null) {
416             Session session = null;
417 
418             try {
419                 session = openSession();
420 
421                 bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
422                         new Long(folderId));
423             }
424             catch (Exception e) {
425                 throw processException(e);
426             }
427             finally {
428                 if (bookmarksFolder != null) {
429                     cacheResult(bookmarksFolder);
430                 }
431 
432                 closeSession(session);
433             }
434         }
435 
436         return bookmarksFolder;
437     }
438 
439     public List<BookmarksFolder> findByUuid(String uuid)
440         throws SystemException {
441         Object[] finderArgs = new Object[] { uuid };
442 
443         List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
444                 finderArgs, this);
445 
446         if (list == null) {
447             Session session = null;
448 
449             try {
450                 session = openSession();
451 
452                 StringBundler query = new StringBundler(3);
453 
454                 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
455 
456                 if (uuid == null) {
457                     query.append(_FINDER_COLUMN_UUID_UUID_1);
458                 }
459                 else {
460                     if (uuid.equals(StringPool.BLANK)) {
461                         query.append(_FINDER_COLUMN_UUID_UUID_3);
462                     }
463                     else {
464                         query.append(_FINDER_COLUMN_UUID_UUID_2);
465                     }
466                 }
467 
468                 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
469 
470                 String sql = query.toString();
471 
472                 Query q = session.createQuery(sql);
473 
474                 QueryPos qPos = QueryPos.getInstance(q);
475 
476                 if (uuid != null) {
477                     qPos.add(uuid);
478                 }
479 
480                 list = q.list();
481             }
482             catch (Exception e) {
483                 throw processException(e);
484             }
485             finally {
486                 if (list == null) {
487                     list = new ArrayList<BookmarksFolder>();
488                 }
489 
490                 cacheResult(list);
491 
492                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
493                     list);
494 
495                 closeSession(session);
496             }
497         }
498 
499         return list;
500     }
501 
502     public List<BookmarksFolder> findByUuid(String uuid, int start, int end)
503         throws SystemException {
504         return findByUuid(uuid, start, end, null);
505     }
506 
507     public List<BookmarksFolder> findByUuid(String uuid, int start, int end,
508         OrderByComparator orderByComparator) throws SystemException {
509         Object[] finderArgs = new Object[] {
510                 uuid,
511                 
512                 String.valueOf(start), String.valueOf(end),
513                 String.valueOf(orderByComparator)
514             };
515 
516         List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
517                 finderArgs, this);
518 
519         if (list == null) {
520             Session session = null;
521 
522             try {
523                 session = openSession();
524 
525                 StringBundler query = null;
526 
527                 if (orderByComparator != null) {
528                     query = new StringBundler(3 +
529                             (orderByComparator.getOrderByFields().length * 3));
530                 }
531                 else {
532                     query = new StringBundler(3);
533                 }
534 
535                 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
536 
537                 if (uuid == null) {
538                     query.append(_FINDER_COLUMN_UUID_UUID_1);
539                 }
540                 else {
541                     if (uuid.equals(StringPool.BLANK)) {
542                         query.append(_FINDER_COLUMN_UUID_UUID_3);
543                     }
544                     else {
545                         query.append(_FINDER_COLUMN_UUID_UUID_2);
546                     }
547                 }
548 
549                 if (orderByComparator != null) {
550                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
551                         orderByComparator);
552                 }
553 
554                 else {
555                     query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
556                 }
557 
558                 String sql = query.toString();
559 
560                 Query q = session.createQuery(sql);
561 
562                 QueryPos qPos = QueryPos.getInstance(q);
563 
564                 if (uuid != null) {
565                     qPos.add(uuid);
566                 }
567 
568                 list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
569                         start, end);
570             }
571             catch (Exception e) {
572                 throw processException(e);
573             }
574             finally {
575                 if (list == null) {
576                     list = new ArrayList<BookmarksFolder>();
577                 }
578 
579                 cacheResult(list);
580 
581                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
582                     finderArgs, list);
583 
584                 closeSession(session);
585             }
586         }
587 
588         return list;
589     }
590 
591     public BookmarksFolder findByUuid_First(String uuid,
592         OrderByComparator orderByComparator)
593         throws NoSuchFolderException, SystemException {
594         List<BookmarksFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
595 
596         if (list.isEmpty()) {
597             StringBundler msg = new StringBundler(4);
598 
599             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
600 
601             msg.append("uuid=");
602             msg.append(uuid);
603 
604             msg.append(StringPool.CLOSE_CURLY_BRACE);
605 
606             throw new NoSuchFolderException(msg.toString());
607         }
608         else {
609             return list.get(0);
610         }
611     }
612 
613     public BookmarksFolder findByUuid_Last(String uuid,
614         OrderByComparator orderByComparator)
615         throws NoSuchFolderException, SystemException {
616         int count = countByUuid(uuid);
617 
618         List<BookmarksFolder> list = findByUuid(uuid, count - 1, count,
619                 orderByComparator);
620 
621         if (list.isEmpty()) {
622             StringBundler msg = new StringBundler(4);
623 
624             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
625 
626             msg.append("uuid=");
627             msg.append(uuid);
628 
629             msg.append(StringPool.CLOSE_CURLY_BRACE);
630 
631             throw new NoSuchFolderException(msg.toString());
632         }
633         else {
634             return list.get(0);
635         }
636     }
637 
638     public BookmarksFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
639         OrderByComparator orderByComparator)
640         throws NoSuchFolderException, SystemException {
641         BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
642 
643         int count = countByUuid(uuid);
644 
645         Session session = null;
646 
647         try {
648             session = openSession();
649 
650             StringBundler query = null;
651 
652             if (orderByComparator != null) {
653                 query = new StringBundler(3 +
654                         (orderByComparator.getOrderByFields().length * 3));
655             }
656             else {
657                 query = new StringBundler(3);
658             }
659 
660             query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
661 
662             if (uuid == null) {
663                 query.append(_FINDER_COLUMN_UUID_UUID_1);
664             }
665             else {
666                 if (uuid.equals(StringPool.BLANK)) {
667                     query.append(_FINDER_COLUMN_UUID_UUID_3);
668                 }
669                 else {
670                     query.append(_FINDER_COLUMN_UUID_UUID_2);
671                 }
672             }
673 
674             if (orderByComparator != null) {
675                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
676                     orderByComparator);
677             }
678 
679             else {
680                 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
681             }
682 
683             String sql = query.toString();
684 
685             Query q = session.createQuery(sql);
686 
687             QueryPos qPos = QueryPos.getInstance(q);
688 
689             if (uuid != null) {
690                 qPos.add(uuid);
691             }
692 
693             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
694                     orderByComparator, bookmarksFolder);
695 
696             BookmarksFolder[] array = new BookmarksFolderImpl[3];
697 
698             array[0] = (BookmarksFolder)objArray[0];
699             array[1] = (BookmarksFolder)objArray[1];
700             array[2] = (BookmarksFolder)objArray[2];
701 
702             return array;
703         }
704         catch (Exception e) {
705             throw processException(e);
706         }
707         finally {
708             closeSession(session);
709         }
710     }
711 
712     public BookmarksFolder findByUUID_G(String uuid, long groupId)
713         throws NoSuchFolderException, SystemException {
714         BookmarksFolder bookmarksFolder = fetchByUUID_G(uuid, groupId);
715 
716         if (bookmarksFolder == null) {
717             StringBundler msg = new StringBundler(6);
718 
719             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
720 
721             msg.append("uuid=");
722             msg.append(uuid);
723 
724             msg.append(", groupId=");
725             msg.append(groupId);
726 
727             msg.append(StringPool.CLOSE_CURLY_BRACE);
728 
729             if (_log.isWarnEnabled()) {
730                 _log.warn(msg.toString());
731             }
732 
733             throw new NoSuchFolderException(msg.toString());
734         }
735 
736         return bookmarksFolder;
737     }
738 
739     public BookmarksFolder fetchByUUID_G(String uuid, long groupId)
740         throws SystemException {
741         return fetchByUUID_G(uuid, groupId, true);
742     }
743 
744     public BookmarksFolder fetchByUUID_G(String uuid, long groupId,
745         boolean retrieveFromCache) throws SystemException {
746         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
747 
748         Object result = null;
749 
750         if (retrieveFromCache) {
751             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
752                     finderArgs, this);
753         }
754 
755         if (result == null) {
756             Session session = null;
757 
758             try {
759                 session = openSession();
760 
761                 StringBundler query = new StringBundler(4);
762 
763                 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
764 
765                 if (uuid == null) {
766                     query.append(_FINDER_COLUMN_UUID_G_UUID_1);
767                 }
768                 else {
769                     if (uuid.equals(StringPool.BLANK)) {
770                         query.append(_FINDER_COLUMN_UUID_G_UUID_3);
771                     }
772                     else {
773                         query.append(_FINDER_COLUMN_UUID_G_UUID_2);
774                     }
775                 }
776 
777                 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
778 
779                 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
780 
781                 String sql = query.toString();
782 
783                 Query q = session.createQuery(sql);
784 
785                 QueryPos qPos = QueryPos.getInstance(q);
786 
787                 if (uuid != null) {
788                     qPos.add(uuid);
789                 }
790 
791                 qPos.add(groupId);
792 
793                 List<BookmarksFolder> list = q.list();
794 
795                 result = list;
796 
797                 BookmarksFolder bookmarksFolder = null;
798 
799                 if (list.isEmpty()) {
800                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
801                         finderArgs, list);
802                 }
803                 else {
804                     bookmarksFolder = list.get(0);
805 
806                     cacheResult(bookmarksFolder);
807 
808                     if ((bookmarksFolder.getUuid() == null) ||
809                             !bookmarksFolder.getUuid().equals(uuid) ||
810                             (bookmarksFolder.getGroupId() != groupId)) {
811                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
812                             finderArgs, bookmarksFolder);
813                     }
814                 }
815 
816                 return bookmarksFolder;
817             }
818             catch (Exception e) {
819                 throw processException(e);
820             }
821             finally {
822                 if (result == null) {
823                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
824                         finderArgs, new ArrayList<BookmarksFolder>());
825                 }
826 
827                 closeSession(session);
828             }
829         }
830         else {
831             if (result instanceof List<?>) {
832                 return null;
833             }
834             else {
835                 return (BookmarksFolder)result;
836             }
837         }
838     }
839 
840     public List<BookmarksFolder> findByGroupId(long groupId)
841         throws SystemException {
842         Object[] finderArgs = new Object[] { new Long(groupId) };
843 
844         List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
845                 finderArgs, this);
846 
847         if (list == null) {
848             Session session = null;
849 
850             try {
851                 session = openSession();
852 
853                 StringBundler query = new StringBundler(3);
854 
855                 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
856 
857                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
858 
859                 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
860 
861                 String sql = query.toString();
862 
863                 Query q = session.createQuery(sql);
864 
865                 QueryPos qPos = QueryPos.getInstance(q);
866 
867                 qPos.add(groupId);
868 
869                 list = q.list();
870             }
871             catch (Exception e) {
872                 throw processException(e);
873             }
874             finally {
875                 if (list == null) {
876                     list = new ArrayList<BookmarksFolder>();
877                 }
878 
879                 cacheResult(list);
880 
881                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
882                     finderArgs, list);
883 
884                 closeSession(session);
885             }
886         }
887 
888         return list;
889     }
890 
891     public List<BookmarksFolder> findByGroupId(long groupId, int start, int end)
892         throws SystemException {
893         return findByGroupId(groupId, start, end, null);
894     }
895 
896     public List<BookmarksFolder> findByGroupId(long groupId, int start,
897         int end, OrderByComparator orderByComparator) throws SystemException {
898         Object[] finderArgs = new Object[] {
899                 new Long(groupId),
900                 
901                 String.valueOf(start), String.valueOf(end),
902                 String.valueOf(orderByComparator)
903             };
904 
905         List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
906                 finderArgs, this);
907 
908         if (list == null) {
909             Session session = null;
910 
911             try {
912                 session = openSession();
913 
914                 StringBundler query = null;
915 
916                 if (orderByComparator != null) {
917                     query = new StringBundler(3 +
918                             (orderByComparator.getOrderByFields().length * 3));
919                 }
920                 else {
921                     query = new StringBundler(3);
922                 }
923 
924                 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
925 
926                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
927 
928                 if (orderByComparator != null) {
929                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
930                         orderByComparator);
931                 }
932 
933                 else {
934                     query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
935                 }
936 
937                 String sql = query.toString();
938 
939                 Query q = session.createQuery(sql);
940 
941                 QueryPos qPos = QueryPos.getInstance(q);
942 
943                 qPos.add(groupId);
944 
945                 list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
946                         start, end);
947             }
948             catch (Exception e) {
949                 throw processException(e);
950             }
951             finally {
952                 if (list == null) {
953                     list = new ArrayList<BookmarksFolder>();
954                 }
955 
956                 cacheResult(list);
957 
958                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
959                     finderArgs, list);
960 
961                 closeSession(session);
962             }
963         }
964 
965         return list;
966     }
967 
968     public BookmarksFolder findByGroupId_First(long groupId,
969         OrderByComparator orderByComparator)
970         throws NoSuchFolderException, SystemException {
971         List<BookmarksFolder> list = findByGroupId(groupId, 0, 1,
972                 orderByComparator);
973 
974         if (list.isEmpty()) {
975             StringBundler msg = new StringBundler(4);
976 
977             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
978 
979             msg.append("groupId=");
980             msg.append(groupId);
981 
982             msg.append(StringPool.CLOSE_CURLY_BRACE);
983 
984             throw new NoSuchFolderException(msg.toString());
985         }
986         else {
987             return list.get(0);
988         }
989     }
990 
991     public BookmarksFolder findByGroupId_Last(long groupId,
992         OrderByComparator orderByComparator)
993         throws NoSuchFolderException, SystemException {
994         int count = countByGroupId(groupId);
995 
996         List<BookmarksFolder> list = findByGroupId(groupId, count - 1, count,
997                 orderByComparator);
998 
999         if (list.isEmpty()) {
1000            StringBundler msg = new StringBundler(4);
1001
1002            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1003
1004            msg.append("groupId=");
1005            msg.append(groupId);
1006
1007            msg.append(StringPool.CLOSE_CURLY_BRACE);
1008
1009            throw new NoSuchFolderException(msg.toString());
1010        }
1011        else {
1012            return list.get(0);
1013        }
1014    }
1015
1016    public BookmarksFolder[] findByGroupId_PrevAndNext(long folderId,
1017        long groupId, OrderByComparator orderByComparator)
1018        throws NoSuchFolderException, SystemException {
1019        BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
1020
1021        int count = countByGroupId(groupId);
1022
1023        Session session = null;
1024
1025        try {
1026            session = openSession();
1027
1028            StringBundler query = null;
1029
1030            if (orderByComparator != null) {
1031                query = new StringBundler(3 +
1032                        (orderByComparator.getOrderByFields().length * 3));
1033            }
1034            else {
1035                query = new StringBundler(3);
1036            }
1037
1038            query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1039
1040            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1041
1042            if (orderByComparator != null) {
1043                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1044                    orderByComparator);
1045            }
1046
1047            else {
1048                query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1049            }
1050
1051            String sql = query.toString();
1052
1053            Query q = session.createQuery(sql);
1054
1055            QueryPos qPos = QueryPos.getInstance(q);
1056
1057            qPos.add(groupId);
1058
1059            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1060                    orderByComparator, bookmarksFolder);
1061
1062            BookmarksFolder[] array = new BookmarksFolderImpl[3];
1063
1064            array[0] = (BookmarksFolder)objArray[0];
1065            array[1] = (BookmarksFolder)objArray[1];
1066            array[2] = (BookmarksFolder)objArray[2];
1067
1068            return array;
1069        }
1070        catch (Exception e) {
1071            throw processException(e);
1072        }
1073        finally {
1074            closeSession(session);
1075        }
1076    }
1077
1078    public List<BookmarksFolder> findByCompanyId(long companyId)
1079        throws SystemException {
1080        Object[] finderArgs = new Object[] { new Long(companyId) };
1081
1082        List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1083                finderArgs, this);
1084
1085        if (list == null) {
1086            Session session = null;
1087
1088            try {
1089                session = openSession();
1090
1091                StringBundler query = new StringBundler(3);
1092
1093                query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1094
1095                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1096
1097                query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1098
1099                String sql = query.toString();
1100
1101                Query q = session.createQuery(sql);
1102
1103                QueryPos qPos = QueryPos.getInstance(q);
1104
1105                qPos.add(companyId);
1106
1107                list = q.list();
1108            }
1109            catch (Exception e) {
1110                throw processException(e);
1111            }
1112            finally {
1113                if (list == null) {
1114                    list = new ArrayList<BookmarksFolder>();
1115                }
1116
1117                cacheResult(list);
1118
1119                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1120                    finderArgs, list);
1121
1122                closeSession(session);
1123            }
1124        }
1125
1126        return list;
1127    }
1128
1129    public List<BookmarksFolder> findByCompanyId(long companyId, int start,
1130        int end) throws SystemException {
1131        return findByCompanyId(companyId, start, end, null);
1132    }
1133
1134    public List<BookmarksFolder> findByCompanyId(long companyId, int start,
1135        int end, OrderByComparator orderByComparator) throws SystemException {
1136        Object[] finderArgs = new Object[] {
1137                new Long(companyId),
1138                
1139                String.valueOf(start), String.valueOf(end),
1140                String.valueOf(orderByComparator)
1141            };
1142
1143        List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1144                finderArgs, this);
1145
1146        if (list == null) {
1147            Session session = null;
1148
1149            try {
1150                session = openSession();
1151
1152                StringBundler query = null;
1153
1154                if (orderByComparator != null) {
1155                    query = new StringBundler(3 +
1156                            (orderByComparator.getOrderByFields().length * 3));
1157                }
1158                else {
1159                    query = new StringBundler(3);
1160                }
1161
1162                query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1163
1164                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1165
1166                if (orderByComparator != null) {
1167                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1168                        orderByComparator);
1169                }
1170
1171                else {
1172                    query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1173                }
1174
1175                String sql = query.toString();
1176
1177                Query q = session.createQuery(sql);
1178
1179                QueryPos qPos = QueryPos.getInstance(q);
1180
1181                qPos.add(companyId);
1182
1183                list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1184                        start, end);
1185            }
1186            catch (Exception e) {
1187                throw processException(e);
1188            }
1189            finally {
1190                if (list == null) {
1191                    list = new ArrayList<BookmarksFolder>();
1192                }
1193
1194                cacheResult(list);
1195
1196                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1197                    finderArgs, list);
1198
1199                closeSession(session);
1200            }
1201        }
1202
1203        return list;
1204    }
1205
1206    public BookmarksFolder findByCompanyId_First(long companyId,
1207        OrderByComparator orderByComparator)
1208        throws NoSuchFolderException, SystemException {
1209        List<BookmarksFolder> list = findByCompanyId(companyId, 0, 1,
1210                orderByComparator);
1211
1212        if (list.isEmpty()) {
1213            StringBundler msg = new StringBundler(4);
1214
1215            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1216
1217            msg.append("companyId=");
1218            msg.append(companyId);
1219
1220            msg.append(StringPool.CLOSE_CURLY_BRACE);
1221
1222            throw new NoSuchFolderException(msg.toString());
1223        }
1224        else {
1225            return list.get(0);
1226        }
1227    }
1228
1229    public BookmarksFolder findByCompanyId_Last(long companyId,
1230        OrderByComparator orderByComparator)
1231        throws NoSuchFolderException, SystemException {
1232        int count = countByCompanyId(companyId);
1233
1234        List<BookmarksFolder> list = findByCompanyId(companyId, count - 1,
1235                count, orderByComparator);
1236
1237        if (list.isEmpty()) {
1238            StringBundler msg = new StringBundler(4);
1239
1240            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1241
1242            msg.append("companyId=");
1243            msg.append(companyId);
1244
1245            msg.append(StringPool.CLOSE_CURLY_BRACE);
1246
1247            throw new NoSuchFolderException(msg.toString());
1248        }
1249        else {
1250            return list.get(0);
1251        }
1252    }
1253
1254    public BookmarksFolder[] findByCompanyId_PrevAndNext(long folderId,
1255        long companyId, OrderByComparator orderByComparator)
1256        throws NoSuchFolderException, SystemException {
1257        BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
1258
1259        int count = countByCompanyId(companyId);
1260
1261        Session session = null;
1262
1263        try {
1264            session = openSession();
1265
1266            StringBundler query = null;
1267
1268            if (orderByComparator != null) {
1269                query = new StringBundler(3 +
1270                        (orderByComparator.getOrderByFields().length * 3));
1271            }
1272            else {
1273                query = new StringBundler(3);
1274            }
1275
1276            query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1277
1278            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1279
1280            if (orderByComparator != null) {
1281                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1282                    orderByComparator);
1283            }
1284
1285            else {
1286                query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1287            }
1288
1289            String sql = query.toString();
1290
1291            Query q = session.createQuery(sql);
1292
1293            QueryPos qPos = QueryPos.getInstance(q);
1294
1295            qPos.add(companyId);
1296
1297            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1298                    orderByComparator, bookmarksFolder);
1299
1300            BookmarksFolder[] array = new BookmarksFolderImpl[3];
1301
1302            array[0] = (BookmarksFolder)objArray[0];
1303            array[1] = (BookmarksFolder)objArray[1];
1304            array[2] = (BookmarksFolder)objArray[2];
1305
1306            return array;
1307        }
1308        catch (Exception e) {
1309            throw processException(e);
1310        }
1311        finally {
1312            closeSession(session);
1313        }
1314    }
1315
1316    public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId)
1317        throws SystemException {
1318        Object[] finderArgs = new Object[] {
1319                new Long(groupId), new Long(parentFolderId)
1320            };
1321
1322        List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1323                finderArgs, this);
1324
1325        if (list == null) {
1326            Session session = null;
1327
1328            try {
1329                session = openSession();
1330
1331                StringBundler query = new StringBundler(4);
1332
1333                query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1334
1335                query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1336
1337                query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
1338
1339                query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1340
1341                String sql = query.toString();
1342
1343                Query q = session.createQuery(sql);
1344
1345                QueryPos qPos = QueryPos.getInstance(q);
1346
1347                qPos.add(groupId);
1348
1349                qPos.add(parentFolderId);
1350
1351                list = q.list();
1352            }
1353            catch (Exception e) {
1354                throw processException(e);
1355            }
1356            finally {
1357                if (list == null) {
1358                    list = new ArrayList<BookmarksFolder>();
1359                }
1360
1361                cacheResult(list);
1362
1363                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
1364                    list);
1365
1366                closeSession(session);
1367            }
1368        }
1369
1370        return list;
1371    }
1372
1373    public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId,
1374        int start, int end) throws SystemException {
1375        return findByG_P(groupId, parentFolderId, start, end, null);
1376    }
1377
1378    public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId,
1379        int start, int end, OrderByComparator orderByComparator)
1380        throws SystemException {
1381        Object[] finderArgs = new Object[] {
1382                new Long(groupId), new Long(parentFolderId),
1383                
1384                String.valueOf(start), String.valueOf(end),
1385                String.valueOf(orderByComparator)
1386            };
1387
1388        List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_P,
1389                finderArgs, this);
1390
1391        if (list == null) {
1392            Session session = null;
1393
1394            try {
1395                session = openSession();
1396
1397                StringBundler query = null;
1398
1399                if (orderByComparator != null) {
1400                    query = new StringBundler(4 +
1401                            (orderByComparator.getOrderByFields().length * 3));
1402                }
1403                else {
1404                    query = new StringBundler(4);
1405                }
1406
1407                query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1408
1409                query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1410
1411                query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
1412
1413                if (orderByComparator != null) {
1414                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1415                        orderByComparator);
1416                }
1417
1418                else {
1419                    query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1420                }
1421
1422                String sql = query.toString();
1423
1424                Query q = session.createQuery(sql);
1425
1426                QueryPos qPos = QueryPos.getInstance(q);
1427
1428                qPos.add(groupId);
1429
1430                qPos.add(parentFolderId);
1431
1432                list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1433                        start, end);
1434            }
1435            catch (Exception e) {
1436                throw processException(e);
1437            }
1438            finally {
1439                if (list == null) {
1440                    list = new ArrayList<BookmarksFolder>();
1441                }
1442
1443                cacheResult(list);
1444
1445                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_P,
1446                    finderArgs, list);
1447
1448                closeSession(session);
1449            }
1450        }
1451
1452        return list;
1453    }
1454
1455    public BookmarksFolder findByG_P_First(long groupId, long parentFolderId,
1456        OrderByComparator orderByComparator)
1457        throws NoSuchFolderException, SystemException {
1458        List<BookmarksFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
1459                orderByComparator);
1460
1461        if (list.isEmpty()) {
1462            StringBundler msg = new StringBundler(6);
1463
1464            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1465
1466            msg.append("groupId=");
1467            msg.append(groupId);
1468
1469            msg.append(", parentFolderId=");
1470            msg.append(parentFolderId);
1471
1472            msg.append(StringPool.CLOSE_CURLY_BRACE);
1473
1474            throw new NoSuchFolderException(msg.toString());
1475        }
1476        else {
1477            return list.get(0);
1478        }
1479    }
1480
1481    public BookmarksFolder findByG_P_Last(long groupId, long parentFolderId,
1482        OrderByComparator orderByComparator)
1483        throws NoSuchFolderException, SystemException {
1484        int count = countByG_P(groupId, parentFolderId);
1485
1486        List<BookmarksFolder> list = findByG_P(groupId, parentFolderId,
1487                count - 1, count, orderByComparator);
1488
1489        if (list.isEmpty()) {
1490            StringBundler msg = new StringBundler(6);
1491
1492            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1493
1494            msg.append("groupId=");
1495            msg.append(groupId);
1496
1497            msg.append(", parentFolderId=");
1498            msg.append(parentFolderId);
1499
1500            msg.append(StringPool.CLOSE_CURLY_BRACE);
1501
1502            throw new NoSuchFolderException(msg.toString());
1503        }
1504        else {
1505            return list.get(0);
1506        }
1507    }
1508
1509    public BookmarksFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
1510        long parentFolderId, OrderByComparator orderByComparator)
1511        throws NoSuchFolderException, SystemException {
1512        BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
1513
1514        int count = countByG_P(groupId, parentFolderId);
1515
1516        Session session = null;
1517
1518        try {
1519            session = openSession();
1520
1521            StringBundler query = null;
1522
1523            if (orderByComparator != null) {
1524                query = new StringBundler(4 +
1525                        (orderByComparator.getOrderByFields().length * 3));
1526            }
1527            else {
1528                query = new StringBundler(4);
1529            }
1530
1531            query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1532
1533            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1534
1535            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
1536
1537            if (orderByComparator != null) {
1538                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1539                    orderByComparator);
1540            }
1541
1542            else {
1543                query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1544            }
1545
1546            String sql = query.toString();
1547
1548            Query q = session.createQuery(sql);
1549
1550            QueryPos qPos = QueryPos.getInstance(q);
1551
1552            qPos.add(groupId);
1553
1554            qPos.add(parentFolderId);
1555
1556            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1557                    orderByComparator, bookmarksFolder);
1558
1559            BookmarksFolder[] array = new BookmarksFolderImpl[3];
1560
1561            array[0] = (BookmarksFolder)objArray[0];
1562            array[1] = (BookmarksFolder)objArray[1];
1563            array[2] = (BookmarksFolder)objArray[2];
1564
1565            return array;
1566        }
1567        catch (Exception e) {
1568            throw processException(e);
1569        }
1570        finally {
1571            closeSession(session);
1572        }
1573    }
1574
1575    public List<BookmarksFolder> findAll() throws SystemException {
1576        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1577    }
1578
1579    public List<BookmarksFolder> findAll(int start, int end)
1580        throws SystemException {
1581        return findAll(start, end, null);
1582    }
1583
1584    public List<BookmarksFolder> findAll(int start, int end,
1585        OrderByComparator orderByComparator) throws SystemException {
1586        Object[] finderArgs = new Object[] {
1587                String.valueOf(start), String.valueOf(end),
1588                String.valueOf(orderByComparator)
1589            };
1590
1591        List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1592                finderArgs, this);
1593
1594        if (list == null) {
1595            Session session = null;
1596
1597            try {
1598                session = openSession();
1599
1600                StringBundler query = null;
1601                String sql = null;
1602
1603                if (orderByComparator != null) {
1604                    query = new StringBundler(2 +
1605                            (orderByComparator.getOrderByFields().length * 3));
1606
1607                    query.append(_SQL_SELECT_BOOKMARKSFOLDER);
1608
1609                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1610                        orderByComparator);
1611
1612                    sql = query.toString();
1613                }
1614
1615                else {
1616                    sql = _SQL_SELECT_BOOKMARKSFOLDER.concat(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1617                }
1618
1619                Query q = session.createQuery(sql);
1620
1621                if (orderByComparator == null) {
1622                    list = (List<BookmarksFolder>)QueryUtil.list(q,
1623                            getDialect(), start, end, false);
1624
1625                    Collections.sort(list);
1626                }
1627                else {
1628                    list = (List<BookmarksFolder>)QueryUtil.list(q,
1629                            getDialect(), start, end);
1630                }
1631            }
1632            catch (Exception e) {
1633                throw processException(e);
1634            }
1635            finally {
1636                if (list == null) {
1637                    list = new ArrayList<BookmarksFolder>();
1638                }
1639
1640                cacheResult(list);
1641
1642                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1643
1644                closeSession(session);
1645            }
1646        }
1647
1648        return list;
1649    }
1650
1651    public void removeByUuid(String uuid) throws SystemException {
1652        for (BookmarksFolder bookmarksFolder : findByUuid(uuid)) {
1653            remove(bookmarksFolder);
1654        }
1655    }
1656
1657    public void removeByUUID_G(String uuid, long groupId)
1658        throws NoSuchFolderException, SystemException {
1659        BookmarksFolder bookmarksFolder = findByUUID_G(uuid, groupId);
1660
1661        remove(bookmarksFolder);
1662    }
1663
1664    public void removeByGroupId(long groupId) throws SystemException {
1665        for (BookmarksFolder bookmarksFolder : findByGroupId(groupId)) {
1666            remove(bookmarksFolder);
1667        }
1668    }
1669
1670    public void removeByCompanyId(long companyId) throws SystemException {
1671        for (BookmarksFolder bookmarksFolder : findByCompanyId(companyId)) {
1672            remove(bookmarksFolder);
1673        }
1674    }
1675
1676    public void removeByG_P(long groupId, long parentFolderId)
1677        throws SystemException {
1678        for (BookmarksFolder bookmarksFolder : findByG_P(groupId, parentFolderId)) {
1679            remove(bookmarksFolder);
1680        }
1681    }
1682
1683    public void removeAll() throws SystemException {
1684        for (BookmarksFolder bookmarksFolder : findAll()) {
1685            remove(bookmarksFolder);
1686        }
1687    }
1688
1689    public int countByUuid(String uuid) throws SystemException {
1690        Object[] finderArgs = new Object[] { uuid };
1691
1692        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1693                finderArgs, this);
1694
1695        if (count == null) {
1696            Session session = null;
1697
1698            try {
1699                session = openSession();
1700
1701                StringBundler query = new StringBundler(2);
1702
1703                query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
1704
1705                if (uuid == null) {
1706                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1707                }
1708                else {
1709                    if (uuid.equals(StringPool.BLANK)) {
1710                        query.append(_FINDER_COLUMN_UUID_UUID_3);
1711                    }
1712                    else {
1713                        query.append(_FINDER_COLUMN_UUID_UUID_2);
1714                    }
1715                }
1716
1717                String sql = query.toString();
1718
1719                Query q = session.createQuery(sql);
1720
1721                QueryPos qPos = QueryPos.getInstance(q);
1722
1723                if (uuid != null) {
1724                    qPos.add(uuid);
1725                }
1726
1727                count = (Long)q.uniqueResult();
1728            }
1729            catch (Exception e) {
1730                throw processException(e);
1731            }
1732            finally {
1733                if (count == null) {
1734                    count = Long.valueOf(0);
1735                }
1736
1737                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1738                    finderArgs, count);
1739
1740                closeSession(session);
1741            }
1742        }
1743
1744        return count.intValue();
1745    }
1746
1747    public int countByUUID_G(String uuid, long groupId)
1748        throws SystemException {
1749        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1750
1751        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1752                finderArgs, this);
1753
1754        if (count == null) {
1755            Session session = null;
1756
1757            try {
1758                session = openSession();
1759
1760                StringBundler query = new StringBundler(3);
1761
1762                query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
1763
1764                if (uuid == null) {
1765                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1766                }
1767                else {
1768                    if (uuid.equals(StringPool.BLANK)) {
1769                        query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1770                    }
1771                    else {
1772                        query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1773                    }
1774                }
1775
1776                query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1777
1778                String sql = query.toString();
1779
1780                Query q = session.createQuery(sql);
1781
1782                QueryPos qPos = QueryPos.getInstance(q);
1783
1784                if (uuid != null) {
1785                    qPos.add(uuid);
1786                }
1787
1788                qPos.add(groupId);
1789
1790                count = (Long)q.uniqueResult();
1791            }
1792            catch (Exception e) {
1793                throw processException(e);
1794            }
1795            finally {
1796                if (count == null) {
1797                    count = Long.valueOf(0);
1798                }
1799
1800                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1801                    finderArgs, count);
1802
1803                closeSession(session);
1804            }
1805        }
1806
1807        return count.intValue();
1808    }
1809
1810    public int countByGroupId(long groupId) throws SystemException {
1811        Object[] finderArgs = new Object[] { new Long(groupId) };
1812
1813        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1814                finderArgs, this);
1815
1816        if (count == null) {
1817            Session session = null;
1818
1819            try {
1820                session = openSession();
1821
1822                StringBundler query = new StringBundler(2);
1823
1824                query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
1825
1826                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1827
1828                String sql = query.toString();
1829
1830                Query q = session.createQuery(sql);
1831
1832                QueryPos qPos = QueryPos.getInstance(q);
1833
1834                qPos.add(groupId);
1835
1836                count = (Long)q.uniqueResult();
1837            }
1838            catch (Exception e) {
1839                throw processException(e);
1840            }
1841            finally {
1842                if (count == null) {
1843                    count = Long.valueOf(0);
1844                }
1845
1846                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1847                    finderArgs, count);
1848
1849                closeSession(session);
1850            }
1851        }
1852
1853        return count.intValue();
1854    }
1855
1856    public int countByCompanyId(long companyId) throws SystemException {
1857        Object[] finderArgs = new Object[] { new Long(companyId) };
1858
1859        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1860                finderArgs, this);
1861
1862        if (count == null) {
1863            Session session = null;
1864
1865            try {
1866                session = openSession();
1867
1868                StringBundler query = new StringBundler(2);
1869
1870                query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
1871
1872                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1873
1874                String sql = query.toString();
1875
1876                Query q = session.createQuery(sql);
1877
1878                QueryPos qPos = QueryPos.getInstance(q);
1879
1880                qPos.add(companyId);
1881
1882                count = (Long)q.uniqueResult();
1883            }
1884            catch (Exception e) {
1885                throw processException(e);
1886            }
1887            finally {
1888                if (count == null) {
1889                    count = Long.valueOf(0);
1890                }
1891
1892                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1893                    finderArgs, count);
1894
1895                closeSession(session);
1896            }
1897        }
1898
1899        return count.intValue();
1900    }
1901
1902    public int countByG_P(long groupId, long parentFolderId)
1903        throws SystemException {
1904        Object[] finderArgs = new Object[] {
1905                new Long(groupId), new Long(parentFolderId)
1906            };
1907
1908        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1909                finderArgs, this);
1910
1911        if (count == null) {
1912            Session session = null;
1913
1914            try {
1915                session = openSession();
1916
1917                StringBundler query = new StringBundler(3);
1918
1919                query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
1920
1921                query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1922
1923                query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
1924
1925                String sql = query.toString();
1926
1927                Query q = session.createQuery(sql);
1928
1929                QueryPos qPos = QueryPos.getInstance(q);
1930
1931                qPos.add(groupId);
1932
1933                qPos.add(parentFolderId);
1934
1935                count = (Long)q.uniqueResult();
1936            }
1937            catch (Exception e) {
1938                throw processException(e);
1939            }
1940            finally {
1941                if (count == null) {
1942                    count = Long.valueOf(0);
1943                }
1944
1945                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1946                    count);
1947
1948                closeSession(session);
1949            }
1950        }
1951
1952        return count.intValue();
1953    }
1954
1955    public int countAll() throws SystemException {
1956        Object[] finderArgs = new Object[0];
1957
1958        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1959                finderArgs, this);
1960
1961        if (count == null) {
1962            Session session = null;
1963
1964            try {
1965                session = openSession();
1966
1967                Query q = session.createQuery(_SQL_COUNT_BOOKMARKSFOLDER);
1968
1969                count = (Long)q.uniqueResult();
1970            }
1971            catch (Exception e) {
1972                throw processException(e);
1973            }
1974            finally {
1975                if (count == null) {
1976                    count = Long.valueOf(0);
1977                }
1978
1979                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1980                    count);
1981
1982                closeSession(session);
1983            }
1984        }
1985
1986        return count.intValue();
1987    }
1988
1989    public void afterPropertiesSet() {
1990        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1991                    com.liferay.portal.util.PropsUtil.get(
1992                        "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksFolder")));
1993
1994        if (listenerClassNames.length > 0) {
1995            try {
1996                List<ModelListener<BookmarksFolder>> listenersList = new ArrayList<ModelListener<BookmarksFolder>>();
1997
1998                for (String listenerClassName : listenerClassNames) {
1999                    listenersList.add((ModelListener<BookmarksFolder>)Class.forName(
2000                            listenerClassName).newInstance());
2001                }
2002
2003                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2004            }
2005            catch (Exception e) {
2006                _log.error(e);
2007            }
2008        }
2009    }
2010
2011    @BeanReference(type = BookmarksEntryPersistence.class)
2012    protected BookmarksEntryPersistence bookmarksEntryPersistence;
2013    @BeanReference(type = BookmarksFolderPersistence.class)
2014    protected BookmarksFolderPersistence bookmarksFolderPersistence;
2015    @BeanReference(type = GroupPersistence.class)
2016    protected GroupPersistence groupPersistence;
2017    @BeanReference(type = ResourcePersistence.class)
2018    protected ResourcePersistence resourcePersistence;
2019    @BeanReference(type = UserPersistence.class)
2020    protected UserPersistence userPersistence;
2021    @BeanReference(type = ExpandoValuePersistence.class)
2022    protected ExpandoValuePersistence expandoValuePersistence;
2023    private static final String _SQL_SELECT_BOOKMARKSFOLDER = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder";
2024    private static final String _SQL_SELECT_BOOKMARKSFOLDER_WHERE = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder WHERE ";
2025    private static final String _SQL_COUNT_BOOKMARKSFOLDER = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder";
2026    private static final String _SQL_COUNT_BOOKMARKSFOLDER_WHERE = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder WHERE ";
2027    private static final String _FINDER_COLUMN_UUID_UUID_1 = "bookmarksFolder.uuid IS NULL";
2028    private static final String _FINDER_COLUMN_UUID_UUID_2 = "bookmarksFolder.uuid = ?";
2029    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(bookmarksFolder.uuid IS NULL OR bookmarksFolder.uuid = ?)";
2030    private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "bookmarksFolder.uuid IS NULL AND ";
2031    private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "bookmarksFolder.uuid = ? AND ";
2032    private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(bookmarksFolder.uuid IS NULL OR bookmarksFolder.uuid = ?) AND ";
2033    private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "bookmarksFolder.groupId = ?";
2034    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "bookmarksFolder.groupId = ?";
2035    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "bookmarksFolder.companyId = ?";
2036    private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "bookmarksFolder.groupId = ? AND ";
2037    private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "bookmarksFolder.parentFolderId = ?";
2038    private static final String _ORDER_BY_ENTITY_ALIAS = "bookmarksFolder.";
2039    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BookmarksFolder exists with the primary key ";
2040    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BookmarksFolder exists with the key {";
2041    private static Log _log = LogFactoryUtil.getLog(BookmarksFolderPersistenceImpl.class);
2042}