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.bean.InitializingBean;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.kernel.util.Validator;
39  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
40  import com.liferay.portal.model.ModelListener;
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, InitializingBean {
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             session.delete(bookmarksFolder);
138 
139             session.flush();
140 
141             return bookmarksFolder;
142         }
143         catch (Exception e) {
144             throw processException(e);
145         }
146         finally {
147             closeSession(session);
148 
149             FinderCacheUtil.clearCache(BookmarksFolder.class.getName());
150         }
151     }
152 
153     /**
154      * @deprecated Use <code>update(BookmarksFolder bookmarksFolder, boolean merge)</code>.
155      */
156     public BookmarksFolder update(BookmarksFolder bookmarksFolder)
157         throws SystemException {
158         if (_log.isWarnEnabled()) {
159             _log.warn(
160                 "Using the deprecated update(BookmarksFolder bookmarksFolder) method. Use update(BookmarksFolder bookmarksFolder, boolean merge) instead.");
161         }
162 
163         return update(bookmarksFolder, false);
164     }
165 
166     /**
167      * Add, update, or merge, the entity. This method also calls the model
168      * listeners to trigger the proper events associated with adding, deleting,
169      * or updating an entity.
170      *
171      * @param        bookmarksFolder the entity to add, update, or merge
172      * @param        merge boolean value for whether to merge the entity. The
173      *                default value is false. Setting merge to true is more
174      *                expensive and should only be true when bookmarksFolder is
175      *                transient. See LEP-5473 for a detailed discussion of this
176      *                method.
177      * @return        true if the portlet can be displayed via Ajax
178      */
179     public BookmarksFolder update(BookmarksFolder bookmarksFolder, boolean merge)
180         throws SystemException {
181         boolean isNew = bookmarksFolder.isNew();
182 
183         if (_listeners.length > 0) {
184             for (ModelListener listener : _listeners) {
185                 if (isNew) {
186                     listener.onBeforeCreate(bookmarksFolder);
187                 }
188                 else {
189                     listener.onBeforeUpdate(bookmarksFolder);
190                 }
191             }
192         }
193 
194         bookmarksFolder = updateImpl(bookmarksFolder, merge);
195 
196         if (_listeners.length > 0) {
197             for (ModelListener listener : _listeners) {
198                 if (isNew) {
199                     listener.onAfterCreate(bookmarksFolder);
200                 }
201                 else {
202                     listener.onAfterUpdate(bookmarksFolder);
203                 }
204             }
205         }
206 
207         return bookmarksFolder;
208     }
209 
210     public BookmarksFolder updateImpl(
211         com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder,
212         boolean merge) throws SystemException {
213         if (Validator.isNull(bookmarksFolder.getUuid())) {
214             String uuid = PortalUUIDUtil.generate();
215 
216             bookmarksFolder.setUuid(uuid);
217         }
218 
219         Session session = null;
220 
221         try {
222             session = openSession();
223 
224             if (merge) {
225                 session.merge(bookmarksFolder);
226             }
227             else {
228                 if (bookmarksFolder.isNew()) {
229                     session.save(bookmarksFolder);
230                 }
231             }
232 
233             session.flush();
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 = (List<BookmarksFolder>)QueryUtil.list(q,
1521                        getDialect(), start, end);
1522
1523                if (obc == null) {
1524                    Collections.sort(list);
1525                }
1526
1527                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1528                    finderClassName, finderMethodName, finderParams,
1529                    finderArgs, list);
1530
1531                return list;
1532            }
1533            catch (Exception e) {
1534                throw processException(e);
1535            }
1536            finally {
1537                closeSession(session);
1538            }
1539        }
1540        else {
1541            return (List<BookmarksFolder>)result;
1542        }
1543    }
1544
1545    public void removeByUuid(String uuid) throws SystemException {
1546        for (BookmarksFolder bookmarksFolder : findByUuid(uuid)) {
1547            remove(bookmarksFolder);
1548        }
1549    }
1550
1551    public void removeByUUID_G(String uuid, long groupId)
1552        throws NoSuchFolderException, SystemException {
1553        BookmarksFolder bookmarksFolder = findByUUID_G(uuid, groupId);
1554
1555        remove(bookmarksFolder);
1556    }
1557
1558    public void removeByGroupId(long groupId) throws SystemException {
1559        for (BookmarksFolder bookmarksFolder : findByGroupId(groupId)) {
1560            remove(bookmarksFolder);
1561        }
1562    }
1563
1564    public void removeByCompanyId(long companyId) throws SystemException {
1565        for (BookmarksFolder bookmarksFolder : findByCompanyId(companyId)) {
1566            remove(bookmarksFolder);
1567        }
1568    }
1569
1570    public void removeByG_P(long groupId, long parentFolderId)
1571        throws SystemException {
1572        for (BookmarksFolder bookmarksFolder : findByG_P(groupId, parentFolderId)) {
1573            remove(bookmarksFolder);
1574        }
1575    }
1576
1577    public void removeAll() throws SystemException {
1578        for (BookmarksFolder bookmarksFolder : findAll()) {
1579            remove(bookmarksFolder);
1580        }
1581    }
1582
1583    public int countByUuid(String uuid) throws SystemException {
1584        boolean finderClassNameCacheEnabled = BookmarksFolderModelImpl.CACHE_ENABLED;
1585        String finderClassName = BookmarksFolder.class.getName();
1586        String finderMethodName = "countByUuid";
1587        String[] finderParams = new String[] { String.class.getName() };
1588        Object[] finderArgs = new Object[] { uuid };
1589
1590        Object result = null;
1591
1592        if (finderClassNameCacheEnabled) {
1593            result = FinderCacheUtil.getResult(finderClassName,
1594                    finderMethodName, finderParams, finderArgs, this);
1595        }
1596
1597        if (result == null) {
1598            Session session = null;
1599
1600            try {
1601                session = openSession();
1602
1603                StringBuilder query = new StringBuilder();
1604
1605                query.append("SELECT COUNT(*) ");
1606                query.append(
1607                    "FROM com.liferay.portlet.bookmarks.model.BookmarksFolder WHERE ");
1608
1609                if (uuid == null) {
1610                    query.append("uuid_ IS NULL");
1611                }
1612                else {
1613                    query.append("uuid_ = ?");
1614                }
1615
1616                query.append(" ");
1617
1618                Query q = session.createQuery(query.toString());
1619
1620                QueryPos qPos = QueryPos.getInstance(q);
1621
1622                if (uuid != null) {
1623                    qPos.add(uuid);
1624                }
1625
1626                Long count = null;
1627
1628                Iterator<Long> itr = q.list().iterator();
1629
1630                if (itr.hasNext()) {
1631                    count = itr.next();
1632                }
1633
1634                if (count == null) {
1635                    count = new Long(0);
1636                }
1637
1638                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1639                    finderClassName, finderMethodName, finderParams,
1640                    finderArgs, count);
1641
1642                return count.intValue();
1643            }
1644            catch (Exception e) {
1645                throw processException(e);
1646            }
1647            finally {
1648                closeSession(session);
1649            }
1650        }
1651        else {
1652            return ((Long)result).intValue();
1653        }
1654    }
1655
1656    public int countByUUID_G(String uuid, long groupId)
1657        throws SystemException {
1658        boolean finderClassNameCacheEnabled = BookmarksFolderModelImpl.CACHE_ENABLED;
1659        String finderClassName = BookmarksFolder.class.getName();
1660        String finderMethodName = "countByUUID_G";
1661        String[] finderParams = new String[] {
1662                String.class.getName(), Long.class.getName()
1663            };
1664        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1665
1666        Object result = null;
1667
1668        if (finderClassNameCacheEnabled) {
1669            result = FinderCacheUtil.getResult(finderClassName,
1670                    finderMethodName, finderParams, finderArgs, this);
1671        }
1672
1673        if (result == null) {
1674            Session session = null;
1675
1676            try {
1677                session = openSession();
1678
1679                StringBuilder query = new StringBuilder();
1680
1681                query.append("SELECT COUNT(*) ");
1682                query.append(
1683                    "FROM com.liferay.portlet.bookmarks.model.BookmarksFolder WHERE ");
1684
1685                if (uuid == null) {
1686                    query.append("uuid_ IS NULL");
1687                }
1688                else {
1689                    query.append("uuid_ = ?");
1690                }
1691
1692                query.append(" AND ");
1693
1694                query.append("groupId = ?");
1695
1696                query.append(" ");
1697
1698                Query q = session.createQuery(query.toString());
1699
1700                QueryPos qPos = QueryPos.getInstance(q);
1701
1702                if (uuid != null) {
1703                    qPos.add(uuid);
1704                }
1705
1706                qPos.add(groupId);
1707
1708                Long count = null;
1709
1710                Iterator<Long> itr = q.list().iterator();
1711
1712                if (itr.hasNext()) {
1713                    count = itr.next();
1714                }
1715
1716                if (count == null) {
1717                    count = new Long(0);
1718                }
1719
1720                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1721                    finderClassName, finderMethodName, finderParams,
1722                    finderArgs, count);
1723
1724                return count.intValue();
1725            }
1726            catch (Exception e) {
1727                throw processException(e);
1728            }
1729            finally {
1730                closeSession(session);
1731            }
1732        }
1733        else {
1734            return ((Long)result).intValue();
1735        }
1736    }
1737
1738    public int countByGroupId(long groupId) throws SystemException {
1739        boolean finderClassNameCacheEnabled = BookmarksFolderModelImpl.CACHE_ENABLED;
1740        String finderClassName = BookmarksFolder.class.getName();
1741        String finderMethodName = "countByGroupId";
1742        String[] finderParams = new String[] { Long.class.getName() };
1743        Object[] finderArgs = new Object[] { new Long(groupId) };
1744
1745        Object result = null;
1746
1747        if (finderClassNameCacheEnabled) {
1748            result = FinderCacheUtil.getResult(finderClassName,
1749                    finderMethodName, finderParams, finderArgs, this);
1750        }
1751
1752        if (result == null) {
1753            Session session = null;
1754
1755            try {
1756                session = openSession();
1757
1758                StringBuilder query = new StringBuilder();
1759
1760                query.append("SELECT COUNT(*) ");
1761                query.append(
1762                    "FROM com.liferay.portlet.bookmarks.model.BookmarksFolder WHERE ");
1763
1764                query.append("groupId = ?");
1765
1766                query.append(" ");
1767
1768                Query q = session.createQuery(query.toString());
1769
1770                QueryPos qPos = QueryPos.getInstance(q);
1771
1772                qPos.add(groupId);
1773
1774                Long count = null;
1775
1776                Iterator<Long> itr = q.list().iterator();
1777
1778                if (itr.hasNext()) {
1779                    count = itr.next();
1780                }
1781
1782                if (count == null) {
1783                    count = new Long(0);
1784                }
1785
1786                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1787                    finderClassName, finderMethodName, finderParams,
1788                    finderArgs, count);
1789
1790                return count.intValue();
1791            }
1792            catch (Exception e) {
1793                throw processException(e);
1794            }
1795            finally {
1796                closeSession(session);
1797            }
1798        }
1799        else {
1800            return ((Long)result).intValue();
1801        }
1802    }
1803
1804    public int countByCompanyId(long companyId) throws SystemException {
1805        boolean finderClassNameCacheEnabled = BookmarksFolderModelImpl.CACHE_ENABLED;
1806        String finderClassName = BookmarksFolder.class.getName();
1807        String finderMethodName = "countByCompanyId";
1808        String[] finderParams = new String[] { Long.class.getName() };
1809        Object[] finderArgs = new Object[] { new Long(companyId) };
1810
1811        Object result = null;
1812
1813        if (finderClassNameCacheEnabled) {
1814            result = FinderCacheUtil.getResult(finderClassName,
1815                    finderMethodName, finderParams, finderArgs, this);
1816        }
1817
1818        if (result == null) {
1819            Session session = null;
1820
1821            try {
1822                session = openSession();
1823
1824                StringBuilder query = new StringBuilder();
1825
1826                query.append("SELECT COUNT(*) ");
1827                query.append(
1828                    "FROM com.liferay.portlet.bookmarks.model.BookmarksFolder WHERE ");
1829
1830                query.append("companyId = ?");
1831
1832                query.append(" ");
1833
1834                Query q = session.createQuery(query.toString());
1835
1836                QueryPos qPos = QueryPos.getInstance(q);
1837
1838                qPos.add(companyId);
1839
1840                Long count = null;
1841
1842                Iterator<Long> itr = q.list().iterator();
1843
1844                if (itr.hasNext()) {
1845                    count = itr.next();
1846                }
1847
1848                if (count == null) {
1849                    count = new Long(0);
1850                }
1851
1852                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1853                    finderClassName, finderMethodName, finderParams,
1854                    finderArgs, count);
1855
1856                return count.intValue();
1857            }
1858            catch (Exception e) {
1859                throw processException(e);
1860            }
1861            finally {
1862                closeSession(session);
1863            }
1864        }
1865        else {
1866            return ((Long)result).intValue();
1867        }
1868    }
1869
1870    public int countByG_P(long groupId, long parentFolderId)
1871        throws SystemException {
1872        boolean finderClassNameCacheEnabled = BookmarksFolderModelImpl.CACHE_ENABLED;
1873        String finderClassName = BookmarksFolder.class.getName();
1874        String finderMethodName = "countByG_P";
1875        String[] finderParams = new String[] {
1876                Long.class.getName(), Long.class.getName()
1877            };
1878        Object[] finderArgs = new Object[] {
1879                new Long(groupId), new Long(parentFolderId)
1880            };
1881
1882        Object result = null;
1883
1884        if (finderClassNameCacheEnabled) {
1885            result = FinderCacheUtil.getResult(finderClassName,
1886                    finderMethodName, finderParams, finderArgs, this);
1887        }
1888
1889        if (result == null) {
1890            Session session = null;
1891
1892            try {
1893                session = openSession();
1894
1895                StringBuilder query = new StringBuilder();
1896
1897                query.append("SELECT COUNT(*) ");
1898                query.append(
1899                    "FROM com.liferay.portlet.bookmarks.model.BookmarksFolder WHERE ");
1900
1901                query.append("groupId = ?");
1902
1903                query.append(" AND ");
1904
1905                query.append("parentFolderId = ?");
1906
1907                query.append(" ");
1908
1909                Query q = session.createQuery(query.toString());
1910
1911                QueryPos qPos = QueryPos.getInstance(q);
1912
1913                qPos.add(groupId);
1914
1915                qPos.add(parentFolderId);
1916
1917                Long count = null;
1918
1919                Iterator<Long> itr = q.list().iterator();
1920
1921                if (itr.hasNext()) {
1922                    count = itr.next();
1923                }
1924
1925                if (count == null) {
1926                    count = new Long(0);
1927                }
1928
1929                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1930                    finderClassName, finderMethodName, finderParams,
1931                    finderArgs, count);
1932
1933                return count.intValue();
1934            }
1935            catch (Exception e) {
1936                throw processException(e);
1937            }
1938            finally {
1939                closeSession(session);
1940            }
1941        }
1942        else {
1943            return ((Long)result).intValue();
1944        }
1945    }
1946
1947    public int countAll() throws SystemException {
1948        boolean finderClassNameCacheEnabled = BookmarksFolderModelImpl.CACHE_ENABLED;
1949        String finderClassName = BookmarksFolder.class.getName();
1950        String finderMethodName = "countAll";
1951        String[] finderParams = new String[] {  };
1952        Object[] finderArgs = new Object[] {  };
1953
1954        Object result = null;
1955
1956        if (finderClassNameCacheEnabled) {
1957            result = FinderCacheUtil.getResult(finderClassName,
1958                    finderMethodName, finderParams, finderArgs, this);
1959        }
1960
1961        if (result == null) {
1962            Session session = null;
1963
1964            try {
1965                session = openSession();
1966
1967                Query q = session.createQuery(
1968                        "SELECT COUNT(*) FROM com.liferay.portlet.bookmarks.model.BookmarksFolder");
1969
1970                Long count = null;
1971
1972                Iterator<Long> itr = q.list().iterator();
1973
1974                if (itr.hasNext()) {
1975                    count = itr.next();
1976                }
1977
1978                if (count == null) {
1979                    count = new Long(0);
1980                }
1981
1982                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1983                    finderClassName, finderMethodName, finderParams,
1984                    finderArgs, count);
1985
1986                return count.intValue();
1987            }
1988            catch (Exception e) {
1989                throw processException(e);
1990            }
1991            finally {
1992                closeSession(session);
1993            }
1994        }
1995        else {
1996            return ((Long)result).intValue();
1997        }
1998    }
1999
2000    public void registerListener(ModelListener listener) {
2001        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2002
2003        listeners.add(listener);
2004
2005        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2006    }
2007
2008    public void unregisterListener(ModelListener listener) {
2009        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2010
2011        listeners.remove(listener);
2012
2013        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2014    }
2015
2016    public void afterPropertiesSet() {
2017        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2018                    com.liferay.portal.util.PropsUtil.get(
2019                        "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksFolder")));
2020
2021        if (listenerClassNames.length > 0) {
2022            try {
2023                List<ModelListener> listeners = new ArrayList<ModelListener>();
2024
2025                for (String listenerClassName : listenerClassNames) {
2026                    listeners.add((ModelListener)Class.forName(
2027                            listenerClassName).newInstance());
2028                }
2029
2030                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2031            }
2032            catch (Exception e) {
2033                _log.error(e);
2034            }
2035        }
2036    }
2037
2038    private static Log _log = LogFactory.getLog(BookmarksFolderPersistenceImpl.class);
2039    private ModelListener[] _listeners = new ModelListener[0];
2040}