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