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