001
014
015 package com.liferay.portlet.imagegallery.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.ImagePersistence;
044 import com.liferay.portal.service.persistence.LayoutPersistence;
045 import com.liferay.portal.service.persistence.ResourcePersistence;
046 import com.liferay.portal.service.persistence.UserPersistence;
047 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048
049 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
050 import com.liferay.portlet.imagegallery.NoSuchFolderException;
051 import com.liferay.portlet.imagegallery.model.IGFolder;
052 import com.liferay.portlet.imagegallery.model.impl.IGFolderImpl;
053 import com.liferay.portlet.imagegallery.model.impl.IGFolderModelImpl;
054
055 import java.io.Serializable;
056
057 import java.util.ArrayList;
058 import java.util.Collections;
059 import java.util.List;
060
061
077 public class IGFolderPersistenceImpl extends BasePersistenceImpl<IGFolder>
078 implements IGFolderPersistence {
079 public static final String FINDER_CLASS_NAME_ENTITY = IGFolderImpl.class.getName();
080 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
081 ".List";
082 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
083 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084 "findByUuid",
085 new String[] {
086 String.class.getName(),
087
088 "java.lang.Integer", "java.lang.Integer",
089 "com.liferay.portal.kernel.util.OrderByComparator"
090 });
091 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
092 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093 "countByUuid", new String[] { String.class.getName() });
094 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
095 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
096 "fetchByUUID_G",
097 new String[] { String.class.getName(), Long.class.getName() });
098 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
099 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100 "countByUUID_G",
101 new String[] { String.class.getName(), Long.class.getName() });
102 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
103 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "findByGroupId",
105 new String[] {
106 Long.class.getName(),
107
108 "java.lang.Integer", "java.lang.Integer",
109 "com.liferay.portal.kernel.util.OrderByComparator"
110 });
111 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
112 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113 "countByGroupId", new String[] { Long.class.getName() });
114 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
115 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116 "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(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
124 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
125 "countByCompanyId", new String[] { Long.class.getName() });
126 public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
127 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128 "findByG_P",
129 new String[] {
130 Long.class.getName(), Long.class.getName(),
131
132 "java.lang.Integer", "java.lang.Integer",
133 "com.liferay.portal.kernel.util.OrderByComparator"
134 });
135 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
136 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137 "countByG_P",
138 new String[] { Long.class.getName(), Long.class.getName() });
139 public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
140 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
141 "fetchByG_P_N",
142 new String[] {
143 Long.class.getName(), Long.class.getName(),
144 String.class.getName()
145 });
146 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
147 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
148 "countByG_P_N",
149 new String[] {
150 Long.class.getName(), Long.class.getName(),
151 String.class.getName()
152 });
153 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
154 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
155 "findAll", new String[0]);
156 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
157 IGFolderModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
158 "countAll", new String[0]);
159
160
165 public void cacheResult(IGFolder igFolder) {
166 EntityCacheUtil.putResult(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
167 IGFolderImpl.class, igFolder.getPrimaryKey(), igFolder);
168
169 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
170 new Object[] { igFolder.getUuid(), new Long(igFolder.getGroupId()) },
171 igFolder);
172
173 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
174 new Object[] {
175 new Long(igFolder.getGroupId()),
176 new Long(igFolder.getParentFolderId()),
177
178 igFolder.getName()
179 }, igFolder);
180 }
181
182
187 public void cacheResult(List<IGFolder> igFolders) {
188 for (IGFolder igFolder : igFolders) {
189 if (EntityCacheUtil.getResult(
190 IGFolderModelImpl.ENTITY_CACHE_ENABLED,
191 IGFolderImpl.class, igFolder.getPrimaryKey(), this) == null) {
192 cacheResult(igFolder);
193 }
194 }
195 }
196
197
204 public void clearCache() {
205 CacheRegistryUtil.clear(IGFolderImpl.class.getName());
206 EntityCacheUtil.clearCache(IGFolderImpl.class.getName());
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
209 }
210
211
218 public void clearCache(IGFolder igFolder) {
219 EntityCacheUtil.removeResult(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
220 IGFolderImpl.class, igFolder.getPrimaryKey());
221
222 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
223 new Object[] { igFolder.getUuid(), new Long(igFolder.getGroupId()) });
224
225 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
226 new Object[] {
227 new Long(igFolder.getGroupId()),
228 new Long(igFolder.getParentFolderId()),
229
230 igFolder.getName()
231 });
232 }
233
234
240 public IGFolder create(long folderId) {
241 IGFolder igFolder = new IGFolderImpl();
242
243 igFolder.setNew(true);
244 igFolder.setPrimaryKey(folderId);
245
246 String uuid = PortalUUIDUtil.generate();
247
248 igFolder.setUuid(uuid);
249
250 return igFolder;
251 }
252
253
261 public IGFolder remove(Serializable primaryKey)
262 throws NoSuchModelException, SystemException {
263 return remove(((Long)primaryKey).longValue());
264 }
265
266
274 public IGFolder remove(long folderId)
275 throws NoSuchFolderException, SystemException {
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 IGFolder igFolder = (IGFolder)session.get(IGFolderImpl.class,
282 new Long(folderId));
283
284 if (igFolder == null) {
285 if (_log.isWarnEnabled()) {
286 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
287 }
288
289 throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
290 folderId);
291 }
292
293 return remove(igFolder);
294 }
295 catch (NoSuchFolderException nsee) {
296 throw nsee;
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304 }
305
306 protected IGFolder removeImpl(IGFolder igFolder) throws SystemException {
307 igFolder = toUnwrappedModel(igFolder);
308
309 Session session = null;
310
311 try {
312 session = openSession();
313
314 if (igFolder.isCachedModel() || BatchSessionUtil.isEnabled()) {
315 Object staleObject = session.get(IGFolderImpl.class,
316 igFolder.getPrimaryKeyObj());
317
318 if (staleObject != null) {
319 session.evict(staleObject);
320 }
321 }
322
323 session.delete(igFolder);
324
325 session.flush();
326 }
327 catch (Exception e) {
328 throw processException(e);
329 }
330 finally {
331 closeSession(session);
332 }
333
334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
335
336 IGFolderModelImpl igFolderModelImpl = (IGFolderModelImpl)igFolder;
337
338 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
339 new Object[] {
340 igFolderModelImpl.getOriginalUuid(),
341 new Long(igFolderModelImpl.getOriginalGroupId())
342 });
343
344 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
345 new Object[] {
346 new Long(igFolderModelImpl.getOriginalGroupId()),
347 new Long(igFolderModelImpl.getOriginalParentFolderId()),
348
349 igFolderModelImpl.getOriginalName()
350 });
351
352 EntityCacheUtil.removeResult(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
353 IGFolderImpl.class, igFolder.getPrimaryKey());
354
355 return igFolder;
356 }
357
358 public IGFolder updateImpl(
359 com.liferay.portlet.imagegallery.model.IGFolder igFolder, boolean merge)
360 throws SystemException {
361 igFolder = toUnwrappedModel(igFolder);
362
363 boolean isNew = igFolder.isNew();
364
365 IGFolderModelImpl igFolderModelImpl = (IGFolderModelImpl)igFolder;
366
367 if (Validator.isNull(igFolder.getUuid())) {
368 String uuid = PortalUUIDUtil.generate();
369
370 igFolder.setUuid(uuid);
371 }
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 BatchSessionUtil.update(session, igFolder, merge);
379
380 igFolder.setNew(false);
381 }
382 catch (Exception e) {
383 throw processException(e);
384 }
385 finally {
386 closeSession(session);
387 }
388
389 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
390
391 EntityCacheUtil.putResult(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
392 IGFolderImpl.class, igFolder.getPrimaryKey(), igFolder);
393
394 if (!isNew &&
395 (!Validator.equals(igFolder.getUuid(),
396 igFolderModelImpl.getOriginalUuid()) ||
397 (igFolder.getGroupId() != igFolderModelImpl.getOriginalGroupId()))) {
398 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
399 new Object[] {
400 igFolderModelImpl.getOriginalUuid(),
401 new Long(igFolderModelImpl.getOriginalGroupId())
402 });
403 }
404
405 if (isNew ||
406 (!Validator.equals(igFolder.getUuid(),
407 igFolderModelImpl.getOriginalUuid()) ||
408 (igFolder.getGroupId() != igFolderModelImpl.getOriginalGroupId()))) {
409 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
410 new Object[] { igFolder.getUuid(), new Long(
411 igFolder.getGroupId()) }, igFolder);
412 }
413
414 if (!isNew &&
415 ((igFolder.getGroupId() != igFolderModelImpl.getOriginalGroupId()) ||
416 (igFolder.getParentFolderId() != igFolderModelImpl.getOriginalParentFolderId()) ||
417 !Validator.equals(igFolder.getName(),
418 igFolderModelImpl.getOriginalName()))) {
419 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
420 new Object[] {
421 new Long(igFolderModelImpl.getOriginalGroupId()),
422 new Long(igFolderModelImpl.getOriginalParentFolderId()),
423
424 igFolderModelImpl.getOriginalName()
425 });
426 }
427
428 if (isNew ||
429 ((igFolder.getGroupId() != igFolderModelImpl.getOriginalGroupId()) ||
430 (igFolder.getParentFolderId() != igFolderModelImpl.getOriginalParentFolderId()) ||
431 !Validator.equals(igFolder.getName(),
432 igFolderModelImpl.getOriginalName()))) {
433 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
434 new Object[] {
435 new Long(igFolder.getGroupId()),
436 new Long(igFolder.getParentFolderId()),
437
438 igFolder.getName()
439 }, igFolder);
440 }
441
442 return igFolder;
443 }
444
445 protected IGFolder toUnwrappedModel(IGFolder igFolder) {
446 if (igFolder instanceof IGFolderImpl) {
447 return igFolder;
448 }
449
450 IGFolderImpl igFolderImpl = new IGFolderImpl();
451
452 igFolderImpl.setNew(igFolder.isNew());
453 igFolderImpl.setPrimaryKey(igFolder.getPrimaryKey());
454
455 igFolderImpl.setUuid(igFolder.getUuid());
456 igFolderImpl.setFolderId(igFolder.getFolderId());
457 igFolderImpl.setGroupId(igFolder.getGroupId());
458 igFolderImpl.setCompanyId(igFolder.getCompanyId());
459 igFolderImpl.setUserId(igFolder.getUserId());
460 igFolderImpl.setCreateDate(igFolder.getCreateDate());
461 igFolderImpl.setModifiedDate(igFolder.getModifiedDate());
462 igFolderImpl.setParentFolderId(igFolder.getParentFolderId());
463 igFolderImpl.setName(igFolder.getName());
464 igFolderImpl.setDescription(igFolder.getDescription());
465
466 return igFolderImpl;
467 }
468
469
477 public IGFolder findByPrimaryKey(Serializable primaryKey)
478 throws NoSuchModelException, SystemException {
479 return findByPrimaryKey(((Long)primaryKey).longValue());
480 }
481
482
490 public IGFolder findByPrimaryKey(long folderId)
491 throws NoSuchFolderException, SystemException {
492 IGFolder igFolder = fetchByPrimaryKey(folderId);
493
494 if (igFolder == null) {
495 if (_log.isWarnEnabled()) {
496 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
497 }
498
499 throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
500 folderId);
501 }
502
503 return igFolder;
504 }
505
506
513 public IGFolder fetchByPrimaryKey(Serializable primaryKey)
514 throws SystemException {
515 return fetchByPrimaryKey(((Long)primaryKey).longValue());
516 }
517
518
525 public IGFolder fetchByPrimaryKey(long folderId) throws SystemException {
526 IGFolder igFolder = (IGFolder)EntityCacheUtil.getResult(IGFolderModelImpl.ENTITY_CACHE_ENABLED,
527 IGFolderImpl.class, folderId, this);
528
529 if (igFolder == null) {
530 Session session = null;
531
532 try {
533 session = openSession();
534
535 igFolder = (IGFolder)session.get(IGFolderImpl.class,
536 new Long(folderId));
537 }
538 catch (Exception e) {
539 throw processException(e);
540 }
541 finally {
542 if (igFolder != null) {
543 cacheResult(igFolder);
544 }
545
546 closeSession(session);
547 }
548 }
549
550 return igFolder;
551 }
552
553
560 public List<IGFolder> findByUuid(String uuid) throws SystemException {
561 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
562 }
563
564
577 public List<IGFolder> findByUuid(String uuid, int start, int end)
578 throws SystemException {
579 return findByUuid(uuid, start, end, null);
580 }
581
582
596 public List<IGFolder> findByUuid(String uuid, int start, int end,
597 OrderByComparator orderByComparator) throws SystemException {
598 Object[] finderArgs = new Object[] {
599 uuid,
600
601 String.valueOf(start), String.valueOf(end),
602 String.valueOf(orderByComparator)
603 };
604
605 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
606 finderArgs, this);
607
608 if (list == null) {
609 Session session = null;
610
611 try {
612 session = openSession();
613
614 StringBundler query = null;
615
616 if (orderByComparator != null) {
617 query = new StringBundler(3 +
618 (orderByComparator.getOrderByFields().length * 3));
619 }
620 else {
621 query = new StringBundler(3);
622 }
623
624 query.append(_SQL_SELECT_IGFOLDER_WHERE);
625
626 if (uuid == null) {
627 query.append(_FINDER_COLUMN_UUID_UUID_1);
628 }
629 else {
630 if (uuid.equals(StringPool.BLANK)) {
631 query.append(_FINDER_COLUMN_UUID_UUID_3);
632 }
633 else {
634 query.append(_FINDER_COLUMN_UUID_UUID_2);
635 }
636 }
637
638 if (orderByComparator != null) {
639 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
640 orderByComparator);
641 }
642
643 else {
644 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
645 }
646
647 String sql = query.toString();
648
649 Query q = session.createQuery(sql);
650
651 QueryPos qPos = QueryPos.getInstance(q);
652
653 if (uuid != null) {
654 qPos.add(uuid);
655 }
656
657 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
658 end);
659 }
660 catch (Exception e) {
661 throw processException(e);
662 }
663 finally {
664 if (list == null) {
665 list = new ArrayList<IGFolder>();
666 }
667
668 cacheResult(list);
669
670 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
671 list);
672
673 closeSession(session);
674 }
675 }
676
677 return list;
678 }
679
680
693 public IGFolder findByUuid_First(String uuid,
694 OrderByComparator orderByComparator)
695 throws NoSuchFolderException, SystemException {
696 List<IGFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
697
698 if (list.isEmpty()) {
699 StringBundler msg = new StringBundler(4);
700
701 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
702
703 msg.append("uuid=");
704 msg.append(uuid);
705
706 msg.append(StringPool.CLOSE_CURLY_BRACE);
707
708 throw new NoSuchFolderException(msg.toString());
709 }
710 else {
711 return list.get(0);
712 }
713 }
714
715
728 public IGFolder findByUuid_Last(String uuid,
729 OrderByComparator orderByComparator)
730 throws NoSuchFolderException, SystemException {
731 int count = countByUuid(uuid);
732
733 List<IGFolder> list = findByUuid(uuid, count - 1, count,
734 orderByComparator);
735
736 if (list.isEmpty()) {
737 StringBundler msg = new StringBundler(4);
738
739 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
740
741 msg.append("uuid=");
742 msg.append(uuid);
743
744 msg.append(StringPool.CLOSE_CURLY_BRACE);
745
746 throw new NoSuchFolderException(msg.toString());
747 }
748 else {
749 return list.get(0);
750 }
751 }
752
753
767 public IGFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
768 OrderByComparator orderByComparator)
769 throws NoSuchFolderException, SystemException {
770 IGFolder igFolder = findByPrimaryKey(folderId);
771
772 Session session = null;
773
774 try {
775 session = openSession();
776
777 IGFolder[] array = new IGFolderImpl[3];
778
779 array[0] = getByUuid_PrevAndNext(session, igFolder, uuid,
780 orderByComparator, true);
781
782 array[1] = igFolder;
783
784 array[2] = getByUuid_PrevAndNext(session, igFolder, uuid,
785 orderByComparator, false);
786
787 return array;
788 }
789 catch (Exception e) {
790 throw processException(e);
791 }
792 finally {
793 closeSession(session);
794 }
795 }
796
797 protected IGFolder getByUuid_PrevAndNext(Session session,
798 IGFolder igFolder, String uuid, OrderByComparator orderByComparator,
799 boolean previous) {
800 StringBundler query = null;
801
802 if (orderByComparator != null) {
803 query = new StringBundler(6 +
804 (orderByComparator.getOrderByFields().length * 6));
805 }
806 else {
807 query = new StringBundler(3);
808 }
809
810 query.append(_SQL_SELECT_IGFOLDER_WHERE);
811
812 if (uuid == null) {
813 query.append(_FINDER_COLUMN_UUID_UUID_1);
814 }
815 else {
816 if (uuid.equals(StringPool.BLANK)) {
817 query.append(_FINDER_COLUMN_UUID_UUID_3);
818 }
819 else {
820 query.append(_FINDER_COLUMN_UUID_UUID_2);
821 }
822 }
823
824 if (orderByComparator != null) {
825 String[] orderByFields = orderByComparator.getOrderByFields();
826
827 if (orderByFields.length > 0) {
828 query.append(WHERE_AND);
829 }
830
831 for (int i = 0; i < orderByFields.length; i++) {
832 query.append(_ORDER_BY_ENTITY_ALIAS);
833 query.append(orderByFields[i]);
834
835 if ((i + 1) < orderByFields.length) {
836 if (orderByComparator.isAscending() ^ previous) {
837 query.append(WHERE_GREATER_THAN_HAS_NEXT);
838 }
839 else {
840 query.append(WHERE_LESSER_THAN_HAS_NEXT);
841 }
842 }
843 else {
844 if (orderByComparator.isAscending() ^ previous) {
845 query.append(WHERE_GREATER_THAN);
846 }
847 else {
848 query.append(WHERE_LESSER_THAN);
849 }
850 }
851 }
852
853 query.append(ORDER_BY_CLAUSE);
854
855 for (int i = 0; i < orderByFields.length; i++) {
856 query.append(_ORDER_BY_ENTITY_ALIAS);
857 query.append(orderByFields[i]);
858
859 if ((i + 1) < orderByFields.length) {
860 if (orderByComparator.isAscending() ^ previous) {
861 query.append(ORDER_BY_ASC_HAS_NEXT);
862 }
863 else {
864 query.append(ORDER_BY_DESC_HAS_NEXT);
865 }
866 }
867 else {
868 if (orderByComparator.isAscending() ^ previous) {
869 query.append(ORDER_BY_ASC);
870 }
871 else {
872 query.append(ORDER_BY_DESC);
873 }
874 }
875 }
876 }
877
878 else {
879 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
880 }
881
882 String sql = query.toString();
883
884 Query q = session.createQuery(sql);
885
886 q.setFirstResult(0);
887 q.setMaxResults(2);
888
889 QueryPos qPos = QueryPos.getInstance(q);
890
891 if (uuid != null) {
892 qPos.add(uuid);
893 }
894
895 if (orderByComparator != null) {
896 Object[] values = orderByComparator.getOrderByValues(igFolder);
897
898 for (Object value : values) {
899 qPos.add(value);
900 }
901 }
902
903 List<IGFolder> list = q.list();
904
905 if (list.size() == 2) {
906 return list.get(1);
907 }
908 else {
909 return null;
910 }
911 }
912
913
922 public IGFolder findByUUID_G(String uuid, long groupId)
923 throws NoSuchFolderException, SystemException {
924 IGFolder igFolder = fetchByUUID_G(uuid, groupId);
925
926 if (igFolder == null) {
927 StringBundler msg = new StringBundler(6);
928
929 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
930
931 msg.append("uuid=");
932 msg.append(uuid);
933
934 msg.append(", groupId=");
935 msg.append(groupId);
936
937 msg.append(StringPool.CLOSE_CURLY_BRACE);
938
939 if (_log.isWarnEnabled()) {
940 _log.warn(msg.toString());
941 }
942
943 throw new NoSuchFolderException(msg.toString());
944 }
945
946 return igFolder;
947 }
948
949
957 public IGFolder fetchByUUID_G(String uuid, long groupId)
958 throws SystemException {
959 return fetchByUUID_G(uuid, groupId, true);
960 }
961
962
970 public IGFolder fetchByUUID_G(String uuid, long groupId,
971 boolean retrieveFromCache) throws SystemException {
972 Object[] finderArgs = new Object[] { uuid, groupId };
973
974 Object result = null;
975
976 if (retrieveFromCache) {
977 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
978 finderArgs, this);
979 }
980
981 if (result == null) {
982 Session session = null;
983
984 try {
985 session = openSession();
986
987 StringBundler query = new StringBundler(4);
988
989 query.append(_SQL_SELECT_IGFOLDER_WHERE);
990
991 if (uuid == null) {
992 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
993 }
994 else {
995 if (uuid.equals(StringPool.BLANK)) {
996 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
997 }
998 else {
999 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1000 }
1001 }
1002
1003 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1004
1005 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
1006
1007 String sql = query.toString();
1008
1009 Query q = session.createQuery(sql);
1010
1011 QueryPos qPos = QueryPos.getInstance(q);
1012
1013 if (uuid != null) {
1014 qPos.add(uuid);
1015 }
1016
1017 qPos.add(groupId);
1018
1019 List<IGFolder> list = q.list();
1020
1021 result = list;
1022
1023 IGFolder igFolder = null;
1024
1025 if (list.isEmpty()) {
1026 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1027 finderArgs, list);
1028 }
1029 else {
1030 igFolder = list.get(0);
1031
1032 cacheResult(igFolder);
1033
1034 if ((igFolder.getUuid() == null) ||
1035 !igFolder.getUuid().equals(uuid) ||
1036 (igFolder.getGroupId() != groupId)) {
1037 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1038 finderArgs, igFolder);
1039 }
1040 }
1041
1042 return igFolder;
1043 }
1044 catch (Exception e) {
1045 throw processException(e);
1046 }
1047 finally {
1048 if (result == null) {
1049 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1050 finderArgs, new ArrayList<IGFolder>());
1051 }
1052
1053 closeSession(session);
1054 }
1055 }
1056 else {
1057 if (result instanceof List<?>) {
1058 return null;
1059 }
1060 else {
1061 return (IGFolder)result;
1062 }
1063 }
1064 }
1065
1066
1073 public List<IGFolder> findByGroupId(long groupId) throws SystemException {
1074 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1075 }
1076
1077
1090 public List<IGFolder> findByGroupId(long groupId, int start, int end)
1091 throws SystemException {
1092 return findByGroupId(groupId, start, end, null);
1093 }
1094
1095
1109 public List<IGFolder> findByGroupId(long groupId, int start, int end,
1110 OrderByComparator orderByComparator) throws SystemException {
1111 Object[] finderArgs = new Object[] {
1112 groupId,
1113
1114 String.valueOf(start), String.valueOf(end),
1115 String.valueOf(orderByComparator)
1116 };
1117
1118 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1119 finderArgs, this);
1120
1121 if (list == null) {
1122 Session session = null;
1123
1124 try {
1125 session = openSession();
1126
1127 StringBundler query = null;
1128
1129 if (orderByComparator != null) {
1130 query = new StringBundler(3 +
1131 (orderByComparator.getOrderByFields().length * 3));
1132 }
1133 else {
1134 query = new StringBundler(3);
1135 }
1136
1137 query.append(_SQL_SELECT_IGFOLDER_WHERE);
1138
1139 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1140
1141 if (orderByComparator != null) {
1142 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1143 orderByComparator);
1144 }
1145
1146 else {
1147 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
1148 }
1149
1150 String sql = query.toString();
1151
1152 Query q = session.createQuery(sql);
1153
1154 QueryPos qPos = QueryPos.getInstance(q);
1155
1156 qPos.add(groupId);
1157
1158 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
1159 end);
1160 }
1161 catch (Exception e) {
1162 throw processException(e);
1163 }
1164 finally {
1165 if (list == null) {
1166 list = new ArrayList<IGFolder>();
1167 }
1168
1169 cacheResult(list);
1170
1171 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1172 finderArgs, list);
1173
1174 closeSession(session);
1175 }
1176 }
1177
1178 return list;
1179 }
1180
1181
1194 public IGFolder findByGroupId_First(long groupId,
1195 OrderByComparator orderByComparator)
1196 throws NoSuchFolderException, SystemException {
1197 List<IGFolder> list = findByGroupId(groupId, 0, 1, orderByComparator);
1198
1199 if (list.isEmpty()) {
1200 StringBundler msg = new StringBundler(4);
1201
1202 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1203
1204 msg.append("groupId=");
1205 msg.append(groupId);
1206
1207 msg.append(StringPool.CLOSE_CURLY_BRACE);
1208
1209 throw new NoSuchFolderException(msg.toString());
1210 }
1211 else {
1212 return list.get(0);
1213 }
1214 }
1215
1216
1229 public IGFolder findByGroupId_Last(long groupId,
1230 OrderByComparator orderByComparator)
1231 throws NoSuchFolderException, SystemException {
1232 int count = countByGroupId(groupId);
1233
1234 List<IGFolder> list = findByGroupId(groupId, count - 1, count,
1235 orderByComparator);
1236
1237 if (list.isEmpty()) {
1238 StringBundler msg = new StringBundler(4);
1239
1240 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1241
1242 msg.append("groupId=");
1243 msg.append(groupId);
1244
1245 msg.append(StringPool.CLOSE_CURLY_BRACE);
1246
1247 throw new NoSuchFolderException(msg.toString());
1248 }
1249 else {
1250 return list.get(0);
1251 }
1252 }
1253
1254
1268 public IGFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
1269 OrderByComparator orderByComparator)
1270 throws NoSuchFolderException, SystemException {
1271 IGFolder igFolder = findByPrimaryKey(folderId);
1272
1273 Session session = null;
1274
1275 try {
1276 session = openSession();
1277
1278 IGFolder[] array = new IGFolderImpl[3];
1279
1280 array[0] = getByGroupId_PrevAndNext(session, igFolder, groupId,
1281 orderByComparator, true);
1282
1283 array[1] = igFolder;
1284
1285 array[2] = getByGroupId_PrevAndNext(session, igFolder, groupId,
1286 orderByComparator, false);
1287
1288 return array;
1289 }
1290 catch (Exception e) {
1291 throw processException(e);
1292 }
1293 finally {
1294 closeSession(session);
1295 }
1296 }
1297
1298 protected IGFolder getByGroupId_PrevAndNext(Session session,
1299 IGFolder igFolder, long groupId, OrderByComparator orderByComparator,
1300 boolean previous) {
1301 StringBundler query = null;
1302
1303 if (orderByComparator != null) {
1304 query = new StringBundler(6 +
1305 (orderByComparator.getOrderByFields().length * 6));
1306 }
1307 else {
1308 query = new StringBundler(3);
1309 }
1310
1311 query.append(_SQL_SELECT_IGFOLDER_WHERE);
1312
1313 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1314
1315 if (orderByComparator != null) {
1316 String[] orderByFields = orderByComparator.getOrderByFields();
1317
1318 if (orderByFields.length > 0) {
1319 query.append(WHERE_AND);
1320 }
1321
1322 for (int i = 0; i < orderByFields.length; i++) {
1323 query.append(_ORDER_BY_ENTITY_ALIAS);
1324 query.append(orderByFields[i]);
1325
1326 if ((i + 1) < orderByFields.length) {
1327 if (orderByComparator.isAscending() ^ previous) {
1328 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1329 }
1330 else {
1331 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1332 }
1333 }
1334 else {
1335 if (orderByComparator.isAscending() ^ previous) {
1336 query.append(WHERE_GREATER_THAN);
1337 }
1338 else {
1339 query.append(WHERE_LESSER_THAN);
1340 }
1341 }
1342 }
1343
1344 query.append(ORDER_BY_CLAUSE);
1345
1346 for (int i = 0; i < orderByFields.length; i++) {
1347 query.append(_ORDER_BY_ENTITY_ALIAS);
1348 query.append(orderByFields[i]);
1349
1350 if ((i + 1) < orderByFields.length) {
1351 if (orderByComparator.isAscending() ^ previous) {
1352 query.append(ORDER_BY_ASC_HAS_NEXT);
1353 }
1354 else {
1355 query.append(ORDER_BY_DESC_HAS_NEXT);
1356 }
1357 }
1358 else {
1359 if (orderByComparator.isAscending() ^ previous) {
1360 query.append(ORDER_BY_ASC);
1361 }
1362 else {
1363 query.append(ORDER_BY_DESC);
1364 }
1365 }
1366 }
1367 }
1368
1369 else {
1370 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
1371 }
1372
1373 String sql = query.toString();
1374
1375 Query q = session.createQuery(sql);
1376
1377 q.setFirstResult(0);
1378 q.setMaxResults(2);
1379
1380 QueryPos qPos = QueryPos.getInstance(q);
1381
1382 qPos.add(groupId);
1383
1384 if (orderByComparator != null) {
1385 Object[] values = orderByComparator.getOrderByValues(igFolder);
1386
1387 for (Object value : values) {
1388 qPos.add(value);
1389 }
1390 }
1391
1392 List<IGFolder> list = q.list();
1393
1394 if (list.size() == 2) {
1395 return list.get(1);
1396 }
1397 else {
1398 return null;
1399 }
1400 }
1401
1402
1409 public List<IGFolder> filterFindByGroupId(long groupId)
1410 throws SystemException {
1411 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1412 QueryUtil.ALL_POS, null);
1413 }
1414
1415
1428 public List<IGFolder> filterFindByGroupId(long groupId, int start, int end)
1429 throws SystemException {
1430 return filterFindByGroupId(groupId, start, end, null);
1431 }
1432
1433
1447 public List<IGFolder> filterFindByGroupId(long groupId, int start, int end,
1448 OrderByComparator orderByComparator) throws SystemException {
1449 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1450 return findByGroupId(groupId, start, end, orderByComparator);
1451 }
1452
1453 Session session = null;
1454
1455 try {
1456 session = openSession();
1457
1458 StringBundler query = null;
1459
1460 if (orderByComparator != null) {
1461 query = new StringBundler(3 +
1462 (orderByComparator.getOrderByFields().length * 3));
1463 }
1464 else {
1465 query = new StringBundler(3);
1466 }
1467
1468 query.append(_FILTER_SQL_SELECT_IGFOLDER_WHERE);
1469
1470 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1471
1472 if (orderByComparator != null) {
1473 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1474 orderByComparator);
1475 }
1476
1477 else {
1478 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
1479 }
1480
1481 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1482 IGFolder.class.getName(), _FILTER_COLUMN_PK,
1483 _FILTER_COLUMN_USERID, groupId);
1484
1485 SQLQuery q = session.createSQLQuery(sql);
1486
1487 q.addEntity(_FILTER_ENTITY_ALIAS, IGFolderImpl.class);
1488
1489 QueryPos qPos = QueryPos.getInstance(q);
1490
1491 qPos.add(groupId);
1492
1493 return (List<IGFolder>)QueryUtil.list(q, getDialect(), start, end);
1494 }
1495 catch (Exception e) {
1496 throw processException(e);
1497 }
1498 finally {
1499 closeSession(session);
1500 }
1501 }
1502
1503
1510 public List<IGFolder> findByCompanyId(long companyId)
1511 throws SystemException {
1512 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1513 null);
1514 }
1515
1516
1529 public List<IGFolder> findByCompanyId(long companyId, int start, int end)
1530 throws SystemException {
1531 return findByCompanyId(companyId, start, end, null);
1532 }
1533
1534
1548 public List<IGFolder> findByCompanyId(long companyId, int start, int end,
1549 OrderByComparator orderByComparator) throws SystemException {
1550 Object[] finderArgs = new Object[] {
1551 companyId,
1552
1553 String.valueOf(start), String.valueOf(end),
1554 String.valueOf(orderByComparator)
1555 };
1556
1557 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1558 finderArgs, this);
1559
1560 if (list == null) {
1561 Session session = null;
1562
1563 try {
1564 session = openSession();
1565
1566 StringBundler query = null;
1567
1568 if (orderByComparator != null) {
1569 query = new StringBundler(3 +
1570 (orderByComparator.getOrderByFields().length * 3));
1571 }
1572 else {
1573 query = new StringBundler(3);
1574 }
1575
1576 query.append(_SQL_SELECT_IGFOLDER_WHERE);
1577
1578 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1579
1580 if (orderByComparator != null) {
1581 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1582 orderByComparator);
1583 }
1584
1585 else {
1586 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
1587 }
1588
1589 String sql = query.toString();
1590
1591 Query q = session.createQuery(sql);
1592
1593 QueryPos qPos = QueryPos.getInstance(q);
1594
1595 qPos.add(companyId);
1596
1597 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
1598 end);
1599 }
1600 catch (Exception e) {
1601 throw processException(e);
1602 }
1603 finally {
1604 if (list == null) {
1605 list = new ArrayList<IGFolder>();
1606 }
1607
1608 cacheResult(list);
1609
1610 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1611 finderArgs, list);
1612
1613 closeSession(session);
1614 }
1615 }
1616
1617 return list;
1618 }
1619
1620
1633 public IGFolder findByCompanyId_First(long companyId,
1634 OrderByComparator orderByComparator)
1635 throws NoSuchFolderException, SystemException {
1636 List<IGFolder> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1637
1638 if (list.isEmpty()) {
1639 StringBundler msg = new StringBundler(4);
1640
1641 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1642
1643 msg.append("companyId=");
1644 msg.append(companyId);
1645
1646 msg.append(StringPool.CLOSE_CURLY_BRACE);
1647
1648 throw new NoSuchFolderException(msg.toString());
1649 }
1650 else {
1651 return list.get(0);
1652 }
1653 }
1654
1655
1668 public IGFolder findByCompanyId_Last(long companyId,
1669 OrderByComparator orderByComparator)
1670 throws NoSuchFolderException, SystemException {
1671 int count = countByCompanyId(companyId);
1672
1673 List<IGFolder> list = findByCompanyId(companyId, count - 1, count,
1674 orderByComparator);
1675
1676 if (list.isEmpty()) {
1677 StringBundler msg = new StringBundler(4);
1678
1679 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1680
1681 msg.append("companyId=");
1682 msg.append(companyId);
1683
1684 msg.append(StringPool.CLOSE_CURLY_BRACE);
1685
1686 throw new NoSuchFolderException(msg.toString());
1687 }
1688 else {
1689 return list.get(0);
1690 }
1691 }
1692
1693
1707 public IGFolder[] findByCompanyId_PrevAndNext(long folderId,
1708 long companyId, OrderByComparator orderByComparator)
1709 throws NoSuchFolderException, SystemException {
1710 IGFolder igFolder = findByPrimaryKey(folderId);
1711
1712 Session session = null;
1713
1714 try {
1715 session = openSession();
1716
1717 IGFolder[] array = new IGFolderImpl[3];
1718
1719 array[0] = getByCompanyId_PrevAndNext(session, igFolder, companyId,
1720 orderByComparator, true);
1721
1722 array[1] = igFolder;
1723
1724 array[2] = getByCompanyId_PrevAndNext(session, igFolder, companyId,
1725 orderByComparator, false);
1726
1727 return array;
1728 }
1729 catch (Exception e) {
1730 throw processException(e);
1731 }
1732 finally {
1733 closeSession(session);
1734 }
1735 }
1736
1737 protected IGFolder getByCompanyId_PrevAndNext(Session session,
1738 IGFolder igFolder, long companyId, OrderByComparator orderByComparator,
1739 boolean previous) {
1740 StringBundler query = null;
1741
1742 if (orderByComparator != null) {
1743 query = new StringBundler(6 +
1744 (orderByComparator.getOrderByFields().length * 6));
1745 }
1746 else {
1747 query = new StringBundler(3);
1748 }
1749
1750 query.append(_SQL_SELECT_IGFOLDER_WHERE);
1751
1752 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1753
1754 if (orderByComparator != null) {
1755 String[] orderByFields = orderByComparator.getOrderByFields();
1756
1757 if (orderByFields.length > 0) {
1758 query.append(WHERE_AND);
1759 }
1760
1761 for (int i = 0; i < orderByFields.length; i++) {
1762 query.append(_ORDER_BY_ENTITY_ALIAS);
1763 query.append(orderByFields[i]);
1764
1765 if ((i + 1) < orderByFields.length) {
1766 if (orderByComparator.isAscending() ^ previous) {
1767 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1768 }
1769 else {
1770 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1771 }
1772 }
1773 else {
1774 if (orderByComparator.isAscending() ^ previous) {
1775 query.append(WHERE_GREATER_THAN);
1776 }
1777 else {
1778 query.append(WHERE_LESSER_THAN);
1779 }
1780 }
1781 }
1782
1783 query.append(ORDER_BY_CLAUSE);
1784
1785 for (int i = 0; i < orderByFields.length; i++) {
1786 query.append(_ORDER_BY_ENTITY_ALIAS);
1787 query.append(orderByFields[i]);
1788
1789 if ((i + 1) < orderByFields.length) {
1790 if (orderByComparator.isAscending() ^ previous) {
1791 query.append(ORDER_BY_ASC_HAS_NEXT);
1792 }
1793 else {
1794 query.append(ORDER_BY_DESC_HAS_NEXT);
1795 }
1796 }
1797 else {
1798 if (orderByComparator.isAscending() ^ previous) {
1799 query.append(ORDER_BY_ASC);
1800 }
1801 else {
1802 query.append(ORDER_BY_DESC);
1803 }
1804 }
1805 }
1806 }
1807
1808 else {
1809 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
1810 }
1811
1812 String sql = query.toString();
1813
1814 Query q = session.createQuery(sql);
1815
1816 q.setFirstResult(0);
1817 q.setMaxResults(2);
1818
1819 QueryPos qPos = QueryPos.getInstance(q);
1820
1821 qPos.add(companyId);
1822
1823 if (orderByComparator != null) {
1824 Object[] values = orderByComparator.getOrderByValues(igFolder);
1825
1826 for (Object value : values) {
1827 qPos.add(value);
1828 }
1829 }
1830
1831 List<IGFolder> list = q.list();
1832
1833 if (list.size() == 2) {
1834 return list.get(1);
1835 }
1836 else {
1837 return null;
1838 }
1839 }
1840
1841
1849 public List<IGFolder> findByG_P(long groupId, long parentFolderId)
1850 throws SystemException {
1851 return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
1852 QueryUtil.ALL_POS, null);
1853 }
1854
1855
1869 public List<IGFolder> findByG_P(long groupId, long parentFolderId,
1870 int start, int end) throws SystemException {
1871 return findByG_P(groupId, parentFolderId, start, end, null);
1872 }
1873
1874
1889 public List<IGFolder> findByG_P(long groupId, long parentFolderId,
1890 int start, int end, OrderByComparator orderByComparator)
1891 throws SystemException {
1892 Object[] finderArgs = new Object[] {
1893 groupId, parentFolderId,
1894
1895 String.valueOf(start), String.valueOf(end),
1896 String.valueOf(orderByComparator)
1897 };
1898
1899 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1900 finderArgs, this);
1901
1902 if (list == null) {
1903 Session session = null;
1904
1905 try {
1906 session = openSession();
1907
1908 StringBundler query = null;
1909
1910 if (orderByComparator != null) {
1911 query = new StringBundler(4 +
1912 (orderByComparator.getOrderByFields().length * 3));
1913 }
1914 else {
1915 query = new StringBundler(4);
1916 }
1917
1918 query.append(_SQL_SELECT_IGFOLDER_WHERE);
1919
1920 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1921
1922 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
1923
1924 if (orderByComparator != null) {
1925 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1926 orderByComparator);
1927 }
1928
1929 else {
1930 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
1931 }
1932
1933 String sql = query.toString();
1934
1935 Query q = session.createQuery(sql);
1936
1937 QueryPos qPos = QueryPos.getInstance(q);
1938
1939 qPos.add(groupId);
1940
1941 qPos.add(parentFolderId);
1942
1943 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
1944 end);
1945 }
1946 catch (Exception e) {
1947 throw processException(e);
1948 }
1949 finally {
1950 if (list == null) {
1951 list = new ArrayList<IGFolder>();
1952 }
1953
1954 cacheResult(list);
1955
1956 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
1957 list);
1958
1959 closeSession(session);
1960 }
1961 }
1962
1963 return list;
1964 }
1965
1966
1980 public IGFolder findByG_P_First(long groupId, long parentFolderId,
1981 OrderByComparator orderByComparator)
1982 throws NoSuchFolderException, SystemException {
1983 List<IGFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
1984 orderByComparator);
1985
1986 if (list.isEmpty()) {
1987 StringBundler msg = new StringBundler(6);
1988
1989 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1990
1991 msg.append("groupId=");
1992 msg.append(groupId);
1993
1994 msg.append(", parentFolderId=");
1995 msg.append(parentFolderId);
1996
1997 msg.append(StringPool.CLOSE_CURLY_BRACE);
1998
1999 throw new NoSuchFolderException(msg.toString());
2000 }
2001 else {
2002 return list.get(0);
2003 }
2004 }
2005
2006
2020 public IGFolder findByG_P_Last(long groupId, long parentFolderId,
2021 OrderByComparator orderByComparator)
2022 throws NoSuchFolderException, SystemException {
2023 int count = countByG_P(groupId, parentFolderId);
2024
2025 List<IGFolder> list = findByG_P(groupId, parentFolderId, count - 1,
2026 count, orderByComparator);
2027
2028 if (list.isEmpty()) {
2029 StringBundler msg = new StringBundler(6);
2030
2031 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2032
2033 msg.append("groupId=");
2034 msg.append(groupId);
2035
2036 msg.append(", parentFolderId=");
2037 msg.append(parentFolderId);
2038
2039 msg.append(StringPool.CLOSE_CURLY_BRACE);
2040
2041 throw new NoSuchFolderException(msg.toString());
2042 }
2043 else {
2044 return list.get(0);
2045 }
2046 }
2047
2048
2063 public IGFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
2064 long parentFolderId, OrderByComparator orderByComparator)
2065 throws NoSuchFolderException, SystemException {
2066 IGFolder igFolder = findByPrimaryKey(folderId);
2067
2068 Session session = null;
2069
2070 try {
2071 session = openSession();
2072
2073 IGFolder[] array = new IGFolderImpl[3];
2074
2075 array[0] = getByG_P_PrevAndNext(session, igFolder, groupId,
2076 parentFolderId, orderByComparator, true);
2077
2078 array[1] = igFolder;
2079
2080 array[2] = getByG_P_PrevAndNext(session, igFolder, groupId,
2081 parentFolderId, orderByComparator, false);
2082
2083 return array;
2084 }
2085 catch (Exception e) {
2086 throw processException(e);
2087 }
2088 finally {
2089 closeSession(session);
2090 }
2091 }
2092
2093 protected IGFolder getByG_P_PrevAndNext(Session session, IGFolder igFolder,
2094 long groupId, long parentFolderId, OrderByComparator orderByComparator,
2095 boolean previous) {
2096 StringBundler query = null;
2097
2098 if (orderByComparator != null) {
2099 query = new StringBundler(6 +
2100 (orderByComparator.getOrderByFields().length * 6));
2101 }
2102 else {
2103 query = new StringBundler(3);
2104 }
2105
2106 query.append(_SQL_SELECT_IGFOLDER_WHERE);
2107
2108 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2109
2110 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2111
2112 if (orderByComparator != null) {
2113 String[] orderByFields = orderByComparator.getOrderByFields();
2114
2115 if (orderByFields.length > 0) {
2116 query.append(WHERE_AND);
2117 }
2118
2119 for (int i = 0; i < orderByFields.length; i++) {
2120 query.append(_ORDER_BY_ENTITY_ALIAS);
2121 query.append(orderByFields[i]);
2122
2123 if ((i + 1) < orderByFields.length) {
2124 if (orderByComparator.isAscending() ^ previous) {
2125 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2126 }
2127 else {
2128 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2129 }
2130 }
2131 else {
2132 if (orderByComparator.isAscending() ^ previous) {
2133 query.append(WHERE_GREATER_THAN);
2134 }
2135 else {
2136 query.append(WHERE_LESSER_THAN);
2137 }
2138 }
2139 }
2140
2141 query.append(ORDER_BY_CLAUSE);
2142
2143 for (int i = 0; i < orderByFields.length; i++) {
2144 query.append(_ORDER_BY_ENTITY_ALIAS);
2145 query.append(orderByFields[i]);
2146
2147 if ((i + 1) < orderByFields.length) {
2148 if (orderByComparator.isAscending() ^ previous) {
2149 query.append(ORDER_BY_ASC_HAS_NEXT);
2150 }
2151 else {
2152 query.append(ORDER_BY_DESC_HAS_NEXT);
2153 }
2154 }
2155 else {
2156 if (orderByComparator.isAscending() ^ previous) {
2157 query.append(ORDER_BY_ASC);
2158 }
2159 else {
2160 query.append(ORDER_BY_DESC);
2161 }
2162 }
2163 }
2164 }
2165
2166 else {
2167 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
2168 }
2169
2170 String sql = query.toString();
2171
2172 Query q = session.createQuery(sql);
2173
2174 q.setFirstResult(0);
2175 q.setMaxResults(2);
2176
2177 QueryPos qPos = QueryPos.getInstance(q);
2178
2179 qPos.add(groupId);
2180
2181 qPos.add(parentFolderId);
2182
2183 if (orderByComparator != null) {
2184 Object[] values = orderByComparator.getOrderByValues(igFolder);
2185
2186 for (Object value : values) {
2187 qPos.add(value);
2188 }
2189 }
2190
2191 List<IGFolder> list = q.list();
2192
2193 if (list.size() == 2) {
2194 return list.get(1);
2195 }
2196 else {
2197 return null;
2198 }
2199 }
2200
2201
2209 public List<IGFolder> filterFindByG_P(long groupId, long parentFolderId)
2210 throws SystemException {
2211 return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
2212 QueryUtil.ALL_POS, null);
2213 }
2214
2215
2229 public List<IGFolder> filterFindByG_P(long groupId, long parentFolderId,
2230 int start, int end) throws SystemException {
2231 return filterFindByG_P(groupId, parentFolderId, start, end, null);
2232 }
2233
2234
2249 public List<IGFolder> filterFindByG_P(long groupId, long parentFolderId,
2250 int start, int end, OrderByComparator orderByComparator)
2251 throws SystemException {
2252 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2253 return findByG_P(groupId, parentFolderId, start, end,
2254 orderByComparator);
2255 }
2256
2257 Session session = null;
2258
2259 try {
2260 session = openSession();
2261
2262 StringBundler query = null;
2263
2264 if (orderByComparator != null) {
2265 query = new StringBundler(4 +
2266 (orderByComparator.getOrderByFields().length * 3));
2267 }
2268 else {
2269 query = new StringBundler(4);
2270 }
2271
2272 query.append(_FILTER_SQL_SELECT_IGFOLDER_WHERE);
2273
2274 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2275
2276 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2277
2278 if (orderByComparator != null) {
2279 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2280 orderByComparator);
2281 }
2282
2283 else {
2284 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
2285 }
2286
2287 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2288 IGFolder.class.getName(), _FILTER_COLUMN_PK,
2289 _FILTER_COLUMN_USERID, groupId);
2290
2291 SQLQuery q = session.createSQLQuery(sql);
2292
2293 q.addEntity(_FILTER_ENTITY_ALIAS, IGFolderImpl.class);
2294
2295 QueryPos qPos = QueryPos.getInstance(q);
2296
2297 qPos.add(groupId);
2298
2299 qPos.add(parentFolderId);
2300
2301 return (List<IGFolder>)QueryUtil.list(q, getDialect(), start, end);
2302 }
2303 catch (Exception e) {
2304 throw processException(e);
2305 }
2306 finally {
2307 closeSession(session);
2308 }
2309 }
2310
2311
2321 public IGFolder findByG_P_N(long groupId, long parentFolderId, String name)
2322 throws NoSuchFolderException, SystemException {
2323 IGFolder igFolder = fetchByG_P_N(groupId, parentFolderId, name);
2324
2325 if (igFolder == null) {
2326 StringBundler msg = new StringBundler(8);
2327
2328 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2329
2330 msg.append("groupId=");
2331 msg.append(groupId);
2332
2333 msg.append(", parentFolderId=");
2334 msg.append(parentFolderId);
2335
2336 msg.append(", name=");
2337 msg.append(name);
2338
2339 msg.append(StringPool.CLOSE_CURLY_BRACE);
2340
2341 if (_log.isWarnEnabled()) {
2342 _log.warn(msg.toString());
2343 }
2344
2345 throw new NoSuchFolderException(msg.toString());
2346 }
2347
2348 return igFolder;
2349 }
2350
2351
2360 public IGFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
2361 throws SystemException {
2362 return fetchByG_P_N(groupId, parentFolderId, name, true);
2363 }
2364
2365
2374 public IGFolder fetchByG_P_N(long groupId, long parentFolderId,
2375 String name, boolean retrieveFromCache) throws SystemException {
2376 Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
2377
2378 Object result = null;
2379
2380 if (retrieveFromCache) {
2381 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
2382 finderArgs, this);
2383 }
2384
2385 if (result == null) {
2386 Session session = null;
2387
2388 try {
2389 session = openSession();
2390
2391 StringBundler query = new StringBundler(5);
2392
2393 query.append(_SQL_SELECT_IGFOLDER_WHERE);
2394
2395 query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
2396
2397 query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
2398
2399 if (name == null) {
2400 query.append(_FINDER_COLUMN_G_P_N_NAME_1);
2401 }
2402 else {
2403 if (name.equals(StringPool.BLANK)) {
2404 query.append(_FINDER_COLUMN_G_P_N_NAME_3);
2405 }
2406 else {
2407 query.append(_FINDER_COLUMN_G_P_N_NAME_2);
2408 }
2409 }
2410
2411 query.append(IGFolderModelImpl.ORDER_BY_JPQL);
2412
2413 String sql = query.toString();
2414
2415 Query q = session.createQuery(sql);
2416
2417 QueryPos qPos = QueryPos.getInstance(q);
2418
2419 qPos.add(groupId);
2420
2421 qPos.add(parentFolderId);
2422
2423 if (name != null) {
2424 qPos.add(name);
2425 }
2426
2427 List<IGFolder> list = q.list();
2428
2429 result = list;
2430
2431 IGFolder igFolder = null;
2432
2433 if (list.isEmpty()) {
2434 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2435 finderArgs, list);
2436 }
2437 else {
2438 igFolder = list.get(0);
2439
2440 cacheResult(igFolder);
2441
2442 if ((igFolder.getGroupId() != groupId) ||
2443 (igFolder.getParentFolderId() != parentFolderId) ||
2444 (igFolder.getName() == null) ||
2445 !igFolder.getName().equals(name)) {
2446 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2447 finderArgs, igFolder);
2448 }
2449 }
2450
2451 return igFolder;
2452 }
2453 catch (Exception e) {
2454 throw processException(e);
2455 }
2456 finally {
2457 if (result == null) {
2458 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2459 finderArgs, new ArrayList<IGFolder>());
2460 }
2461
2462 closeSession(session);
2463 }
2464 }
2465 else {
2466 if (result instanceof List<?>) {
2467 return null;
2468 }
2469 else {
2470 return (IGFolder)result;
2471 }
2472 }
2473 }
2474
2475
2481 public List<IGFolder> findAll() throws SystemException {
2482 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2483 }
2484
2485
2497 public List<IGFolder> findAll(int start, int end) throws SystemException {
2498 return findAll(start, end, null);
2499 }
2500
2501
2514 public List<IGFolder> findAll(int start, int end,
2515 OrderByComparator orderByComparator) throws SystemException {
2516 Object[] finderArgs = new Object[] {
2517 String.valueOf(start), String.valueOf(end),
2518 String.valueOf(orderByComparator)
2519 };
2520
2521 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2522 finderArgs, this);
2523
2524 if (list == null) {
2525 Session session = null;
2526
2527 try {
2528 session = openSession();
2529
2530 StringBundler query = null;
2531 String sql = null;
2532
2533 if (orderByComparator != null) {
2534 query = new StringBundler(2 +
2535 (orderByComparator.getOrderByFields().length * 3));
2536
2537 query.append(_SQL_SELECT_IGFOLDER);
2538
2539 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2540 orderByComparator);
2541
2542 sql = query.toString();
2543 }
2544 else {
2545 sql = _SQL_SELECT_IGFOLDER.concat(IGFolderModelImpl.ORDER_BY_JPQL);
2546 }
2547
2548 Query q = session.createQuery(sql);
2549
2550 if (orderByComparator == null) {
2551 list = (List<IGFolder>)QueryUtil.list(q, getDialect(),
2552 start, end, false);
2553
2554 Collections.sort(list);
2555 }
2556 else {
2557 list = (List<IGFolder>)QueryUtil.list(q, getDialect(),
2558 start, end);
2559 }
2560 }
2561 catch (Exception e) {
2562 throw processException(e);
2563 }
2564 finally {
2565 if (list == null) {
2566 list = new ArrayList<IGFolder>();
2567 }
2568
2569 cacheResult(list);
2570
2571 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2572
2573 closeSession(session);
2574 }
2575 }
2576
2577 return list;
2578 }
2579
2580
2586 public void removeByUuid(String uuid) throws SystemException {
2587 for (IGFolder igFolder : findByUuid(uuid)) {
2588 remove(igFolder);
2589 }
2590 }
2591
2592
2599 public void removeByUUID_G(String uuid, long groupId)
2600 throws NoSuchFolderException, SystemException {
2601 IGFolder igFolder = findByUUID_G(uuid, groupId);
2602
2603 remove(igFolder);
2604 }
2605
2606
2612 public void removeByGroupId(long groupId) throws SystemException {
2613 for (IGFolder igFolder : findByGroupId(groupId)) {
2614 remove(igFolder);
2615 }
2616 }
2617
2618
2624 public void removeByCompanyId(long companyId) throws SystemException {
2625 for (IGFolder igFolder : findByCompanyId(companyId)) {
2626 remove(igFolder);
2627 }
2628 }
2629
2630
2637 public void removeByG_P(long groupId, long parentFolderId)
2638 throws SystemException {
2639 for (IGFolder igFolder : findByG_P(groupId, parentFolderId)) {
2640 remove(igFolder);
2641 }
2642 }
2643
2644
2652 public void removeByG_P_N(long groupId, long parentFolderId, String name)
2653 throws NoSuchFolderException, SystemException {
2654 IGFolder igFolder = findByG_P_N(groupId, parentFolderId, name);
2655
2656 remove(igFolder);
2657 }
2658
2659
2664 public void removeAll() throws SystemException {
2665 for (IGFolder igFolder : findAll()) {
2666 remove(igFolder);
2667 }
2668 }
2669
2670
2677 public int countByUuid(String uuid) throws SystemException {
2678 Object[] finderArgs = new Object[] { uuid };
2679
2680 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2681 finderArgs, this);
2682
2683 if (count == null) {
2684 Session session = null;
2685
2686 try {
2687 session = openSession();
2688
2689 StringBundler query = new StringBundler(2);
2690
2691 query.append(_SQL_COUNT_IGFOLDER_WHERE);
2692
2693 if (uuid == null) {
2694 query.append(_FINDER_COLUMN_UUID_UUID_1);
2695 }
2696 else {
2697 if (uuid.equals(StringPool.BLANK)) {
2698 query.append(_FINDER_COLUMN_UUID_UUID_3);
2699 }
2700 else {
2701 query.append(_FINDER_COLUMN_UUID_UUID_2);
2702 }
2703 }
2704
2705 String sql = query.toString();
2706
2707 Query q = session.createQuery(sql);
2708
2709 QueryPos qPos = QueryPos.getInstance(q);
2710
2711 if (uuid != null) {
2712 qPos.add(uuid);
2713 }
2714
2715 count = (Long)q.uniqueResult();
2716 }
2717 catch (Exception e) {
2718 throw processException(e);
2719 }
2720 finally {
2721 if (count == null) {
2722 count = Long.valueOf(0);
2723 }
2724
2725 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2726 finderArgs, count);
2727
2728 closeSession(session);
2729 }
2730 }
2731
2732 return count.intValue();
2733 }
2734
2735
2743 public int countByUUID_G(String uuid, long groupId)
2744 throws SystemException {
2745 Object[] finderArgs = new Object[] { uuid, groupId };
2746
2747 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2748 finderArgs, this);
2749
2750 if (count == null) {
2751 Session session = null;
2752
2753 try {
2754 session = openSession();
2755
2756 StringBundler query = new StringBundler(3);
2757
2758 query.append(_SQL_COUNT_IGFOLDER_WHERE);
2759
2760 if (uuid == null) {
2761 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2762 }
2763 else {
2764 if (uuid.equals(StringPool.BLANK)) {
2765 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2766 }
2767 else {
2768 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2769 }
2770 }
2771
2772 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2773
2774 String sql = query.toString();
2775
2776 Query q = session.createQuery(sql);
2777
2778 QueryPos qPos = QueryPos.getInstance(q);
2779
2780 if (uuid != null) {
2781 qPos.add(uuid);
2782 }
2783
2784 qPos.add(groupId);
2785
2786 count = (Long)q.uniqueResult();
2787 }
2788 catch (Exception e) {
2789 throw processException(e);
2790 }
2791 finally {
2792 if (count == null) {
2793 count = Long.valueOf(0);
2794 }
2795
2796 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2797 finderArgs, count);
2798
2799 closeSession(session);
2800 }
2801 }
2802
2803 return count.intValue();
2804 }
2805
2806
2813 public int countByGroupId(long groupId) throws SystemException {
2814 Object[] finderArgs = new Object[] { groupId };
2815
2816 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2817 finderArgs, this);
2818
2819 if (count == null) {
2820 Session session = null;
2821
2822 try {
2823 session = openSession();
2824
2825 StringBundler query = new StringBundler(2);
2826
2827 query.append(_SQL_COUNT_IGFOLDER_WHERE);
2828
2829 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2830
2831 String sql = query.toString();
2832
2833 Query q = session.createQuery(sql);
2834
2835 QueryPos qPos = QueryPos.getInstance(q);
2836
2837 qPos.add(groupId);
2838
2839 count = (Long)q.uniqueResult();
2840 }
2841 catch (Exception e) {
2842 throw processException(e);
2843 }
2844 finally {
2845 if (count == null) {
2846 count = Long.valueOf(0);
2847 }
2848
2849 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2850 finderArgs, count);
2851
2852 closeSession(session);
2853 }
2854 }
2855
2856 return count.intValue();
2857 }
2858
2859
2866 public int filterCountByGroupId(long groupId) throws SystemException {
2867 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2868 return countByGroupId(groupId);
2869 }
2870
2871 Session session = null;
2872
2873 try {
2874 session = openSession();
2875
2876 StringBundler query = new StringBundler(2);
2877
2878 query.append(_FILTER_SQL_COUNT_IGFOLDER_WHERE);
2879
2880 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2881
2882 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2883 IGFolder.class.getName(), _FILTER_COLUMN_PK,
2884 _FILTER_COLUMN_USERID, groupId);
2885
2886 SQLQuery q = session.createSQLQuery(sql);
2887
2888 q.addScalar(COUNT_COLUMN_NAME,
2889 com.liferay.portal.kernel.dao.orm.Type.LONG);
2890
2891 QueryPos qPos = QueryPos.getInstance(q);
2892
2893 qPos.add(groupId);
2894
2895 Long count = (Long)q.uniqueResult();
2896
2897 return count.intValue();
2898 }
2899 catch (Exception e) {
2900 throw processException(e);
2901 }
2902 finally {
2903 closeSession(session);
2904 }
2905 }
2906
2907
2914 public int countByCompanyId(long companyId) throws SystemException {
2915 Object[] finderArgs = new Object[] { companyId };
2916
2917 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2918 finderArgs, this);
2919
2920 if (count == null) {
2921 Session session = null;
2922
2923 try {
2924 session = openSession();
2925
2926 StringBundler query = new StringBundler(2);
2927
2928 query.append(_SQL_COUNT_IGFOLDER_WHERE);
2929
2930 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2931
2932 String sql = query.toString();
2933
2934 Query q = session.createQuery(sql);
2935
2936 QueryPos qPos = QueryPos.getInstance(q);
2937
2938 qPos.add(companyId);
2939
2940 count = (Long)q.uniqueResult();
2941 }
2942 catch (Exception e) {
2943 throw processException(e);
2944 }
2945 finally {
2946 if (count == null) {
2947 count = Long.valueOf(0);
2948 }
2949
2950 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2951 finderArgs, count);
2952
2953 closeSession(session);
2954 }
2955 }
2956
2957 return count.intValue();
2958 }
2959
2960
2968 public int countByG_P(long groupId, long parentFolderId)
2969 throws SystemException {
2970 Object[] finderArgs = new Object[] { groupId, parentFolderId };
2971
2972 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
2973 finderArgs, this);
2974
2975 if (count == null) {
2976 Session session = null;
2977
2978 try {
2979 session = openSession();
2980
2981 StringBundler query = new StringBundler(3);
2982
2983 query.append(_SQL_COUNT_IGFOLDER_WHERE);
2984
2985 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2986
2987 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2988
2989 String sql = query.toString();
2990
2991 Query q = session.createQuery(sql);
2992
2993 QueryPos qPos = QueryPos.getInstance(q);
2994
2995 qPos.add(groupId);
2996
2997 qPos.add(parentFolderId);
2998
2999 count = (Long)q.uniqueResult();
3000 }
3001 catch (Exception e) {
3002 throw processException(e);
3003 }
3004 finally {
3005 if (count == null) {
3006 count = Long.valueOf(0);
3007 }
3008
3009 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3010 count);
3011
3012 closeSession(session);
3013 }
3014 }
3015
3016 return count.intValue();
3017 }
3018
3019
3027 public int filterCountByG_P(long groupId, long parentFolderId)
3028 throws SystemException {
3029 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3030 return countByG_P(groupId, parentFolderId);
3031 }
3032
3033 Session session = null;
3034
3035 try {
3036 session = openSession();
3037
3038 StringBundler query = new StringBundler(3);
3039
3040 query.append(_FILTER_SQL_COUNT_IGFOLDER_WHERE);
3041
3042 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3043
3044 query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3045
3046 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3047 IGFolder.class.getName(), _FILTER_COLUMN_PK,
3048 _FILTER_COLUMN_USERID, groupId);
3049
3050 SQLQuery q = session.createSQLQuery(sql);
3051
3052 q.addScalar(COUNT_COLUMN_NAME,
3053 com.liferay.portal.kernel.dao.orm.Type.LONG);
3054
3055 QueryPos qPos = QueryPos.getInstance(q);
3056
3057 qPos.add(groupId);
3058
3059 qPos.add(parentFolderId);
3060
3061 Long count = (Long)q.uniqueResult();
3062
3063 return count.intValue();
3064 }
3065 catch (Exception e) {
3066 throw processException(e);
3067 }
3068 finally {
3069 closeSession(session);
3070 }
3071 }
3072
3073
3082 public int countByG_P_N(long groupId, long parentFolderId, String name)
3083 throws SystemException {
3084 Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
3085
3086 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_N,
3087 finderArgs, this);
3088
3089 if (count == null) {
3090 Session session = null;
3091
3092 try {
3093 session = openSession();
3094
3095 StringBundler query = new StringBundler(4);
3096
3097 query.append(_SQL_COUNT_IGFOLDER_WHERE);
3098
3099 query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
3100
3101 query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
3102
3103 if (name == null) {
3104 query.append(_FINDER_COLUMN_G_P_N_NAME_1);
3105 }
3106 else {
3107 if (name.equals(StringPool.BLANK)) {
3108 query.append(_FINDER_COLUMN_G_P_N_NAME_3);
3109 }
3110 else {
3111 query.append(_FINDER_COLUMN_G_P_N_NAME_2);
3112 }
3113 }
3114
3115 String sql = query.toString();
3116
3117 Query q = session.createQuery(sql);
3118
3119 QueryPos qPos = QueryPos.getInstance(q);
3120
3121 qPos.add(groupId);
3122
3123 qPos.add(parentFolderId);
3124
3125 if (name != null) {
3126 qPos.add(name);
3127 }
3128
3129 count = (Long)q.uniqueResult();
3130 }
3131 catch (Exception e) {
3132 throw processException(e);
3133 }
3134 finally {
3135 if (count == null) {
3136 count = Long.valueOf(0);
3137 }
3138
3139 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N,
3140 finderArgs, count);
3141
3142 closeSession(session);
3143 }
3144 }
3145
3146 return count.intValue();
3147 }
3148
3149
3158 public int filterCountByG_P_N(long groupId, long parentFolderId, String name)
3159 throws SystemException {
3160 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3161 return countByG_P_N(groupId, parentFolderId, name);
3162 }
3163
3164 Session session = null;
3165
3166 try {
3167 session = openSession();
3168
3169 StringBundler query = new StringBundler(4);
3170
3171 query.append(_FILTER_SQL_COUNT_IGFOLDER_WHERE);
3172
3173 query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
3174
3175 query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
3176
3177 if (name == null) {
3178 query.append(_FINDER_COLUMN_G_P_N_NAME_1);
3179 }
3180 else {
3181 if (name.equals(StringPool.BLANK)) {
3182 query.append(_FINDER_COLUMN_G_P_N_NAME_3);
3183 }
3184 else {
3185 query.append(_FINDER_COLUMN_G_P_N_NAME_2);
3186 }
3187 }
3188
3189 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3190 IGFolder.class.getName(), _FILTER_COLUMN_PK,
3191 _FILTER_COLUMN_USERID, groupId);
3192
3193 SQLQuery q = session.createSQLQuery(sql);
3194
3195 q.addScalar(COUNT_COLUMN_NAME,
3196 com.liferay.portal.kernel.dao.orm.Type.LONG);
3197
3198 QueryPos qPos = QueryPos.getInstance(q);
3199
3200 qPos.add(groupId);
3201
3202 qPos.add(parentFolderId);
3203
3204 if (name != null) {
3205 qPos.add(name);
3206 }
3207
3208 Long count = (Long)q.uniqueResult();
3209
3210 return count.intValue();
3211 }
3212 catch (Exception e) {
3213 throw processException(e);
3214 }
3215 finally {
3216 closeSession(session);
3217 }
3218 }
3219
3220
3226 public int countAll() throws SystemException {
3227 Object[] finderArgs = new Object[0];
3228
3229 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3230 finderArgs, this);
3231
3232 if (count == null) {
3233 Session session = null;
3234
3235 try {
3236 session = openSession();
3237
3238 Query q = session.createQuery(_SQL_COUNT_IGFOLDER);
3239
3240 count = (Long)q.uniqueResult();
3241 }
3242 catch (Exception e) {
3243 throw processException(e);
3244 }
3245 finally {
3246 if (count == null) {
3247 count = Long.valueOf(0);
3248 }
3249
3250 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3251 count);
3252
3253 closeSession(session);
3254 }
3255 }
3256
3257 return count.intValue();
3258 }
3259
3260
3263 public void afterPropertiesSet() {
3264 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3265 com.liferay.portal.util.PropsUtil.get(
3266 "value.object.listener.com.liferay.portlet.imagegallery.model.IGFolder")));
3267
3268 if (listenerClassNames.length > 0) {
3269 try {
3270 List<ModelListener<IGFolder>> listenersList = new ArrayList<ModelListener<IGFolder>>();
3271
3272 for (String listenerClassName : listenerClassNames) {
3273 listenersList.add((ModelListener<IGFolder>)InstanceFactory.newInstance(
3274 listenerClassName));
3275 }
3276
3277 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3278 }
3279 catch (Exception e) {
3280 _log.error(e);
3281 }
3282 }
3283 }
3284
3285 @BeanReference(type = IGFolderPersistence.class)
3286 protected IGFolderPersistence igFolderPersistence;
3287 @BeanReference(type = IGImagePersistence.class)
3288 protected IGImagePersistence igImagePersistence;
3289 @BeanReference(type = GroupPersistence.class)
3290 protected GroupPersistence groupPersistence;
3291 @BeanReference(type = ImagePersistence.class)
3292 protected ImagePersistence imagePersistence;
3293 @BeanReference(type = LayoutPersistence.class)
3294 protected LayoutPersistence layoutPersistence;
3295 @BeanReference(type = ResourcePersistence.class)
3296 protected ResourcePersistence resourcePersistence;
3297 @BeanReference(type = UserPersistence.class)
3298 protected UserPersistence userPersistence;
3299 @BeanReference(type = ExpandoValuePersistence.class)
3300 protected ExpandoValuePersistence expandoValuePersistence;
3301 private static final String _SQL_SELECT_IGFOLDER = "SELECT igFolder FROM IGFolder igFolder";
3302 private static final String _SQL_SELECT_IGFOLDER_WHERE = "SELECT igFolder FROM IGFolder igFolder WHERE ";
3303 private static final String _SQL_COUNT_IGFOLDER = "SELECT COUNT(igFolder) FROM IGFolder igFolder";
3304 private static final String _SQL_COUNT_IGFOLDER_WHERE = "SELECT COUNT(igFolder) FROM IGFolder igFolder WHERE ";
3305 private static final String _FINDER_COLUMN_UUID_UUID_1 = "igFolder.uuid IS NULL";
3306 private static final String _FINDER_COLUMN_UUID_UUID_2 = "igFolder.uuid = ?";
3307 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(igFolder.uuid IS NULL OR igFolder.uuid = ?)";
3308 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "igFolder.uuid IS NULL AND ";
3309 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "igFolder.uuid = ? AND ";
3310 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(igFolder.uuid IS NULL OR igFolder.uuid = ?) AND ";
3311 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "igFolder.groupId = ?";
3312 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "igFolder.groupId = ?";
3313 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "igFolder.companyId = ?";
3314 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "igFolder.groupId = ? AND ";
3315 private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "igFolder.parentFolderId = ?";
3316 private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "igFolder.groupId = ? AND ";
3317 private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "igFolder.parentFolderId = ? AND ";
3318 private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "igFolder.name IS NULL";
3319 private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "igFolder.name = ?";
3320 private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(igFolder.name IS NULL OR igFolder.name = ?)";
3321 private static final String _FILTER_SQL_SELECT_IGFOLDER_WHERE = "SELECT DISTINCT {igFolder.*} FROM IGFolder igFolder WHERE ";
3322 private static final String _FILTER_SQL_COUNT_IGFOLDER_WHERE = "SELECT COUNT(DISTINCT igFolder.folderId) AS COUNT_VALUE FROM IGFolder igFolder WHERE ";
3323 private static final String _FILTER_COLUMN_PK = "igFolder.folderId";
3324 private static final String _FILTER_COLUMN_USERID = "igFolder.userId";
3325 private static final String _FILTER_ENTITY_ALIAS = "igFolder";
3326 private static final String _ORDER_BY_ENTITY_ALIAS = "igFolder.";
3327 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No IGFolder exists with the primary key ";
3328 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No IGFolder exists with the key {";
3329 private static Log _log = LogFactoryUtil.getLog(IGFolderPersistenceImpl.class);
3330 }