1
19
20 package com.liferay.portlet.bookmarks.service.persistence;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
24 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
25 import com.liferay.portal.kernel.dao.orm.Query;
26 import com.liferay.portal.kernel.dao.orm.QueryPos;
27 import com.liferay.portal.kernel.dao.orm.QueryUtil;
28 import com.liferay.portal.kernel.dao.orm.Session;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.util.GetterUtil;
32 import com.liferay.portal.kernel.util.OrderByComparator;
33 import com.liferay.portal.kernel.util.StringPool;
34 import com.liferay.portal.kernel.util.StringUtil;
35 import com.liferay.portal.kernel.util.Validator;
36 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
37 import com.liferay.portal.model.ModelListener;
38 import com.liferay.portal.service.persistence.BatchSessionUtil;
39 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40
41 import com.liferay.portlet.bookmarks.NoSuchEntryException;
42 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
43 import com.liferay.portlet.bookmarks.model.impl.BookmarksEntryImpl;
44 import com.liferay.portlet.bookmarks.model.impl.BookmarksEntryModelImpl;
45
46 import java.util.ArrayList;
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class BookmarksEntryPersistenceImpl extends BasePersistenceImpl
58 implements BookmarksEntryPersistence {
59 public BookmarksEntry create(long entryId) {
60 BookmarksEntry bookmarksEntry = new BookmarksEntryImpl();
61
62 bookmarksEntry.setNew(true);
63 bookmarksEntry.setPrimaryKey(entryId);
64
65 String uuid = PortalUUIDUtil.generate();
66
67 bookmarksEntry.setUuid(uuid);
68
69 return bookmarksEntry;
70 }
71
72 public BookmarksEntry remove(long entryId)
73 throws NoSuchEntryException, SystemException {
74 Session session = null;
75
76 try {
77 session = openSession();
78
79 BookmarksEntry bookmarksEntry = (BookmarksEntry)session.get(BookmarksEntryImpl.class,
80 new Long(entryId));
81
82 if (bookmarksEntry == null) {
83 if (_log.isWarnEnabled()) {
84 _log.warn("No BookmarksEntry exists with the primary key " +
85 entryId);
86 }
87
88 throw new NoSuchEntryException(
89 "No BookmarksEntry exists with the primary key " + entryId);
90 }
91
92 return remove(bookmarksEntry);
93 }
94 catch (NoSuchEntryException nsee) {
95 throw nsee;
96 }
97 catch (Exception e) {
98 throw processException(e);
99 }
100 finally {
101 closeSession(session);
102 }
103 }
104
105 public BookmarksEntry remove(BookmarksEntry bookmarksEntry)
106 throws SystemException {
107 for (ModelListener listener : listeners) {
108 listener.onBeforeRemove(bookmarksEntry);
109 }
110
111 bookmarksEntry = removeImpl(bookmarksEntry);
112
113 for (ModelListener listener : listeners) {
114 listener.onAfterRemove(bookmarksEntry);
115 }
116
117 return bookmarksEntry;
118 }
119
120 protected BookmarksEntry removeImpl(BookmarksEntry bookmarksEntry)
121 throws SystemException {
122 Session session = null;
123
124 try {
125 session = openSession();
126
127 if (BatchSessionUtil.isEnabled()) {
128 Object staleObject = session.get(BookmarksEntryImpl.class,
129 bookmarksEntry.getPrimaryKeyObj());
130
131 if (staleObject != null) {
132 session.evict(staleObject);
133 }
134 }
135
136 session.delete(bookmarksEntry);
137
138 session.flush();
139
140 return bookmarksEntry;
141 }
142 catch (Exception e) {
143 throw processException(e);
144 }
145 finally {
146 closeSession(session);
147
148 FinderCacheUtil.clearCache(BookmarksEntry.class.getName());
149 }
150 }
151
152
155 public BookmarksEntry update(BookmarksEntry bookmarksEntry)
156 throws SystemException {
157 if (_log.isWarnEnabled()) {
158 _log.warn(
159 "Using the deprecated update(BookmarksEntry bookmarksEntry) method. Use update(BookmarksEntry bookmarksEntry, boolean merge) instead.");
160 }
161
162 return update(bookmarksEntry, false);
163 }
164
165
178 public BookmarksEntry update(BookmarksEntry bookmarksEntry, boolean merge)
179 throws SystemException {
180 boolean isNew = bookmarksEntry.isNew();
181
182 for (ModelListener listener : listeners) {
183 if (isNew) {
184 listener.onBeforeCreate(bookmarksEntry);
185 }
186 else {
187 listener.onBeforeUpdate(bookmarksEntry);
188 }
189 }
190
191 bookmarksEntry = updateImpl(bookmarksEntry, merge);
192
193 for (ModelListener listener : listeners) {
194 if (isNew) {
195 listener.onAfterCreate(bookmarksEntry);
196 }
197 else {
198 listener.onAfterUpdate(bookmarksEntry);
199 }
200 }
201
202 return bookmarksEntry;
203 }
204
205 public BookmarksEntry updateImpl(
206 com.liferay.portlet.bookmarks.model.BookmarksEntry bookmarksEntry,
207 boolean merge) throws SystemException {
208 if (Validator.isNull(bookmarksEntry.getUuid())) {
209 String uuid = PortalUUIDUtil.generate();
210
211 bookmarksEntry.setUuid(uuid);
212 }
213
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 BatchSessionUtil.update(session, bookmarksEntry, merge);
220
221 bookmarksEntry.setNew(false);
222
223 return bookmarksEntry;
224 }
225 catch (Exception e) {
226 throw processException(e);
227 }
228 finally {
229 closeSession(session);
230
231 FinderCacheUtil.clearCache(BookmarksEntry.class.getName());
232 }
233 }
234
235 public BookmarksEntry findByPrimaryKey(long entryId)
236 throws NoSuchEntryException, SystemException {
237 BookmarksEntry bookmarksEntry = fetchByPrimaryKey(entryId);
238
239 if (bookmarksEntry == null) {
240 if (_log.isWarnEnabled()) {
241 _log.warn("No BookmarksEntry exists with the primary key " +
242 entryId);
243 }
244
245 throw new NoSuchEntryException(
246 "No BookmarksEntry exists with the primary key " + entryId);
247 }
248
249 return bookmarksEntry;
250 }
251
252 public BookmarksEntry fetchByPrimaryKey(long entryId)
253 throws SystemException {
254 Session session = null;
255
256 try {
257 session = openSession();
258
259 return (BookmarksEntry)session.get(BookmarksEntryImpl.class,
260 new Long(entryId));
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268 }
269
270 public List<BookmarksEntry> findByUuid(String uuid)
271 throws SystemException {
272 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
273 String finderClassName = BookmarksEntry.class.getName();
274 String finderMethodName = "findByUuid";
275 String[] finderParams = new String[] { String.class.getName() };
276 Object[] finderArgs = new Object[] { uuid };
277
278 Object result = null;
279
280 if (finderClassNameCacheEnabled) {
281 result = FinderCacheUtil.getResult(finderClassName,
282 finderMethodName, finderParams, finderArgs, this);
283 }
284
285 if (result == null) {
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 StringBuilder query = new StringBuilder();
292
293 query.append(
294 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
295
296 if (uuid == null) {
297 query.append("uuid_ IS NULL");
298 }
299 else {
300 query.append("uuid_ = ?");
301 }
302
303 query.append(" ");
304
305 query.append("ORDER BY ");
306
307 query.append("folderId ASC, ");
308 query.append("name ASC");
309
310 Query q = session.createQuery(query.toString());
311
312 QueryPos qPos = QueryPos.getInstance(q);
313
314 if (uuid != null) {
315 qPos.add(uuid);
316 }
317
318 List<BookmarksEntry> list = q.list();
319
320 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
321 finderClassName, finderMethodName, finderParams,
322 finderArgs, list);
323
324 return list;
325 }
326 catch (Exception e) {
327 throw processException(e);
328 }
329 finally {
330 closeSession(session);
331 }
332 }
333 else {
334 return (List<BookmarksEntry>)result;
335 }
336 }
337
338 public List<BookmarksEntry> findByUuid(String uuid, int start, int end)
339 throws SystemException {
340 return findByUuid(uuid, start, end, null);
341 }
342
343 public List<BookmarksEntry> findByUuid(String uuid, int start, int end,
344 OrderByComparator obc) throws SystemException {
345 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
346 String finderClassName = BookmarksEntry.class.getName();
347 String finderMethodName = "findByUuid";
348 String[] finderParams = new String[] {
349 String.class.getName(),
350
351 "java.lang.Integer", "java.lang.Integer",
352 "com.liferay.portal.kernel.util.OrderByComparator"
353 };
354 Object[] finderArgs = new Object[] {
355 uuid,
356
357 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
358 };
359
360 Object result = null;
361
362 if (finderClassNameCacheEnabled) {
363 result = FinderCacheUtil.getResult(finderClassName,
364 finderMethodName, finderParams, finderArgs, this);
365 }
366
367 if (result == null) {
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 StringBuilder query = new StringBuilder();
374
375 query.append(
376 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
377
378 if (uuid == null) {
379 query.append("uuid_ IS NULL");
380 }
381 else {
382 query.append("uuid_ = ?");
383 }
384
385 query.append(" ");
386
387 if (obc != null) {
388 query.append("ORDER BY ");
389 query.append(obc.getOrderBy());
390 }
391
392 else {
393 query.append("ORDER BY ");
394
395 query.append("folderId ASC, ");
396 query.append("name ASC");
397 }
398
399 Query q = session.createQuery(query.toString());
400
401 QueryPos qPos = QueryPos.getInstance(q);
402
403 if (uuid != null) {
404 qPos.add(uuid);
405 }
406
407 List<BookmarksEntry> list = (List<BookmarksEntry>)QueryUtil.list(q,
408 getDialect(), start, end);
409
410 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
411 finderClassName, finderMethodName, finderParams,
412 finderArgs, list);
413
414 return list;
415 }
416 catch (Exception e) {
417 throw processException(e);
418 }
419 finally {
420 closeSession(session);
421 }
422 }
423 else {
424 return (List<BookmarksEntry>)result;
425 }
426 }
427
428 public BookmarksEntry findByUuid_First(String uuid, OrderByComparator obc)
429 throws NoSuchEntryException, SystemException {
430 List<BookmarksEntry> list = findByUuid(uuid, 0, 1, obc);
431
432 if (list.size() == 0) {
433 StringBuilder msg = new StringBuilder();
434
435 msg.append("No BookmarksEntry exists with the key {");
436
437 msg.append("uuid=" + uuid);
438
439 msg.append(StringPool.CLOSE_CURLY_BRACE);
440
441 throw new NoSuchEntryException(msg.toString());
442 }
443 else {
444 return list.get(0);
445 }
446 }
447
448 public BookmarksEntry findByUuid_Last(String uuid, OrderByComparator obc)
449 throws NoSuchEntryException, SystemException {
450 int count = countByUuid(uuid);
451
452 List<BookmarksEntry> list = findByUuid(uuid, count - 1, count, obc);
453
454 if (list.size() == 0) {
455 StringBuilder msg = new StringBuilder();
456
457 msg.append("No BookmarksEntry exists with the key {");
458
459 msg.append("uuid=" + uuid);
460
461 msg.append(StringPool.CLOSE_CURLY_BRACE);
462
463 throw new NoSuchEntryException(msg.toString());
464 }
465 else {
466 return list.get(0);
467 }
468 }
469
470 public BookmarksEntry[] findByUuid_PrevAndNext(long entryId, String uuid,
471 OrderByComparator obc) throws NoSuchEntryException, SystemException {
472 BookmarksEntry bookmarksEntry = findByPrimaryKey(entryId);
473
474 int count = countByUuid(uuid);
475
476 Session session = null;
477
478 try {
479 session = openSession();
480
481 StringBuilder query = new StringBuilder();
482
483 query.append(
484 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
485
486 if (uuid == null) {
487 query.append("uuid_ IS NULL");
488 }
489 else {
490 query.append("uuid_ = ?");
491 }
492
493 query.append(" ");
494
495 if (obc != null) {
496 query.append("ORDER BY ");
497 query.append(obc.getOrderBy());
498 }
499
500 else {
501 query.append("ORDER BY ");
502
503 query.append("folderId ASC, ");
504 query.append("name ASC");
505 }
506
507 Query q = session.createQuery(query.toString());
508
509 QueryPos qPos = QueryPos.getInstance(q);
510
511 if (uuid != null) {
512 qPos.add(uuid);
513 }
514
515 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
516 bookmarksEntry);
517
518 BookmarksEntry[] array = new BookmarksEntryImpl[3];
519
520 array[0] = (BookmarksEntry)objArray[0];
521 array[1] = (BookmarksEntry)objArray[1];
522 array[2] = (BookmarksEntry)objArray[2];
523
524 return array;
525 }
526 catch (Exception e) {
527 throw processException(e);
528 }
529 finally {
530 closeSession(session);
531 }
532 }
533
534 public List<BookmarksEntry> findByFolderId(long folderId)
535 throws SystemException {
536 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
537 String finderClassName = BookmarksEntry.class.getName();
538 String finderMethodName = "findByFolderId";
539 String[] finderParams = new String[] { Long.class.getName() };
540 Object[] finderArgs = new Object[] { new Long(folderId) };
541
542 Object result = null;
543
544 if (finderClassNameCacheEnabled) {
545 result = FinderCacheUtil.getResult(finderClassName,
546 finderMethodName, finderParams, finderArgs, this);
547 }
548
549 if (result == null) {
550 Session session = null;
551
552 try {
553 session = openSession();
554
555 StringBuilder query = new StringBuilder();
556
557 query.append(
558 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
559
560 query.append("folderId = ?");
561
562 query.append(" ");
563
564 query.append("ORDER BY ");
565
566 query.append("folderId ASC, ");
567 query.append("name ASC");
568
569 Query q = session.createQuery(query.toString());
570
571 QueryPos qPos = QueryPos.getInstance(q);
572
573 qPos.add(folderId);
574
575 List<BookmarksEntry> list = q.list();
576
577 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
578 finderClassName, finderMethodName, finderParams,
579 finderArgs, list);
580
581 return list;
582 }
583 catch (Exception e) {
584 throw processException(e);
585 }
586 finally {
587 closeSession(session);
588 }
589 }
590 else {
591 return (List<BookmarksEntry>)result;
592 }
593 }
594
595 public List<BookmarksEntry> findByFolderId(long folderId, int start, int end)
596 throws SystemException {
597 return findByFolderId(folderId, start, end, null);
598 }
599
600 public List<BookmarksEntry> findByFolderId(long folderId, int start,
601 int end, OrderByComparator obc) throws SystemException {
602 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
603 String finderClassName = BookmarksEntry.class.getName();
604 String finderMethodName = "findByFolderId";
605 String[] finderParams = new String[] {
606 Long.class.getName(),
607
608 "java.lang.Integer", "java.lang.Integer",
609 "com.liferay.portal.kernel.util.OrderByComparator"
610 };
611 Object[] finderArgs = new Object[] {
612 new Long(folderId),
613
614 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
615 };
616
617 Object result = null;
618
619 if (finderClassNameCacheEnabled) {
620 result = FinderCacheUtil.getResult(finderClassName,
621 finderMethodName, finderParams, finderArgs, this);
622 }
623
624 if (result == null) {
625 Session session = null;
626
627 try {
628 session = openSession();
629
630 StringBuilder query = new StringBuilder();
631
632 query.append(
633 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
634
635 query.append("folderId = ?");
636
637 query.append(" ");
638
639 if (obc != null) {
640 query.append("ORDER BY ");
641 query.append(obc.getOrderBy());
642 }
643
644 else {
645 query.append("ORDER BY ");
646
647 query.append("folderId ASC, ");
648 query.append("name ASC");
649 }
650
651 Query q = session.createQuery(query.toString());
652
653 QueryPos qPos = QueryPos.getInstance(q);
654
655 qPos.add(folderId);
656
657 List<BookmarksEntry> list = (List<BookmarksEntry>)QueryUtil.list(q,
658 getDialect(), start, end);
659
660 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
661 finderClassName, finderMethodName, finderParams,
662 finderArgs, list);
663
664 return list;
665 }
666 catch (Exception e) {
667 throw processException(e);
668 }
669 finally {
670 closeSession(session);
671 }
672 }
673 else {
674 return (List<BookmarksEntry>)result;
675 }
676 }
677
678 public BookmarksEntry findByFolderId_First(long folderId,
679 OrderByComparator obc) throws NoSuchEntryException, SystemException {
680 List<BookmarksEntry> list = findByFolderId(folderId, 0, 1, obc);
681
682 if (list.size() == 0) {
683 StringBuilder msg = new StringBuilder();
684
685 msg.append("No BookmarksEntry exists with the key {");
686
687 msg.append("folderId=" + folderId);
688
689 msg.append(StringPool.CLOSE_CURLY_BRACE);
690
691 throw new NoSuchEntryException(msg.toString());
692 }
693 else {
694 return list.get(0);
695 }
696 }
697
698 public BookmarksEntry findByFolderId_Last(long folderId,
699 OrderByComparator obc) throws NoSuchEntryException, SystemException {
700 int count = countByFolderId(folderId);
701
702 List<BookmarksEntry> list = findByFolderId(folderId, count - 1, count,
703 obc);
704
705 if (list.size() == 0) {
706 StringBuilder msg = new StringBuilder();
707
708 msg.append("No BookmarksEntry exists with the key {");
709
710 msg.append("folderId=" + folderId);
711
712 msg.append(StringPool.CLOSE_CURLY_BRACE);
713
714 throw new NoSuchEntryException(msg.toString());
715 }
716 else {
717 return list.get(0);
718 }
719 }
720
721 public BookmarksEntry[] findByFolderId_PrevAndNext(long entryId,
722 long folderId, OrderByComparator obc)
723 throws NoSuchEntryException, SystemException {
724 BookmarksEntry bookmarksEntry = findByPrimaryKey(entryId);
725
726 int count = countByFolderId(folderId);
727
728 Session session = null;
729
730 try {
731 session = openSession();
732
733 StringBuilder query = new StringBuilder();
734
735 query.append(
736 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
737
738 query.append("folderId = ?");
739
740 query.append(" ");
741
742 if (obc != null) {
743 query.append("ORDER BY ");
744 query.append(obc.getOrderBy());
745 }
746
747 else {
748 query.append("ORDER BY ");
749
750 query.append("folderId ASC, ");
751 query.append("name ASC");
752 }
753
754 Query q = session.createQuery(query.toString());
755
756 QueryPos qPos = QueryPos.getInstance(q);
757
758 qPos.add(folderId);
759
760 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
761 bookmarksEntry);
762
763 BookmarksEntry[] array = new BookmarksEntryImpl[3];
764
765 array[0] = (BookmarksEntry)objArray[0];
766 array[1] = (BookmarksEntry)objArray[1];
767 array[2] = (BookmarksEntry)objArray[2];
768
769 return array;
770 }
771 catch (Exception e) {
772 throw processException(e);
773 }
774 finally {
775 closeSession(session);
776 }
777 }
778
779 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
780 throws SystemException {
781 Session session = null;
782
783 try {
784 session = openSession();
785
786 dynamicQuery.compile(session);
787
788 return dynamicQuery.list();
789 }
790 catch (Exception e) {
791 throw processException(e);
792 }
793 finally {
794 closeSession(session);
795 }
796 }
797
798 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
799 int start, int end) throws SystemException {
800 Session session = null;
801
802 try {
803 session = openSession();
804
805 dynamicQuery.setLimit(start, end);
806
807 dynamicQuery.compile(session);
808
809 return dynamicQuery.list();
810 }
811 catch (Exception e) {
812 throw processException(e);
813 }
814 finally {
815 closeSession(session);
816 }
817 }
818
819 public List<BookmarksEntry> findAll() throws SystemException {
820 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
821 }
822
823 public List<BookmarksEntry> findAll(int start, int end)
824 throws SystemException {
825 return findAll(start, end, null);
826 }
827
828 public List<BookmarksEntry> findAll(int start, int end,
829 OrderByComparator obc) throws SystemException {
830 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
831 String finderClassName = BookmarksEntry.class.getName();
832 String finderMethodName = "findAll";
833 String[] finderParams = new String[] {
834 "java.lang.Integer", "java.lang.Integer",
835 "com.liferay.portal.kernel.util.OrderByComparator"
836 };
837 Object[] finderArgs = new Object[] {
838 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
839 };
840
841 Object result = null;
842
843 if (finderClassNameCacheEnabled) {
844 result = FinderCacheUtil.getResult(finderClassName,
845 finderMethodName, finderParams, finderArgs, this);
846 }
847
848 if (result == null) {
849 Session session = null;
850
851 try {
852 session = openSession();
853
854 StringBuilder query = new StringBuilder();
855
856 query.append(
857 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry ");
858
859 if (obc != null) {
860 query.append("ORDER BY ");
861 query.append(obc.getOrderBy());
862 }
863
864 else {
865 query.append("ORDER BY ");
866
867 query.append("folderId ASC, ");
868 query.append("name ASC");
869 }
870
871 Query q = session.createQuery(query.toString());
872
873 List<BookmarksEntry> list = null;
874
875 if (obc == null) {
876 list = (List<BookmarksEntry>)QueryUtil.list(q,
877 getDialect(), start, end, false);
878
879 Collections.sort(list);
880 }
881 else {
882 list = (List<BookmarksEntry>)QueryUtil.list(q,
883 getDialect(), start, end);
884 }
885
886 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
887 finderClassName, finderMethodName, finderParams,
888 finderArgs, list);
889
890 return list;
891 }
892 catch (Exception e) {
893 throw processException(e);
894 }
895 finally {
896 closeSession(session);
897 }
898 }
899 else {
900 return (List<BookmarksEntry>)result;
901 }
902 }
903
904 public void removeByUuid(String uuid) throws SystemException {
905 for (BookmarksEntry bookmarksEntry : findByUuid(uuid)) {
906 remove(bookmarksEntry);
907 }
908 }
909
910 public void removeByFolderId(long folderId) throws SystemException {
911 for (BookmarksEntry bookmarksEntry : findByFolderId(folderId)) {
912 remove(bookmarksEntry);
913 }
914 }
915
916 public void removeAll() throws SystemException {
917 for (BookmarksEntry bookmarksEntry : findAll()) {
918 remove(bookmarksEntry);
919 }
920 }
921
922 public int countByUuid(String uuid) throws SystemException {
923 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
924 String finderClassName = BookmarksEntry.class.getName();
925 String finderMethodName = "countByUuid";
926 String[] finderParams = new String[] { String.class.getName() };
927 Object[] finderArgs = new Object[] { uuid };
928
929 Object result = null;
930
931 if (finderClassNameCacheEnabled) {
932 result = FinderCacheUtil.getResult(finderClassName,
933 finderMethodName, finderParams, finderArgs, this);
934 }
935
936 if (result == null) {
937 Session session = null;
938
939 try {
940 session = openSession();
941
942 StringBuilder query = new StringBuilder();
943
944 query.append("SELECT COUNT(*) ");
945 query.append(
946 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
947
948 if (uuid == null) {
949 query.append("uuid_ IS NULL");
950 }
951 else {
952 query.append("uuid_ = ?");
953 }
954
955 query.append(" ");
956
957 Query q = session.createQuery(query.toString());
958
959 QueryPos qPos = QueryPos.getInstance(q);
960
961 if (uuid != null) {
962 qPos.add(uuid);
963 }
964
965 Long count = null;
966
967 Iterator<Long> itr = q.list().iterator();
968
969 if (itr.hasNext()) {
970 count = itr.next();
971 }
972
973 if (count == null) {
974 count = new Long(0);
975 }
976
977 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
978 finderClassName, finderMethodName, finderParams,
979 finderArgs, count);
980
981 return count.intValue();
982 }
983 catch (Exception e) {
984 throw processException(e);
985 }
986 finally {
987 closeSession(session);
988 }
989 }
990 else {
991 return ((Long)result).intValue();
992 }
993 }
994
995 public int countByFolderId(long folderId) throws SystemException {
996 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
997 String finderClassName = BookmarksEntry.class.getName();
998 String finderMethodName = "countByFolderId";
999 String[] finderParams = new String[] { Long.class.getName() };
1000 Object[] finderArgs = new Object[] { new Long(folderId) };
1001
1002 Object result = null;
1003
1004 if (finderClassNameCacheEnabled) {
1005 result = FinderCacheUtil.getResult(finderClassName,
1006 finderMethodName, finderParams, finderArgs, this);
1007 }
1008
1009 if (result == null) {
1010 Session session = null;
1011
1012 try {
1013 session = openSession();
1014
1015 StringBuilder query = new StringBuilder();
1016
1017 query.append("SELECT COUNT(*) ");
1018 query.append(
1019 "FROM com.liferay.portlet.bookmarks.model.BookmarksEntry WHERE ");
1020
1021 query.append("folderId = ?");
1022
1023 query.append(" ");
1024
1025 Query q = session.createQuery(query.toString());
1026
1027 QueryPos qPos = QueryPos.getInstance(q);
1028
1029 qPos.add(folderId);
1030
1031 Long count = null;
1032
1033 Iterator<Long> itr = q.list().iterator();
1034
1035 if (itr.hasNext()) {
1036 count = itr.next();
1037 }
1038
1039 if (count == null) {
1040 count = new Long(0);
1041 }
1042
1043 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1044 finderClassName, finderMethodName, finderParams,
1045 finderArgs, count);
1046
1047 return count.intValue();
1048 }
1049 catch (Exception e) {
1050 throw processException(e);
1051 }
1052 finally {
1053 closeSession(session);
1054 }
1055 }
1056 else {
1057 return ((Long)result).intValue();
1058 }
1059 }
1060
1061 public int countAll() throws SystemException {
1062 boolean finderClassNameCacheEnabled = BookmarksEntryModelImpl.CACHE_ENABLED;
1063 String finderClassName = BookmarksEntry.class.getName();
1064 String finderMethodName = "countAll";
1065 String[] finderParams = new String[] { };
1066 Object[] finderArgs = new Object[] { };
1067
1068 Object result = null;
1069
1070 if (finderClassNameCacheEnabled) {
1071 result = FinderCacheUtil.getResult(finderClassName,
1072 finderMethodName, finderParams, finderArgs, this);
1073 }
1074
1075 if (result == null) {
1076 Session session = null;
1077
1078 try {
1079 session = openSession();
1080
1081 Query q = session.createQuery(
1082 "SELECT COUNT(*) FROM com.liferay.portlet.bookmarks.model.BookmarksEntry");
1083
1084 Long count = null;
1085
1086 Iterator<Long> itr = q.list().iterator();
1087
1088 if (itr.hasNext()) {
1089 count = itr.next();
1090 }
1091
1092 if (count == null) {
1093 count = new Long(0);
1094 }
1095
1096 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1097 finderClassName, finderMethodName, finderParams,
1098 finderArgs, count);
1099
1100 return count.intValue();
1101 }
1102 catch (Exception e) {
1103 throw processException(e);
1104 }
1105 finally {
1106 closeSession(session);
1107 }
1108 }
1109 else {
1110 return ((Long)result).intValue();
1111 }
1112 }
1113
1114 public void afterPropertiesSet() {
1115 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1116 com.liferay.portal.util.PropsUtil.get(
1117 "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksEntry")));
1118
1119 if (listenerClassNames.length > 0) {
1120 try {
1121 List<ModelListener> listenersList = new ArrayList<ModelListener>();
1122
1123 for (String listenerClassName : listenerClassNames) {
1124 listenersList.add((ModelListener)Class.forName(
1125 listenerClassName).newInstance());
1126 }
1127
1128 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1129 }
1130 catch (Exception e) {
1131 _log.error(e);
1132 }
1133 }
1134 }
1135
1136 private static Log _log = LogFactoryUtil.getLog(BookmarksEntryPersistenceImpl.class);
1137}