001
014
015 package com.liferay.portlet.imagegallery.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.BatchSessionUtil;
042 import com.liferay.portal.service.persistence.ImagePersistence;
043 import com.liferay.portal.service.persistence.ResourcePersistence;
044 import com.liferay.portal.service.persistence.UserPersistence;
045 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046
047 import com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence;
048 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
049 import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
050 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
051 import com.liferay.portlet.imagegallery.NoSuchImageException;
052 import com.liferay.portlet.imagegallery.model.IGImage;
053 import com.liferay.portlet.imagegallery.model.impl.IGImageImpl;
054 import com.liferay.portlet.imagegallery.model.impl.IGImageModelImpl;
055 import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
056
057 import java.io.Serializable;
058
059 import java.util.ArrayList;
060 import java.util.Collections;
061 import java.util.List;
062
063
079 public class IGImagePersistenceImpl extends BasePersistenceImpl<IGImage>
080 implements IGImagePersistence {
081 public static final String FINDER_CLASS_NAME_ENTITY = IGImageImpl.class.getName();
082 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
083 ".List";
084 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
085 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
086 "findByUuid",
087 new String[] {
088 String.class.getName(),
089
090 "java.lang.Integer", "java.lang.Integer",
091 "com.liferay.portal.kernel.util.OrderByComparator"
092 });
093 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
094 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
095 "countByUuid", new String[] { String.class.getName() });
096 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
097 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
098 "fetchByUUID_G",
099 new String[] { String.class.getName(), Long.class.getName() });
100 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
101 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102 "countByUUID_G",
103 new String[] { String.class.getName(), Long.class.getName() });
104 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
105 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106 "findByGroupId",
107 new String[] {
108 Long.class.getName(),
109
110 "java.lang.Integer", "java.lang.Integer",
111 "com.liferay.portal.kernel.util.OrderByComparator"
112 });
113 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
114 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115 "countByGroupId", new String[] { Long.class.getName() });
116 public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
117 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
118 "fetchBySmallImageId", new String[] { Long.class.getName() });
119 public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
120 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121 "countBySmallImageId", new String[] { Long.class.getName() });
122 public static final FinderPath FINDER_PATH_FETCH_BY_LARGEIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
123 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
124 "fetchByLargeImageId", new String[] { Long.class.getName() });
125 public static final FinderPath FINDER_PATH_COUNT_BY_LARGEIMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
126 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127 "countByLargeImageId", new String[] { Long.class.getName() });
128 public static final FinderPath FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
129 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
130 "fetchByCustom1ImageId", new String[] { Long.class.getName() });
131 public static final FinderPath FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
132 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133 "countByCustom1ImageId", new String[] { Long.class.getName() });
134 public static final FinderPath FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
135 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
136 "fetchByCustom2ImageId", new String[] { Long.class.getName() });
137 public static final FinderPath FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
138 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
139 "countByCustom2ImageId", new String[] { Long.class.getName() });
140 public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
141 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
142 "findByG_U",
143 new String[] {
144 Long.class.getName(), Long.class.getName(),
145
146 "java.lang.Integer", "java.lang.Integer",
147 "com.liferay.portal.kernel.util.OrderByComparator"
148 });
149 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
150 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
151 "countByG_U",
152 new String[] { Long.class.getName(), Long.class.getName() });
153 public static final FinderPath FINDER_PATH_FIND_BY_G_F = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
154 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
155 "findByG_F",
156 new String[] {
157 Long.class.getName(), Long.class.getName(),
158
159 "java.lang.Integer", "java.lang.Integer",
160 "com.liferay.portal.kernel.util.OrderByComparator"
161 });
162 public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
163 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
164 "countByG_F",
165 new String[] { Long.class.getName(), Long.class.getName() });
166 public static final FinderPath FINDER_PATH_FIND_BY_G_F_N = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
167 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
168 "findByG_F_N",
169 new String[] {
170 Long.class.getName(), Long.class.getName(),
171 String.class.getName(),
172
173 "java.lang.Integer", "java.lang.Integer",
174 "com.liferay.portal.kernel.util.OrderByComparator"
175 });
176 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
177 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
178 "countByG_F_N",
179 new String[] {
180 Long.class.getName(), Long.class.getName(),
181 String.class.getName()
182 });
183 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
184 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
185 "findAll", new String[0]);
186 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(IGImageModelImpl.ENTITY_CACHE_ENABLED,
187 IGImageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
188 "countAll", new String[0]);
189
190
195 public void cacheResult(IGImage igImage) {
196 EntityCacheUtil.putResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
197 IGImageImpl.class, igImage.getPrimaryKey(), igImage);
198
199 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
200 new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) },
201 igImage);
202
203 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
204 new Object[] { new Long(igImage.getSmallImageId()) }, igImage);
205
206 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
207 new Object[] { new Long(igImage.getLargeImageId()) }, igImage);
208
209 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
210 new Object[] { new Long(igImage.getCustom1ImageId()) }, igImage);
211
212 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
213 new Object[] { new Long(igImage.getCustom2ImageId()) }, igImage);
214 }
215
216
221 public void cacheResult(List<IGImage> igImages) {
222 for (IGImage igImage : igImages) {
223 if (EntityCacheUtil.getResult(
224 IGImageModelImpl.ENTITY_CACHE_ENABLED,
225 IGImageImpl.class, igImage.getPrimaryKey(), this) == null) {
226 cacheResult(igImage);
227 }
228 }
229 }
230
231
238 public void clearCache() {
239 CacheRegistryUtil.clear(IGImageImpl.class.getName());
240 EntityCacheUtil.clearCache(IGImageImpl.class.getName());
241 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
242 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243 }
244
245
252 public void clearCache(IGImage igImage) {
253 EntityCacheUtil.removeResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
254 IGImageImpl.class, igImage.getPrimaryKey());
255
256 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
257 new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) });
258
259 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
260 new Object[] { new Long(igImage.getSmallImageId()) });
261
262 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
263 new Object[] { new Long(igImage.getLargeImageId()) });
264
265 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
266 new Object[] { new Long(igImage.getCustom1ImageId()) });
267
268 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
269 new Object[] { new Long(igImage.getCustom2ImageId()) });
270 }
271
272
278 public IGImage create(long imageId) {
279 IGImage igImage = new IGImageImpl();
280
281 igImage.setNew(true);
282 igImage.setPrimaryKey(imageId);
283
284 String uuid = PortalUUIDUtil.generate();
285
286 igImage.setUuid(uuid);
287
288 return igImage;
289 }
290
291
299 public IGImage remove(Serializable primaryKey)
300 throws NoSuchModelException, SystemException {
301 return remove(((Long)primaryKey).longValue());
302 }
303
304
312 public IGImage remove(long imageId)
313 throws NoSuchImageException, SystemException {
314 Session session = null;
315
316 try {
317 session = openSession();
318
319 IGImage igImage = (IGImage)session.get(IGImageImpl.class,
320 new Long(imageId));
321
322 if (igImage == null) {
323 if (_log.isWarnEnabled()) {
324 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + imageId);
325 }
326
327 throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
328 imageId);
329 }
330
331 return remove(igImage);
332 }
333 catch (NoSuchImageException nsee) {
334 throw nsee;
335 }
336 catch (Exception e) {
337 throw processException(e);
338 }
339 finally {
340 closeSession(session);
341 }
342 }
343
344 protected IGImage removeImpl(IGImage igImage) throws SystemException {
345 igImage = toUnwrappedModel(igImage);
346
347 Session session = null;
348
349 try {
350 session = openSession();
351
352 BatchSessionUtil.delete(session, igImage);
353 }
354 catch (Exception e) {
355 throw processException(e);
356 }
357 finally {
358 closeSession(session);
359 }
360
361 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
362
363 IGImageModelImpl igImageModelImpl = (IGImageModelImpl)igImage;
364
365 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
366 new Object[] {
367 igImageModelImpl.getUuid(),
368 new Long(igImageModelImpl.getGroupId())
369 });
370
371 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
372 new Object[] { new Long(igImageModelImpl.getSmallImageId()) });
373
374 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
375 new Object[] { new Long(igImageModelImpl.getLargeImageId()) });
376
377 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
378 new Object[] { new Long(igImageModelImpl.getCustom1ImageId()) });
379
380 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
381 new Object[] { new Long(igImageModelImpl.getCustom2ImageId()) });
382
383 EntityCacheUtil.removeResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
384 IGImageImpl.class, igImage.getPrimaryKey());
385
386 return igImage;
387 }
388
389 public IGImage updateImpl(
390 com.liferay.portlet.imagegallery.model.IGImage igImage, boolean merge)
391 throws SystemException {
392 igImage = toUnwrappedModel(igImage);
393
394 boolean isNew = igImage.isNew();
395
396 IGImageModelImpl igImageModelImpl = (IGImageModelImpl)igImage;
397
398 if (Validator.isNull(igImage.getUuid())) {
399 String uuid = PortalUUIDUtil.generate();
400
401 igImage.setUuid(uuid);
402 }
403
404 Session session = null;
405
406 try {
407 session = openSession();
408
409 BatchSessionUtil.update(session, igImage, merge);
410
411 igImage.setNew(false);
412 }
413 catch (Exception e) {
414 throw processException(e);
415 }
416 finally {
417 closeSession(session);
418 }
419
420 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
421
422 EntityCacheUtil.putResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
423 IGImageImpl.class, igImage.getPrimaryKey(), igImage);
424
425 if (!isNew &&
426 (!Validator.equals(igImage.getUuid(),
427 igImageModelImpl.getOriginalUuid()) ||
428 (igImage.getGroupId() != igImageModelImpl.getOriginalGroupId()))) {
429 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
430 new Object[] {
431 igImageModelImpl.getOriginalUuid(),
432 new Long(igImageModelImpl.getOriginalGroupId())
433 });
434 }
435
436 if (isNew ||
437 (!Validator.equals(igImage.getUuid(),
438 igImageModelImpl.getOriginalUuid()) ||
439 (igImage.getGroupId() != igImageModelImpl.getOriginalGroupId()))) {
440 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
441 new Object[] { igImage.getUuid(), new Long(igImage.getGroupId()) },
442 igImage);
443 }
444
445 if (!isNew &&
446 (igImage.getSmallImageId() != igImageModelImpl.getOriginalSmallImageId())) {
447 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
448 new Object[] {
449 new Long(igImageModelImpl.getOriginalSmallImageId())
450 });
451 }
452
453 if (isNew ||
454 (igImage.getSmallImageId() != igImageModelImpl.getOriginalSmallImageId())) {
455 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
456 new Object[] { new Long(igImage.getSmallImageId()) }, igImage);
457 }
458
459 if (!isNew &&
460 (igImage.getLargeImageId() != igImageModelImpl.getOriginalLargeImageId())) {
461 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
462 new Object[] {
463 new Long(igImageModelImpl.getOriginalLargeImageId())
464 });
465 }
466
467 if (isNew ||
468 (igImage.getLargeImageId() != igImageModelImpl.getOriginalLargeImageId())) {
469 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
470 new Object[] { new Long(igImage.getLargeImageId()) }, igImage);
471 }
472
473 if (!isNew &&
474 (igImage.getCustom1ImageId() != igImageModelImpl.getOriginalCustom1ImageId())) {
475 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
476 new Object[] {
477 new Long(igImageModelImpl.getOriginalCustom1ImageId())
478 });
479 }
480
481 if (isNew ||
482 (igImage.getCustom1ImageId() != igImageModelImpl.getOriginalCustom1ImageId())) {
483 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
484 new Object[] { new Long(igImage.getCustom1ImageId()) }, igImage);
485 }
486
487 if (!isNew &&
488 (igImage.getCustom2ImageId() != igImageModelImpl.getOriginalCustom2ImageId())) {
489 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
490 new Object[] {
491 new Long(igImageModelImpl.getOriginalCustom2ImageId())
492 });
493 }
494
495 if (isNew ||
496 (igImage.getCustom2ImageId() != igImageModelImpl.getOriginalCustom2ImageId())) {
497 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
498 new Object[] { new Long(igImage.getCustom2ImageId()) }, igImage);
499 }
500
501 return igImage;
502 }
503
504 protected IGImage toUnwrappedModel(IGImage igImage) {
505 if (igImage instanceof IGImageImpl) {
506 return igImage;
507 }
508
509 IGImageImpl igImageImpl = new IGImageImpl();
510
511 igImageImpl.setNew(igImage.isNew());
512 igImageImpl.setPrimaryKey(igImage.getPrimaryKey());
513
514 igImageImpl.setUuid(igImage.getUuid());
515 igImageImpl.setImageId(igImage.getImageId());
516 igImageImpl.setGroupId(igImage.getGroupId());
517 igImageImpl.setCompanyId(igImage.getCompanyId());
518 igImageImpl.setUserId(igImage.getUserId());
519 igImageImpl.setCreateDate(igImage.getCreateDate());
520 igImageImpl.setModifiedDate(igImage.getModifiedDate());
521 igImageImpl.setFolderId(igImage.getFolderId());
522 igImageImpl.setName(igImage.getName());
523 igImageImpl.setDescription(igImage.getDescription());
524 igImageImpl.setSmallImageId(igImage.getSmallImageId());
525 igImageImpl.setLargeImageId(igImage.getLargeImageId());
526 igImageImpl.setCustom1ImageId(igImage.getCustom1ImageId());
527 igImageImpl.setCustom2ImageId(igImage.getCustom2ImageId());
528
529 return igImageImpl;
530 }
531
532
540 public IGImage findByPrimaryKey(Serializable primaryKey)
541 throws NoSuchModelException, SystemException {
542 return findByPrimaryKey(((Long)primaryKey).longValue());
543 }
544
545
553 public IGImage findByPrimaryKey(long imageId)
554 throws NoSuchImageException, SystemException {
555 IGImage igImage = fetchByPrimaryKey(imageId);
556
557 if (igImage == null) {
558 if (_log.isWarnEnabled()) {
559 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + imageId);
560 }
561
562 throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
563 imageId);
564 }
565
566 return igImage;
567 }
568
569
576 public IGImage fetchByPrimaryKey(Serializable primaryKey)
577 throws SystemException {
578 return fetchByPrimaryKey(((Long)primaryKey).longValue());
579 }
580
581
588 public IGImage fetchByPrimaryKey(long imageId) throws SystemException {
589 IGImage igImage = (IGImage)EntityCacheUtil.getResult(IGImageModelImpl.ENTITY_CACHE_ENABLED,
590 IGImageImpl.class, imageId, this);
591
592 if (igImage == null) {
593 Session session = null;
594
595 try {
596 session = openSession();
597
598 igImage = (IGImage)session.get(IGImageImpl.class,
599 new Long(imageId));
600 }
601 catch (Exception e) {
602 throw processException(e);
603 }
604 finally {
605 if (igImage != null) {
606 cacheResult(igImage);
607 }
608
609 closeSession(session);
610 }
611 }
612
613 return igImage;
614 }
615
616
623 public List<IGImage> findByUuid(String uuid) throws SystemException {
624 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
625 }
626
627
640 public List<IGImage> findByUuid(String uuid, int start, int end)
641 throws SystemException {
642 return findByUuid(uuid, start, end, null);
643 }
644
645
659 public List<IGImage> findByUuid(String uuid, int start, int end,
660 OrderByComparator orderByComparator) throws SystemException {
661 Object[] finderArgs = new Object[] {
662 uuid,
663
664 String.valueOf(start), String.valueOf(end),
665 String.valueOf(orderByComparator)
666 };
667
668 List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
669 finderArgs, this);
670
671 if (list == null) {
672 StringBundler query = null;
673
674 if (orderByComparator != null) {
675 query = new StringBundler(3 +
676 (orderByComparator.getOrderByFields().length * 3));
677 }
678 else {
679 query = new StringBundler(3);
680 }
681
682 query.append(_SQL_SELECT_IGIMAGE_WHERE);
683
684 if (uuid == null) {
685 query.append(_FINDER_COLUMN_UUID_UUID_1);
686 }
687 else {
688 if (uuid.equals(StringPool.BLANK)) {
689 query.append(_FINDER_COLUMN_UUID_UUID_3);
690 }
691 else {
692 query.append(_FINDER_COLUMN_UUID_UUID_2);
693 }
694 }
695
696 if (orderByComparator != null) {
697 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
698 orderByComparator);
699 }
700
701 else {
702 query.append(IGImageModelImpl.ORDER_BY_JPQL);
703 }
704
705 String sql = query.toString();
706
707 Session session = null;
708
709 try {
710 session = openSession();
711
712 Query q = session.createQuery(sql);
713
714 QueryPos qPos = QueryPos.getInstance(q);
715
716 if (uuid != null) {
717 qPos.add(uuid);
718 }
719
720 list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
721 }
722 catch (Exception e) {
723 throw processException(e);
724 }
725 finally {
726 if (list == null) {
727 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
728 finderArgs);
729 }
730 else {
731 cacheResult(list);
732
733 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
734 finderArgs, list);
735 }
736
737 closeSession(session);
738 }
739 }
740
741 return list;
742 }
743
744
757 public IGImage findByUuid_First(String uuid,
758 OrderByComparator orderByComparator)
759 throws NoSuchImageException, SystemException {
760 List<IGImage> list = findByUuid(uuid, 0, 1, orderByComparator);
761
762 if (list.isEmpty()) {
763 StringBundler msg = new StringBundler(4);
764
765 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
766
767 msg.append("uuid=");
768 msg.append(uuid);
769
770 msg.append(StringPool.CLOSE_CURLY_BRACE);
771
772 throw new NoSuchImageException(msg.toString());
773 }
774 else {
775 return list.get(0);
776 }
777 }
778
779
792 public IGImage findByUuid_Last(String uuid,
793 OrderByComparator orderByComparator)
794 throws NoSuchImageException, SystemException {
795 int count = countByUuid(uuid);
796
797 List<IGImage> list = findByUuid(uuid, count - 1, count,
798 orderByComparator);
799
800 if (list.isEmpty()) {
801 StringBundler msg = new StringBundler(4);
802
803 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
804
805 msg.append("uuid=");
806 msg.append(uuid);
807
808 msg.append(StringPool.CLOSE_CURLY_BRACE);
809
810 throw new NoSuchImageException(msg.toString());
811 }
812 else {
813 return list.get(0);
814 }
815 }
816
817
831 public IGImage[] findByUuid_PrevAndNext(long imageId, String uuid,
832 OrderByComparator orderByComparator)
833 throws NoSuchImageException, SystemException {
834 IGImage igImage = findByPrimaryKey(imageId);
835
836 Session session = null;
837
838 try {
839 session = openSession();
840
841 IGImage[] array = new IGImageImpl[3];
842
843 array[0] = getByUuid_PrevAndNext(session, igImage, uuid,
844 orderByComparator, true);
845
846 array[1] = igImage;
847
848 array[2] = getByUuid_PrevAndNext(session, igImage, uuid,
849 orderByComparator, false);
850
851 return array;
852 }
853 catch (Exception e) {
854 throw processException(e);
855 }
856 finally {
857 closeSession(session);
858 }
859 }
860
861 protected IGImage getByUuid_PrevAndNext(Session session, IGImage igImage,
862 String uuid, OrderByComparator orderByComparator, boolean previous) {
863 StringBundler query = null;
864
865 if (orderByComparator != null) {
866 query = new StringBundler(6 +
867 (orderByComparator.getOrderByFields().length * 6));
868 }
869 else {
870 query = new StringBundler(3);
871 }
872
873 query.append(_SQL_SELECT_IGIMAGE_WHERE);
874
875 if (uuid == null) {
876 query.append(_FINDER_COLUMN_UUID_UUID_1);
877 }
878 else {
879 if (uuid.equals(StringPool.BLANK)) {
880 query.append(_FINDER_COLUMN_UUID_UUID_3);
881 }
882 else {
883 query.append(_FINDER_COLUMN_UUID_UUID_2);
884 }
885 }
886
887 if (orderByComparator != null) {
888 String[] orderByFields = orderByComparator.getOrderByFields();
889
890 if (orderByFields.length > 0) {
891 query.append(WHERE_AND);
892 }
893
894 for (int i = 0; i < orderByFields.length; i++) {
895 query.append(_ORDER_BY_ENTITY_ALIAS);
896 query.append(orderByFields[i]);
897
898 if ((i + 1) < orderByFields.length) {
899 if (orderByComparator.isAscending() ^ previous) {
900 query.append(WHERE_GREATER_THAN_HAS_NEXT);
901 }
902 else {
903 query.append(WHERE_LESSER_THAN_HAS_NEXT);
904 }
905 }
906 else {
907 if (orderByComparator.isAscending() ^ previous) {
908 query.append(WHERE_GREATER_THAN);
909 }
910 else {
911 query.append(WHERE_LESSER_THAN);
912 }
913 }
914 }
915
916 query.append(ORDER_BY_CLAUSE);
917
918 for (int i = 0; i < orderByFields.length; i++) {
919 query.append(_ORDER_BY_ENTITY_ALIAS);
920 query.append(orderByFields[i]);
921
922 if ((i + 1) < orderByFields.length) {
923 if (orderByComparator.isAscending() ^ previous) {
924 query.append(ORDER_BY_ASC_HAS_NEXT);
925 }
926 else {
927 query.append(ORDER_BY_DESC_HAS_NEXT);
928 }
929 }
930 else {
931 if (orderByComparator.isAscending() ^ previous) {
932 query.append(ORDER_BY_ASC);
933 }
934 else {
935 query.append(ORDER_BY_DESC);
936 }
937 }
938 }
939 }
940
941 else {
942 query.append(IGImageModelImpl.ORDER_BY_JPQL);
943 }
944
945 String sql = query.toString();
946
947 Query q = session.createQuery(sql);
948
949 q.setFirstResult(0);
950 q.setMaxResults(2);
951
952 QueryPos qPos = QueryPos.getInstance(q);
953
954 if (uuid != null) {
955 qPos.add(uuid);
956 }
957
958 if (orderByComparator != null) {
959 Object[] values = orderByComparator.getOrderByValues(igImage);
960
961 for (Object value : values) {
962 qPos.add(value);
963 }
964 }
965
966 List<IGImage> list = q.list();
967
968 if (list.size() == 2) {
969 return list.get(1);
970 }
971 else {
972 return null;
973 }
974 }
975
976
985 public IGImage findByUUID_G(String uuid, long groupId)
986 throws NoSuchImageException, SystemException {
987 IGImage igImage = fetchByUUID_G(uuid, groupId);
988
989 if (igImage == null) {
990 StringBundler msg = new StringBundler(6);
991
992 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
993
994 msg.append("uuid=");
995 msg.append(uuid);
996
997 msg.append(", groupId=");
998 msg.append(groupId);
999
1000 msg.append(StringPool.CLOSE_CURLY_BRACE);
1001
1002 if (_log.isWarnEnabled()) {
1003 _log.warn(msg.toString());
1004 }
1005
1006 throw new NoSuchImageException(msg.toString());
1007 }
1008
1009 return igImage;
1010 }
1011
1012
1020 public IGImage fetchByUUID_G(String uuid, long groupId)
1021 throws SystemException {
1022 return fetchByUUID_G(uuid, groupId, true);
1023 }
1024
1025
1033 public IGImage fetchByUUID_G(String uuid, long groupId,
1034 boolean retrieveFromCache) throws SystemException {
1035 Object[] finderArgs = new Object[] { uuid, groupId };
1036
1037 Object result = null;
1038
1039 if (retrieveFromCache) {
1040 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1041 finderArgs, this);
1042 }
1043
1044 if (result == null) {
1045 StringBundler query = new StringBundler(4);
1046
1047 query.append(_SQL_SELECT_IGIMAGE_WHERE);
1048
1049 if (uuid == null) {
1050 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1051 }
1052 else {
1053 if (uuid.equals(StringPool.BLANK)) {
1054 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1055 }
1056 else {
1057 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1058 }
1059 }
1060
1061 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1062
1063 query.append(IGImageModelImpl.ORDER_BY_JPQL);
1064
1065 String sql = query.toString();
1066
1067 Session session = null;
1068
1069 try {
1070 session = openSession();
1071
1072 Query q = session.createQuery(sql);
1073
1074 QueryPos qPos = QueryPos.getInstance(q);
1075
1076 if (uuid != null) {
1077 qPos.add(uuid);
1078 }
1079
1080 qPos.add(groupId);
1081
1082 List<IGImage> list = q.list();
1083
1084 result = list;
1085
1086 IGImage igImage = null;
1087
1088 if (list.isEmpty()) {
1089 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1090 finderArgs, list);
1091 }
1092 else {
1093 igImage = list.get(0);
1094
1095 cacheResult(igImage);
1096
1097 if ((igImage.getUuid() == null) ||
1098 !igImage.getUuid().equals(uuid) ||
1099 (igImage.getGroupId() != groupId)) {
1100 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1101 finderArgs, igImage);
1102 }
1103 }
1104
1105 return igImage;
1106 }
1107 catch (Exception e) {
1108 throw processException(e);
1109 }
1110 finally {
1111 if (result == null) {
1112 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1113 finderArgs);
1114 }
1115
1116 closeSession(session);
1117 }
1118 }
1119 else {
1120 if (result instanceof List<?>) {
1121 return null;
1122 }
1123 else {
1124 return (IGImage)result;
1125 }
1126 }
1127 }
1128
1129
1136 public List<IGImage> findByGroupId(long groupId) throws SystemException {
1137 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1138 }
1139
1140
1153 public List<IGImage> findByGroupId(long groupId, int start, int end)
1154 throws SystemException {
1155 return findByGroupId(groupId, start, end, null);
1156 }
1157
1158
1172 public List<IGImage> findByGroupId(long groupId, int start, int end,
1173 OrderByComparator orderByComparator) throws SystemException {
1174 Object[] finderArgs = new Object[] {
1175 groupId,
1176
1177 String.valueOf(start), String.valueOf(end),
1178 String.valueOf(orderByComparator)
1179 };
1180
1181 List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1182 finderArgs, this);
1183
1184 if (list == null) {
1185 StringBundler query = null;
1186
1187 if (orderByComparator != null) {
1188 query = new StringBundler(3 +
1189 (orderByComparator.getOrderByFields().length * 3));
1190 }
1191 else {
1192 query = new StringBundler(3);
1193 }
1194
1195 query.append(_SQL_SELECT_IGIMAGE_WHERE);
1196
1197 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1198
1199 if (orderByComparator != null) {
1200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1201 orderByComparator);
1202 }
1203
1204 else {
1205 query.append(IGImageModelImpl.ORDER_BY_JPQL);
1206 }
1207
1208 String sql = query.toString();
1209
1210 Session session = null;
1211
1212 try {
1213 session = openSession();
1214
1215 Query q = session.createQuery(sql);
1216
1217 QueryPos qPos = QueryPos.getInstance(q);
1218
1219 qPos.add(groupId);
1220
1221 list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
1222 }
1223 catch (Exception e) {
1224 throw processException(e);
1225 }
1226 finally {
1227 if (list == null) {
1228 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
1229 finderArgs);
1230 }
1231 else {
1232 cacheResult(list);
1233
1234 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1235 finderArgs, list);
1236 }
1237
1238 closeSession(session);
1239 }
1240 }
1241
1242 return list;
1243 }
1244
1245
1258 public IGImage findByGroupId_First(long groupId,
1259 OrderByComparator orderByComparator)
1260 throws NoSuchImageException, SystemException {
1261 List<IGImage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1262
1263 if (list.isEmpty()) {
1264 StringBundler msg = new StringBundler(4);
1265
1266 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1267
1268 msg.append("groupId=");
1269 msg.append(groupId);
1270
1271 msg.append(StringPool.CLOSE_CURLY_BRACE);
1272
1273 throw new NoSuchImageException(msg.toString());
1274 }
1275 else {
1276 return list.get(0);
1277 }
1278 }
1279
1280
1293 public IGImage findByGroupId_Last(long groupId,
1294 OrderByComparator orderByComparator)
1295 throws NoSuchImageException, SystemException {
1296 int count = countByGroupId(groupId);
1297
1298 List<IGImage> list = findByGroupId(groupId, count - 1, count,
1299 orderByComparator);
1300
1301 if (list.isEmpty()) {
1302 StringBundler msg = new StringBundler(4);
1303
1304 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1305
1306 msg.append("groupId=");
1307 msg.append(groupId);
1308
1309 msg.append(StringPool.CLOSE_CURLY_BRACE);
1310
1311 throw new NoSuchImageException(msg.toString());
1312 }
1313 else {
1314 return list.get(0);
1315 }
1316 }
1317
1318
1332 public IGImage[] findByGroupId_PrevAndNext(long imageId, long groupId,
1333 OrderByComparator orderByComparator)
1334 throws NoSuchImageException, SystemException {
1335 IGImage igImage = findByPrimaryKey(imageId);
1336
1337 Session session = null;
1338
1339 try {
1340 session = openSession();
1341
1342 IGImage[] array = new IGImageImpl[3];
1343
1344 array[0] = getByGroupId_PrevAndNext(session, igImage, groupId,
1345 orderByComparator, true);
1346
1347 array[1] = igImage;
1348
1349 array[2] = getByGroupId_PrevAndNext(session, igImage, groupId,
1350 orderByComparator, false);
1351
1352 return array;
1353 }
1354 catch (Exception e) {
1355 throw processException(e);
1356 }
1357 finally {
1358 closeSession(session);
1359 }
1360 }
1361
1362 protected IGImage getByGroupId_PrevAndNext(Session session,
1363 IGImage igImage, long groupId, OrderByComparator orderByComparator,
1364 boolean previous) {
1365 StringBundler query = null;
1366
1367 if (orderByComparator != null) {
1368 query = new StringBundler(6 +
1369 (orderByComparator.getOrderByFields().length * 6));
1370 }
1371 else {
1372 query = new StringBundler(3);
1373 }
1374
1375 query.append(_SQL_SELECT_IGIMAGE_WHERE);
1376
1377 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1378
1379 if (orderByComparator != null) {
1380 String[] orderByFields = orderByComparator.getOrderByFields();
1381
1382 if (orderByFields.length > 0) {
1383 query.append(WHERE_AND);
1384 }
1385
1386 for (int i = 0; i < orderByFields.length; i++) {
1387 query.append(_ORDER_BY_ENTITY_ALIAS);
1388 query.append(orderByFields[i]);
1389
1390 if ((i + 1) < orderByFields.length) {
1391 if (orderByComparator.isAscending() ^ previous) {
1392 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1393 }
1394 else {
1395 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1396 }
1397 }
1398 else {
1399 if (orderByComparator.isAscending() ^ previous) {
1400 query.append(WHERE_GREATER_THAN);
1401 }
1402 else {
1403 query.append(WHERE_LESSER_THAN);
1404 }
1405 }
1406 }
1407
1408 query.append(ORDER_BY_CLAUSE);
1409
1410 for (int i = 0; i < orderByFields.length; i++) {
1411 query.append(_ORDER_BY_ENTITY_ALIAS);
1412 query.append(orderByFields[i]);
1413
1414 if ((i + 1) < orderByFields.length) {
1415 if (orderByComparator.isAscending() ^ previous) {
1416 query.append(ORDER_BY_ASC_HAS_NEXT);
1417 }
1418 else {
1419 query.append(ORDER_BY_DESC_HAS_NEXT);
1420 }
1421 }
1422 else {
1423 if (orderByComparator.isAscending() ^ previous) {
1424 query.append(ORDER_BY_ASC);
1425 }
1426 else {
1427 query.append(ORDER_BY_DESC);
1428 }
1429 }
1430 }
1431 }
1432
1433 else {
1434 query.append(IGImageModelImpl.ORDER_BY_JPQL);
1435 }
1436
1437 String sql = query.toString();
1438
1439 Query q = session.createQuery(sql);
1440
1441 q.setFirstResult(0);
1442 q.setMaxResults(2);
1443
1444 QueryPos qPos = QueryPos.getInstance(q);
1445
1446 qPos.add(groupId);
1447
1448 if (orderByComparator != null) {
1449 Object[] values = orderByComparator.getOrderByValues(igImage);
1450
1451 for (Object value : values) {
1452 qPos.add(value);
1453 }
1454 }
1455
1456 List<IGImage> list = q.list();
1457
1458 if (list.size() == 2) {
1459 return list.get(1);
1460 }
1461 else {
1462 return null;
1463 }
1464 }
1465
1466
1473 public List<IGImage> filterFindByGroupId(long groupId)
1474 throws SystemException {
1475 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1476 QueryUtil.ALL_POS, null);
1477 }
1478
1479
1492 public List<IGImage> filterFindByGroupId(long groupId, int start, int end)
1493 throws SystemException {
1494 return filterFindByGroupId(groupId, start, end, null);
1495 }
1496
1497
1511 public List<IGImage> filterFindByGroupId(long groupId, int start, int end,
1512 OrderByComparator orderByComparator) throws SystemException {
1513 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1514 return findByGroupId(groupId, start, end, orderByComparator);
1515 }
1516
1517 StringBundler query = null;
1518
1519 if (orderByComparator != null) {
1520 query = new StringBundler(3 +
1521 (orderByComparator.getOrderByFields().length * 3));
1522 }
1523 else {
1524 query = new StringBundler(3);
1525 }
1526
1527 if (getDB().isSupportsInlineDistinct()) {
1528 query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
1529 }
1530 else {
1531 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_1);
1532 }
1533
1534 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1535
1536 if (!getDB().isSupportsInlineDistinct()) {
1537 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_2);
1538 }
1539
1540 if (orderByComparator != null) {
1541 if (getDB().isSupportsInlineDistinct()) {
1542 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1543 orderByComparator);
1544 }
1545 else {
1546 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1547 orderByComparator);
1548 }
1549 }
1550
1551 else {
1552 if (getDB().isSupportsInlineDistinct()) {
1553 query.append(IGImageModelImpl.ORDER_BY_JPQL);
1554 }
1555 else {
1556 query.append(IGImageModelImpl.ORDER_BY_SQL);
1557 }
1558 }
1559
1560 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1561 IGImage.class.getName(), _FILTER_COLUMN_PK,
1562 _FILTER_COLUMN_USERID, groupId);
1563
1564 Session session = null;
1565
1566 try {
1567 session = openSession();
1568
1569 SQLQuery q = session.createSQLQuery(sql);
1570
1571 if (getDB().isSupportsInlineDistinct()) {
1572 q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
1573 }
1574 else {
1575 q.addEntity(_FILTER_ENTITY_TABLE, IGImageImpl.class);
1576 }
1577
1578 QueryPos qPos = QueryPos.getInstance(q);
1579
1580 qPos.add(groupId);
1581
1582 return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
1583 }
1584 catch (Exception e) {
1585 throw processException(e);
1586 }
1587 finally {
1588 closeSession(session);
1589 }
1590 }
1591
1592
1600 public IGImage findBySmallImageId(long smallImageId)
1601 throws NoSuchImageException, SystemException {
1602 IGImage igImage = fetchBySmallImageId(smallImageId);
1603
1604 if (igImage == null) {
1605 StringBundler msg = new StringBundler(4);
1606
1607 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1608
1609 msg.append("smallImageId=");
1610 msg.append(smallImageId);
1611
1612 msg.append(StringPool.CLOSE_CURLY_BRACE);
1613
1614 if (_log.isWarnEnabled()) {
1615 _log.warn(msg.toString());
1616 }
1617
1618 throw new NoSuchImageException(msg.toString());
1619 }
1620
1621 return igImage;
1622 }
1623
1624
1631 public IGImage fetchBySmallImageId(long smallImageId)
1632 throws SystemException {
1633 return fetchBySmallImageId(smallImageId, true);
1634 }
1635
1636
1643 public IGImage fetchBySmallImageId(long smallImageId,
1644 boolean retrieveFromCache) throws SystemException {
1645 Object[] finderArgs = new Object[] { smallImageId };
1646
1647 Object result = null;
1648
1649 if (retrieveFromCache) {
1650 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1651 finderArgs, this);
1652 }
1653
1654 if (result == null) {
1655 StringBundler query = new StringBundler(3);
1656
1657 query.append(_SQL_SELECT_IGIMAGE_WHERE);
1658
1659 query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
1660
1661 query.append(IGImageModelImpl.ORDER_BY_JPQL);
1662
1663 String sql = query.toString();
1664
1665 Session session = null;
1666
1667 try {
1668 session = openSession();
1669
1670 Query q = session.createQuery(sql);
1671
1672 QueryPos qPos = QueryPos.getInstance(q);
1673
1674 qPos.add(smallImageId);
1675
1676 List<IGImage> list = q.list();
1677
1678 result = list;
1679
1680 IGImage igImage = null;
1681
1682 if (list.isEmpty()) {
1683 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1684 finderArgs, list);
1685 }
1686 else {
1687 igImage = list.get(0);
1688
1689 cacheResult(igImage);
1690
1691 if ((igImage.getSmallImageId() != smallImageId)) {
1692 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1693 finderArgs, igImage);
1694 }
1695 }
1696
1697 return igImage;
1698 }
1699 catch (Exception e) {
1700 throw processException(e);
1701 }
1702 finally {
1703 if (result == null) {
1704 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1705 finderArgs);
1706 }
1707
1708 closeSession(session);
1709 }
1710 }
1711 else {
1712 if (result instanceof List<?>) {
1713 return null;
1714 }
1715 else {
1716 return (IGImage)result;
1717 }
1718 }
1719 }
1720
1721
1729 public IGImage findByLargeImageId(long largeImageId)
1730 throws NoSuchImageException, SystemException {
1731 IGImage igImage = fetchByLargeImageId(largeImageId);
1732
1733 if (igImage == null) {
1734 StringBundler msg = new StringBundler(4);
1735
1736 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1737
1738 msg.append("largeImageId=");
1739 msg.append(largeImageId);
1740
1741 msg.append(StringPool.CLOSE_CURLY_BRACE);
1742
1743 if (_log.isWarnEnabled()) {
1744 _log.warn(msg.toString());
1745 }
1746
1747 throw new NoSuchImageException(msg.toString());
1748 }
1749
1750 return igImage;
1751 }
1752
1753
1760 public IGImage fetchByLargeImageId(long largeImageId)
1761 throws SystemException {
1762 return fetchByLargeImageId(largeImageId, true);
1763 }
1764
1765
1772 public IGImage fetchByLargeImageId(long largeImageId,
1773 boolean retrieveFromCache) throws SystemException {
1774 Object[] finderArgs = new Object[] { largeImageId };
1775
1776 Object result = null;
1777
1778 if (retrieveFromCache) {
1779 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1780 finderArgs, this);
1781 }
1782
1783 if (result == null) {
1784 StringBundler query = new StringBundler(3);
1785
1786 query.append(_SQL_SELECT_IGIMAGE_WHERE);
1787
1788 query.append(_FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2);
1789
1790 query.append(IGImageModelImpl.ORDER_BY_JPQL);
1791
1792 String sql = query.toString();
1793
1794 Session session = null;
1795
1796 try {
1797 session = openSession();
1798
1799 Query q = session.createQuery(sql);
1800
1801 QueryPos qPos = QueryPos.getInstance(q);
1802
1803 qPos.add(largeImageId);
1804
1805 List<IGImage> list = q.list();
1806
1807 result = list;
1808
1809 IGImage igImage = null;
1810
1811 if (list.isEmpty()) {
1812 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1813 finderArgs, list);
1814 }
1815 else {
1816 igImage = list.get(0);
1817
1818 cacheResult(igImage);
1819
1820 if ((igImage.getLargeImageId() != largeImageId)) {
1821 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1822 finderArgs, igImage);
1823 }
1824 }
1825
1826 return igImage;
1827 }
1828 catch (Exception e) {
1829 throw processException(e);
1830 }
1831 finally {
1832 if (result == null) {
1833 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1834 finderArgs);
1835 }
1836
1837 closeSession(session);
1838 }
1839 }
1840 else {
1841 if (result instanceof List<?>) {
1842 return null;
1843 }
1844 else {
1845 return (IGImage)result;
1846 }
1847 }
1848 }
1849
1850
1858 public IGImage findByCustom1ImageId(long custom1ImageId)
1859 throws NoSuchImageException, SystemException {
1860 IGImage igImage = fetchByCustom1ImageId(custom1ImageId);
1861
1862 if (igImage == null) {
1863 StringBundler msg = new StringBundler(4);
1864
1865 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1866
1867 msg.append("custom1ImageId=");
1868 msg.append(custom1ImageId);
1869
1870 msg.append(StringPool.CLOSE_CURLY_BRACE);
1871
1872 if (_log.isWarnEnabled()) {
1873 _log.warn(msg.toString());
1874 }
1875
1876 throw new NoSuchImageException(msg.toString());
1877 }
1878
1879 return igImage;
1880 }
1881
1882
1889 public IGImage fetchByCustom1ImageId(long custom1ImageId)
1890 throws SystemException {
1891 return fetchByCustom1ImageId(custom1ImageId, true);
1892 }
1893
1894
1901 public IGImage fetchByCustom1ImageId(long custom1ImageId,
1902 boolean retrieveFromCache) throws SystemException {
1903 Object[] finderArgs = new Object[] { custom1ImageId };
1904
1905 Object result = null;
1906
1907 if (retrieveFromCache) {
1908 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1909 finderArgs, this);
1910 }
1911
1912 if (result == null) {
1913 StringBundler query = new StringBundler(3);
1914
1915 query.append(_SQL_SELECT_IGIMAGE_WHERE);
1916
1917 query.append(_FINDER_COLUMN_CUSTOM1IMAGEID_CUSTOM1IMAGEID_2);
1918
1919 query.append(IGImageModelImpl.ORDER_BY_JPQL);
1920
1921 String sql = query.toString();
1922
1923 Session session = null;
1924
1925 try {
1926 session = openSession();
1927
1928 Query q = session.createQuery(sql);
1929
1930 QueryPos qPos = QueryPos.getInstance(q);
1931
1932 qPos.add(custom1ImageId);
1933
1934 List<IGImage> list = q.list();
1935
1936 result = list;
1937
1938 IGImage igImage = null;
1939
1940 if (list.isEmpty()) {
1941 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1942 finderArgs, list);
1943 }
1944 else {
1945 igImage = list.get(0);
1946
1947 cacheResult(igImage);
1948
1949 if ((igImage.getCustom1ImageId() != custom1ImageId)) {
1950 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1951 finderArgs, igImage);
1952 }
1953 }
1954
1955 return igImage;
1956 }
1957 catch (Exception e) {
1958 throw processException(e);
1959 }
1960 finally {
1961 if (result == null) {
1962 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM1IMAGEID,
1963 finderArgs);
1964 }
1965
1966 closeSession(session);
1967 }
1968 }
1969 else {
1970 if (result instanceof List<?>) {
1971 return null;
1972 }
1973 else {
1974 return (IGImage)result;
1975 }
1976 }
1977 }
1978
1979
1987 public IGImage findByCustom2ImageId(long custom2ImageId)
1988 throws NoSuchImageException, SystemException {
1989 IGImage igImage = fetchByCustom2ImageId(custom2ImageId);
1990
1991 if (igImage == null) {
1992 StringBundler msg = new StringBundler(4);
1993
1994 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1995
1996 msg.append("custom2ImageId=");
1997 msg.append(custom2ImageId);
1998
1999 msg.append(StringPool.CLOSE_CURLY_BRACE);
2000
2001 if (_log.isWarnEnabled()) {
2002 _log.warn(msg.toString());
2003 }
2004
2005 throw new NoSuchImageException(msg.toString());
2006 }
2007
2008 return igImage;
2009 }
2010
2011
2018 public IGImage fetchByCustom2ImageId(long custom2ImageId)
2019 throws SystemException {
2020 return fetchByCustom2ImageId(custom2ImageId, true);
2021 }
2022
2023
2030 public IGImage fetchByCustom2ImageId(long custom2ImageId,
2031 boolean retrieveFromCache) throws SystemException {
2032 Object[] finderArgs = new Object[] { custom2ImageId };
2033
2034 Object result = null;
2035
2036 if (retrieveFromCache) {
2037 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2038 finderArgs, this);
2039 }
2040
2041 if (result == null) {
2042 StringBundler query = new StringBundler(3);
2043
2044 query.append(_SQL_SELECT_IGIMAGE_WHERE);
2045
2046 query.append(_FINDER_COLUMN_CUSTOM2IMAGEID_CUSTOM2IMAGEID_2);
2047
2048 query.append(IGImageModelImpl.ORDER_BY_JPQL);
2049
2050 String sql = query.toString();
2051
2052 Session session = null;
2053
2054 try {
2055 session = openSession();
2056
2057 Query q = session.createQuery(sql);
2058
2059 QueryPos qPos = QueryPos.getInstance(q);
2060
2061 qPos.add(custom2ImageId);
2062
2063 List<IGImage> list = q.list();
2064
2065 result = list;
2066
2067 IGImage igImage = null;
2068
2069 if (list.isEmpty()) {
2070 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2071 finderArgs, list);
2072 }
2073 else {
2074 igImage = list.get(0);
2075
2076 cacheResult(igImage);
2077
2078 if ((igImage.getCustom2ImageId() != custom2ImageId)) {
2079 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2080 finderArgs, igImage);
2081 }
2082 }
2083
2084 return igImage;
2085 }
2086 catch (Exception e) {
2087 throw processException(e);
2088 }
2089 finally {
2090 if (result == null) {
2091 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CUSTOM2IMAGEID,
2092 finderArgs);
2093 }
2094
2095 closeSession(session);
2096 }
2097 }
2098 else {
2099 if (result instanceof List<?>) {
2100 return null;
2101 }
2102 else {
2103 return (IGImage)result;
2104 }
2105 }
2106 }
2107
2108
2116 public List<IGImage> findByG_U(long groupId, long userId)
2117 throws SystemException {
2118 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2119 null);
2120 }
2121
2122
2136 public List<IGImage> findByG_U(long groupId, long userId, int start, int end)
2137 throws SystemException {
2138 return findByG_U(groupId, userId, start, end, null);
2139 }
2140
2141
2156 public List<IGImage> findByG_U(long groupId, long userId, int start,
2157 int end, OrderByComparator orderByComparator) throws SystemException {
2158 Object[] finderArgs = new Object[] {
2159 groupId, userId,
2160
2161 String.valueOf(start), String.valueOf(end),
2162 String.valueOf(orderByComparator)
2163 };
2164
2165 List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
2166 finderArgs, this);
2167
2168 if (list == null) {
2169 StringBundler query = null;
2170
2171 if (orderByComparator != null) {
2172 query = new StringBundler(4 +
2173 (orderByComparator.getOrderByFields().length * 3));
2174 }
2175 else {
2176 query = new StringBundler(4);
2177 }
2178
2179 query.append(_SQL_SELECT_IGIMAGE_WHERE);
2180
2181 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2182
2183 query.append(_FINDER_COLUMN_G_U_USERID_2);
2184
2185 if (orderByComparator != null) {
2186 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2187 orderByComparator);
2188 }
2189
2190 else {
2191 query.append(IGImageModelImpl.ORDER_BY_JPQL);
2192 }
2193
2194 String sql = query.toString();
2195
2196 Session session = null;
2197
2198 try {
2199 session = openSession();
2200
2201 Query q = session.createQuery(sql);
2202
2203 QueryPos qPos = QueryPos.getInstance(q);
2204
2205 qPos.add(groupId);
2206
2207 qPos.add(userId);
2208
2209 list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2210 }
2211 catch (Exception e) {
2212 throw processException(e);
2213 }
2214 finally {
2215 if (list == null) {
2216 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_U,
2217 finderArgs);
2218 }
2219 else {
2220 cacheResult(list);
2221
2222 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U,
2223 finderArgs, list);
2224 }
2225
2226 closeSession(session);
2227 }
2228 }
2229
2230 return list;
2231 }
2232
2233
2247 public IGImage findByG_U_First(long groupId, long userId,
2248 OrderByComparator orderByComparator)
2249 throws NoSuchImageException, SystemException {
2250 List<IGImage> list = findByG_U(groupId, userId, 0, 1, orderByComparator);
2251
2252 if (list.isEmpty()) {
2253 StringBundler msg = new StringBundler(6);
2254
2255 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2256
2257 msg.append("groupId=");
2258 msg.append(groupId);
2259
2260 msg.append(", userId=");
2261 msg.append(userId);
2262
2263 msg.append(StringPool.CLOSE_CURLY_BRACE);
2264
2265 throw new NoSuchImageException(msg.toString());
2266 }
2267 else {
2268 return list.get(0);
2269 }
2270 }
2271
2272
2286 public IGImage findByG_U_Last(long groupId, long userId,
2287 OrderByComparator orderByComparator)
2288 throws NoSuchImageException, SystemException {
2289 int count = countByG_U(groupId, userId);
2290
2291 List<IGImage> list = findByG_U(groupId, userId, count - 1, count,
2292 orderByComparator);
2293
2294 if (list.isEmpty()) {
2295 StringBundler msg = new StringBundler(6);
2296
2297 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2298
2299 msg.append("groupId=");
2300 msg.append(groupId);
2301
2302 msg.append(", userId=");
2303 msg.append(userId);
2304
2305 msg.append(StringPool.CLOSE_CURLY_BRACE);
2306
2307 throw new NoSuchImageException(msg.toString());
2308 }
2309 else {
2310 return list.get(0);
2311 }
2312 }
2313
2314
2329 public IGImage[] findByG_U_PrevAndNext(long imageId, long groupId,
2330 long userId, OrderByComparator orderByComparator)
2331 throws NoSuchImageException, SystemException {
2332 IGImage igImage = findByPrimaryKey(imageId);
2333
2334 Session session = null;
2335
2336 try {
2337 session = openSession();
2338
2339 IGImage[] array = new IGImageImpl[3];
2340
2341 array[0] = getByG_U_PrevAndNext(session, igImage, groupId, userId,
2342 orderByComparator, true);
2343
2344 array[1] = igImage;
2345
2346 array[2] = getByG_U_PrevAndNext(session, igImage, groupId, userId,
2347 orderByComparator, false);
2348
2349 return array;
2350 }
2351 catch (Exception e) {
2352 throw processException(e);
2353 }
2354 finally {
2355 closeSession(session);
2356 }
2357 }
2358
2359 protected IGImage getByG_U_PrevAndNext(Session session, IGImage igImage,
2360 long groupId, long userId, OrderByComparator orderByComparator,
2361 boolean previous) {
2362 StringBundler query = null;
2363
2364 if (orderByComparator != null) {
2365 query = new StringBundler(6 +
2366 (orderByComparator.getOrderByFields().length * 6));
2367 }
2368 else {
2369 query = new StringBundler(3);
2370 }
2371
2372 query.append(_SQL_SELECT_IGIMAGE_WHERE);
2373
2374 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2375
2376 query.append(_FINDER_COLUMN_G_U_USERID_2);
2377
2378 if (orderByComparator != null) {
2379 String[] orderByFields = orderByComparator.getOrderByFields();
2380
2381 if (orderByFields.length > 0) {
2382 query.append(WHERE_AND);
2383 }
2384
2385 for (int i = 0; i < orderByFields.length; i++) {
2386 query.append(_ORDER_BY_ENTITY_ALIAS);
2387 query.append(orderByFields[i]);
2388
2389 if ((i + 1) < orderByFields.length) {
2390 if (orderByComparator.isAscending() ^ previous) {
2391 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2392 }
2393 else {
2394 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2395 }
2396 }
2397 else {
2398 if (orderByComparator.isAscending() ^ previous) {
2399 query.append(WHERE_GREATER_THAN);
2400 }
2401 else {
2402 query.append(WHERE_LESSER_THAN);
2403 }
2404 }
2405 }
2406
2407 query.append(ORDER_BY_CLAUSE);
2408
2409 for (int i = 0; i < orderByFields.length; i++) {
2410 query.append(_ORDER_BY_ENTITY_ALIAS);
2411 query.append(orderByFields[i]);
2412
2413 if ((i + 1) < orderByFields.length) {
2414 if (orderByComparator.isAscending() ^ previous) {
2415 query.append(ORDER_BY_ASC_HAS_NEXT);
2416 }
2417 else {
2418 query.append(ORDER_BY_DESC_HAS_NEXT);
2419 }
2420 }
2421 else {
2422 if (orderByComparator.isAscending() ^ previous) {
2423 query.append(ORDER_BY_ASC);
2424 }
2425 else {
2426 query.append(ORDER_BY_DESC);
2427 }
2428 }
2429 }
2430 }
2431
2432 else {
2433 query.append(IGImageModelImpl.ORDER_BY_JPQL);
2434 }
2435
2436 String sql = query.toString();
2437
2438 Query q = session.createQuery(sql);
2439
2440 q.setFirstResult(0);
2441 q.setMaxResults(2);
2442
2443 QueryPos qPos = QueryPos.getInstance(q);
2444
2445 qPos.add(groupId);
2446
2447 qPos.add(userId);
2448
2449 if (orderByComparator != null) {
2450 Object[] values = orderByComparator.getOrderByValues(igImage);
2451
2452 for (Object value : values) {
2453 qPos.add(value);
2454 }
2455 }
2456
2457 List<IGImage> list = q.list();
2458
2459 if (list.size() == 2) {
2460 return list.get(1);
2461 }
2462 else {
2463 return null;
2464 }
2465 }
2466
2467
2475 public List<IGImage> filterFindByG_U(long groupId, long userId)
2476 throws SystemException {
2477 return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
2478 QueryUtil.ALL_POS, null);
2479 }
2480
2481
2495 public List<IGImage> filterFindByG_U(long groupId, long userId, int start,
2496 int end) throws SystemException {
2497 return filterFindByG_U(groupId, userId, start, end, null);
2498 }
2499
2500
2515 public List<IGImage> filterFindByG_U(long groupId, long userId, int start,
2516 int end, OrderByComparator orderByComparator) throws SystemException {
2517 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2518 return findByG_U(groupId, userId, start, end, orderByComparator);
2519 }
2520
2521 StringBundler query = null;
2522
2523 if (orderByComparator != null) {
2524 query = new StringBundler(4 +
2525 (orderByComparator.getOrderByFields().length * 3));
2526 }
2527 else {
2528 query = new StringBundler(4);
2529 }
2530
2531 if (getDB().isSupportsInlineDistinct()) {
2532 query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
2533 }
2534 else {
2535 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_1);
2536 }
2537
2538 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2539
2540 query.append(_FINDER_COLUMN_G_U_USERID_2);
2541
2542 if (!getDB().isSupportsInlineDistinct()) {
2543 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_2);
2544 }
2545
2546 if (orderByComparator != null) {
2547 if (getDB().isSupportsInlineDistinct()) {
2548 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2549 orderByComparator);
2550 }
2551 else {
2552 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2553 orderByComparator);
2554 }
2555 }
2556
2557 else {
2558 if (getDB().isSupportsInlineDistinct()) {
2559 query.append(IGImageModelImpl.ORDER_BY_JPQL);
2560 }
2561 else {
2562 query.append(IGImageModelImpl.ORDER_BY_SQL);
2563 }
2564 }
2565
2566 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2567 IGImage.class.getName(), _FILTER_COLUMN_PK,
2568 _FILTER_COLUMN_USERID, groupId);
2569
2570 Session session = null;
2571
2572 try {
2573 session = openSession();
2574
2575 SQLQuery q = session.createSQLQuery(sql);
2576
2577 if (getDB().isSupportsInlineDistinct()) {
2578 q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
2579 }
2580 else {
2581 q.addEntity(_FILTER_ENTITY_TABLE, IGImageImpl.class);
2582 }
2583
2584 QueryPos qPos = QueryPos.getInstance(q);
2585
2586 qPos.add(groupId);
2587
2588 qPos.add(userId);
2589
2590 return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2591 }
2592 catch (Exception e) {
2593 throw processException(e);
2594 }
2595 finally {
2596 closeSession(session);
2597 }
2598 }
2599
2600
2608 public List<IGImage> findByG_F(long groupId, long folderId)
2609 throws SystemException {
2610 return findByG_F(groupId, folderId, QueryUtil.ALL_POS,
2611 QueryUtil.ALL_POS, null);
2612 }
2613
2614
2628 public List<IGImage> findByG_F(long groupId, long folderId, int start,
2629 int end) throws SystemException {
2630 return findByG_F(groupId, folderId, start, end, null);
2631 }
2632
2633
2648 public List<IGImage> findByG_F(long groupId, long folderId, int start,
2649 int end, OrderByComparator orderByComparator) throws SystemException {
2650 Object[] finderArgs = new Object[] {
2651 groupId, folderId,
2652
2653 String.valueOf(start), String.valueOf(end),
2654 String.valueOf(orderByComparator)
2655 };
2656
2657 List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F,
2658 finderArgs, this);
2659
2660 if (list == null) {
2661 StringBundler query = null;
2662
2663 if (orderByComparator != null) {
2664 query = new StringBundler(4 +
2665 (orderByComparator.getOrderByFields().length * 3));
2666 }
2667 else {
2668 query = new StringBundler(4);
2669 }
2670
2671 query.append(_SQL_SELECT_IGIMAGE_WHERE);
2672
2673 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2674
2675 query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
2676
2677 if (orderByComparator != null) {
2678 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2679 orderByComparator);
2680 }
2681
2682 else {
2683 query.append(IGImageModelImpl.ORDER_BY_JPQL);
2684 }
2685
2686 String sql = query.toString();
2687
2688 Session session = null;
2689
2690 try {
2691 session = openSession();
2692
2693 Query q = session.createQuery(sql);
2694
2695 QueryPos qPos = QueryPos.getInstance(q);
2696
2697 qPos.add(groupId);
2698
2699 qPos.add(folderId);
2700
2701 list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
2702 }
2703 catch (Exception e) {
2704 throw processException(e);
2705 }
2706 finally {
2707 if (list == null) {
2708 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_F,
2709 finderArgs);
2710 }
2711 else {
2712 cacheResult(list);
2713
2714 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F,
2715 finderArgs, list);
2716 }
2717
2718 closeSession(session);
2719 }
2720 }
2721
2722 return list;
2723 }
2724
2725
2739 public IGImage findByG_F_First(long groupId, long folderId,
2740 OrderByComparator orderByComparator)
2741 throws NoSuchImageException, SystemException {
2742 List<IGImage> list = findByG_F(groupId, folderId, 0, 1,
2743 orderByComparator);
2744
2745 if (list.isEmpty()) {
2746 StringBundler msg = new StringBundler(6);
2747
2748 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2749
2750 msg.append("groupId=");
2751 msg.append(groupId);
2752
2753 msg.append(", folderId=");
2754 msg.append(folderId);
2755
2756 msg.append(StringPool.CLOSE_CURLY_BRACE);
2757
2758 throw new NoSuchImageException(msg.toString());
2759 }
2760 else {
2761 return list.get(0);
2762 }
2763 }
2764
2765
2779 public IGImage findByG_F_Last(long groupId, long folderId,
2780 OrderByComparator orderByComparator)
2781 throws NoSuchImageException, SystemException {
2782 int count = countByG_F(groupId, folderId);
2783
2784 List<IGImage> list = findByG_F(groupId, folderId, count - 1, count,
2785 orderByComparator);
2786
2787 if (list.isEmpty()) {
2788 StringBundler msg = new StringBundler(6);
2789
2790 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2791
2792 msg.append("groupId=");
2793 msg.append(groupId);
2794
2795 msg.append(", folderId=");
2796 msg.append(folderId);
2797
2798 msg.append(StringPool.CLOSE_CURLY_BRACE);
2799
2800 throw new NoSuchImageException(msg.toString());
2801 }
2802 else {
2803 return list.get(0);
2804 }
2805 }
2806
2807
2822 public IGImage[] findByG_F_PrevAndNext(long imageId, long groupId,
2823 long folderId, OrderByComparator orderByComparator)
2824 throws NoSuchImageException, SystemException {
2825 IGImage igImage = findByPrimaryKey(imageId);
2826
2827 Session session = null;
2828
2829 try {
2830 session = openSession();
2831
2832 IGImage[] array = new IGImageImpl[3];
2833
2834 array[0] = getByG_F_PrevAndNext(session, igImage, groupId,
2835 folderId, orderByComparator, true);
2836
2837 array[1] = igImage;
2838
2839 array[2] = getByG_F_PrevAndNext(session, igImage, groupId,
2840 folderId, orderByComparator, false);
2841
2842 return array;
2843 }
2844 catch (Exception e) {
2845 throw processException(e);
2846 }
2847 finally {
2848 closeSession(session);
2849 }
2850 }
2851
2852 protected IGImage getByG_F_PrevAndNext(Session session, IGImage igImage,
2853 long groupId, long folderId, OrderByComparator orderByComparator,
2854 boolean previous) {
2855 StringBundler query = null;
2856
2857 if (orderByComparator != null) {
2858 query = new StringBundler(6 +
2859 (orderByComparator.getOrderByFields().length * 6));
2860 }
2861 else {
2862 query = new StringBundler(3);
2863 }
2864
2865 query.append(_SQL_SELECT_IGIMAGE_WHERE);
2866
2867 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2868
2869 query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
2870
2871 if (orderByComparator != null) {
2872 String[] orderByFields = orderByComparator.getOrderByFields();
2873
2874 if (orderByFields.length > 0) {
2875 query.append(WHERE_AND);
2876 }
2877
2878 for (int i = 0; i < orderByFields.length; i++) {
2879 query.append(_ORDER_BY_ENTITY_ALIAS);
2880 query.append(orderByFields[i]);
2881
2882 if ((i + 1) < orderByFields.length) {
2883 if (orderByComparator.isAscending() ^ previous) {
2884 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2885 }
2886 else {
2887 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2888 }
2889 }
2890 else {
2891 if (orderByComparator.isAscending() ^ previous) {
2892 query.append(WHERE_GREATER_THAN);
2893 }
2894 else {
2895 query.append(WHERE_LESSER_THAN);
2896 }
2897 }
2898 }
2899
2900 query.append(ORDER_BY_CLAUSE);
2901
2902 for (int i = 0; i < orderByFields.length; i++) {
2903 query.append(_ORDER_BY_ENTITY_ALIAS);
2904 query.append(orderByFields[i]);
2905
2906 if ((i + 1) < orderByFields.length) {
2907 if (orderByComparator.isAscending() ^ previous) {
2908 query.append(ORDER_BY_ASC_HAS_NEXT);
2909 }
2910 else {
2911 query.append(ORDER_BY_DESC_HAS_NEXT);
2912 }
2913 }
2914 else {
2915 if (orderByComparator.isAscending() ^ previous) {
2916 query.append(ORDER_BY_ASC);
2917 }
2918 else {
2919 query.append(ORDER_BY_DESC);
2920 }
2921 }
2922 }
2923 }
2924
2925 else {
2926 query.append(IGImageModelImpl.ORDER_BY_JPQL);
2927 }
2928
2929 String sql = query.toString();
2930
2931 Query q = session.createQuery(sql);
2932
2933 q.setFirstResult(0);
2934 q.setMaxResults(2);
2935
2936 QueryPos qPos = QueryPos.getInstance(q);
2937
2938 qPos.add(groupId);
2939
2940 qPos.add(folderId);
2941
2942 if (orderByComparator != null) {
2943 Object[] values = orderByComparator.getOrderByValues(igImage);
2944
2945 for (Object value : values) {
2946 qPos.add(value);
2947 }
2948 }
2949
2950 List<IGImage> list = q.list();
2951
2952 if (list.size() == 2) {
2953 return list.get(1);
2954 }
2955 else {
2956 return null;
2957 }
2958 }
2959
2960
2972 public List<IGImage> findByG_F(long groupId, long[] folderIds)
2973 throws SystemException {
2974 return findByG_F(groupId, folderIds, QueryUtil.ALL_POS,
2975 QueryUtil.ALL_POS, null);
2976 }
2977
2978
2992 public List<IGImage> findByG_F(long groupId, long[] folderIds, int start,
2993 int end) throws SystemException {
2994 return findByG_F(groupId, folderIds, start, end, null);
2995 }
2996
2997
3012 public List<IGImage> findByG_F(long groupId, long[] folderIds, int start,
3013 int end, OrderByComparator orderByComparator) throws SystemException {
3014 Object[] finderArgs = new Object[] {
3015 groupId, StringUtil.merge(folderIds),
3016
3017 String.valueOf(start), String.valueOf(end),
3018 String.valueOf(orderByComparator)
3019 };
3020
3021 List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F,
3022 finderArgs, this);
3023
3024 if (list == null) {
3025 StringBundler query = new StringBundler();
3026
3027 query.append(_SQL_SELECT_IGIMAGE_WHERE);
3028
3029 boolean conjunctionable = false;
3030
3031 if (conjunctionable) {
3032 query.append(WHERE_AND);
3033 }
3034
3035 query.append(_FINDER_COLUMN_G_F_GROUPID_5);
3036
3037 conjunctionable = true;
3038
3039 if ((folderIds == null) || (folderIds.length > 0)) {
3040 if (conjunctionable) {
3041 query.append(WHERE_AND);
3042 }
3043
3044 query.append(StringPool.OPEN_PARENTHESIS);
3045
3046 for (int i = 0; i < folderIds.length; i++) {
3047 query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
3048
3049 if ((i + 1) < folderIds.length) {
3050 query.append(WHERE_OR);
3051 }
3052 }
3053
3054 query.append(StringPool.CLOSE_PARENTHESIS);
3055
3056 conjunctionable = true;
3057 }
3058
3059 if (orderByComparator != null) {
3060 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3061 orderByComparator);
3062 }
3063
3064 else {
3065 query.append(IGImageModelImpl.ORDER_BY_JPQL);
3066 }
3067
3068 String sql = query.toString();
3069
3070 Session session = null;
3071
3072 try {
3073 session = openSession();
3074
3075 Query q = session.createQuery(sql);
3076
3077 QueryPos qPos = QueryPos.getInstance(q);
3078
3079 qPos.add(groupId);
3080
3081 if (folderIds != null) {
3082 qPos.add(folderIds);
3083 }
3084
3085 list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3086 }
3087 catch (Exception e) {
3088 throw processException(e);
3089 }
3090 finally {
3091 if (list == null) {
3092 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_F,
3093 finderArgs);
3094 }
3095 else {
3096 cacheResult(list);
3097
3098 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F,
3099 finderArgs, list);
3100 }
3101
3102 closeSession(session);
3103 }
3104 }
3105
3106 return list;
3107 }
3108
3109
3117 public List<IGImage> filterFindByG_F(long groupId, long folderId)
3118 throws SystemException {
3119 return filterFindByG_F(groupId, folderId, QueryUtil.ALL_POS,
3120 QueryUtil.ALL_POS, null);
3121 }
3122
3123
3137 public List<IGImage> filterFindByG_F(long groupId, long folderId,
3138 int start, int end) throws SystemException {
3139 return filterFindByG_F(groupId, folderId, start, end, null);
3140 }
3141
3142
3157 public List<IGImage> filterFindByG_F(long groupId, long folderId,
3158 int start, int end, OrderByComparator orderByComparator)
3159 throws SystemException {
3160 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3161 return findByG_F(groupId, folderId, start, end, orderByComparator);
3162 }
3163
3164 StringBundler query = null;
3165
3166 if (orderByComparator != null) {
3167 query = new StringBundler(4 +
3168 (orderByComparator.getOrderByFields().length * 3));
3169 }
3170 else {
3171 query = new StringBundler(4);
3172 }
3173
3174 if (getDB().isSupportsInlineDistinct()) {
3175 query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
3176 }
3177 else {
3178 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_1);
3179 }
3180
3181 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
3182
3183 query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
3184
3185 if (!getDB().isSupportsInlineDistinct()) {
3186 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_2);
3187 }
3188
3189 if (orderByComparator != null) {
3190 if (getDB().isSupportsInlineDistinct()) {
3191 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3192 orderByComparator);
3193 }
3194 else {
3195 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3196 orderByComparator);
3197 }
3198 }
3199
3200 else {
3201 if (getDB().isSupportsInlineDistinct()) {
3202 query.append(IGImageModelImpl.ORDER_BY_JPQL);
3203 }
3204 else {
3205 query.append(IGImageModelImpl.ORDER_BY_SQL);
3206 }
3207 }
3208
3209 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3210 IGImage.class.getName(), _FILTER_COLUMN_PK,
3211 _FILTER_COLUMN_USERID, groupId);
3212
3213 Session session = null;
3214
3215 try {
3216 session = openSession();
3217
3218 SQLQuery q = session.createSQLQuery(sql);
3219
3220 if (getDB().isSupportsInlineDistinct()) {
3221 q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
3222 }
3223 else {
3224 q.addEntity(_FILTER_ENTITY_TABLE, IGImageImpl.class);
3225 }
3226
3227 QueryPos qPos = QueryPos.getInstance(q);
3228
3229 qPos.add(groupId);
3230
3231 qPos.add(folderId);
3232
3233 return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3234 }
3235 catch (Exception e) {
3236 throw processException(e);
3237 }
3238 finally {
3239 closeSession(session);
3240 }
3241 }
3242
3243
3255 public List<IGImage> filterFindByG_F(long groupId, long[] folderIds)
3256 throws SystemException {
3257 return filterFindByG_F(groupId, folderIds, QueryUtil.ALL_POS,
3258 QueryUtil.ALL_POS, null);
3259 }
3260
3261
3275 public List<IGImage> filterFindByG_F(long groupId, long[] folderIds,
3276 int start, int end) throws SystemException {
3277 return filterFindByG_F(groupId, folderIds, start, end, null);
3278 }
3279
3280
3295 public List<IGImage> filterFindByG_F(long groupId, long[] folderIds,
3296 int start, int end, OrderByComparator orderByComparator)
3297 throws SystemException {
3298 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3299 return findByG_F(groupId, folderIds, start, end, orderByComparator);
3300 }
3301
3302 StringBundler query = new StringBundler();
3303
3304 if (getDB().isSupportsInlineDistinct()) {
3305 query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
3306 }
3307 else {
3308 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_1);
3309 }
3310
3311 boolean conjunctionable = false;
3312
3313 if (conjunctionable) {
3314 query.append(WHERE_AND);
3315 }
3316
3317 query.append(_FINDER_COLUMN_G_F_GROUPID_5);
3318
3319 conjunctionable = true;
3320
3321 if ((folderIds == null) || (folderIds.length > 0)) {
3322 if (conjunctionable) {
3323 query.append(WHERE_AND);
3324 }
3325
3326 query.append(StringPool.OPEN_PARENTHESIS);
3327
3328 for (int i = 0; i < folderIds.length; i++) {
3329 query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
3330
3331 if ((i + 1) < folderIds.length) {
3332 query.append(WHERE_OR);
3333 }
3334 }
3335
3336 query.append(StringPool.CLOSE_PARENTHESIS);
3337
3338 conjunctionable = true;
3339 }
3340
3341 if (!getDB().isSupportsInlineDistinct()) {
3342 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_2);
3343 }
3344
3345 if (orderByComparator != null) {
3346 if (getDB().isSupportsInlineDistinct()) {
3347 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3348 orderByComparator);
3349 }
3350 else {
3351 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3352 orderByComparator);
3353 }
3354 }
3355
3356 else {
3357 if (getDB().isSupportsInlineDistinct()) {
3358 query.append(IGImageModelImpl.ORDER_BY_JPQL);
3359 }
3360 else {
3361 query.append(IGImageModelImpl.ORDER_BY_SQL);
3362 }
3363 }
3364
3365 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3366 IGImage.class.getName(), _FILTER_COLUMN_PK,
3367 _FILTER_COLUMN_USERID, groupId);
3368
3369 Session session = null;
3370
3371 try {
3372 session = openSession();
3373
3374 SQLQuery q = session.createSQLQuery(sql);
3375
3376 if (getDB().isSupportsInlineDistinct()) {
3377 q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
3378 }
3379 else {
3380 q.addEntity(_FILTER_ENTITY_TABLE, IGImageImpl.class);
3381 }
3382
3383 QueryPos qPos = QueryPos.getInstance(q);
3384
3385 qPos.add(groupId);
3386
3387 if (folderIds != null) {
3388 qPos.add(folderIds);
3389 }
3390
3391 return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3392 }
3393 catch (Exception e) {
3394 throw processException(e);
3395 }
3396 finally {
3397 closeSession(session);
3398 }
3399 }
3400
3401
3410 public List<IGImage> findByG_F_N(long groupId, long folderId, String name)
3411 throws SystemException {
3412 return findByG_F_N(groupId, folderId, name, QueryUtil.ALL_POS,
3413 QueryUtil.ALL_POS, null);
3414 }
3415
3416
3431 public List<IGImage> findByG_F_N(long groupId, long folderId, String name,
3432 int start, int end) throws SystemException {
3433 return findByG_F_N(groupId, folderId, name, start, end, null);
3434 }
3435
3436
3452 public List<IGImage> findByG_F_N(long groupId, long folderId, String name,
3453 int start, int end, OrderByComparator orderByComparator)
3454 throws SystemException {
3455 Object[] finderArgs = new Object[] {
3456 groupId, folderId, name,
3457
3458 String.valueOf(start), String.valueOf(end),
3459 String.valueOf(orderByComparator)
3460 };
3461
3462 List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N,
3463 finderArgs, this);
3464
3465 if (list == null) {
3466 StringBundler query = null;
3467
3468 if (orderByComparator != null) {
3469 query = new StringBundler(5 +
3470 (orderByComparator.getOrderByFields().length * 3));
3471 }
3472 else {
3473 query = new StringBundler(5);
3474 }
3475
3476 query.append(_SQL_SELECT_IGIMAGE_WHERE);
3477
3478 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
3479
3480 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
3481
3482 if (name == null) {
3483 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
3484 }
3485 else {
3486 if (name.equals(StringPool.BLANK)) {
3487 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
3488 }
3489 else {
3490 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
3491 }
3492 }
3493
3494 if (orderByComparator != null) {
3495 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3496 orderByComparator);
3497 }
3498
3499 else {
3500 query.append(IGImageModelImpl.ORDER_BY_JPQL);
3501 }
3502
3503 String sql = query.toString();
3504
3505 Session session = null;
3506
3507 try {
3508 session = openSession();
3509
3510 Query q = session.createQuery(sql);
3511
3512 QueryPos qPos = QueryPos.getInstance(q);
3513
3514 qPos.add(groupId);
3515
3516 qPos.add(folderId);
3517
3518 if (name != null) {
3519 qPos.add(name);
3520 }
3521
3522 list = (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3523 }
3524 catch (Exception e) {
3525 throw processException(e);
3526 }
3527 finally {
3528 if (list == null) {
3529 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_F_N,
3530 finderArgs);
3531 }
3532 else {
3533 cacheResult(list);
3534
3535 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N,
3536 finderArgs, list);
3537 }
3538
3539 closeSession(session);
3540 }
3541 }
3542
3543 return list;
3544 }
3545
3546
3561 public IGImage findByG_F_N_First(long groupId, long folderId, String name,
3562 OrderByComparator orderByComparator)
3563 throws NoSuchImageException, SystemException {
3564 List<IGImage> list = findByG_F_N(groupId, folderId, name, 0, 1,
3565 orderByComparator);
3566
3567 if (list.isEmpty()) {
3568 StringBundler msg = new StringBundler(8);
3569
3570 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3571
3572 msg.append("groupId=");
3573 msg.append(groupId);
3574
3575 msg.append(", folderId=");
3576 msg.append(folderId);
3577
3578 msg.append(", name=");
3579 msg.append(name);
3580
3581 msg.append(StringPool.CLOSE_CURLY_BRACE);
3582
3583 throw new NoSuchImageException(msg.toString());
3584 }
3585 else {
3586 return list.get(0);
3587 }
3588 }
3589
3590
3605 public IGImage findByG_F_N_Last(long groupId, long folderId, String name,
3606 OrderByComparator orderByComparator)
3607 throws NoSuchImageException, SystemException {
3608 int count = countByG_F_N(groupId, folderId, name);
3609
3610 List<IGImage> list = findByG_F_N(groupId, folderId, name, count - 1,
3611 count, orderByComparator);
3612
3613 if (list.isEmpty()) {
3614 StringBundler msg = new StringBundler(8);
3615
3616 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3617
3618 msg.append("groupId=");
3619 msg.append(groupId);
3620
3621 msg.append(", folderId=");
3622 msg.append(folderId);
3623
3624 msg.append(", name=");
3625 msg.append(name);
3626
3627 msg.append(StringPool.CLOSE_CURLY_BRACE);
3628
3629 throw new NoSuchImageException(msg.toString());
3630 }
3631 else {
3632 return list.get(0);
3633 }
3634 }
3635
3636
3652 public IGImage[] findByG_F_N_PrevAndNext(long imageId, long groupId,
3653 long folderId, String name, OrderByComparator orderByComparator)
3654 throws NoSuchImageException, SystemException {
3655 IGImage igImage = findByPrimaryKey(imageId);
3656
3657 Session session = null;
3658
3659 try {
3660 session = openSession();
3661
3662 IGImage[] array = new IGImageImpl[3];
3663
3664 array[0] = getByG_F_N_PrevAndNext(session, igImage, groupId,
3665 folderId, name, orderByComparator, true);
3666
3667 array[1] = igImage;
3668
3669 array[2] = getByG_F_N_PrevAndNext(session, igImage, groupId,
3670 folderId, name, orderByComparator, false);
3671
3672 return array;
3673 }
3674 catch (Exception e) {
3675 throw processException(e);
3676 }
3677 finally {
3678 closeSession(session);
3679 }
3680 }
3681
3682 protected IGImage getByG_F_N_PrevAndNext(Session session, IGImage igImage,
3683 long groupId, long folderId, String name,
3684 OrderByComparator orderByComparator, boolean previous) {
3685 StringBundler query = null;
3686
3687 if (orderByComparator != null) {
3688 query = new StringBundler(6 +
3689 (orderByComparator.getOrderByFields().length * 6));
3690 }
3691 else {
3692 query = new StringBundler(3);
3693 }
3694
3695 query.append(_SQL_SELECT_IGIMAGE_WHERE);
3696
3697 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
3698
3699 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
3700
3701 if (name == null) {
3702 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
3703 }
3704 else {
3705 if (name.equals(StringPool.BLANK)) {
3706 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
3707 }
3708 else {
3709 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
3710 }
3711 }
3712
3713 if (orderByComparator != null) {
3714 String[] orderByFields = orderByComparator.getOrderByFields();
3715
3716 if (orderByFields.length > 0) {
3717 query.append(WHERE_AND);
3718 }
3719
3720 for (int i = 0; i < orderByFields.length; i++) {
3721 query.append(_ORDER_BY_ENTITY_ALIAS);
3722 query.append(orderByFields[i]);
3723
3724 if ((i + 1) < orderByFields.length) {
3725 if (orderByComparator.isAscending() ^ previous) {
3726 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3727 }
3728 else {
3729 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3730 }
3731 }
3732 else {
3733 if (orderByComparator.isAscending() ^ previous) {
3734 query.append(WHERE_GREATER_THAN);
3735 }
3736 else {
3737 query.append(WHERE_LESSER_THAN);
3738 }
3739 }
3740 }
3741
3742 query.append(ORDER_BY_CLAUSE);
3743
3744 for (int i = 0; i < orderByFields.length; i++) {
3745 query.append(_ORDER_BY_ENTITY_ALIAS);
3746 query.append(orderByFields[i]);
3747
3748 if ((i + 1) < orderByFields.length) {
3749 if (orderByComparator.isAscending() ^ previous) {
3750 query.append(ORDER_BY_ASC_HAS_NEXT);
3751 }
3752 else {
3753 query.append(ORDER_BY_DESC_HAS_NEXT);
3754 }
3755 }
3756 else {
3757 if (orderByComparator.isAscending() ^ previous) {
3758 query.append(ORDER_BY_ASC);
3759 }
3760 else {
3761 query.append(ORDER_BY_DESC);
3762 }
3763 }
3764 }
3765 }
3766
3767 else {
3768 query.append(IGImageModelImpl.ORDER_BY_JPQL);
3769 }
3770
3771 String sql = query.toString();
3772
3773 Query q = session.createQuery(sql);
3774
3775 q.setFirstResult(0);
3776 q.setMaxResults(2);
3777
3778 QueryPos qPos = QueryPos.getInstance(q);
3779
3780 qPos.add(groupId);
3781
3782 qPos.add(folderId);
3783
3784 if (name != null) {
3785 qPos.add(name);
3786 }
3787
3788 if (orderByComparator != null) {
3789 Object[] values = orderByComparator.getOrderByValues(igImage);
3790
3791 for (Object value : values) {
3792 qPos.add(value);
3793 }
3794 }
3795
3796 List<IGImage> list = q.list();
3797
3798 if (list.size() == 2) {
3799 return list.get(1);
3800 }
3801 else {
3802 return null;
3803 }
3804 }
3805
3806
3815 public List<IGImage> filterFindByG_F_N(long groupId, long folderId,
3816 String name) throws SystemException {
3817 return filterFindByG_F_N(groupId, folderId, name, QueryUtil.ALL_POS,
3818 QueryUtil.ALL_POS, null);
3819 }
3820
3821
3836 public List<IGImage> filterFindByG_F_N(long groupId, long folderId,
3837 String name, int start, int end) throws SystemException {
3838 return filterFindByG_F_N(groupId, folderId, name, start, end, null);
3839 }
3840
3841
3857 public List<IGImage> filterFindByG_F_N(long groupId, long folderId,
3858 String name, int start, int end, OrderByComparator orderByComparator)
3859 throws SystemException {
3860 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3861 return findByG_F_N(groupId, folderId, name, start, end,
3862 orderByComparator);
3863 }
3864
3865 StringBundler query = null;
3866
3867 if (orderByComparator != null) {
3868 query = new StringBundler(5 +
3869 (orderByComparator.getOrderByFields().length * 3));
3870 }
3871 else {
3872 query = new StringBundler(5);
3873 }
3874
3875 if (getDB().isSupportsInlineDistinct()) {
3876 query.append(_FILTER_SQL_SELECT_IGIMAGE_WHERE);
3877 }
3878 else {
3879 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_1);
3880 }
3881
3882 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
3883
3884 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
3885
3886 if (name == null) {
3887 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
3888 }
3889 else {
3890 if (name.equals(StringPool.BLANK)) {
3891 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
3892 }
3893 else {
3894 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
3895 }
3896 }
3897
3898 if (!getDB().isSupportsInlineDistinct()) {
3899 query.append(_FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_2);
3900 }
3901
3902 if (orderByComparator != null) {
3903 if (getDB().isSupportsInlineDistinct()) {
3904 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3905 orderByComparator);
3906 }
3907 else {
3908 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3909 orderByComparator);
3910 }
3911 }
3912
3913 else {
3914 if (getDB().isSupportsInlineDistinct()) {
3915 query.append(IGImageModelImpl.ORDER_BY_JPQL);
3916 }
3917 else {
3918 query.append(IGImageModelImpl.ORDER_BY_SQL);
3919 }
3920 }
3921
3922 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3923 IGImage.class.getName(), _FILTER_COLUMN_PK,
3924 _FILTER_COLUMN_USERID, groupId);
3925
3926 Session session = null;
3927
3928 try {
3929 session = openSession();
3930
3931 SQLQuery q = session.createSQLQuery(sql);
3932
3933 if (getDB().isSupportsInlineDistinct()) {
3934 q.addEntity(_FILTER_ENTITY_ALIAS, IGImageImpl.class);
3935 }
3936 else {
3937 q.addEntity(_FILTER_ENTITY_TABLE, IGImageImpl.class);
3938 }
3939
3940 QueryPos qPos = QueryPos.getInstance(q);
3941
3942 qPos.add(groupId);
3943
3944 qPos.add(folderId);
3945
3946 if (name != null) {
3947 qPos.add(name);
3948 }
3949
3950 return (List<IGImage>)QueryUtil.list(q, getDialect(), start, end);
3951 }
3952 catch (Exception e) {
3953 throw processException(e);
3954 }
3955 finally {
3956 closeSession(session);
3957 }
3958 }
3959
3960
3966 public List<IGImage> findAll() throws SystemException {
3967 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3968 }
3969
3970
3982 public List<IGImage> findAll(int start, int end) throws SystemException {
3983 return findAll(start, end, null);
3984 }
3985
3986
3999 public List<IGImage> findAll(int start, int end,
4000 OrderByComparator orderByComparator) throws SystemException {
4001 Object[] finderArgs = new Object[] {
4002 String.valueOf(start), String.valueOf(end),
4003 String.valueOf(orderByComparator)
4004 };
4005
4006 List<IGImage> list = (List<IGImage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
4007 finderArgs, this);
4008
4009 if (list == null) {
4010 StringBundler query = null;
4011 String sql = null;
4012
4013 if (orderByComparator != null) {
4014 query = new StringBundler(2 +
4015 (orderByComparator.getOrderByFields().length * 3));
4016
4017 query.append(_SQL_SELECT_IGIMAGE);
4018
4019 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4020 orderByComparator);
4021
4022 sql = query.toString();
4023 }
4024 else {
4025 sql = _SQL_SELECT_IGIMAGE.concat(IGImageModelImpl.ORDER_BY_JPQL);
4026 }
4027
4028 Session session = null;
4029
4030 try {
4031 session = openSession();
4032
4033 Query q = session.createQuery(sql);
4034
4035 if (orderByComparator == null) {
4036 list = (List<IGImage>)QueryUtil.list(q, getDialect(),
4037 start, end, false);
4038
4039 Collections.sort(list);
4040 }
4041 else {
4042 list = (List<IGImage>)QueryUtil.list(q, getDialect(),
4043 start, end);
4044 }
4045 }
4046 catch (Exception e) {
4047 throw processException(e);
4048 }
4049 finally {
4050 if (list == null) {
4051 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
4052 finderArgs);
4053 }
4054 else {
4055 cacheResult(list);
4056
4057 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
4058 list);
4059 }
4060
4061 closeSession(session);
4062 }
4063 }
4064
4065 return list;
4066 }
4067
4068
4074 public void removeByUuid(String uuid) throws SystemException {
4075 for (IGImage igImage : findByUuid(uuid)) {
4076 remove(igImage);
4077 }
4078 }
4079
4080
4087 public void removeByUUID_G(String uuid, long groupId)
4088 throws NoSuchImageException, SystemException {
4089 IGImage igImage = findByUUID_G(uuid, groupId);
4090
4091 remove(igImage);
4092 }
4093
4094
4100 public void removeByGroupId(long groupId) throws SystemException {
4101 for (IGImage igImage : findByGroupId(groupId)) {
4102 remove(igImage);
4103 }
4104 }
4105
4106
4112 public void removeBySmallImageId(long smallImageId)
4113 throws NoSuchImageException, SystemException {
4114 IGImage igImage = findBySmallImageId(smallImageId);
4115
4116 remove(igImage);
4117 }
4118
4119
4125 public void removeByLargeImageId(long largeImageId)
4126 throws NoSuchImageException, SystemException {
4127 IGImage igImage = findByLargeImageId(largeImageId);
4128
4129 remove(igImage);
4130 }
4131
4132
4138 public void removeByCustom1ImageId(long custom1ImageId)
4139 throws NoSuchImageException, SystemException {
4140 IGImage igImage = findByCustom1ImageId(custom1ImageId);
4141
4142 remove(igImage);
4143 }
4144
4145
4151 public void removeByCustom2ImageId(long custom2ImageId)
4152 throws NoSuchImageException, SystemException {
4153 IGImage igImage = findByCustom2ImageId(custom2ImageId);
4154
4155 remove(igImage);
4156 }
4157
4158
4165 public void removeByG_U(long groupId, long userId)
4166 throws SystemException {
4167 for (IGImage igImage : findByG_U(groupId, userId)) {
4168 remove(igImage);
4169 }
4170 }
4171
4172
4179 public void removeByG_F(long groupId, long folderId)
4180 throws SystemException {
4181 for (IGImage igImage : findByG_F(groupId, folderId)) {
4182 remove(igImage);
4183 }
4184 }
4185
4186
4194 public void removeByG_F_N(long groupId, long folderId, String name)
4195 throws SystemException {
4196 for (IGImage igImage : findByG_F_N(groupId, folderId, name)) {
4197 remove(igImage);
4198 }
4199 }
4200
4201
4206 public void removeAll() throws SystemException {
4207 for (IGImage igImage : findAll()) {
4208 remove(igImage);
4209 }
4210 }
4211
4212
4219 public int countByUuid(String uuid) throws SystemException {
4220 Object[] finderArgs = new Object[] { uuid };
4221
4222 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4223 finderArgs, this);
4224
4225 if (count == null) {
4226 StringBundler query = new StringBundler(2);
4227
4228 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4229
4230 if (uuid == null) {
4231 query.append(_FINDER_COLUMN_UUID_UUID_1);
4232 }
4233 else {
4234 if (uuid.equals(StringPool.BLANK)) {
4235 query.append(_FINDER_COLUMN_UUID_UUID_3);
4236 }
4237 else {
4238 query.append(_FINDER_COLUMN_UUID_UUID_2);
4239 }
4240 }
4241
4242 String sql = query.toString();
4243
4244 Session session = null;
4245
4246 try {
4247 session = openSession();
4248
4249 Query q = session.createQuery(sql);
4250
4251 QueryPos qPos = QueryPos.getInstance(q);
4252
4253 if (uuid != null) {
4254 qPos.add(uuid);
4255 }
4256
4257 count = (Long)q.uniqueResult();
4258 }
4259 catch (Exception e) {
4260 throw processException(e);
4261 }
4262 finally {
4263 if (count == null) {
4264 count = Long.valueOf(0);
4265 }
4266
4267 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4268 finderArgs, count);
4269
4270 closeSession(session);
4271 }
4272 }
4273
4274 return count.intValue();
4275 }
4276
4277
4285 public int countByUUID_G(String uuid, long groupId)
4286 throws SystemException {
4287 Object[] finderArgs = new Object[] { uuid, groupId };
4288
4289 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4290 finderArgs, this);
4291
4292 if (count == null) {
4293 StringBundler query = new StringBundler(3);
4294
4295 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4296
4297 if (uuid == null) {
4298 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4299 }
4300 else {
4301 if (uuid.equals(StringPool.BLANK)) {
4302 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4303 }
4304 else {
4305 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4306 }
4307 }
4308
4309 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4310
4311 String sql = query.toString();
4312
4313 Session session = null;
4314
4315 try {
4316 session = openSession();
4317
4318 Query q = session.createQuery(sql);
4319
4320 QueryPos qPos = QueryPos.getInstance(q);
4321
4322 if (uuid != null) {
4323 qPos.add(uuid);
4324 }
4325
4326 qPos.add(groupId);
4327
4328 count = (Long)q.uniqueResult();
4329 }
4330 catch (Exception e) {
4331 throw processException(e);
4332 }
4333 finally {
4334 if (count == null) {
4335 count = Long.valueOf(0);
4336 }
4337
4338 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4339 finderArgs, count);
4340
4341 closeSession(session);
4342 }
4343 }
4344
4345 return count.intValue();
4346 }
4347
4348
4355 public int countByGroupId(long groupId) throws SystemException {
4356 Object[] finderArgs = new Object[] { groupId };
4357
4358 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4359 finderArgs, this);
4360
4361 if (count == null) {
4362 StringBundler query = new StringBundler(2);
4363
4364 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4365
4366 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4367
4368 String sql = query.toString();
4369
4370 Session session = null;
4371
4372 try {
4373 session = openSession();
4374
4375 Query q = session.createQuery(sql);
4376
4377 QueryPos qPos = QueryPos.getInstance(q);
4378
4379 qPos.add(groupId);
4380
4381 count = (Long)q.uniqueResult();
4382 }
4383 catch (Exception e) {
4384 throw processException(e);
4385 }
4386 finally {
4387 if (count == null) {
4388 count = Long.valueOf(0);
4389 }
4390
4391 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4392 finderArgs, count);
4393
4394 closeSession(session);
4395 }
4396 }
4397
4398 return count.intValue();
4399 }
4400
4401
4408 public int filterCountByGroupId(long groupId) throws SystemException {
4409 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4410 return countByGroupId(groupId);
4411 }
4412
4413 StringBundler query = new StringBundler(2);
4414
4415 query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4416
4417 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4418
4419 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4420 IGImage.class.getName(), _FILTER_COLUMN_PK,
4421 _FILTER_COLUMN_USERID, groupId);
4422
4423 Session session = null;
4424
4425 try {
4426 session = openSession();
4427
4428 SQLQuery q = session.createSQLQuery(sql);
4429
4430 q.addScalar(COUNT_COLUMN_NAME,
4431 com.liferay.portal.kernel.dao.orm.Type.LONG);
4432
4433 QueryPos qPos = QueryPos.getInstance(q);
4434
4435 qPos.add(groupId);
4436
4437 Long count = (Long)q.uniqueResult();
4438
4439 return count.intValue();
4440 }
4441 catch (Exception e) {
4442 throw processException(e);
4443 }
4444 finally {
4445 closeSession(session);
4446 }
4447 }
4448
4449
4456 public int countBySmallImageId(long smallImageId) throws SystemException {
4457 Object[] finderArgs = new Object[] { smallImageId };
4458
4459 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
4460 finderArgs, this);
4461
4462 if (count == null) {
4463 StringBundler query = new StringBundler(2);
4464
4465 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4466
4467 query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
4468
4469 String sql = query.toString();
4470
4471 Session session = null;
4472
4473 try {
4474 session = openSession();
4475
4476 Query q = session.createQuery(sql);
4477
4478 QueryPos qPos = QueryPos.getInstance(q);
4479
4480 qPos.add(smallImageId);
4481
4482 count = (Long)q.uniqueResult();
4483 }
4484 catch (Exception e) {
4485 throw processException(e);
4486 }
4487 finally {
4488 if (count == null) {
4489 count = Long.valueOf(0);
4490 }
4491
4492 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
4493 finderArgs, count);
4494
4495 closeSession(session);
4496 }
4497 }
4498
4499 return count.intValue();
4500 }
4501
4502
4509 public int countByLargeImageId(long largeImageId) throws SystemException {
4510 Object[] finderArgs = new Object[] { largeImageId };
4511
4512 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
4513 finderArgs, this);
4514
4515 if (count == null) {
4516 StringBundler query = new StringBundler(2);
4517
4518 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4519
4520 query.append(_FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2);
4521
4522 String sql = query.toString();
4523
4524 Session session = null;
4525
4526 try {
4527 session = openSession();
4528
4529 Query q = session.createQuery(sql);
4530
4531 QueryPos qPos = QueryPos.getInstance(q);
4532
4533 qPos.add(largeImageId);
4534
4535 count = (Long)q.uniqueResult();
4536 }
4537 catch (Exception e) {
4538 throw processException(e);
4539 }
4540 finally {
4541 if (count == null) {
4542 count = Long.valueOf(0);
4543 }
4544
4545 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
4546 finderArgs, count);
4547
4548 closeSession(session);
4549 }
4550 }
4551
4552 return count.intValue();
4553 }
4554
4555
4562 public int countByCustom1ImageId(long custom1ImageId)
4563 throws SystemException {
4564 Object[] finderArgs = new Object[] { custom1ImageId };
4565
4566 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID,
4567 finderArgs, this);
4568
4569 if (count == null) {
4570 StringBundler query = new StringBundler(2);
4571
4572 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4573
4574 query.append(_FINDER_COLUMN_CUSTOM1IMAGEID_CUSTOM1IMAGEID_2);
4575
4576 String sql = query.toString();
4577
4578 Session session = null;
4579
4580 try {
4581 session = openSession();
4582
4583 Query q = session.createQuery(sql);
4584
4585 QueryPos qPos = QueryPos.getInstance(q);
4586
4587 qPos.add(custom1ImageId);
4588
4589 count = (Long)q.uniqueResult();
4590 }
4591 catch (Exception e) {
4592 throw processException(e);
4593 }
4594 finally {
4595 if (count == null) {
4596 count = Long.valueOf(0);
4597 }
4598
4599 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CUSTOM1IMAGEID,
4600 finderArgs, count);
4601
4602 closeSession(session);
4603 }
4604 }
4605
4606 return count.intValue();
4607 }
4608
4609
4616 public int countByCustom2ImageId(long custom2ImageId)
4617 throws SystemException {
4618 Object[] finderArgs = new Object[] { custom2ImageId };
4619
4620 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID,
4621 finderArgs, this);
4622
4623 if (count == null) {
4624 StringBundler query = new StringBundler(2);
4625
4626 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4627
4628 query.append(_FINDER_COLUMN_CUSTOM2IMAGEID_CUSTOM2IMAGEID_2);
4629
4630 String sql = query.toString();
4631
4632 Session session = null;
4633
4634 try {
4635 session = openSession();
4636
4637 Query q = session.createQuery(sql);
4638
4639 QueryPos qPos = QueryPos.getInstance(q);
4640
4641 qPos.add(custom2ImageId);
4642
4643 count = (Long)q.uniqueResult();
4644 }
4645 catch (Exception e) {
4646 throw processException(e);
4647 }
4648 finally {
4649 if (count == null) {
4650 count = Long.valueOf(0);
4651 }
4652
4653 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CUSTOM2IMAGEID,
4654 finderArgs, count);
4655
4656 closeSession(session);
4657 }
4658 }
4659
4660 return count.intValue();
4661 }
4662
4663
4671 public int countByG_U(long groupId, long userId) throws SystemException {
4672 Object[] finderArgs = new Object[] { groupId, userId };
4673
4674 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
4675 finderArgs, this);
4676
4677 if (count == null) {
4678 StringBundler query = new StringBundler(3);
4679
4680 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4681
4682 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4683
4684 query.append(_FINDER_COLUMN_G_U_USERID_2);
4685
4686 String sql = query.toString();
4687
4688 Session session = null;
4689
4690 try {
4691 session = openSession();
4692
4693 Query q = session.createQuery(sql);
4694
4695 QueryPos qPos = QueryPos.getInstance(q);
4696
4697 qPos.add(groupId);
4698
4699 qPos.add(userId);
4700
4701 count = (Long)q.uniqueResult();
4702 }
4703 catch (Exception e) {
4704 throw processException(e);
4705 }
4706 finally {
4707 if (count == null) {
4708 count = Long.valueOf(0);
4709 }
4710
4711 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
4712 count);
4713
4714 closeSession(session);
4715 }
4716 }
4717
4718 return count.intValue();
4719 }
4720
4721
4729 public int filterCountByG_U(long groupId, long userId)
4730 throws SystemException {
4731 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4732 return countByG_U(groupId, userId);
4733 }
4734
4735 StringBundler query = new StringBundler(3);
4736
4737 query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4738
4739 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4740
4741 query.append(_FINDER_COLUMN_G_U_USERID_2);
4742
4743 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4744 IGImage.class.getName(), _FILTER_COLUMN_PK,
4745 _FILTER_COLUMN_USERID, groupId);
4746
4747 Session session = null;
4748
4749 try {
4750 session = openSession();
4751
4752 SQLQuery q = session.createSQLQuery(sql);
4753
4754 q.addScalar(COUNT_COLUMN_NAME,
4755 com.liferay.portal.kernel.dao.orm.Type.LONG);
4756
4757 QueryPos qPos = QueryPos.getInstance(q);
4758
4759 qPos.add(groupId);
4760
4761 qPos.add(userId);
4762
4763 Long count = (Long)q.uniqueResult();
4764
4765 return count.intValue();
4766 }
4767 catch (Exception e) {
4768 throw processException(e);
4769 }
4770 finally {
4771 closeSession(session);
4772 }
4773 }
4774
4775
4783 public int countByG_F(long groupId, long folderId)
4784 throws SystemException {
4785 Object[] finderArgs = new Object[] { groupId, folderId };
4786
4787 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
4788 finderArgs, this);
4789
4790 if (count == null) {
4791 StringBundler query = new StringBundler(3);
4792
4793 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4794
4795 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
4796
4797 query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
4798
4799 String sql = query.toString();
4800
4801 Session session = null;
4802
4803 try {
4804 session = openSession();
4805
4806 Query q = session.createQuery(sql);
4807
4808 QueryPos qPos = QueryPos.getInstance(q);
4809
4810 qPos.add(groupId);
4811
4812 qPos.add(folderId);
4813
4814 count = (Long)q.uniqueResult();
4815 }
4816 catch (Exception e) {
4817 throw processException(e);
4818 }
4819 finally {
4820 if (count == null) {
4821 count = Long.valueOf(0);
4822 }
4823
4824 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
4825 count);
4826
4827 closeSession(session);
4828 }
4829 }
4830
4831 return count.intValue();
4832 }
4833
4834
4842 public int countByG_F(long groupId, long[] folderIds)
4843 throws SystemException {
4844 Object[] finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
4845
4846 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
4847 finderArgs, this);
4848
4849 if (count == null) {
4850 StringBundler query = new StringBundler();
4851
4852 query.append(_SQL_COUNT_IGIMAGE_WHERE);
4853
4854 boolean conjunctionable = false;
4855
4856 if (conjunctionable) {
4857 query.append(WHERE_AND);
4858 }
4859
4860 query.append(_FINDER_COLUMN_G_F_GROUPID_5);
4861
4862 conjunctionable = true;
4863
4864 if ((folderIds == null) || (folderIds.length > 0)) {
4865 if (conjunctionable) {
4866 query.append(WHERE_AND);
4867 }
4868
4869 query.append(StringPool.OPEN_PARENTHESIS);
4870
4871 for (int i = 0; i < folderIds.length; i++) {
4872 query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
4873
4874 if ((i + 1) < folderIds.length) {
4875 query.append(WHERE_OR);
4876 }
4877 }
4878
4879 query.append(StringPool.CLOSE_PARENTHESIS);
4880
4881 conjunctionable = true;
4882 }
4883
4884 String sql = query.toString();
4885
4886 Session session = null;
4887
4888 try {
4889 session = openSession();
4890
4891 Query q = session.createQuery(sql);
4892
4893 QueryPos qPos = QueryPos.getInstance(q);
4894
4895 qPos.add(groupId);
4896
4897 if (folderIds != null) {
4898 qPos.add(folderIds);
4899 }
4900
4901 count = (Long)q.uniqueResult();
4902 }
4903 catch (Exception e) {
4904 throw processException(e);
4905 }
4906 finally {
4907 if (count == null) {
4908 count = Long.valueOf(0);
4909 }
4910
4911 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
4912 count);
4913
4914 closeSession(session);
4915 }
4916 }
4917
4918 return count.intValue();
4919 }
4920
4921
4929 public int filterCountByG_F(long groupId, long folderId)
4930 throws SystemException {
4931 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4932 return countByG_F(groupId, folderId);
4933 }
4934
4935 StringBundler query = new StringBundler(3);
4936
4937 query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4938
4939 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
4940
4941 query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
4942
4943 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4944 IGImage.class.getName(), _FILTER_COLUMN_PK,
4945 _FILTER_COLUMN_USERID, groupId);
4946
4947 Session session = null;
4948
4949 try {
4950 session = openSession();
4951
4952 SQLQuery q = session.createSQLQuery(sql);
4953
4954 q.addScalar(COUNT_COLUMN_NAME,
4955 com.liferay.portal.kernel.dao.orm.Type.LONG);
4956
4957 QueryPos qPos = QueryPos.getInstance(q);
4958
4959 qPos.add(groupId);
4960
4961 qPos.add(folderId);
4962
4963 Long count = (Long)q.uniqueResult();
4964
4965 return count.intValue();
4966 }
4967 catch (Exception e) {
4968 throw processException(e);
4969 }
4970 finally {
4971 closeSession(session);
4972 }
4973 }
4974
4975
4983 public int filterCountByG_F(long groupId, long[] folderIds)
4984 throws SystemException {
4985 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4986 return countByG_F(groupId, folderIds);
4987 }
4988
4989 StringBundler query = new StringBundler();
4990
4991 query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
4992
4993 boolean conjunctionable = false;
4994
4995 if (conjunctionable) {
4996 query.append(WHERE_AND);
4997 }
4998
4999 query.append(_FINDER_COLUMN_G_F_GROUPID_5);
5000
5001 conjunctionable = true;
5002
5003 if ((folderIds == null) || (folderIds.length > 0)) {
5004 if (conjunctionable) {
5005 query.append(WHERE_AND);
5006 }
5007
5008 query.append(StringPool.OPEN_PARENTHESIS);
5009
5010 for (int i = 0; i < folderIds.length; i++) {
5011 query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
5012
5013 if ((i + 1) < folderIds.length) {
5014 query.append(WHERE_OR);
5015 }
5016 }
5017
5018 query.append(StringPool.CLOSE_PARENTHESIS);
5019
5020 conjunctionable = true;
5021 }
5022
5023 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5024 IGImage.class.getName(), _FILTER_COLUMN_PK,
5025 _FILTER_COLUMN_USERID, groupId);
5026
5027 Session session = null;
5028
5029 try {
5030 session = openSession();
5031
5032 SQLQuery q = session.createSQLQuery(sql);
5033
5034 q.addScalar(COUNT_COLUMN_NAME,
5035 com.liferay.portal.kernel.dao.orm.Type.LONG);
5036
5037 QueryPos qPos = QueryPos.getInstance(q);
5038
5039 qPos.add(groupId);
5040
5041 if (folderIds != null) {
5042 qPos.add(folderIds);
5043 }
5044
5045 Long count = (Long)q.uniqueResult();
5046
5047 return count.intValue();
5048 }
5049 catch (Exception e) {
5050 throw processException(e);
5051 }
5052 finally {
5053 closeSession(session);
5054 }
5055 }
5056
5057
5066 public int countByG_F_N(long groupId, long folderId, String name)
5067 throws SystemException {
5068 Object[] finderArgs = new Object[] { groupId, folderId, name };
5069
5070 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N,
5071 finderArgs, this);
5072
5073 if (count == null) {
5074 StringBundler query = new StringBundler(4);
5075
5076 query.append(_SQL_COUNT_IGIMAGE_WHERE);
5077
5078 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
5079
5080 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
5081
5082 if (name == null) {
5083 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
5084 }
5085 else {
5086 if (name.equals(StringPool.BLANK)) {
5087 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
5088 }
5089 else {
5090 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
5091 }
5092 }
5093
5094 String sql = query.toString();
5095
5096 Session session = null;
5097
5098 try {
5099 session = openSession();
5100
5101 Query q = session.createQuery(sql);
5102
5103 QueryPos qPos = QueryPos.getInstance(q);
5104
5105 qPos.add(groupId);
5106
5107 qPos.add(folderId);
5108
5109 if (name != null) {
5110 qPos.add(name);
5111 }
5112
5113 count = (Long)q.uniqueResult();
5114 }
5115 catch (Exception e) {
5116 throw processException(e);
5117 }
5118 finally {
5119 if (count == null) {
5120 count = Long.valueOf(0);
5121 }
5122
5123 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N,
5124 finderArgs, count);
5125
5126 closeSession(session);
5127 }
5128 }
5129
5130 return count.intValue();
5131 }
5132
5133
5142 public int filterCountByG_F_N(long groupId, long folderId, String name)
5143 throws SystemException {
5144 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5145 return countByG_F_N(groupId, folderId, name);
5146 }
5147
5148 StringBundler query = new StringBundler(4);
5149
5150 query.append(_FILTER_SQL_COUNT_IGIMAGE_WHERE);
5151
5152 query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
5153
5154 query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
5155
5156 if (name == null) {
5157 query.append(_FINDER_COLUMN_G_F_N_NAME_1);
5158 }
5159 else {
5160 if (name.equals(StringPool.BLANK)) {
5161 query.append(_FINDER_COLUMN_G_F_N_NAME_3);
5162 }
5163 else {
5164 query.append(_FINDER_COLUMN_G_F_N_NAME_2);
5165 }
5166 }
5167
5168 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5169 IGImage.class.getName(), _FILTER_COLUMN_PK,
5170 _FILTER_COLUMN_USERID, groupId);
5171
5172 Session session = null;
5173
5174 try {
5175 session = openSession();
5176
5177 SQLQuery q = session.createSQLQuery(sql);
5178
5179 q.addScalar(COUNT_COLUMN_NAME,
5180 com.liferay.portal.kernel.dao.orm.Type.LONG);
5181
5182 QueryPos qPos = QueryPos.getInstance(q);
5183
5184 qPos.add(groupId);
5185
5186 qPos.add(folderId);
5187
5188 if (name != null) {
5189 qPos.add(name);
5190 }
5191
5192 Long count = (Long)q.uniqueResult();
5193
5194 return count.intValue();
5195 }
5196 catch (Exception e) {
5197 throw processException(e);
5198 }
5199 finally {
5200 closeSession(session);
5201 }
5202 }
5203
5204
5210 public int countAll() throws SystemException {
5211 Object[] finderArgs = new Object[0];
5212
5213 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5214 finderArgs, this);
5215
5216 if (count == null) {
5217 Session session = null;
5218
5219 try {
5220 session = openSession();
5221
5222 Query q = session.createQuery(_SQL_COUNT_IGIMAGE);
5223
5224 count = (Long)q.uniqueResult();
5225 }
5226 catch (Exception e) {
5227 throw processException(e);
5228 }
5229 finally {
5230 if (count == null) {
5231 count = Long.valueOf(0);
5232 }
5233
5234 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
5235 count);
5236
5237 closeSession(session);
5238 }
5239 }
5240
5241 return count.intValue();
5242 }
5243
5244
5247 public void afterPropertiesSet() {
5248 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5249 com.liferay.portal.util.PropsUtil.get(
5250 "value.object.listener.com.liferay.portlet.imagegallery.model.IGImage")));
5251
5252 if (listenerClassNames.length > 0) {
5253 try {
5254 List<ModelListener<IGImage>> listenersList = new ArrayList<ModelListener<IGImage>>();
5255
5256 for (String listenerClassName : listenerClassNames) {
5257 listenersList.add((ModelListener<IGImage>)InstanceFactory.newInstance(
5258 listenerClassName));
5259 }
5260
5261 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5262 }
5263 catch (Exception e) {
5264 _log.error(e);
5265 }
5266 }
5267 }
5268
5269 public void destroy() {
5270 EntityCacheUtil.removeCache(IGImageImpl.class.getName());
5271 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5272 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
5273 }
5274
5275 @BeanReference(type = IGFolderPersistence.class)
5276 protected IGFolderPersistence igFolderPersistence;
5277 @BeanReference(type = IGImagePersistence.class)
5278 protected IGImagePersistence igImagePersistence;
5279 @BeanReference(type = ImagePersistence.class)
5280 protected ImagePersistence imagePersistence;
5281 @BeanReference(type = ResourcePersistence.class)
5282 protected ResourcePersistence resourcePersistence;
5283 @BeanReference(type = UserPersistence.class)
5284 protected UserPersistence userPersistence;
5285 @BeanReference(type = AssetCategoryPersistence.class)
5286 protected AssetCategoryPersistence assetCategoryPersistence;
5287 @BeanReference(type = AssetEntryPersistence.class)
5288 protected AssetEntryPersistence assetEntryPersistence;
5289 @BeanReference(type = AssetTagPersistence.class)
5290 protected AssetTagPersistence assetTagPersistence;
5291 @BeanReference(type = ExpandoValuePersistence.class)
5292 protected ExpandoValuePersistence expandoValuePersistence;
5293 @BeanReference(type = SocialActivityPersistence.class)
5294 protected SocialActivityPersistence socialActivityPersistence;
5295 private static final String _SQL_SELECT_IGIMAGE = "SELECT igImage FROM IGImage igImage";
5296 private static final String _SQL_SELECT_IGIMAGE_WHERE = "SELECT igImage FROM IGImage igImage WHERE ";
5297 private static final String _SQL_COUNT_IGIMAGE = "SELECT COUNT(igImage) FROM IGImage igImage";
5298 private static final String _SQL_COUNT_IGIMAGE_WHERE = "SELECT COUNT(igImage) FROM IGImage igImage WHERE ";
5299 private static final String _FINDER_COLUMN_UUID_UUID_1 = "igImage.uuid IS NULL";
5300 private static final String _FINDER_COLUMN_UUID_UUID_2 = "igImage.uuid = ?";
5301 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(igImage.uuid IS NULL OR igImage.uuid = ?)";
5302 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "igImage.uuid IS NULL AND ";
5303 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "igImage.uuid = ? AND ";
5304 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(igImage.uuid IS NULL OR igImage.uuid = ?) AND ";
5305 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "igImage.groupId = ?";
5306 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "igImage.groupId = ?";
5307 private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "igImage.smallImageId = ?";
5308 private static final String _FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2 = "igImage.largeImageId = ?";
5309 private static final String _FINDER_COLUMN_CUSTOM1IMAGEID_CUSTOM1IMAGEID_2 = "igImage.custom1ImageId = ?";
5310 private static final String _FINDER_COLUMN_CUSTOM2IMAGEID_CUSTOM2IMAGEID_2 = "igImage.custom2ImageId = ?";
5311 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "igImage.groupId = ? AND ";
5312 private static final String _FINDER_COLUMN_G_U_USERID_2 = "igImage.userId = ?";
5313 private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "igImage.groupId = ? AND ";
5314 private static final String _FINDER_COLUMN_G_F_GROUPID_5 = "(" +
5315 _removeConjunction(_FINDER_COLUMN_G_F_GROUPID_2) + ")";
5316 private static final String _FINDER_COLUMN_G_F_FOLDERID_2 = "igImage.folderId = ?";
5317 private static final String _FINDER_COLUMN_G_F_FOLDERID_5 = "(" +
5318 _removeConjunction(_FINDER_COLUMN_G_F_FOLDERID_2) + ")";
5319 private static final String _FINDER_COLUMN_G_F_N_GROUPID_2 = "igImage.groupId = ? AND ";
5320 private static final String _FINDER_COLUMN_G_F_N_FOLDERID_2 = "igImage.folderId = ? AND ";
5321 private static final String _FINDER_COLUMN_G_F_N_NAME_1 = "igImage.name IS NULL";
5322 private static final String _FINDER_COLUMN_G_F_N_NAME_2 = "igImage.name = ?";
5323 private static final String _FINDER_COLUMN_G_F_N_NAME_3 = "(igImage.name IS NULL OR igImage.name = ?)";
5324
5325 private static String _removeConjunction(String sql) {
5326 int pos = sql.indexOf(" AND ");
5327
5328 if (pos != -1) {
5329 sql = sql.substring(0, pos);
5330 }
5331
5332 return sql;
5333 }
5334
5335 private static final String _FILTER_SQL_SELECT_IGIMAGE_WHERE = "SELECT DISTINCT {igImage.*} FROM IGImage igImage WHERE ";
5336 private static final String _FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_1 =
5337 "SELECT {IGImage.*} FROM (SELECT DISTINCT igImage.imageId FROM IGImage igImage WHERE ";
5338 private static final String _FILTER_SQL_SELECT_IGIMAGE_NO_INLINE_DISTINCT_WHERE_2 =
5339 ") TEMP_TABLE INNER JOIN IGImage ON TEMP_TABLE.imageId = IGImage.imageId";
5340 private static final String _FILTER_SQL_COUNT_IGIMAGE_WHERE = "SELECT COUNT(DISTINCT igImage.imageId) AS COUNT_VALUE FROM IGImage igImage WHERE ";
5341 private static final String _FILTER_COLUMN_PK = "igImage.imageId";
5342 private static final String _FILTER_COLUMN_USERID = "igImage.userId";
5343 private static final String _FILTER_ENTITY_ALIAS = "igImage";
5344 private static final String _FILTER_ENTITY_TABLE = "IGImage";
5345 private static final String _ORDER_BY_ENTITY_ALIAS = "igImage.";
5346 private static final String _ORDER_BY_ENTITY_TABLE = "IGImage.";
5347 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No IGImage exists with the primary key ";
5348 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No IGImage exists with the key {";
5349 private static Log _log = LogFactoryUtil.getLog(IGImagePersistenceImpl.class);
5350 }