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