001
014
015 package com.liferay.portlet.bookmarks.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.BatchSessionUtil;
042 import com.liferay.portal.service.persistence.GroupPersistence;
043 import com.liferay.portal.service.persistence.ResourcePersistence;
044 import com.liferay.portal.service.persistence.UserPersistence;
045 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046
047 import com.liferay.portlet.bookmarks.NoSuchFolderException;
048 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
049 import com.liferay.portlet.bookmarks.model.impl.BookmarksFolderImpl;
050 import com.liferay.portlet.bookmarks.model.impl.BookmarksFolderModelImpl;
051 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
052
053 import java.io.Serializable;
054
055 import java.util.ArrayList;
056 import java.util.Collections;
057 import java.util.List;
058
059
075 public class BookmarksFolderPersistenceImpl extends BasePersistenceImpl<BookmarksFolder>
076 implements BookmarksFolderPersistence {
077 public static final String FINDER_CLASS_NAME_ENTITY = BookmarksFolderImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
079 ".List";
080 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
081 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
082 FINDER_CLASS_NAME_LIST, "findByUuid",
083 new String[] {
084 String.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
090 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
091 FINDER_CLASS_NAME_LIST, "countByUuid",
092 new String[] { String.class.getName() });
093 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
094 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
095 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
096 new String[] { String.class.getName(), Long.class.getName() });
097 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
098 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
099 FINDER_CLASS_NAME_LIST, "countByUUID_G",
100 new String[] { String.class.getName(), Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
102 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_LIST, "findByGroupId",
104 new String[] {
105 Long.class.getName(),
106
107 "java.lang.Integer", "java.lang.Integer",
108 "com.liferay.portal.kernel.util.OrderByComparator"
109 });
110 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
111 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
112 FINDER_CLASS_NAME_LIST, "countByGroupId",
113 new String[] { Long.class.getName() });
114 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
115 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
116 FINDER_CLASS_NAME_LIST, "findByCompanyId",
117 new String[] {
118 Long.class.getName(),
119
120 "java.lang.Integer", "java.lang.Integer",
121 "com.liferay.portal.kernel.util.OrderByComparator"
122 });
123 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
124 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
125 FINDER_CLASS_NAME_LIST, "countByCompanyId",
126 new String[] { Long.class.getName() });
127 public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
128 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
129 FINDER_CLASS_NAME_LIST, "findByG_P",
130 new String[] {
131 Long.class.getName(), Long.class.getName(),
132
133 "java.lang.Integer", "java.lang.Integer",
134 "com.liferay.portal.kernel.util.OrderByComparator"
135 });
136 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
137 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
138 FINDER_CLASS_NAME_LIST, "countByG_P",
139 new String[] { Long.class.getName(), Long.class.getName() });
140 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
141 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
142 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
143 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
144 BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
145 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
146
147
152 public void cacheResult(BookmarksFolder bookmarksFolder) {
153 EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
154 BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
155 bookmarksFolder);
156
157 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
158 new Object[] {
159 bookmarksFolder.getUuid(),
160 new Long(bookmarksFolder.getGroupId())
161 }, bookmarksFolder);
162 }
163
164
169 public void cacheResult(List<BookmarksFolder> bookmarksFolders) {
170 for (BookmarksFolder bookmarksFolder : bookmarksFolders) {
171 if (EntityCacheUtil.getResult(
172 BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
173 BookmarksFolderImpl.class,
174 bookmarksFolder.getPrimaryKey(), this) == null) {
175 cacheResult(bookmarksFolder);
176 }
177 }
178 }
179
180
187 public void clearCache() {
188 CacheRegistryUtil.clear(BookmarksFolderImpl.class.getName());
189 EntityCacheUtil.clearCache(BookmarksFolderImpl.class.getName());
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
192 }
193
194
201 public void clearCache(BookmarksFolder bookmarksFolder) {
202 EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
203 BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey());
204
205 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
206 new Object[] {
207 bookmarksFolder.getUuid(),
208 new Long(bookmarksFolder.getGroupId())
209 });
210 }
211
212
218 public BookmarksFolder create(long folderId) {
219 BookmarksFolder bookmarksFolder = new BookmarksFolderImpl();
220
221 bookmarksFolder.setNew(true);
222 bookmarksFolder.setPrimaryKey(folderId);
223
224 String uuid = PortalUUIDUtil.generate();
225
226 bookmarksFolder.setUuid(uuid);
227
228 return bookmarksFolder;
229 }
230
231
239 public BookmarksFolder remove(Serializable primaryKey)
240 throws NoSuchModelException, SystemException {
241 return remove(((Long)primaryKey).longValue());
242 }
243
244
252 public BookmarksFolder remove(long folderId)
253 throws NoSuchFolderException, SystemException {
254 Session session = null;
255
256 try {
257 session = openSession();
258
259 BookmarksFolder bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
260 new Long(folderId));
261
262 if (bookmarksFolder == null) {
263 if (_log.isWarnEnabled()) {
264 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
265 }
266
267 throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
268 folderId);
269 }
270
271 return remove(bookmarksFolder);
272 }
273 catch (NoSuchFolderException nsee) {
274 throw nsee;
275 }
276 catch (Exception e) {
277 throw processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282 }
283
284 protected BookmarksFolder removeImpl(BookmarksFolder bookmarksFolder)
285 throws SystemException {
286 bookmarksFolder = toUnwrappedModel(bookmarksFolder);
287
288 Session session = null;
289
290 try {
291 session = openSession();
292
293 if (bookmarksFolder.isCachedModel() ||
294 BatchSessionUtil.isEnabled()) {
295 Object staleObject = session.get(BookmarksFolderImpl.class,
296 bookmarksFolder.getPrimaryKeyObj());
297
298 if (staleObject != null) {
299 session.evict(staleObject);
300 }
301 }
302
303 session.delete(bookmarksFolder);
304
305 session.flush();
306 }
307 catch (Exception e) {
308 throw processException(e);
309 }
310 finally {
311 closeSession(session);
312 }
313
314 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
315
316 BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
317
318 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
319 new Object[] {
320 bookmarksFolderModelImpl.getOriginalUuid(),
321 new Long(bookmarksFolderModelImpl.getOriginalGroupId())
322 });
323
324 EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
325 BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey());
326
327 return bookmarksFolder;
328 }
329
330 public BookmarksFolder updateImpl(
331 com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder,
332 boolean merge) throws SystemException {
333 bookmarksFolder = toUnwrappedModel(bookmarksFolder);
334
335 boolean isNew = bookmarksFolder.isNew();
336
337 BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
338
339 if (Validator.isNull(bookmarksFolder.getUuid())) {
340 String uuid = PortalUUIDUtil.generate();
341
342 bookmarksFolder.setUuid(uuid);
343 }
344
345 Session session = null;
346
347 try {
348 session = openSession();
349
350 BatchSessionUtil.update(session, bookmarksFolder, merge);
351
352 bookmarksFolder.setNew(false);
353 }
354 catch (Exception e) {
355 throw processException(e);
356 }
357 finally {
358 closeSession(session);
359 }
360
361 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
362
363 EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
364 BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
365 bookmarksFolder);
366
367 if (!isNew &&
368 (!Validator.equals(bookmarksFolder.getUuid(),
369 bookmarksFolderModelImpl.getOriginalUuid()) ||
370 (bookmarksFolder.getGroupId() != bookmarksFolderModelImpl.getOriginalGroupId()))) {
371 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
372 new Object[] {
373 bookmarksFolderModelImpl.getOriginalUuid(),
374 new Long(bookmarksFolderModelImpl.getOriginalGroupId())
375 });
376 }
377
378 if (isNew ||
379 (!Validator.equals(bookmarksFolder.getUuid(),
380 bookmarksFolderModelImpl.getOriginalUuid()) ||
381 (bookmarksFolder.getGroupId() != bookmarksFolderModelImpl.getOriginalGroupId()))) {
382 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
383 new Object[] {
384 bookmarksFolder.getUuid(),
385 new Long(bookmarksFolder.getGroupId())
386 }, bookmarksFolder);
387 }
388
389 return bookmarksFolder;
390 }
391
392 protected BookmarksFolder toUnwrappedModel(BookmarksFolder bookmarksFolder) {
393 if (bookmarksFolder instanceof BookmarksFolderImpl) {
394 return bookmarksFolder;
395 }
396
397 BookmarksFolderImpl bookmarksFolderImpl = new BookmarksFolderImpl();
398
399 bookmarksFolderImpl.setNew(bookmarksFolder.isNew());
400 bookmarksFolderImpl.setPrimaryKey(bookmarksFolder.getPrimaryKey());
401
402 bookmarksFolderImpl.setUuid(bookmarksFolder.getUuid());
403 bookmarksFolderImpl.setFolderId(bookmarksFolder.getFolderId());
404 bookmarksFolderImpl.setGroupId(bookmarksFolder.getGroupId());
405 bookmarksFolderImpl.setCompanyId(bookmarksFolder.getCompanyId());
406 bookmarksFolderImpl.setUserId(bookmarksFolder.getUserId());
407 bookmarksFolderImpl.setCreateDate(bookmarksFolder.getCreateDate());
408 bookmarksFolderImpl.setModifiedDate(bookmarksFolder.getModifiedDate());
409 bookmarksFolderImpl.setParentFolderId(bookmarksFolder.getParentFolderId());
410 bookmarksFolderImpl.setName(bookmarksFolder.getName());
411 bookmarksFolderImpl.setDescription(bookmarksFolder.getDescription());
412
413 return bookmarksFolderImpl;
414 }
415
416
424 public BookmarksFolder findByPrimaryKey(Serializable primaryKey)
425 throws NoSuchModelException, SystemException {
426 return findByPrimaryKey(((Long)primaryKey).longValue());
427 }
428
429
437 public BookmarksFolder findByPrimaryKey(long folderId)
438 throws NoSuchFolderException, SystemException {
439 BookmarksFolder bookmarksFolder = fetchByPrimaryKey(folderId);
440
441 if (bookmarksFolder == null) {
442 if (_log.isWarnEnabled()) {
443 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
444 }
445
446 throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
447 folderId);
448 }
449
450 return bookmarksFolder;
451 }
452
453
460 public BookmarksFolder fetchByPrimaryKey(Serializable primaryKey)
461 throws SystemException {
462 return fetchByPrimaryKey(((Long)primaryKey).longValue());
463 }
464
465
472 public BookmarksFolder fetchByPrimaryKey(long folderId)
473 throws SystemException {
474 BookmarksFolder bookmarksFolder = (BookmarksFolder)EntityCacheUtil.getResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
475 BookmarksFolderImpl.class, folderId, this);
476
477 if (bookmarksFolder == null) {
478 Session session = null;
479
480 try {
481 session = openSession();
482
483 bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
484 new Long(folderId));
485 }
486 catch (Exception e) {
487 throw processException(e);
488 }
489 finally {
490 if (bookmarksFolder != null) {
491 cacheResult(bookmarksFolder);
492 }
493
494 closeSession(session);
495 }
496 }
497
498 return bookmarksFolder;
499 }
500
501
508 public List<BookmarksFolder> findByUuid(String uuid)
509 throws SystemException {
510 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
511 }
512
513
526 public List<BookmarksFolder> findByUuid(String uuid, int start, int end)
527 throws SystemException {
528 return findByUuid(uuid, start, end, null);
529 }
530
531
545 public List<BookmarksFolder> findByUuid(String uuid, int start, int end,
546 OrderByComparator orderByComparator) throws SystemException {
547 Object[] finderArgs = new Object[] {
548 uuid,
549
550 String.valueOf(start), String.valueOf(end),
551 String.valueOf(orderByComparator)
552 };
553
554 List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
555 finderArgs, this);
556
557 if (list == null) {
558 Session session = null;
559
560 try {
561 session = openSession();
562
563 StringBundler query = null;
564
565 if (orderByComparator != null) {
566 query = new StringBundler(3 +
567 (orderByComparator.getOrderByFields().length * 3));
568 }
569 else {
570 query = new StringBundler(3);
571 }
572
573 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
574
575 if (uuid == null) {
576 query.append(_FINDER_COLUMN_UUID_UUID_1);
577 }
578 else {
579 if (uuid.equals(StringPool.BLANK)) {
580 query.append(_FINDER_COLUMN_UUID_UUID_3);
581 }
582 else {
583 query.append(_FINDER_COLUMN_UUID_UUID_2);
584 }
585 }
586
587 if (orderByComparator != null) {
588 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
589 orderByComparator);
590 }
591
592 else {
593 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
594 }
595
596 String sql = query.toString();
597
598 Query q = session.createQuery(sql);
599
600 QueryPos qPos = QueryPos.getInstance(q);
601
602 if (uuid != null) {
603 qPos.add(uuid);
604 }
605
606 list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
607 start, end);
608 }
609 catch (Exception e) {
610 throw processException(e);
611 }
612 finally {
613 if (list == null) {
614 list = new ArrayList<BookmarksFolder>();
615 }
616
617 cacheResult(list);
618
619 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
620 list);
621
622 closeSession(session);
623 }
624 }
625
626 return list;
627 }
628
629
642 public BookmarksFolder findByUuid_First(String uuid,
643 OrderByComparator orderByComparator)
644 throws NoSuchFolderException, SystemException {
645 List<BookmarksFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
646
647 if (list.isEmpty()) {
648 StringBundler msg = new StringBundler(4);
649
650 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
651
652 msg.append("uuid=");
653 msg.append(uuid);
654
655 msg.append(StringPool.CLOSE_CURLY_BRACE);
656
657 throw new NoSuchFolderException(msg.toString());
658 }
659 else {
660 return list.get(0);
661 }
662 }
663
664
677 public BookmarksFolder findByUuid_Last(String uuid,
678 OrderByComparator orderByComparator)
679 throws NoSuchFolderException, SystemException {
680 int count = countByUuid(uuid);
681
682 List<BookmarksFolder> list = findByUuid(uuid, count - 1, count,
683 orderByComparator);
684
685 if (list.isEmpty()) {
686 StringBundler msg = new StringBundler(4);
687
688 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
689
690 msg.append("uuid=");
691 msg.append(uuid);
692
693 msg.append(StringPool.CLOSE_CURLY_BRACE);
694
695 throw new NoSuchFolderException(msg.toString());
696 }
697 else {
698 return list.get(0);
699 }
700 }
701
702
716 public BookmarksFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
717 OrderByComparator orderByComparator)
718 throws NoSuchFolderException, SystemException {
719 BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
720
721 Session session = null;
722
723 try {
724 session = openSession();
725
726 BookmarksFolder[] array = new BookmarksFolderImpl[3];
727
728 array[0] = getByUuid_PrevAndNext(session, bookmarksFolder, uuid,
729 orderByComparator, true);
730
731 array[1] = bookmarksFolder;
732
733 array[2] = getByUuid_PrevAndNext(session, bookmarksFolder, uuid,
734 orderByComparator, false);
735
736 return array;
737 }
738 catch (Exception e) {
739 throw processException(e);
740 }
741 finally {
742 closeSession(session);
743 }
744 }
745
746 protected BookmarksFolder getByUuid_PrevAndNext(Session session,
747 BookmarksFolder bookmarksFolder, String uuid,
748 OrderByComparator orderByComparator, boolean previous) {
749 StringBundler query = null;
750
751 if (orderByComparator != null) {
752 query = new StringBundler(6 +
753 (orderByComparator.getOrderByFields().length * 6));
754 }
755 else {
756 query = new StringBundler(3);
757 }
758
759 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
760
761 if (uuid == null) {
762 query.append(_FINDER_COLUMN_UUID_UUID_1);
763 }
764 else {
765 if (uuid.equals(StringPool.BLANK)) {
766 query.append(_FINDER_COLUMN_UUID_UUID_3);
767 }
768 else {
769 query.append(_FINDER_COLUMN_UUID_UUID_2);
770 }
771 }
772
773 if (orderByComparator != null) {
774 String[] orderByFields = orderByComparator.getOrderByFields();
775
776 if (orderByFields.length > 0) {
777 query.append(WHERE_AND);
778 }
779
780 for (int i = 0; i < orderByFields.length; i++) {
781 query.append(_ORDER_BY_ENTITY_ALIAS);
782 query.append(orderByFields[i]);
783
784 if ((i + 1) < orderByFields.length) {
785 if (orderByComparator.isAscending() ^ previous) {
786 query.append(WHERE_GREATER_THAN_HAS_NEXT);
787 }
788 else {
789 query.append(WHERE_LESSER_THAN_HAS_NEXT);
790 }
791 }
792 else {
793 if (orderByComparator.isAscending() ^ previous) {
794 query.append(WHERE_GREATER_THAN);
795 }
796 else {
797 query.append(WHERE_LESSER_THAN);
798 }
799 }
800 }
801
802 query.append(ORDER_BY_CLAUSE);
803
804 for (int i = 0; i < orderByFields.length; i++) {
805 query.append(_ORDER_BY_ENTITY_ALIAS);
806 query.append(orderByFields[i]);
807
808 if ((i + 1) < orderByFields.length) {
809 if (orderByComparator.isAscending() ^ previous) {
810 query.append(ORDER_BY_ASC_HAS_NEXT);
811 }
812 else {
813 query.append(ORDER_BY_DESC_HAS_NEXT);
814 }
815 }
816 else {
817 if (orderByComparator.isAscending() ^ previous) {
818 query.append(ORDER_BY_ASC);
819 }
820 else {
821 query.append(ORDER_BY_DESC);
822 }
823 }
824 }
825 }
826
827 else {
828 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
829 }
830
831 String sql = query.toString();
832
833 Query q = session.createQuery(sql);
834
835 q.setFirstResult(0);
836 q.setMaxResults(2);
837
838 QueryPos qPos = QueryPos.getInstance(q);
839
840 if (uuid != null) {
841 qPos.add(uuid);
842 }
843
844 if (orderByComparator != null) {
845 Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
846
847 for (Object value : values) {
848 qPos.add(value);
849 }
850 }
851
852 List<BookmarksFolder> list = q.list();
853
854 if (list.size() == 2) {
855 return list.get(1);
856 }
857 else {
858 return null;
859 }
860 }
861
862
871 public BookmarksFolder findByUUID_G(String uuid, long groupId)
872 throws NoSuchFolderException, SystemException {
873 BookmarksFolder bookmarksFolder = fetchByUUID_G(uuid, groupId);
874
875 if (bookmarksFolder == null) {
876 StringBundler msg = new StringBundler(6);
877
878 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
879
880 msg.append("uuid=");
881 msg.append(uuid);
882
883 msg.append(", groupId=");
884 msg.append(groupId);
885
886 msg.append(StringPool.CLOSE_CURLY_BRACE);
887
888 if (_log.isWarnEnabled()) {
889 _log.warn(msg.toString());
890 }
891
892 throw new NoSuchFolderException(msg.toString());
893 }
894
895 return bookmarksFolder;
896 }
897
898
906 public BookmarksFolder fetchByUUID_G(String uuid, long groupId)
907 throws SystemException {
908 return fetchByUUID_G(uuid, groupId, true);
909 }
910
911
919 public BookmarksFolder fetchByUUID_G(String uuid, long groupId,
920 boolean retrieveFromCache) throws SystemException {
921 Object[] finderArgs = new Object[] { uuid, groupId };
922
923 Object result = null;
924
925 if (retrieveFromCache) {
926 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
927 finderArgs, this);
928 }
929
930 if (result == null) {
931 Session session = null;
932
933 try {
934 session = openSession();
935
936 StringBundler query = new StringBundler(4);
937
938 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
939
940 if (uuid == null) {
941 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
942 }
943 else {
944 if (uuid.equals(StringPool.BLANK)) {
945 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
946 }
947 else {
948 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
949 }
950 }
951
952 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
953
954 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
955
956 String sql = query.toString();
957
958 Query q = session.createQuery(sql);
959
960 QueryPos qPos = QueryPos.getInstance(q);
961
962 if (uuid != null) {
963 qPos.add(uuid);
964 }
965
966 qPos.add(groupId);
967
968 List<BookmarksFolder> list = q.list();
969
970 result = list;
971
972 BookmarksFolder bookmarksFolder = null;
973
974 if (list.isEmpty()) {
975 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
976 finderArgs, list);
977 }
978 else {
979 bookmarksFolder = list.get(0);
980
981 cacheResult(bookmarksFolder);
982
983 if ((bookmarksFolder.getUuid() == null) ||
984 !bookmarksFolder.getUuid().equals(uuid) ||
985 (bookmarksFolder.getGroupId() != groupId)) {
986 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
987 finderArgs, bookmarksFolder);
988 }
989 }
990
991 return bookmarksFolder;
992 }
993 catch (Exception e) {
994 throw processException(e);
995 }
996 finally {
997 if (result == null) {
998 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
999 finderArgs, new ArrayList<BookmarksFolder>());
1000 }
1001
1002 closeSession(session);
1003 }
1004 }
1005 else {
1006 if (result instanceof List<?>) {
1007 return null;
1008 }
1009 else {
1010 return (BookmarksFolder)result;
1011 }
1012 }
1013 }
1014
1015
1022 public List<BookmarksFolder> findByGroupId(long groupId)
1023 throws SystemException {
1024 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1025 }
1026
1027
1040 public List<BookmarksFolder> findByGroupId(long groupId, int start, int end)
1041 throws SystemException {
1042 return findByGroupId(groupId, start, end, null);
1043 }
1044
1045
1059 public List<BookmarksFolder> findByGroupId(long groupId, int start,
1060 int end, OrderByComparator orderByComparator) throws SystemException {
1061 Object[] finderArgs = new Object[] {
1062 groupId,
1063
1064 String.valueOf(start), String.valueOf(end),
1065 String.valueOf(orderByComparator)
1066 };
1067
1068 List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1069 finderArgs, this);
1070
1071 if (list == null) {
1072 Session session = null;
1073
1074 try {
1075 session = openSession();
1076
1077 StringBundler query = null;
1078
1079 if (orderByComparator != null) {
1080 query = new StringBundler(3 +
1081 (orderByComparator.getOrderByFields().length * 3));
1082 }
1083 else {
1084 query = new StringBundler(3);
1085 }
1086
1087 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1088
1089 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1090
1091 if (orderByComparator != null) {
1092 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1093 orderByComparator);
1094 }
1095
1096 else {
1097 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1098 }
1099
1100 String sql = query.toString();
1101
1102 Query q = session.createQuery(sql);
1103
1104 QueryPos qPos = QueryPos.getInstance(q);
1105
1106 qPos.add(groupId);
1107
1108 list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1109 start, end);
1110 }
1111 catch (Exception e) {
1112 throw processException(e);
1113 }
1114 finally {
1115 if (list == null) {
1116 list = new ArrayList<BookmarksFolder>();
1117 }
1118
1119 cacheResult(list);
1120
1121 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1122 finderArgs, list);
1123
1124 closeSession(session);
1125 }
1126 }
1127
1128 return list;
1129 }
1130
1131
1144 public BookmarksFolder findByGroupId_First(long groupId,
1145 OrderByComparator orderByComparator)
1146 throws NoSuchFolderException, SystemException {
1147 List<BookmarksFolder> list = findByGroupId(groupId, 0, 1,
1148 orderByComparator);
1149
1150 if (list.isEmpty()) {
1151 StringBundler msg = new StringBundler(4);
1152
1153 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1154
1155 msg.append("groupId=");
1156 msg.append(groupId);
1157
1158 msg.append(StringPool.CLOSE_CURLY_BRACE);
1159
1160 throw new NoSuchFolderException(msg.toString());
1161 }
1162 else {
1163 return list.get(0);
1164 }
1165 }
1166
1167
1180 public BookmarksFolder findByGroupId_Last(long groupId,
1181 OrderByComparator orderByComparator)
1182 throws NoSuchFolderException, SystemException {
1183 int count = countByGroupId(groupId);
1184
1185 List<BookmarksFolder> list = findByGroupId(groupId, count - 1, count,
1186 orderByComparator);
1187
1188 if (list.isEmpty()) {
1189 StringBundler msg = new StringBundler(4);
1190
1191 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1192
1193 msg.append("groupId=");
1194 msg.append(groupId);
1195
1196 msg.append(StringPool.CLOSE_CURLY_BRACE);
1197
1198 throw new NoSuchFolderException(msg.toString());
1199 }
1200 else {
1201 return list.get(0);
1202 }
1203 }
1204
1205
1219 public BookmarksFolder[] findByGroupId_PrevAndNext(long folderId,
1220 long groupId, OrderByComparator orderByComparator)
1221 throws NoSuchFolderException, SystemException {
1222 BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
1223
1224 Session session = null;
1225
1226 try {
1227 session = openSession();
1228
1229 BookmarksFolder[] array = new BookmarksFolderImpl[3];
1230
1231 array[0] = getByGroupId_PrevAndNext(session, bookmarksFolder,
1232 groupId, orderByComparator, true);
1233
1234 array[1] = bookmarksFolder;
1235
1236 array[2] = getByGroupId_PrevAndNext(session, bookmarksFolder,
1237 groupId, orderByComparator, false);
1238
1239 return array;
1240 }
1241 catch (Exception e) {
1242 throw processException(e);
1243 }
1244 finally {
1245 closeSession(session);
1246 }
1247 }
1248
1249 protected BookmarksFolder getByGroupId_PrevAndNext(Session session,
1250 BookmarksFolder bookmarksFolder, long groupId,
1251 OrderByComparator orderByComparator, boolean previous) {
1252 StringBundler query = null;
1253
1254 if (orderByComparator != null) {
1255 query = new StringBundler(6 +
1256 (orderByComparator.getOrderByFields().length * 6));
1257 }
1258 else {
1259 query = new StringBundler(3);
1260 }
1261
1262 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1263
1264 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1265
1266 if (orderByComparator != null) {
1267 String[] orderByFields = orderByComparator.getOrderByFields();
1268
1269 if (orderByFields.length > 0) {
1270 query.append(WHERE_AND);
1271 }
1272
1273 for (int i = 0; i < orderByFields.length; i++) {
1274 query.append(_ORDER_BY_ENTITY_ALIAS);
1275 query.append(orderByFields[i]);
1276
1277 if ((i + 1) < orderByFields.length) {
1278 if (orderByComparator.isAscending() ^ previous) {
1279 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1280 }
1281 else {
1282 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1283 }
1284 }
1285 else {
1286 if (orderByComparator.isAscending() ^ previous) {
1287 query.append(WHERE_GREATER_THAN);
1288 }
1289 else {
1290 query.append(WHERE_LESSER_THAN);
1291 }
1292 }
1293 }
1294
1295 query.append(ORDER_BY_CLAUSE);
1296
1297 for (int i = 0; i < orderByFields.length; i++) {
1298 query.append(_ORDER_BY_ENTITY_ALIAS);
1299 query.append(orderByFields[i]);
1300
1301 if ((i + 1) < orderByFields.length) {
1302 if (orderByComparator.isAscending() ^ previous) {
1303 query.append(ORDER_BY_ASC_HAS_NEXT);
1304 }
1305 else {
1306 query.append(ORDER_BY_DESC_HAS_NEXT);
1307 }
1308 }
1309 else {
1310 if (orderByComparator.isAscending() ^ previous) {
1311 query.append(ORDER_BY_ASC);
1312 }
1313 else {
1314 query.append(ORDER_BY_DESC);
1315 }
1316 }
1317 }
1318 }
1319
1320 else {
1321 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1322 }
1323
1324 String sql = query.toString();
1325
1326 Query q = session.createQuery(sql);
1327
1328 q.setFirstResult(0);
1329 q.setMaxResults(2);
1330
1331 QueryPos qPos = QueryPos.getInstance(q);
1332
1333 qPos.add(groupId);
1334
1335 if (orderByComparator != null) {
1336 Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
1337
1338 for (Object value : values) {
1339 qPos.add(value);
1340 }
1341 }
1342
1343 List<BookmarksFolder> list = q.list();
1344
1345 if (list.size() == 2) {
1346 return list.get(1);
1347 }
1348 else {
1349 return null;
1350 }
1351 }
1352
1353
1360 public List<BookmarksFolder> filterFindByGroupId(long groupId)
1361 throws SystemException {
1362 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1363 QueryUtil.ALL_POS, null);
1364 }
1365
1366
1379 public List<BookmarksFolder> filterFindByGroupId(long groupId, int start,
1380 int end) throws SystemException {
1381 return filterFindByGroupId(groupId, start, end, null);
1382 }
1383
1384
1398 public List<BookmarksFolder> filterFindByGroupId(long groupId, int start,
1399 int end, OrderByComparator orderByComparator) throws SystemException {
1400 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1401 return findByGroupId(groupId, start, end, orderByComparator);
1402 }
1403
1404 Session session = null;
1405
1406 try {
1407 session = openSession();
1408
1409 StringBundler query = null;
1410
1411 if (orderByComparator != null) {
1412 query = new StringBundler(3 +
1413 (orderByComparator.getOrderByFields().length * 3));
1414 }
1415 else {
1416 query = new StringBundler(3);
1417 }
1418
1419 query.append(_FILTER_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1420
1421 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1422
1423 if (orderByComparator != null) {
1424 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1425 orderByComparator);
1426 }
1427
1428 else {
1429 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1430 }
1431
1432 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1433 BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
1434 _FILTER_COLUMN_USERID, groupId);
1435
1436 SQLQuery q = session.createSQLQuery(sql);
1437
1438 q.addEntity(_FILTER_ENTITY_ALIAS, BookmarksFolderImpl.class);
1439
1440 QueryPos qPos = QueryPos.getInstance(q);
1441
1442 qPos.add(groupId);
1443
1444 return (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1445 start, end);
1446 }
1447 catch (Exception e) {
1448 throw processException(e);
1449 }
1450 finally {
1451 closeSession(session);
1452 }
1453 }
1454
1455
1462 public List<BookmarksFolder> findByCompanyId(long companyId)
1463 throws SystemException {
1464 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1465 null);
1466 }
1467
1468
1481 public List<BookmarksFolder> findByCompanyId(long companyId, int start,
1482 int end) throws SystemException {
1483 return findByCompanyId(companyId, start, end, null);
1484 }
1485
1486
1500 public List<BookmarksFolder> findByCompanyId(long companyId, int start,
1501 int end, OrderByComparator orderByComparator) throws SystemException {
1502 Object[] finderArgs = new Object[] {
1503 companyId,
1504
1505 String.valueOf(start), String.valueOf(end),
1506 String.valueOf(orderByComparator)
1507 };
1508
1509 List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1510 finderArgs, this);
1511
1512 if (list == null) {
1513 Session session = null;
1514
1515 try {
1516 session = openSession();
1517
1518 StringBundler query = null;
1519
1520 if (orderByComparator != null) {
1521 query = new StringBundler(3 +
1522 (orderByComparator.getOrderByFields().length * 3));
1523 }
1524 else {
1525 query = new StringBundler(3);
1526 }
1527
1528 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1529
1530 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1531
1532 if (orderByComparator != null) {
1533 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1534 orderByComparator);
1535 }
1536
1537 else {
1538 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1539 }
1540
1541 String sql = query.toString();
1542
1543 Query q = session.createQuery(sql);
1544
1545 QueryPos qPos = QueryPos.getInstance(q);
1546
1547 qPos.add(companyId);
1548
1549 list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1550 start, end);
1551 }
1552 catch (Exception e) {
1553 throw processException(e);
1554 }
1555 finally {
1556 if (list == null) {
1557 list = new ArrayList<BookmarksFolder>();
1558 }
1559
1560 cacheResult(list);
1561
1562 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1563 finderArgs, list);
1564
1565 closeSession(session);
1566 }
1567 }
1568
1569 return list;
1570 }
1571
1572
1585 public BookmarksFolder findByCompanyId_First(long companyId,
1586 OrderByComparator orderByComparator)
1587 throws NoSuchFolderException, SystemException {
1588 List<BookmarksFolder> list = findByCompanyId(companyId, 0, 1,
1589 orderByComparator);
1590
1591 if (list.isEmpty()) {
1592 StringBundler msg = new StringBundler(4);
1593
1594 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1595
1596 msg.append("companyId=");
1597 msg.append(companyId);
1598
1599 msg.append(StringPool.CLOSE_CURLY_BRACE);
1600
1601 throw new NoSuchFolderException(msg.toString());
1602 }
1603 else {
1604 return list.get(0);
1605 }
1606 }
1607
1608
1621 public BookmarksFolder findByCompanyId_Last(long companyId,
1622 OrderByComparator orderByComparator)
1623 throws NoSuchFolderException, SystemException {
1624 int count = countByCompanyId(companyId);
1625
1626 List<BookmarksFolder> list = findByCompanyId(companyId, count - 1,
1627 count, orderByComparator);
1628
1629 if (list.isEmpty()) {
1630 StringBundler msg = new StringBundler(4);
1631
1632 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1633
1634 msg.append("companyId=");
1635 msg.append(companyId);
1636
1637 msg.append(StringPool.CLOSE_CURLY_BRACE);
1638
1639 throw new NoSuchFolderException(msg.toString());
1640 }
1641 else {
1642 return list.get(0);
1643 }
1644 }
1645
1646
1660 public BookmarksFolder[] findByCompanyId_PrevAndNext(long folderId,
1661 long companyId, OrderByComparator orderByComparator)
1662 throws NoSuchFolderException, SystemException {
1663 BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
1664
1665 Session session = null;
1666
1667 try {
1668 session = openSession();
1669
1670 BookmarksFolder[] array = new BookmarksFolderImpl[3];
1671
1672 array[0] = getByCompanyId_PrevAndNext(session, bookmarksFolder,
1673 companyId, orderByComparator, true);
1674
1675 array[1] = bookmarksFolder;
1676
1677 array[2] = getByCompanyId_PrevAndNext(session, bookmarksFolder,
1678 companyId, orderByComparator, false);
1679
1680 return array;
1681 }
1682 catch (Exception e) {
1683 throw processException(e);
1684 }
1685 finally {
1686 closeSession(session);
1687 }
1688 }
1689
1690 protected BookmarksFolder getByCompanyId_PrevAndNext(Session session,
1691 BookmarksFolder bookmarksFolder, long companyId,
1692 OrderByComparator orderByComparator, boolean previous) {
1693 StringBundler query = null;
1694
1695 if (orderByComparator != null) {
1696 query = new StringBundler(6 +
1697 (orderByComparator.getOrderByFields().length * 6));
1698 }
1699 else {
1700 query = new StringBundler(3);
1701 }
1702
1703 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1704
1705 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1706
1707 if (orderByComparator != null) {
1708 String[] orderByFields = orderByComparator.getOrderByFields();
1709
1710 if (orderByFields.length > 0) {
1711 query.append(WHERE_AND);
1712 }
1713
1714 for (int i = 0; i < orderByFields.length; i++) {
1715 query.append(_ORDER_BY_ENTITY_ALIAS);
1716 query.append(orderByFields[i]);
1717
1718 if ((i + 1) < orderByFields.length) {
1719 if (orderByComparator.isAscending() ^ previous) {
1720 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1721 }
1722 else {
1723 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1724 }
1725 }
1726 else {
1727 if (orderByComparator.isAscending() ^ previous) {
1728 query.append(WHERE_GREATER_THAN);
1729 }
1730 else {
1731 query.append(WHERE_LESSER_THAN);
1732 }
1733 }
1734 }
1735
1736 query.append(ORDER_BY_CLAUSE);
1737
1738 for (int i = 0; i < orderByFields.length; i++) {
1739 query.append(_ORDER_BY_ENTITY_ALIAS);
1740 query.append(orderByFields[i]);
1741
1742 if ((i + 1) < orderByFields.length) {
1743 if (orderByComparator.isAscending() ^ previous) {
1744 query.append(ORDER_BY_ASC_HAS_NEXT);
1745 }
1746 else {
1747 query.append(ORDER_BY_DESC_HAS_NEXT);
1748 }
1749 }
1750 else {
1751 if (orderByComparator.isAscending() ^ previous) {
1752 query.append(ORDER_BY_ASC);
1753 }
1754 else {
1755 query.append(ORDER_BY_DESC);
1756 }
1757 }
1758 }
1759 }
1760
1761 else {
1762 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1763 }
1764
1765 String sql = query.toString();
1766
1767 Query q = session.createQuery(sql);
1768
1769 q.setFirstResult(0);
1770 q.setMaxResults(2);
1771
1772 QueryPos qPos = QueryPos.getInstance(q);
1773
1774 qPos.add(companyId);
1775
1776 if (orderByComparator != null) {
1777 Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
1778
1779 for (Object value : values) {
1780 qPos.add(value);
1781 }
1782 }
1783
1784 List<BookmarksFolder> list = q.list();
1785
1786 if (list.size() == 2) {
1787 return list.get(1);
1788 }
1789 else {
1790 return null;
1791 }
1792 }
1793
1794
1802 public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId)
1803 throws SystemException {
1804 return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
1805 QueryUtil.ALL_POS, null);
1806 }
1807
1808
1822 public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId,
1823 int start, int end) throws SystemException {
1824 return findByG_P(groupId, parentFolderId, start, end, null);
1825 }
1826
1827
1842 public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId,
1843 int start, int end, OrderByComparator orderByComparator)
1844 throws SystemException {
1845 Object[] finderArgs = new Object[] {
1846 groupId, parentFolderId,
1847
1848 String.valueOf(start), String.valueOf(end),
1849 String.valueOf(orderByComparator)
1850 };
1851
1852 List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1853 finderArgs, this);
1854
1855 if (list == null) {
1856 Session session = null;
1857
1858 try {
1859 session = openSession();
1860
1861 StringBundler query = null;
1862
1863 if (orderByComparator != null) {
1864 query = new StringBundler(4 +
1865 (orderByComparator.getOrderByFields().length * 3));
1866 }
1867 else {
1868 query = new StringBundler(4);
1869 }
1870
1871 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1872
1873 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1874
1875 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
1876
1877 if (orderByComparator != null) {
1878 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1879 orderByComparator);
1880 }
1881
1882 else {
1883 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1884 }
1885
1886 String sql = query.toString();
1887
1888 Query q = session.createQuery(sql);
1889
1890 QueryPos qPos = QueryPos.getInstance(q);
1891
1892 qPos.add(groupId);
1893
1894 qPos.add(parentFolderId);
1895
1896 list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1897 start, end);
1898 }
1899 catch (Exception e) {
1900 throw processException(e);
1901 }
1902 finally {
1903 if (list == null) {
1904 list = new ArrayList<BookmarksFolder>();
1905 }
1906
1907 cacheResult(list);
1908
1909 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
1910 list);
1911
1912 closeSession(session);
1913 }
1914 }
1915
1916 return list;
1917 }
1918
1919
1933 public BookmarksFolder findByG_P_First(long groupId, long parentFolderId,
1934 OrderByComparator orderByComparator)
1935 throws NoSuchFolderException, SystemException {
1936 List<BookmarksFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
1937 orderByComparator);
1938
1939 if (list.isEmpty()) {
1940 StringBundler msg = new StringBundler(6);
1941
1942 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1943
1944 msg.append("groupId=");
1945 msg.append(groupId);
1946
1947 msg.append(", parentFolderId=");
1948 msg.append(parentFolderId);
1949
1950 msg.append(StringPool.CLOSE_CURLY_BRACE);
1951
1952 throw new NoSuchFolderException(msg.toString());
1953 }
1954 else {
1955 return list.get(0);
1956 }
1957 }
1958
1959
1973 public BookmarksFolder findByG_P_Last(long groupId, long parentFolderId,
1974 OrderByComparator orderByComparator)
1975 throws NoSuchFolderException, SystemException {
1976 int count = countByG_P(groupId, parentFolderId);
1977
1978 List<BookmarksFolder> list = findByG_P(groupId, parentFolderId,
1979 count - 1, count, orderByComparator);
1980
1981 if (list.isEmpty()) {
1982 StringBundler msg = new StringBundler(6);
1983
1984 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1985
1986 msg.append("groupId=");
1987 msg.append(groupId);
1988
1989 msg.append(", parentFolderId=");
1990 msg.append(parentFolderId);
1991
1992 msg.append(StringPool.CLOSE_CURLY_BRACE);
1993
1994 throw new NoSuchFolderException(msg.toString());
1995 }
1996 else {
1997 return list.get(0);
1998 }
1999 }
2000
2001
2016 public BookmarksFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
2017 long parentFolderId, OrderByComparator orderByComparator)
2018 throws NoSuchFolderException, SystemException {
2019 BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
2020
2021 Session session = null;
2022
2023 try {
2024 session = openSession();
2025
2026 BookmarksFolder[] array = new BookmarksFolderImpl[3];
2027
2028 array[0] = getByG_P_PrevAndNext(session, bookmarksFolder, groupId,
2029 parentFolderId, orderByComparator, true);
2030
2031 array[1] = bookmarksFolder;
2032
2033 array[2] = getByG_P_PrevAndNext(session, bookmarksFolder, groupId,
2034 parentFolderId, orderByComparator, false);
2035
2036 return array;
2037 }
2038 catch (Exception e) {
2039 throw processException(e);
2040 }
2041 finally {
2042 closeSession(session);
2043 }
2044 }
2045
2046 protected BookmarksFolder getByG_P_PrevAndNext(Session session,
2047 BookmarksFolder bookmarksFolder, long groupId, long parentFolderId,
2048 OrderByComparator orderByComparator, boolean previous) {
2049 StringBundler query = null;
2050
2051 if (orderByComparator != null) {
2052 query = new StringBundler(6 +
2053 (orderByComparator.getOrderByFields().length * 6));
2054 }
2055 else {
2056 query = new StringBundler(3);
2057 }
2058
2059 query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
2060
2061 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2062
2063 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2064
2065 if (orderByComparator != null) {
2066 String[] orderByFields = orderByComparator.getOrderByFields();
2067
2068 if (orderByFields.length > 0) {
2069 query.append(WHERE_AND);
2070 }
2071
2072 for (int i = 0; i < orderByFields.length; i++) {
2073 query.append(_ORDER_BY_ENTITY_ALIAS);
2074 query.append(orderByFields[i]);
2075
2076 if ((i + 1) < orderByFields.length) {
2077 if (orderByComparator.isAscending() ^ previous) {
2078 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2079 }
2080 else {
2081 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2082 }
2083 }
2084 else {
2085 if (orderByComparator.isAscending() ^ previous) {
2086 query.append(WHERE_GREATER_THAN);
2087 }
2088 else {
2089 query.append(WHERE_LESSER_THAN);
2090 }
2091 }
2092 }
2093
2094 query.append(ORDER_BY_CLAUSE);
2095
2096 for (int i = 0; i < orderByFields.length; i++) {
2097 query.append(_ORDER_BY_ENTITY_ALIAS);
2098 query.append(orderByFields[i]);
2099
2100 if ((i + 1) < orderByFields.length) {
2101 if (orderByComparator.isAscending() ^ previous) {
2102 query.append(ORDER_BY_ASC_HAS_NEXT);
2103 }
2104 else {
2105 query.append(ORDER_BY_DESC_HAS_NEXT);
2106 }
2107 }
2108 else {
2109 if (orderByComparator.isAscending() ^ previous) {
2110 query.append(ORDER_BY_ASC);
2111 }
2112 else {
2113 query.append(ORDER_BY_DESC);
2114 }
2115 }
2116 }
2117 }
2118
2119 else {
2120 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
2121 }
2122
2123 String sql = query.toString();
2124
2125 Query q = session.createQuery(sql);
2126
2127 q.setFirstResult(0);
2128 q.setMaxResults(2);
2129
2130 QueryPos qPos = QueryPos.getInstance(q);
2131
2132 qPos.add(groupId);
2133
2134 qPos.add(parentFolderId);
2135
2136 if (orderByComparator != null) {
2137 Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
2138
2139 for (Object value : values) {
2140 qPos.add(value);
2141 }
2142 }
2143
2144 List<BookmarksFolder> list = q.list();
2145
2146 if (list.size() == 2) {
2147 return list.get(1);
2148 }
2149 else {
2150 return null;
2151 }
2152 }
2153
2154
2162 public List<BookmarksFolder> filterFindByG_P(long groupId,
2163 long parentFolderId) throws SystemException {
2164 return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
2165 QueryUtil.ALL_POS, null);
2166 }
2167
2168
2182 public List<BookmarksFolder> filterFindByG_P(long groupId,
2183 long parentFolderId, int start, int end) throws SystemException {
2184 return filterFindByG_P(groupId, parentFolderId, start, end, null);
2185 }
2186
2187
2202 public List<BookmarksFolder> filterFindByG_P(long groupId,
2203 long parentFolderId, int start, int end,
2204 OrderByComparator orderByComparator) throws SystemException {
2205 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2206 return findByG_P(groupId, parentFolderId, start, end,
2207 orderByComparator);
2208 }
2209
2210 Session session = null;
2211
2212 try {
2213 session = openSession();
2214
2215 StringBundler query = null;
2216
2217 if (orderByComparator != null) {
2218 query = new StringBundler(4 +
2219 (orderByComparator.getOrderByFields().length * 3));
2220 }
2221 else {
2222 query = new StringBundler(4);
2223 }
2224
2225 query.append(_FILTER_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
2226
2227 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2228
2229 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2230
2231 if (orderByComparator != null) {
2232 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2233 orderByComparator);
2234 }
2235
2236 else {
2237 query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
2238 }
2239
2240 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2241 BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
2242 _FILTER_COLUMN_USERID, groupId);
2243
2244 SQLQuery q = session.createSQLQuery(sql);
2245
2246 q.addEntity(_FILTER_ENTITY_ALIAS, BookmarksFolderImpl.class);
2247
2248 QueryPos qPos = QueryPos.getInstance(q);
2249
2250 qPos.add(groupId);
2251
2252 qPos.add(parentFolderId);
2253
2254 return (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
2255 start, end);
2256 }
2257 catch (Exception e) {
2258 throw processException(e);
2259 }
2260 finally {
2261 closeSession(session);
2262 }
2263 }
2264
2265
2271 public List<BookmarksFolder> findAll() throws SystemException {
2272 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2273 }
2274
2275
2287 public List<BookmarksFolder> findAll(int start, int end)
2288 throws SystemException {
2289 return findAll(start, end, null);
2290 }
2291
2292
2305 public List<BookmarksFolder> findAll(int start, int end,
2306 OrderByComparator orderByComparator) throws SystemException {
2307 Object[] finderArgs = new Object[] {
2308 String.valueOf(start), String.valueOf(end),
2309 String.valueOf(orderByComparator)
2310 };
2311
2312 List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2313 finderArgs, this);
2314
2315 if (list == null) {
2316 Session session = null;
2317
2318 try {
2319 session = openSession();
2320
2321 StringBundler query = null;
2322 String sql = null;
2323
2324 if (orderByComparator != null) {
2325 query = new StringBundler(2 +
2326 (orderByComparator.getOrderByFields().length * 3));
2327
2328 query.append(_SQL_SELECT_BOOKMARKSFOLDER);
2329
2330 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2331 orderByComparator);
2332
2333 sql = query.toString();
2334 }
2335 else {
2336 sql = _SQL_SELECT_BOOKMARKSFOLDER.concat(BookmarksFolderModelImpl.ORDER_BY_JPQL);
2337 }
2338
2339 Query q = session.createQuery(sql);
2340
2341 if (orderByComparator == null) {
2342 list = (List<BookmarksFolder>)QueryUtil.list(q,
2343 getDialect(), start, end, false);
2344
2345 Collections.sort(list);
2346 }
2347 else {
2348 list = (List<BookmarksFolder>)QueryUtil.list(q,
2349 getDialect(), start, end);
2350 }
2351 }
2352 catch (Exception e) {
2353 throw processException(e);
2354 }
2355 finally {
2356 if (list == null) {
2357 list = new ArrayList<BookmarksFolder>();
2358 }
2359
2360 cacheResult(list);
2361
2362 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2363
2364 closeSession(session);
2365 }
2366 }
2367
2368 return list;
2369 }
2370
2371
2377 public void removeByUuid(String uuid) throws SystemException {
2378 for (BookmarksFolder bookmarksFolder : findByUuid(uuid)) {
2379 remove(bookmarksFolder);
2380 }
2381 }
2382
2383
2390 public void removeByUUID_G(String uuid, long groupId)
2391 throws NoSuchFolderException, SystemException {
2392 BookmarksFolder bookmarksFolder = findByUUID_G(uuid, groupId);
2393
2394 remove(bookmarksFolder);
2395 }
2396
2397
2403 public void removeByGroupId(long groupId) throws SystemException {
2404 for (BookmarksFolder bookmarksFolder : findByGroupId(groupId)) {
2405 remove(bookmarksFolder);
2406 }
2407 }
2408
2409
2415 public void removeByCompanyId(long companyId) throws SystemException {
2416 for (BookmarksFolder bookmarksFolder : findByCompanyId(companyId)) {
2417 remove(bookmarksFolder);
2418 }
2419 }
2420
2421
2428 public void removeByG_P(long groupId, long parentFolderId)
2429 throws SystemException {
2430 for (BookmarksFolder bookmarksFolder : findByG_P(groupId, parentFolderId)) {
2431 remove(bookmarksFolder);
2432 }
2433 }
2434
2435
2440 public void removeAll() throws SystemException {
2441 for (BookmarksFolder bookmarksFolder : findAll()) {
2442 remove(bookmarksFolder);
2443 }
2444 }
2445
2446
2453 public int countByUuid(String uuid) throws SystemException {
2454 Object[] finderArgs = new Object[] { uuid };
2455
2456 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2457 finderArgs, this);
2458
2459 if (count == null) {
2460 Session session = null;
2461
2462 try {
2463 session = openSession();
2464
2465 StringBundler query = new StringBundler(2);
2466
2467 query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2468
2469 if (uuid == null) {
2470 query.append(_FINDER_COLUMN_UUID_UUID_1);
2471 }
2472 else {
2473 if (uuid.equals(StringPool.BLANK)) {
2474 query.append(_FINDER_COLUMN_UUID_UUID_3);
2475 }
2476 else {
2477 query.append(_FINDER_COLUMN_UUID_UUID_2);
2478 }
2479 }
2480
2481 String sql = query.toString();
2482
2483 Query q = session.createQuery(sql);
2484
2485 QueryPos qPos = QueryPos.getInstance(q);
2486
2487 if (uuid != null) {
2488 qPos.add(uuid);
2489 }
2490
2491 count = (Long)q.uniqueResult();
2492 }
2493 catch (Exception e) {
2494 throw processException(e);
2495 }
2496 finally {
2497 if (count == null) {
2498 count = Long.valueOf(0);
2499 }
2500
2501 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2502 finderArgs, count);
2503
2504 closeSession(session);
2505 }
2506 }
2507
2508 return count.intValue();
2509 }
2510
2511
2519 public int countByUUID_G(String uuid, long groupId)
2520 throws SystemException {
2521 Object[] finderArgs = new Object[] { uuid, groupId };
2522
2523 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2524 finderArgs, this);
2525
2526 if (count == null) {
2527 Session session = null;
2528
2529 try {
2530 session = openSession();
2531
2532 StringBundler query = new StringBundler(3);
2533
2534 query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2535
2536 if (uuid == null) {
2537 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2538 }
2539 else {
2540 if (uuid.equals(StringPool.BLANK)) {
2541 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2542 }
2543 else {
2544 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2545 }
2546 }
2547
2548 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2549
2550 String sql = query.toString();
2551
2552 Query q = session.createQuery(sql);
2553
2554 QueryPos qPos = QueryPos.getInstance(q);
2555
2556 if (uuid != null) {
2557 qPos.add(uuid);
2558 }
2559
2560 qPos.add(groupId);
2561
2562 count = (Long)q.uniqueResult();
2563 }
2564 catch (Exception e) {
2565 throw processException(e);
2566 }
2567 finally {
2568 if (count == null) {
2569 count = Long.valueOf(0);
2570 }
2571
2572 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2573 finderArgs, count);
2574
2575 closeSession(session);
2576 }
2577 }
2578
2579 return count.intValue();
2580 }
2581
2582
2589 public int countByGroupId(long groupId) throws SystemException {
2590 Object[] finderArgs = new Object[] { groupId };
2591
2592 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2593 finderArgs, this);
2594
2595 if (count == null) {
2596 Session session = null;
2597
2598 try {
2599 session = openSession();
2600
2601 StringBundler query = new StringBundler(2);
2602
2603 query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2604
2605 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2606
2607 String sql = query.toString();
2608
2609 Query q = session.createQuery(sql);
2610
2611 QueryPos qPos = QueryPos.getInstance(q);
2612
2613 qPos.add(groupId);
2614
2615 count = (Long)q.uniqueResult();
2616 }
2617 catch (Exception e) {
2618 throw processException(e);
2619 }
2620 finally {
2621 if (count == null) {
2622 count = Long.valueOf(0);
2623 }
2624
2625 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2626 finderArgs, count);
2627
2628 closeSession(session);
2629 }
2630 }
2631
2632 return count.intValue();
2633 }
2634
2635
2642 public int filterCountByGroupId(long groupId) throws SystemException {
2643 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2644 return countByGroupId(groupId);
2645 }
2646
2647 Session session = null;
2648
2649 try {
2650 session = openSession();
2651
2652 StringBundler query = new StringBundler(2);
2653
2654 query.append(_FILTER_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2655
2656 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2657
2658 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2659 BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
2660 _FILTER_COLUMN_USERID, groupId);
2661
2662 SQLQuery q = session.createSQLQuery(sql);
2663
2664 q.addScalar(COUNT_COLUMN_NAME,
2665 com.liferay.portal.kernel.dao.orm.Type.LONG);
2666
2667 QueryPos qPos = QueryPos.getInstance(q);
2668
2669 qPos.add(groupId);
2670
2671 Long count = (Long)q.uniqueResult();
2672
2673 return count.intValue();
2674 }
2675 catch (Exception e) {
2676 throw processException(e);
2677 }
2678 finally {
2679 closeSession(session);
2680 }
2681 }
2682
2683
2690 public int countByCompanyId(long companyId) throws SystemException {
2691 Object[] finderArgs = new Object[] { companyId };
2692
2693 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2694 finderArgs, this);
2695
2696 if (count == null) {
2697 Session session = null;
2698
2699 try {
2700 session = openSession();
2701
2702 StringBundler query = new StringBundler(2);
2703
2704 query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2705
2706 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2707
2708 String sql = query.toString();
2709
2710 Query q = session.createQuery(sql);
2711
2712 QueryPos qPos = QueryPos.getInstance(q);
2713
2714 qPos.add(companyId);
2715
2716 count = (Long)q.uniqueResult();
2717 }
2718 catch (Exception e) {
2719 throw processException(e);
2720 }
2721 finally {
2722 if (count == null) {
2723 count = Long.valueOf(0);
2724 }
2725
2726 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2727 finderArgs, count);
2728
2729 closeSession(session);
2730 }
2731 }
2732
2733 return count.intValue();
2734 }
2735
2736
2744 public int countByG_P(long groupId, long parentFolderId)
2745 throws SystemException {
2746 Object[] finderArgs = new Object[] { groupId, parentFolderId };
2747
2748 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
2749 finderArgs, this);
2750
2751 if (count == null) {
2752 Session session = null;
2753
2754 try {
2755 session = openSession();
2756
2757 StringBundler query = new StringBundler(3);
2758
2759 query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2760
2761 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2762
2763 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2764
2765 String sql = query.toString();
2766
2767 Query q = session.createQuery(sql);
2768
2769 QueryPos qPos = QueryPos.getInstance(q);
2770
2771 qPos.add(groupId);
2772
2773 qPos.add(parentFolderId);
2774
2775 count = (Long)q.uniqueResult();
2776 }
2777 catch (Exception e) {
2778 throw processException(e);
2779 }
2780 finally {
2781 if (count == null) {
2782 count = Long.valueOf(0);
2783 }
2784
2785 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
2786 count);
2787
2788 closeSession(session);
2789 }
2790 }
2791
2792 return count.intValue();
2793 }
2794
2795
2803 public int filterCountByG_P(long groupId, long parentFolderId)
2804 throws SystemException {
2805 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2806 return countByG_P(groupId, parentFolderId);
2807 }
2808
2809 Session session = null;
2810
2811 try {
2812 session = openSession();
2813
2814 StringBundler query = new StringBundler(3);
2815
2816 query.append(_FILTER_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2817
2818 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2819
2820 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2821
2822 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2823 BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
2824 _FILTER_COLUMN_USERID, groupId);
2825
2826 SQLQuery q = session.createSQLQuery(sql);
2827
2828 q.addScalar(COUNT_COLUMN_NAME,
2829 com.liferay.portal.kernel.dao.orm.Type.LONG);
2830
2831 QueryPos qPos = QueryPos.getInstance(q);
2832
2833 qPos.add(groupId);
2834
2835 qPos.add(parentFolderId);
2836
2837 Long count = (Long)q.uniqueResult();
2838
2839 return count.intValue();
2840 }
2841 catch (Exception e) {
2842 throw processException(e);
2843 }
2844 finally {
2845 closeSession(session);
2846 }
2847 }
2848
2849
2855 public int countAll() throws SystemException {
2856 Object[] finderArgs = new Object[0];
2857
2858 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2859 finderArgs, this);
2860
2861 if (count == null) {
2862 Session session = null;
2863
2864 try {
2865 session = openSession();
2866
2867 Query q = session.createQuery(_SQL_COUNT_BOOKMARKSFOLDER);
2868
2869 count = (Long)q.uniqueResult();
2870 }
2871 catch (Exception e) {
2872 throw processException(e);
2873 }
2874 finally {
2875 if (count == null) {
2876 count = Long.valueOf(0);
2877 }
2878
2879 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2880 count);
2881
2882 closeSession(session);
2883 }
2884 }
2885
2886 return count.intValue();
2887 }
2888
2889
2892 public void afterPropertiesSet() {
2893 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2894 com.liferay.portal.util.PropsUtil.get(
2895 "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksFolder")));
2896
2897 if (listenerClassNames.length > 0) {
2898 try {
2899 List<ModelListener<BookmarksFolder>> listenersList = new ArrayList<ModelListener<BookmarksFolder>>();
2900
2901 for (String listenerClassName : listenerClassNames) {
2902 listenersList.add((ModelListener<BookmarksFolder>)InstanceFactory.newInstance(
2903 listenerClassName));
2904 }
2905
2906 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2907 }
2908 catch (Exception e) {
2909 _log.error(e);
2910 }
2911 }
2912 }
2913
2914 @BeanReference(type = BookmarksEntryPersistence.class)
2915 protected BookmarksEntryPersistence bookmarksEntryPersistence;
2916 @BeanReference(type = BookmarksFolderPersistence.class)
2917 protected BookmarksFolderPersistence bookmarksFolderPersistence;
2918 @BeanReference(type = GroupPersistence.class)
2919 protected GroupPersistence groupPersistence;
2920 @BeanReference(type = ResourcePersistence.class)
2921 protected ResourcePersistence resourcePersistence;
2922 @BeanReference(type = UserPersistence.class)
2923 protected UserPersistence userPersistence;
2924 @BeanReference(type = ExpandoValuePersistence.class)
2925 protected ExpandoValuePersistence expandoValuePersistence;
2926 private static final String _SQL_SELECT_BOOKMARKSFOLDER = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder";
2927 private static final String _SQL_SELECT_BOOKMARKSFOLDER_WHERE = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder WHERE ";
2928 private static final String _SQL_COUNT_BOOKMARKSFOLDER = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder";
2929 private static final String _SQL_COUNT_BOOKMARKSFOLDER_WHERE = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder WHERE ";
2930 private static final String _FINDER_COLUMN_UUID_UUID_1 = "bookmarksFolder.uuid IS NULL";
2931 private static final String _FINDER_COLUMN_UUID_UUID_2 = "bookmarksFolder.uuid = ?";
2932 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(bookmarksFolder.uuid IS NULL OR bookmarksFolder.uuid = ?)";
2933 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "bookmarksFolder.uuid IS NULL AND ";
2934 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "bookmarksFolder.uuid = ? AND ";
2935 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(bookmarksFolder.uuid IS NULL OR bookmarksFolder.uuid = ?) AND ";
2936 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "bookmarksFolder.groupId = ?";
2937 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "bookmarksFolder.groupId = ?";
2938 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "bookmarksFolder.companyId = ?";
2939 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "bookmarksFolder.groupId = ? AND ";
2940 private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "bookmarksFolder.parentFolderId = ?";
2941 private static final String _FILTER_SQL_SELECT_BOOKMARKSFOLDER_WHERE = "SELECT DISTINCT {bookmarksFolder.*} FROM BookmarksFolder bookmarksFolder WHERE ";
2942 private static final String _FILTER_SQL_COUNT_BOOKMARKSFOLDER_WHERE = "SELECT COUNT(DISTINCT bookmarksFolder.folderId) AS COUNT_VALUE FROM BookmarksFolder bookmarksFolder WHERE ";
2943 private static final String _FILTER_COLUMN_PK = "bookmarksFolder.folderId";
2944 private static final String _FILTER_COLUMN_USERID = "bookmarksFolder.userId";
2945 private static final String _FILTER_ENTITY_ALIAS = "bookmarksFolder";
2946 private static final String _ORDER_BY_ENTITY_ALIAS = "bookmarksFolder.";
2947 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BookmarksFolder exists with the primary key ";
2948 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BookmarksFolder exists with the key {";
2949 private static Log _log = LogFactoryUtil.getLog(BookmarksFolderPersistenceImpl.class);
2950 }