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