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