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