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(
500 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
501
502 if (uuid == null) {
503 query.append("uuid_ IS NULL");
504 }
505 else {
506 query.append("uuid_ = ?");
507 }
508
509 query.append(" ");
510
511 query.append("ORDER BY ");
512
513 query.append("folderId ASC, ");
514 query.append("name ASC");
515
516 Query q = session.createQuery(query.toString());
517
518 QueryPos qPos = QueryPos.getInstance(q);
519
520 if (uuid != null) {
521 qPos.add(uuid);
522 }
523
524 list = q.list();
525 }
526 catch (Exception e) {
527 throw processException(e);
528 }
529 finally {
530 if (list == null) {
531 list = new ArrayList<IGFolder>();
532 }
533
534 cacheResult(list);
535
536 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
537 list);
538
539 closeSession(session);
540 }
541 }
542
543 return list;
544 }
545
546 public List<IGFolder> findByUuid(String uuid, int start, int end)
547 throws SystemException {
548 return findByUuid(uuid, start, end, null);
549 }
550
551 public List<IGFolder> findByUuid(String uuid, int start, int end,
552 OrderByComparator obc) throws SystemException {
553 Object[] finderArgs = new Object[] {
554 uuid,
555
556 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
557 };
558
559 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
560 finderArgs, this);
561
562 if (list == null) {
563 Session session = null;
564
565 try {
566 session = openSession();
567
568 StringBuilder query = new StringBuilder();
569
570 query.append(
571 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
572
573 if (uuid == null) {
574 query.append("uuid_ IS NULL");
575 }
576 else {
577 query.append("uuid_ = ?");
578 }
579
580 query.append(" ");
581
582 if (obc != null) {
583 query.append("ORDER BY ");
584 query.append(obc.getOrderBy());
585 }
586
587 else {
588 query.append("ORDER BY ");
589
590 query.append("folderId ASC, ");
591 query.append("name ASC");
592 }
593
594 Query q = session.createQuery(query.toString());
595
596 QueryPos qPos = QueryPos.getInstance(q);
597
598 if (uuid != null) {
599 qPos.add(uuid);
600 }
601
602 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
603 end);
604 }
605 catch (Exception e) {
606 throw processException(e);
607 }
608 finally {
609 if (list == null) {
610 list = new ArrayList<IGFolder>();
611 }
612
613 cacheResult(list);
614
615 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
616 finderArgs, list);
617
618 closeSession(session);
619 }
620 }
621
622 return list;
623 }
624
625 public IGFolder findByUuid_First(String uuid, OrderByComparator obc)
626 throws NoSuchFolderException, SystemException {
627 List<IGFolder> list = findByUuid(uuid, 0, 1, obc);
628
629 if (list.isEmpty()) {
630 StringBuilder msg = new StringBuilder();
631
632 msg.append("No IGFolder exists with the key {");
633
634 msg.append("uuid=" + uuid);
635
636 msg.append(StringPool.CLOSE_CURLY_BRACE);
637
638 throw new NoSuchFolderException(msg.toString());
639 }
640 else {
641 return list.get(0);
642 }
643 }
644
645 public IGFolder findByUuid_Last(String uuid, OrderByComparator obc)
646 throws NoSuchFolderException, SystemException {
647 int count = countByUuid(uuid);
648
649 List<IGFolder> list = findByUuid(uuid, count - 1, count, obc);
650
651 if (list.isEmpty()) {
652 StringBuilder msg = new StringBuilder();
653
654 msg.append("No IGFolder exists with the key {");
655
656 msg.append("uuid=" + uuid);
657
658 msg.append(StringPool.CLOSE_CURLY_BRACE);
659
660 throw new NoSuchFolderException(msg.toString());
661 }
662 else {
663 return list.get(0);
664 }
665 }
666
667 public IGFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
668 OrderByComparator obc) throws NoSuchFolderException, SystemException {
669 IGFolder igFolder = findByPrimaryKey(folderId);
670
671 int count = countByUuid(uuid);
672
673 Session session = null;
674
675 try {
676 session = openSession();
677
678 StringBuilder query = new StringBuilder();
679
680 query.append(
681 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
682
683 if (uuid == null) {
684 query.append("uuid_ IS NULL");
685 }
686 else {
687 query.append("uuid_ = ?");
688 }
689
690 query.append(" ");
691
692 if (obc != null) {
693 query.append("ORDER BY ");
694 query.append(obc.getOrderBy());
695 }
696
697 else {
698 query.append("ORDER BY ");
699
700 query.append("folderId ASC, ");
701 query.append("name ASC");
702 }
703
704 Query q = session.createQuery(query.toString());
705
706 QueryPos qPos = QueryPos.getInstance(q);
707
708 if (uuid != null) {
709 qPos.add(uuid);
710 }
711
712 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
713
714 IGFolder[] array = new IGFolderImpl[3];
715
716 array[0] = (IGFolder)objArray[0];
717 array[1] = (IGFolder)objArray[1];
718 array[2] = (IGFolder)objArray[2];
719
720 return array;
721 }
722 catch (Exception e) {
723 throw processException(e);
724 }
725 finally {
726 closeSession(session);
727 }
728 }
729
730 public IGFolder findByUUID_G(String uuid, long groupId)
731 throws NoSuchFolderException, SystemException {
732 IGFolder igFolder = fetchByUUID_G(uuid, groupId);
733
734 if (igFolder == null) {
735 StringBuilder msg = new StringBuilder();
736
737 msg.append("No IGFolder exists with the key {");
738
739 msg.append("uuid=" + uuid);
740
741 msg.append(", ");
742 msg.append("groupId=" + groupId);
743
744 msg.append(StringPool.CLOSE_CURLY_BRACE);
745
746 if (_log.isWarnEnabled()) {
747 _log.warn(msg.toString());
748 }
749
750 throw new NoSuchFolderException(msg.toString());
751 }
752
753 return igFolder;
754 }
755
756 public IGFolder fetchByUUID_G(String uuid, long groupId)
757 throws SystemException {
758 return fetchByUUID_G(uuid, groupId, true);
759 }
760
761 public IGFolder fetchByUUID_G(String uuid, long groupId,
762 boolean retrieveFromCache) throws SystemException {
763 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
764
765 Object result = null;
766
767 if (retrieveFromCache) {
768 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
769 finderArgs, this);
770 }
771
772 if (result == null) {
773 Session session = null;
774
775 try {
776 session = openSession();
777
778 StringBuilder query = new StringBuilder();
779
780 query.append(
781 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
782
783 if (uuid == null) {
784 query.append("uuid_ IS NULL");
785 }
786 else {
787 query.append("uuid_ = ?");
788 }
789
790 query.append(" AND ");
791
792 query.append("groupId = ?");
793
794 query.append(" ");
795
796 query.append("ORDER BY ");
797
798 query.append("folderId ASC, ");
799 query.append("name ASC");
800
801 Query q = session.createQuery(query.toString());
802
803 QueryPos qPos = QueryPos.getInstance(q);
804
805 if (uuid != null) {
806 qPos.add(uuid);
807 }
808
809 qPos.add(groupId);
810
811 List<IGFolder> list = q.list();
812
813 result = list;
814
815 IGFolder igFolder = null;
816
817 if (list.isEmpty()) {
818 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
819 finderArgs, list);
820 }
821 else {
822 igFolder = list.get(0);
823
824 cacheResult(igFolder);
825
826 if ((igFolder.getUuid() == null) ||
827 !igFolder.getUuid().equals(uuid) ||
828 (igFolder.getGroupId() != groupId)) {
829 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
830 finderArgs, igFolder);
831 }
832 }
833
834 return igFolder;
835 }
836 catch (Exception e) {
837 throw processException(e);
838 }
839 finally {
840 if (result == null) {
841 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
842 finderArgs, new ArrayList<IGFolder>());
843 }
844
845 closeSession(session);
846 }
847 }
848 else {
849 if (result instanceof List) {
850 return null;
851 }
852 else {
853 return (IGFolder)result;
854 }
855 }
856 }
857
858 public List<IGFolder> findByGroupId(long groupId) throws SystemException {
859 Object[] finderArgs = new Object[] { new Long(groupId) };
860
861 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
862 finderArgs, this);
863
864 if (list == null) {
865 Session session = null;
866
867 try {
868 session = openSession();
869
870 StringBuilder query = new StringBuilder();
871
872 query.append(
873 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
874
875 query.append("groupId = ?");
876
877 query.append(" ");
878
879 query.append("ORDER BY ");
880
881 query.append("folderId ASC, ");
882 query.append("name ASC");
883
884 Query q = session.createQuery(query.toString());
885
886 QueryPos qPos = QueryPos.getInstance(q);
887
888 qPos.add(groupId);
889
890 list = q.list();
891 }
892 catch (Exception e) {
893 throw processException(e);
894 }
895 finally {
896 if (list == null) {
897 list = new ArrayList<IGFolder>();
898 }
899
900 cacheResult(list);
901
902 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
903 finderArgs, list);
904
905 closeSession(session);
906 }
907 }
908
909 return list;
910 }
911
912 public List<IGFolder> findByGroupId(long groupId, int start, int end)
913 throws SystemException {
914 return findByGroupId(groupId, start, end, null);
915 }
916
917 public List<IGFolder> findByGroupId(long groupId, int start, int end,
918 OrderByComparator obc) throws SystemException {
919 Object[] finderArgs = new Object[] {
920 new Long(groupId),
921
922 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
923 };
924
925 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
926 finderArgs, this);
927
928 if (list == null) {
929 Session session = null;
930
931 try {
932 session = openSession();
933
934 StringBuilder query = new StringBuilder();
935
936 query.append(
937 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
938
939 query.append("groupId = ?");
940
941 query.append(" ");
942
943 if (obc != null) {
944 query.append("ORDER BY ");
945 query.append(obc.getOrderBy());
946 }
947
948 else {
949 query.append("ORDER BY ");
950
951 query.append("folderId ASC, ");
952 query.append("name ASC");
953 }
954
955 Query q = session.createQuery(query.toString());
956
957 QueryPos qPos = QueryPos.getInstance(q);
958
959 qPos.add(groupId);
960
961 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
962 end);
963 }
964 catch (Exception e) {
965 throw processException(e);
966 }
967 finally {
968 if (list == null) {
969 list = new ArrayList<IGFolder>();
970 }
971
972 cacheResult(list);
973
974 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
975 finderArgs, list);
976
977 closeSession(session);
978 }
979 }
980
981 return list;
982 }
983
984 public IGFolder findByGroupId_First(long groupId, OrderByComparator obc)
985 throws NoSuchFolderException, SystemException {
986 List<IGFolder> list = findByGroupId(groupId, 0, 1, obc);
987
988 if (list.isEmpty()) {
989 StringBuilder msg = new StringBuilder();
990
991 msg.append("No IGFolder exists with the key {");
992
993 msg.append("groupId=" + groupId);
994
995 msg.append(StringPool.CLOSE_CURLY_BRACE);
996
997 throw new NoSuchFolderException(msg.toString());
998 }
999 else {
1000 return list.get(0);
1001 }
1002 }
1003
1004 public IGFolder findByGroupId_Last(long groupId, OrderByComparator obc)
1005 throws NoSuchFolderException, SystemException {
1006 int count = countByGroupId(groupId);
1007
1008 List<IGFolder> list = findByGroupId(groupId, count - 1, count, obc);
1009
1010 if (list.isEmpty()) {
1011 StringBuilder msg = new StringBuilder();
1012
1013 msg.append("No IGFolder exists with the key {");
1014
1015 msg.append("groupId=" + groupId);
1016
1017 msg.append(StringPool.CLOSE_CURLY_BRACE);
1018
1019 throw new NoSuchFolderException(msg.toString());
1020 }
1021 else {
1022 return list.get(0);
1023 }
1024 }
1025
1026 public IGFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
1027 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1028 IGFolder igFolder = findByPrimaryKey(folderId);
1029
1030 int count = countByGroupId(groupId);
1031
1032 Session session = null;
1033
1034 try {
1035 session = openSession();
1036
1037 StringBuilder query = new StringBuilder();
1038
1039 query.append(
1040 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1041
1042 query.append("groupId = ?");
1043
1044 query.append(" ");
1045
1046 if (obc != null) {
1047 query.append("ORDER BY ");
1048 query.append(obc.getOrderBy());
1049 }
1050
1051 else {
1052 query.append("ORDER BY ");
1053
1054 query.append("folderId ASC, ");
1055 query.append("name ASC");
1056 }
1057
1058 Query q = session.createQuery(query.toString());
1059
1060 QueryPos qPos = QueryPos.getInstance(q);
1061
1062 qPos.add(groupId);
1063
1064 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
1065
1066 IGFolder[] array = new IGFolderImpl[3];
1067
1068 array[0] = (IGFolder)objArray[0];
1069 array[1] = (IGFolder)objArray[1];
1070 array[2] = (IGFolder)objArray[2];
1071
1072 return array;
1073 }
1074 catch (Exception e) {
1075 throw processException(e);
1076 }
1077 finally {
1078 closeSession(session);
1079 }
1080 }
1081
1082 public List<IGFolder> findByCompanyId(long companyId)
1083 throws SystemException {
1084 Object[] finderArgs = new Object[] { new Long(companyId) };
1085
1086 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1087 finderArgs, this);
1088
1089 if (list == null) {
1090 Session session = null;
1091
1092 try {
1093 session = openSession();
1094
1095 StringBuilder query = new StringBuilder();
1096
1097 query.append(
1098 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1099
1100 query.append("companyId = ?");
1101
1102 query.append(" ");
1103
1104 query.append("ORDER BY ");
1105
1106 query.append("folderId ASC, ");
1107 query.append("name ASC");
1108
1109 Query q = session.createQuery(query.toString());
1110
1111 QueryPos qPos = QueryPos.getInstance(q);
1112
1113 qPos.add(companyId);
1114
1115 list = q.list();
1116 }
1117 catch (Exception e) {
1118 throw processException(e);
1119 }
1120 finally {
1121 if (list == null) {
1122 list = new ArrayList<IGFolder>();
1123 }
1124
1125 cacheResult(list);
1126
1127 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1128 finderArgs, list);
1129
1130 closeSession(session);
1131 }
1132 }
1133
1134 return list;
1135 }
1136
1137 public List<IGFolder> findByCompanyId(long companyId, int start, int end)
1138 throws SystemException {
1139 return findByCompanyId(companyId, start, end, null);
1140 }
1141
1142 public List<IGFolder> findByCompanyId(long companyId, int start, int end,
1143 OrderByComparator obc) throws SystemException {
1144 Object[] finderArgs = new Object[] {
1145 new Long(companyId),
1146
1147 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1148 };
1149
1150 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1151 finderArgs, this);
1152
1153 if (list == null) {
1154 Session session = null;
1155
1156 try {
1157 session = openSession();
1158
1159 StringBuilder query = new StringBuilder();
1160
1161 query.append(
1162 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1163
1164 query.append("companyId = ?");
1165
1166 query.append(" ");
1167
1168 if (obc != null) {
1169 query.append("ORDER BY ");
1170 query.append(obc.getOrderBy());
1171 }
1172
1173 else {
1174 query.append("ORDER BY ");
1175
1176 query.append("folderId ASC, ");
1177 query.append("name ASC");
1178 }
1179
1180 Query q = session.createQuery(query.toString());
1181
1182 QueryPos qPos = QueryPos.getInstance(q);
1183
1184 qPos.add(companyId);
1185
1186 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
1187 end);
1188 }
1189 catch (Exception e) {
1190 throw processException(e);
1191 }
1192 finally {
1193 if (list == null) {
1194 list = new ArrayList<IGFolder>();
1195 }
1196
1197 cacheResult(list);
1198
1199 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1200 finderArgs, list);
1201
1202 closeSession(session);
1203 }
1204 }
1205
1206 return list;
1207 }
1208
1209 public IGFolder findByCompanyId_First(long companyId, OrderByComparator obc)
1210 throws NoSuchFolderException, SystemException {
1211 List<IGFolder> list = findByCompanyId(companyId, 0, 1, obc);
1212
1213 if (list.isEmpty()) {
1214 StringBuilder msg = new StringBuilder();
1215
1216 msg.append("No IGFolder exists with the key {");
1217
1218 msg.append("companyId=" + companyId);
1219
1220 msg.append(StringPool.CLOSE_CURLY_BRACE);
1221
1222 throw new NoSuchFolderException(msg.toString());
1223 }
1224 else {
1225 return list.get(0);
1226 }
1227 }
1228
1229 public IGFolder findByCompanyId_Last(long companyId, OrderByComparator obc)
1230 throws NoSuchFolderException, SystemException {
1231 int count = countByCompanyId(companyId);
1232
1233 List<IGFolder> list = findByCompanyId(companyId, count - 1, count, obc);
1234
1235 if (list.isEmpty()) {
1236 StringBuilder msg = new StringBuilder();
1237
1238 msg.append("No IGFolder exists with the key {");
1239
1240 msg.append("companyId=" + companyId);
1241
1242 msg.append(StringPool.CLOSE_CURLY_BRACE);
1243
1244 throw new NoSuchFolderException(msg.toString());
1245 }
1246 else {
1247 return list.get(0);
1248 }
1249 }
1250
1251 public IGFolder[] findByCompanyId_PrevAndNext(long folderId,
1252 long companyId, OrderByComparator obc)
1253 throws NoSuchFolderException, SystemException {
1254 IGFolder igFolder = findByPrimaryKey(folderId);
1255
1256 int count = countByCompanyId(companyId);
1257
1258 Session session = null;
1259
1260 try {
1261 session = openSession();
1262
1263 StringBuilder query = new StringBuilder();
1264
1265 query.append(
1266 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1267
1268 query.append("companyId = ?");
1269
1270 query.append(" ");
1271
1272 if (obc != null) {
1273 query.append("ORDER BY ");
1274 query.append(obc.getOrderBy());
1275 }
1276
1277 else {
1278 query.append("ORDER BY ");
1279
1280 query.append("folderId ASC, ");
1281 query.append("name ASC");
1282 }
1283
1284 Query q = session.createQuery(query.toString());
1285
1286 QueryPos qPos = QueryPos.getInstance(q);
1287
1288 qPos.add(companyId);
1289
1290 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
1291
1292 IGFolder[] array = new IGFolderImpl[3];
1293
1294 array[0] = (IGFolder)objArray[0];
1295 array[1] = (IGFolder)objArray[1];
1296 array[2] = (IGFolder)objArray[2];
1297
1298 return array;
1299 }
1300 catch (Exception e) {
1301 throw processException(e);
1302 }
1303 finally {
1304 closeSession(session);
1305 }
1306 }
1307
1308 public List<IGFolder> findByG_P(long groupId, long parentFolderId)
1309 throws SystemException {
1310 Object[] finderArgs = new Object[] {
1311 new Long(groupId), new Long(parentFolderId)
1312 };
1313
1314 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1315 finderArgs, this);
1316
1317 if (list == null) {
1318 Session session = null;
1319
1320 try {
1321 session = openSession();
1322
1323 StringBuilder query = new StringBuilder();
1324
1325 query.append(
1326 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1327
1328 query.append("groupId = ?");
1329
1330 query.append(" AND ");
1331
1332 query.append("parentFolderId = ?");
1333
1334 query.append(" ");
1335
1336 query.append("ORDER BY ");
1337
1338 query.append("folderId ASC, ");
1339 query.append("name ASC");
1340
1341 Query q = session.createQuery(query.toString());
1342
1343 QueryPos qPos = QueryPos.getInstance(q);
1344
1345 qPos.add(groupId);
1346
1347 qPos.add(parentFolderId);
1348
1349 list = q.list();
1350 }
1351 catch (Exception e) {
1352 throw processException(e);
1353 }
1354 finally {
1355 if (list == null) {
1356 list = new ArrayList<IGFolder>();
1357 }
1358
1359 cacheResult(list);
1360
1361 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
1362 list);
1363
1364 closeSession(session);
1365 }
1366 }
1367
1368 return list;
1369 }
1370
1371 public List<IGFolder> findByG_P(long groupId, long parentFolderId,
1372 int start, int end) throws SystemException {
1373 return findByG_P(groupId, parentFolderId, start, end, null);
1374 }
1375
1376 public List<IGFolder> findByG_P(long groupId, long parentFolderId,
1377 int start, int end, OrderByComparator obc) throws SystemException {
1378 Object[] finderArgs = new Object[] {
1379 new Long(groupId), new Long(parentFolderId),
1380
1381 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1382 };
1383
1384 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_P,
1385 finderArgs, this);
1386
1387 if (list == null) {
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 StringBuilder query = new StringBuilder();
1394
1395 query.append(
1396 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1397
1398 query.append("groupId = ?");
1399
1400 query.append(" AND ");
1401
1402 query.append("parentFolderId = ?");
1403
1404 query.append(" ");
1405
1406 if (obc != null) {
1407 query.append("ORDER BY ");
1408 query.append(obc.getOrderBy());
1409 }
1410
1411 else {
1412 query.append("ORDER BY ");
1413
1414 query.append("folderId ASC, ");
1415 query.append("name ASC");
1416 }
1417
1418 Query q = session.createQuery(query.toString());
1419
1420 QueryPos qPos = QueryPos.getInstance(q);
1421
1422 qPos.add(groupId);
1423
1424 qPos.add(parentFolderId);
1425
1426 list = (List<IGFolder>)QueryUtil.list(q, getDialect(), start,
1427 end);
1428 }
1429 catch (Exception e) {
1430 throw processException(e);
1431 }
1432 finally {
1433 if (list == null) {
1434 list = new ArrayList<IGFolder>();
1435 }
1436
1437 cacheResult(list);
1438
1439 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_P,
1440 finderArgs, list);
1441
1442 closeSession(session);
1443 }
1444 }
1445
1446 return list;
1447 }
1448
1449 public IGFolder findByG_P_First(long groupId, long parentFolderId,
1450 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1451 List<IGFolder> list = findByG_P(groupId, parentFolderId, 0, 1, obc);
1452
1453 if (list.isEmpty()) {
1454 StringBuilder msg = new StringBuilder();
1455
1456 msg.append("No IGFolder exists with the key {");
1457
1458 msg.append("groupId=" + groupId);
1459
1460 msg.append(", ");
1461 msg.append("parentFolderId=" + parentFolderId);
1462
1463 msg.append(StringPool.CLOSE_CURLY_BRACE);
1464
1465 throw new NoSuchFolderException(msg.toString());
1466 }
1467 else {
1468 return list.get(0);
1469 }
1470 }
1471
1472 public IGFolder findByG_P_Last(long groupId, long parentFolderId,
1473 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1474 int count = countByG_P(groupId, parentFolderId);
1475
1476 List<IGFolder> list = findByG_P(groupId, parentFolderId, count - 1,
1477 count, obc);
1478
1479 if (list.isEmpty()) {
1480 StringBuilder msg = new StringBuilder();
1481
1482 msg.append("No IGFolder exists with the key {");
1483
1484 msg.append("groupId=" + groupId);
1485
1486 msg.append(", ");
1487 msg.append("parentFolderId=" + parentFolderId);
1488
1489 msg.append(StringPool.CLOSE_CURLY_BRACE);
1490
1491 throw new NoSuchFolderException(msg.toString());
1492 }
1493 else {
1494 return list.get(0);
1495 }
1496 }
1497
1498 public IGFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
1499 long parentFolderId, OrderByComparator obc)
1500 throws NoSuchFolderException, SystemException {
1501 IGFolder igFolder = findByPrimaryKey(folderId);
1502
1503 int count = countByG_P(groupId, parentFolderId);
1504
1505 Session session = null;
1506
1507 try {
1508 session = openSession();
1509
1510 StringBuilder query = new StringBuilder();
1511
1512 query.append(
1513 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1514
1515 query.append("groupId = ?");
1516
1517 query.append(" AND ");
1518
1519 query.append("parentFolderId = ?");
1520
1521 query.append(" ");
1522
1523 if (obc != null) {
1524 query.append("ORDER BY ");
1525 query.append(obc.getOrderBy());
1526 }
1527
1528 else {
1529 query.append("ORDER BY ");
1530
1531 query.append("folderId ASC, ");
1532 query.append("name ASC");
1533 }
1534
1535 Query q = session.createQuery(query.toString());
1536
1537 QueryPos qPos = QueryPos.getInstance(q);
1538
1539 qPos.add(groupId);
1540
1541 qPos.add(parentFolderId);
1542
1543 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
1544
1545 IGFolder[] array = new IGFolderImpl[3];
1546
1547 array[0] = (IGFolder)objArray[0];
1548 array[1] = (IGFolder)objArray[1];
1549 array[2] = (IGFolder)objArray[2];
1550
1551 return array;
1552 }
1553 catch (Exception e) {
1554 throw processException(e);
1555 }
1556 finally {
1557 closeSession(session);
1558 }
1559 }
1560
1561 public IGFolder findByG_P_N(long groupId, long parentFolderId, String name)
1562 throws NoSuchFolderException, SystemException {
1563 IGFolder igFolder = fetchByG_P_N(groupId, parentFolderId, name);
1564
1565 if (igFolder == null) {
1566 StringBuilder msg = new StringBuilder();
1567
1568 msg.append("No IGFolder exists with the key {");
1569
1570 msg.append("groupId=" + groupId);
1571
1572 msg.append(", ");
1573 msg.append("parentFolderId=" + parentFolderId);
1574
1575 msg.append(", ");
1576 msg.append("name=" + name);
1577
1578 msg.append(StringPool.CLOSE_CURLY_BRACE);
1579
1580 if (_log.isWarnEnabled()) {
1581 _log.warn(msg.toString());
1582 }
1583
1584 throw new NoSuchFolderException(msg.toString());
1585 }
1586
1587 return igFolder;
1588 }
1589
1590 public IGFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
1591 throws SystemException {
1592 return fetchByG_P_N(groupId, parentFolderId, name, true);
1593 }
1594
1595 public IGFolder fetchByG_P_N(long groupId, long parentFolderId,
1596 String name, boolean retrieveFromCache) throws SystemException {
1597 Object[] finderArgs = new Object[] {
1598 new Long(groupId), new Long(parentFolderId),
1599
1600 name
1601 };
1602
1603 Object result = null;
1604
1605 if (retrieveFromCache) {
1606 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
1607 finderArgs, this);
1608 }
1609
1610 if (result == null) {
1611 Session session = null;
1612
1613 try {
1614 session = openSession();
1615
1616 StringBuilder query = new StringBuilder();
1617
1618 query.append(
1619 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1620
1621 query.append("groupId = ?");
1622
1623 query.append(" AND ");
1624
1625 query.append("parentFolderId = ?");
1626
1627 query.append(" AND ");
1628
1629 if (name == null) {
1630 query.append("name IS NULL");
1631 }
1632 else {
1633 query.append("name = ?");
1634 }
1635
1636 query.append(" ");
1637
1638 query.append("ORDER BY ");
1639
1640 query.append("folderId ASC, ");
1641 query.append("name ASC");
1642
1643 Query q = session.createQuery(query.toString());
1644
1645 QueryPos qPos = QueryPos.getInstance(q);
1646
1647 qPos.add(groupId);
1648
1649 qPos.add(parentFolderId);
1650
1651 if (name != null) {
1652 qPos.add(name);
1653 }
1654
1655 List<IGFolder> list = q.list();
1656
1657 result = list;
1658
1659 IGFolder igFolder = null;
1660
1661 if (list.isEmpty()) {
1662 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
1663 finderArgs, list);
1664 }
1665 else {
1666 igFolder = list.get(0);
1667
1668 cacheResult(igFolder);
1669
1670 if ((igFolder.getGroupId() != groupId) ||
1671 (igFolder.getParentFolderId() != parentFolderId) ||
1672 (igFolder.getName() == null) ||
1673 !igFolder.getName().equals(name)) {
1674 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
1675 finderArgs, igFolder);
1676 }
1677 }
1678
1679 return igFolder;
1680 }
1681 catch (Exception e) {
1682 throw processException(e);
1683 }
1684 finally {
1685 if (result == null) {
1686 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
1687 finderArgs, new ArrayList<IGFolder>());
1688 }
1689
1690 closeSession(session);
1691 }
1692 }
1693 else {
1694 if (result instanceof List) {
1695 return null;
1696 }
1697 else {
1698 return (IGFolder)result;
1699 }
1700 }
1701 }
1702
1703 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1704 throws SystemException {
1705 Session session = null;
1706
1707 try {
1708 session = openSession();
1709
1710 dynamicQuery.compile(session);
1711
1712 return dynamicQuery.list();
1713 }
1714 catch (Exception e) {
1715 throw processException(e);
1716 }
1717 finally {
1718 closeSession(session);
1719 }
1720 }
1721
1722 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1723 int start, int end) throws SystemException {
1724 Session session = null;
1725
1726 try {
1727 session = openSession();
1728
1729 dynamicQuery.setLimit(start, end);
1730
1731 dynamicQuery.compile(session);
1732
1733 return dynamicQuery.list();
1734 }
1735 catch (Exception e) {
1736 throw processException(e);
1737 }
1738 finally {
1739 closeSession(session);
1740 }
1741 }
1742
1743 public List<IGFolder> findAll() throws SystemException {
1744 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1745 }
1746
1747 public List<IGFolder> findAll(int start, int end) throws SystemException {
1748 return findAll(start, end, null);
1749 }
1750
1751 public List<IGFolder> findAll(int start, int end, OrderByComparator obc)
1752 throws SystemException {
1753 Object[] finderArgs = new Object[] {
1754 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1755 };
1756
1757 List<IGFolder> list = (List<IGFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1758 finderArgs, this);
1759
1760 if (list == null) {
1761 Session session = null;
1762
1763 try {
1764 session = openSession();
1765
1766 StringBuilder query = new StringBuilder();
1767
1768 query.append(
1769 "FROM com.liferay.portlet.imagegallery.model.IGFolder ");
1770
1771 if (obc != null) {
1772 query.append("ORDER BY ");
1773 query.append(obc.getOrderBy());
1774 }
1775
1776 else {
1777 query.append("ORDER BY ");
1778
1779 query.append("folderId ASC, ");
1780 query.append("name ASC");
1781 }
1782
1783 Query q = session.createQuery(query.toString());
1784
1785 if (obc == null) {
1786 list = (List<IGFolder>)QueryUtil.list(q, getDialect(),
1787 start, end, false);
1788
1789 Collections.sort(list);
1790 }
1791 else {
1792 list = (List<IGFolder>)QueryUtil.list(q, getDialect(),
1793 start, end);
1794 }
1795 }
1796 catch (Exception e) {
1797 throw processException(e);
1798 }
1799 finally {
1800 if (list == null) {
1801 list = new ArrayList<IGFolder>();
1802 }
1803
1804 cacheResult(list);
1805
1806 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1807
1808 closeSession(session);
1809 }
1810 }
1811
1812 return list;
1813 }
1814
1815 public void removeByUuid(String uuid) throws SystemException {
1816 for (IGFolder igFolder : findByUuid(uuid)) {
1817 remove(igFolder);
1818 }
1819 }
1820
1821 public void removeByUUID_G(String uuid, long groupId)
1822 throws NoSuchFolderException, SystemException {
1823 IGFolder igFolder = findByUUID_G(uuid, groupId);
1824
1825 remove(igFolder);
1826 }
1827
1828 public void removeByGroupId(long groupId) throws SystemException {
1829 for (IGFolder igFolder : findByGroupId(groupId)) {
1830 remove(igFolder);
1831 }
1832 }
1833
1834 public void removeByCompanyId(long companyId) throws SystemException {
1835 for (IGFolder igFolder : findByCompanyId(companyId)) {
1836 remove(igFolder);
1837 }
1838 }
1839
1840 public void removeByG_P(long groupId, long parentFolderId)
1841 throws SystemException {
1842 for (IGFolder igFolder : findByG_P(groupId, parentFolderId)) {
1843 remove(igFolder);
1844 }
1845 }
1846
1847 public void removeByG_P_N(long groupId, long parentFolderId, String name)
1848 throws NoSuchFolderException, SystemException {
1849 IGFolder igFolder = findByG_P_N(groupId, parentFolderId, name);
1850
1851 remove(igFolder);
1852 }
1853
1854 public void removeAll() throws SystemException {
1855 for (IGFolder igFolder : findAll()) {
1856 remove(igFolder);
1857 }
1858 }
1859
1860 public int countByUuid(String uuid) throws SystemException {
1861 Object[] finderArgs = new Object[] { uuid };
1862
1863 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1864 finderArgs, this);
1865
1866 if (count == null) {
1867 Session session = null;
1868
1869 try {
1870 session = openSession();
1871
1872 StringBuilder query = new StringBuilder();
1873
1874 query.append("SELECT COUNT(*) ");
1875 query.append(
1876 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1877
1878 if (uuid == null) {
1879 query.append("uuid_ IS NULL");
1880 }
1881 else {
1882 query.append("uuid_ = ?");
1883 }
1884
1885 query.append(" ");
1886
1887 Query q = session.createQuery(query.toString());
1888
1889 QueryPos qPos = QueryPos.getInstance(q);
1890
1891 if (uuid != null) {
1892 qPos.add(uuid);
1893 }
1894
1895 count = (Long)q.uniqueResult();
1896 }
1897 catch (Exception e) {
1898 throw processException(e);
1899 }
1900 finally {
1901 if (count == null) {
1902 count = Long.valueOf(0);
1903 }
1904
1905 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1906 finderArgs, count);
1907
1908 closeSession(session);
1909 }
1910 }
1911
1912 return count.intValue();
1913 }
1914
1915 public int countByUUID_G(String uuid, long groupId)
1916 throws SystemException {
1917 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1918
1919 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1920 finderArgs, this);
1921
1922 if (count == null) {
1923 Session session = null;
1924
1925 try {
1926 session = openSession();
1927
1928 StringBuilder query = new StringBuilder();
1929
1930 query.append("SELECT COUNT(*) ");
1931 query.append(
1932 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1933
1934 if (uuid == null) {
1935 query.append("uuid_ IS NULL");
1936 }
1937 else {
1938 query.append("uuid_ = ?");
1939 }
1940
1941 query.append(" AND ");
1942
1943 query.append("groupId = ?");
1944
1945 query.append(" ");
1946
1947 Query q = session.createQuery(query.toString());
1948
1949 QueryPos qPos = QueryPos.getInstance(q);
1950
1951 if (uuid != null) {
1952 qPos.add(uuid);
1953 }
1954
1955 qPos.add(groupId);
1956
1957 count = (Long)q.uniqueResult();
1958 }
1959 catch (Exception e) {
1960 throw processException(e);
1961 }
1962 finally {
1963 if (count == null) {
1964 count = Long.valueOf(0);
1965 }
1966
1967 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1968 finderArgs, count);
1969
1970 closeSession(session);
1971 }
1972 }
1973
1974 return count.intValue();
1975 }
1976
1977 public int countByGroupId(long groupId) throws SystemException {
1978 Object[] finderArgs = new Object[] { new Long(groupId) };
1979
1980 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1981 finderArgs, this);
1982
1983 if (count == null) {
1984 Session session = null;
1985
1986 try {
1987 session = openSession();
1988
1989 StringBuilder query = new StringBuilder();
1990
1991 query.append("SELECT COUNT(*) ");
1992 query.append(
1993 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1994
1995 query.append("groupId = ?");
1996
1997 query.append(" ");
1998
1999 Query q = session.createQuery(query.toString());
2000
2001 QueryPos qPos = QueryPos.getInstance(q);
2002
2003 qPos.add(groupId);
2004
2005 count = (Long)q.uniqueResult();
2006 }
2007 catch (Exception e) {
2008 throw processException(e);
2009 }
2010 finally {
2011 if (count == null) {
2012 count = Long.valueOf(0);
2013 }
2014
2015 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2016 finderArgs, count);
2017
2018 closeSession(session);
2019 }
2020 }
2021
2022 return count.intValue();
2023 }
2024
2025 public int countByCompanyId(long companyId) throws SystemException {
2026 Object[] finderArgs = new Object[] { new Long(companyId) };
2027
2028 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2029 finderArgs, this);
2030
2031 if (count == null) {
2032 Session session = null;
2033
2034 try {
2035 session = openSession();
2036
2037 StringBuilder query = new StringBuilder();
2038
2039 query.append("SELECT COUNT(*) ");
2040 query.append(
2041 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
2042
2043 query.append("companyId = ?");
2044
2045 query.append(" ");
2046
2047 Query q = session.createQuery(query.toString());
2048
2049 QueryPos qPos = QueryPos.getInstance(q);
2050
2051 qPos.add(companyId);
2052
2053 count = (Long)q.uniqueResult();
2054 }
2055 catch (Exception e) {
2056 throw processException(e);
2057 }
2058 finally {
2059 if (count == null) {
2060 count = Long.valueOf(0);
2061 }
2062
2063 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2064 finderArgs, count);
2065
2066 closeSession(session);
2067 }
2068 }
2069
2070 return count.intValue();
2071 }
2072
2073 public int countByG_P(long groupId, long parentFolderId)
2074 throws SystemException {
2075 Object[] finderArgs = new Object[] {
2076 new Long(groupId), new Long(parentFolderId)
2077 };
2078
2079 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
2080 finderArgs, this);
2081
2082 if (count == null) {
2083 Session session = null;
2084
2085 try {
2086 session = openSession();
2087
2088 StringBuilder query = new StringBuilder();
2089
2090 query.append("SELECT COUNT(*) ");
2091 query.append(
2092 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
2093
2094 query.append("groupId = ?");
2095
2096 query.append(" AND ");
2097
2098 query.append("parentFolderId = ?");
2099
2100 query.append(" ");
2101
2102 Query q = session.createQuery(query.toString());
2103
2104 QueryPos qPos = QueryPos.getInstance(q);
2105
2106 qPos.add(groupId);
2107
2108 qPos.add(parentFolderId);
2109
2110 count = (Long)q.uniqueResult();
2111 }
2112 catch (Exception e) {
2113 throw processException(e);
2114 }
2115 finally {
2116 if (count == null) {
2117 count = Long.valueOf(0);
2118 }
2119
2120 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
2121 count);
2122
2123 closeSession(session);
2124 }
2125 }
2126
2127 return count.intValue();
2128 }
2129
2130 public int countByG_P_N(long groupId, long parentFolderId, String name)
2131 throws SystemException {
2132 Object[] finderArgs = new Object[] {
2133 new Long(groupId), new Long(parentFolderId),
2134
2135 name
2136 };
2137
2138 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_N,
2139 finderArgs, this);
2140
2141 if (count == null) {
2142 Session session = null;
2143
2144 try {
2145 session = openSession();
2146
2147 StringBuilder query = new StringBuilder();
2148
2149 query.append("SELECT COUNT(*) ");
2150 query.append(
2151 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
2152
2153 query.append("groupId = ?");
2154
2155 query.append(" AND ");
2156
2157 query.append("parentFolderId = ?");
2158
2159 query.append(" AND ");
2160
2161 if (name == null) {
2162 query.append("name IS NULL");
2163 }
2164 else {
2165 query.append("name = ?");
2166 }
2167
2168 query.append(" ");
2169
2170 Query q = session.createQuery(query.toString());
2171
2172 QueryPos qPos = QueryPos.getInstance(q);
2173
2174 qPos.add(groupId);
2175
2176 qPos.add(parentFolderId);
2177
2178 if (name != null) {
2179 qPos.add(name);
2180 }
2181
2182 count = (Long)q.uniqueResult();
2183 }
2184 catch (Exception e) {
2185 throw processException(e);
2186 }
2187 finally {
2188 if (count == null) {
2189 count = Long.valueOf(0);
2190 }
2191
2192 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N,
2193 finderArgs, count);
2194
2195 closeSession(session);
2196 }
2197 }
2198
2199 return count.intValue();
2200 }
2201
2202 public int countAll() throws SystemException {
2203 Object[] finderArgs = new Object[0];
2204
2205 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2206 finderArgs, this);
2207
2208 if (count == null) {
2209 Session session = null;
2210
2211 try {
2212 session = openSession();
2213
2214 Query q = session.createQuery(
2215 "SELECT COUNT(*) FROM com.liferay.portlet.imagegallery.model.IGFolder");
2216
2217 count = (Long)q.uniqueResult();
2218 }
2219 catch (Exception e) {
2220 throw processException(e);
2221 }
2222 finally {
2223 if (count == null) {
2224 count = Long.valueOf(0);
2225 }
2226
2227 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2228 count);
2229
2230 closeSession(session);
2231 }
2232 }
2233
2234 return count.intValue();
2235 }
2236
2237 public void afterPropertiesSet() {
2238 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2239 com.liferay.portal.util.PropsUtil.get(
2240 "value.object.listener.com.liferay.portlet.imagegallery.model.IGFolder")));
2241
2242 if (listenerClassNames.length > 0) {
2243 try {
2244 List<ModelListener<IGFolder>> listenersList = new ArrayList<ModelListener<IGFolder>>();
2245
2246 for (String listenerClassName : listenerClassNames) {
2247 listenersList.add((ModelListener<IGFolder>)Class.forName(
2248 listenerClassName).newInstance());
2249 }
2250
2251 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2252 }
2253 catch (Exception e) {
2254 _log.error(e);
2255 }
2256 }
2257 }
2258
2259 @BeanReference(name = "com.liferay.portlet.imagegallery.service.persistence.IGFolderPersistence.impl")
2260 protected com.liferay.portlet.imagegallery.service.persistence.IGFolderPersistence igFolderPersistence;
2261 @BeanReference(name = "com.liferay.portlet.imagegallery.service.persistence.IGImagePersistence.impl")
2262 protected com.liferay.portlet.imagegallery.service.persistence.IGImagePersistence igImagePersistence;
2263 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
2264 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
2265 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
2266 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
2267 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2268 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2269 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2270 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2271 @BeanReference(name = "com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence.impl")
2272 protected com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence expandoValuePersistence;
2273 private static Log _log = LogFactoryUtil.getLog(IGFolderPersistenceImpl.class);
2274}