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