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