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