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