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