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