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