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