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