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