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