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