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