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