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