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