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