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