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