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