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