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.dao.jdbc.MappingSqlQuery;
27  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
28  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
29  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
30  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
31  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
32  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
33  import com.liferay.portal.kernel.dao.orm.Query;
34  import com.liferay.portal.kernel.dao.orm.QueryPos;
35  import com.liferay.portal.kernel.dao.orm.QueryUtil;
36  import com.liferay.portal.kernel.dao.orm.SQLQuery;
37  import com.liferay.portal.kernel.dao.orm.Session;
38  import com.liferay.portal.kernel.dao.orm.Type;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.ListUtil;
41  import com.liferay.portal.kernel.util.OrderByComparator;
42  import com.liferay.portal.kernel.util.StringPool;
43  import com.liferay.portal.kernel.util.StringUtil;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.service.persistence.BatchSessionUtil;
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 {
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             if (BatchSessionUtil.isEnabled()) {
151                 Object staleObject = session.get(SCProductEntryImpl.class,
152                         scProductEntry.getPrimaryKeyObj());
153 
154                 if (staleObject != null) {
155                     session.evict(staleObject);
156                 }
157             }
158 
159             session.delete(scProductEntry);
160 
161             session.flush();
162 
163             return scProductEntry;
164         }
165         catch (Exception e) {
166             throw processException(e);
167         }
168         finally {
169             closeSession(session);
170 
171             FinderCacheUtil.clearCache(SCProductEntry.class.getName());
172         }
173     }
174 
175     /**
176      * @deprecated Use <code>update(SCProductEntry scProductEntry, boolean merge)</code>.
177      */
178     public SCProductEntry update(SCProductEntry scProductEntry)
179         throws SystemException {
180         if (_log.isWarnEnabled()) {
181             _log.warn(
182                 "Using the deprecated update(SCProductEntry scProductEntry) method. Use update(SCProductEntry scProductEntry, boolean merge) instead.");
183         }
184 
185         return update(scProductEntry, false);
186     }
187 
188     /**
189      * Add, update, or merge, the entity. This method also calls the model
190      * listeners to trigger the proper events associated with adding, deleting,
191      * or updating an entity.
192      *
193      * @param        scProductEntry the entity to add, update, or merge
194      * @param        merge boolean value for whether to merge the entity. The
195      *                default value is false. Setting merge to true is more
196      *                expensive and should only be true when scProductEntry is
197      *                transient. See LEP-5473 for a detailed discussion of this
198      *                method.
199      * @return        true if the portlet can be displayed via Ajax
200      */
201     public SCProductEntry update(SCProductEntry scProductEntry, boolean merge)
202         throws SystemException {
203         boolean isNew = scProductEntry.isNew();
204 
205         if (_listeners.length > 0) {
206             for (ModelListener listener : _listeners) {
207                 if (isNew) {
208                     listener.onBeforeCreate(scProductEntry);
209                 }
210                 else {
211                     listener.onBeforeUpdate(scProductEntry);
212                 }
213             }
214         }
215 
216         scProductEntry = updateImpl(scProductEntry, merge);
217 
218         if (_listeners.length > 0) {
219             for (ModelListener listener : _listeners) {
220                 if (isNew) {
221                     listener.onAfterCreate(scProductEntry);
222                 }
223                 else {
224                     listener.onAfterUpdate(scProductEntry);
225                 }
226             }
227         }
228 
229         return scProductEntry;
230     }
231 
232     public SCProductEntry updateImpl(
233         com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry,
234         boolean merge) throws SystemException {
235         FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
236 
237         Session session = null;
238 
239         try {
240             session = openSession();
241 
242             BatchSessionUtil.update(session, scProductEntry, merge);
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 = null;
1275
1276                if (obc == null) {
1277                    list = (List<SCProductEntry>)QueryUtil.list(q,
1278                            getDialect(), start, end, false);
1279
1280                    Collections.sort(list);
1281                }
1282                else {
1283                    list = (List<SCProductEntry>)QueryUtil.list(q,
1284                            getDialect(), start, end);
1285                }
1286
1287                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1288                    finderClassName, finderMethodName, finderParams,
1289                    finderArgs, list);
1290
1291                return list;
1292            }
1293            catch (Exception e) {
1294                throw processException(e);
1295            }
1296            finally {
1297                closeSession(session);
1298            }
1299        }
1300        else {
1301            return (List<SCProductEntry>)result;
1302        }
1303    }
1304
1305    public void removeByGroupId(long groupId) throws SystemException {
1306        for (SCProductEntry scProductEntry : findByGroupId(groupId)) {
1307            remove(scProductEntry);
1308        }
1309    }
1310
1311    public void removeByCompanyId(long companyId) throws SystemException {
1312        for (SCProductEntry scProductEntry : findByCompanyId(companyId)) {
1313            remove(scProductEntry);
1314        }
1315    }
1316
1317    public void removeByG_U(long groupId, long userId)
1318        throws SystemException {
1319        for (SCProductEntry scProductEntry : findByG_U(groupId, userId)) {
1320            remove(scProductEntry);
1321        }
1322    }
1323
1324    public void removeByRG_RA(String repoGroupId, String repoArtifactId)
1325        throws NoSuchProductEntryException, SystemException {
1326        SCProductEntry scProductEntry = findByRG_RA(repoGroupId, repoArtifactId);
1327
1328        remove(scProductEntry);
1329    }
1330
1331    public void removeAll() throws SystemException {
1332        for (SCProductEntry scProductEntry : findAll()) {
1333            remove(scProductEntry);
1334        }
1335    }
1336
1337    public int countByGroupId(long groupId) throws SystemException {
1338        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1339        String finderClassName = SCProductEntry.class.getName();
1340        String finderMethodName = "countByGroupId";
1341        String[] finderParams = new String[] { Long.class.getName() };
1342        Object[] finderArgs = new Object[] { new Long(groupId) };
1343
1344        Object result = null;
1345
1346        if (finderClassNameCacheEnabled) {
1347            result = FinderCacheUtil.getResult(finderClassName,
1348                    finderMethodName, finderParams, finderArgs, this);
1349        }
1350
1351        if (result == null) {
1352            Session session = null;
1353
1354            try {
1355                session = openSession();
1356
1357                StringBuilder query = new StringBuilder();
1358
1359                query.append("SELECT COUNT(*) ");
1360                query.append(
1361                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1362
1363                query.append("groupId = ?");
1364
1365                query.append(" ");
1366
1367                Query q = session.createQuery(query.toString());
1368
1369                QueryPos qPos = QueryPos.getInstance(q);
1370
1371                qPos.add(groupId);
1372
1373                Long count = null;
1374
1375                Iterator<Long> itr = q.list().iterator();
1376
1377                if (itr.hasNext()) {
1378                    count = itr.next();
1379                }
1380
1381                if (count == null) {
1382                    count = new Long(0);
1383                }
1384
1385                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1386                    finderClassName, finderMethodName, finderParams,
1387                    finderArgs, count);
1388
1389                return count.intValue();
1390            }
1391            catch (Exception e) {
1392                throw processException(e);
1393            }
1394            finally {
1395                closeSession(session);
1396            }
1397        }
1398        else {
1399            return ((Long)result).intValue();
1400        }
1401    }
1402
1403    public int countByCompanyId(long companyId) throws SystemException {
1404        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1405        String finderClassName = SCProductEntry.class.getName();
1406        String finderMethodName = "countByCompanyId";
1407        String[] finderParams = new String[] { Long.class.getName() };
1408        Object[] finderArgs = new Object[] { new Long(companyId) };
1409
1410        Object result = null;
1411
1412        if (finderClassNameCacheEnabled) {
1413            result = FinderCacheUtil.getResult(finderClassName,
1414                    finderMethodName, finderParams, finderArgs, this);
1415        }
1416
1417        if (result == null) {
1418            Session session = null;
1419
1420            try {
1421                session = openSession();
1422
1423                StringBuilder query = new StringBuilder();
1424
1425                query.append("SELECT COUNT(*) ");
1426                query.append(
1427                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1428
1429                query.append("companyId = ?");
1430
1431                query.append(" ");
1432
1433                Query q = session.createQuery(query.toString());
1434
1435                QueryPos qPos = QueryPos.getInstance(q);
1436
1437                qPos.add(companyId);
1438
1439                Long count = null;
1440
1441                Iterator<Long> itr = q.list().iterator();
1442
1443                if (itr.hasNext()) {
1444                    count = itr.next();
1445                }
1446
1447                if (count == null) {
1448                    count = new Long(0);
1449                }
1450
1451                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1452                    finderClassName, finderMethodName, finderParams,
1453                    finderArgs, count);
1454
1455                return count.intValue();
1456            }
1457            catch (Exception e) {
1458                throw processException(e);
1459            }
1460            finally {
1461                closeSession(session);
1462            }
1463        }
1464        else {
1465            return ((Long)result).intValue();
1466        }
1467    }
1468
1469    public int countByG_U(long groupId, long userId) throws SystemException {
1470        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1471        String finderClassName = SCProductEntry.class.getName();
1472        String finderMethodName = "countByG_U";
1473        String[] finderParams = new String[] {
1474                Long.class.getName(), Long.class.getName()
1475            };
1476        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1477
1478        Object result = null;
1479
1480        if (finderClassNameCacheEnabled) {
1481            result = FinderCacheUtil.getResult(finderClassName,
1482                    finderMethodName, finderParams, finderArgs, this);
1483        }
1484
1485        if (result == null) {
1486            Session session = null;
1487
1488            try {
1489                session = openSession();
1490
1491                StringBuilder query = new StringBuilder();
1492
1493                query.append("SELECT COUNT(*) ");
1494                query.append(
1495                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1496
1497                query.append("groupId = ?");
1498
1499                query.append(" AND ");
1500
1501                query.append("userId = ?");
1502
1503                query.append(" ");
1504
1505                Query q = session.createQuery(query.toString());
1506
1507                QueryPos qPos = QueryPos.getInstance(q);
1508
1509                qPos.add(groupId);
1510
1511                qPos.add(userId);
1512
1513                Long count = null;
1514
1515                Iterator<Long> itr = q.list().iterator();
1516
1517                if (itr.hasNext()) {
1518                    count = itr.next();
1519                }
1520
1521                if (count == null) {
1522                    count = new Long(0);
1523                }
1524
1525                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1526                    finderClassName, finderMethodName, finderParams,
1527                    finderArgs, count);
1528
1529                return count.intValue();
1530            }
1531            catch (Exception e) {
1532                throw processException(e);
1533            }
1534            finally {
1535                closeSession(session);
1536            }
1537        }
1538        else {
1539            return ((Long)result).intValue();
1540        }
1541    }
1542
1543    public int countByRG_RA(String repoGroupId, String repoArtifactId)
1544        throws SystemException {
1545        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1546        String finderClassName = SCProductEntry.class.getName();
1547        String finderMethodName = "countByRG_RA";
1548        String[] finderParams = new String[] {
1549                String.class.getName(), String.class.getName()
1550            };
1551        Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
1552
1553        Object result = null;
1554
1555        if (finderClassNameCacheEnabled) {
1556            result = FinderCacheUtil.getResult(finderClassName,
1557                    finderMethodName, finderParams, finderArgs, this);
1558        }
1559
1560        if (result == null) {
1561            Session session = null;
1562
1563            try {
1564                session = openSession();
1565
1566                StringBuilder query = new StringBuilder();
1567
1568                query.append("SELECT COUNT(*) ");
1569                query.append(
1570                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1571
1572                if (repoGroupId == null) {
1573                    query.append("repoGroupId IS NULL");
1574                }
1575                else {
1576                    query.append("lower(repoGroupId) = ?");
1577                }
1578
1579                query.append(" AND ");
1580
1581                if (repoArtifactId == null) {
1582                    query.append("repoArtifactId IS NULL");
1583                }
1584                else {
1585                    query.append("lower(repoArtifactId) = ?");
1586                }
1587
1588                query.append(" ");
1589
1590                Query q = session.createQuery(query.toString());
1591
1592                QueryPos qPos = QueryPos.getInstance(q);
1593
1594                if (repoGroupId != null) {
1595                    qPos.add(repoGroupId);
1596                }
1597
1598                if (repoArtifactId != null) {
1599                    qPos.add(repoArtifactId);
1600                }
1601
1602                Long count = null;
1603
1604                Iterator<Long> itr = q.list().iterator();
1605
1606                if (itr.hasNext()) {
1607                    count = itr.next();
1608                }
1609
1610                if (count == null) {
1611                    count = new Long(0);
1612                }
1613
1614                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1615                    finderClassName, finderMethodName, finderParams,
1616                    finderArgs, count);
1617
1618                return count.intValue();
1619            }
1620            catch (Exception e) {
1621                throw processException(e);
1622            }
1623            finally {
1624                closeSession(session);
1625            }
1626        }
1627        else {
1628            return ((Long)result).intValue();
1629        }
1630    }
1631
1632    public int countAll() throws SystemException {
1633        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1634        String finderClassName = SCProductEntry.class.getName();
1635        String finderMethodName = "countAll";
1636        String[] finderParams = new String[] {  };
1637        Object[] finderArgs = new Object[] {  };
1638
1639        Object result = null;
1640
1641        if (finderClassNameCacheEnabled) {
1642            result = FinderCacheUtil.getResult(finderClassName,
1643                    finderMethodName, finderParams, finderArgs, this);
1644        }
1645
1646        if (result == null) {
1647            Session session = null;
1648
1649            try {
1650                session = openSession();
1651
1652                Query q = session.createQuery(
1653                        "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry");
1654
1655                Long count = null;
1656
1657                Iterator<Long> itr = q.list().iterator();
1658
1659                if (itr.hasNext()) {
1660                    count = itr.next();
1661                }
1662
1663                if (count == null) {
1664                    count = new Long(0);
1665                }
1666
1667                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1668                    finderClassName, finderMethodName, finderParams,
1669                    finderArgs, count);
1670
1671                return count.intValue();
1672            }
1673            catch (Exception e) {
1674                throw processException(e);
1675            }
1676            finally {
1677                closeSession(session);
1678            }
1679        }
1680        else {
1681            return ((Long)result).intValue();
1682        }
1683    }
1684
1685    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1686        long pk) throws SystemException {
1687        return getSCLicenses(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1688    }
1689
1690    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1691        long pk, int start, int end) throws SystemException {
1692        return getSCLicenses(pk, start, end, null);
1693    }
1694
1695    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1696        long pk, int start, int end, OrderByComparator obc)
1697        throws SystemException {
1698        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1699
1700        String finderClassName = "SCLicenses_SCProductEntries";
1701
1702        String finderMethodName = "getSCLicenses";
1703        String[] finderParams = new String[] {
1704                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1705                "com.liferay.portal.kernel.util.OrderByComparator"
1706            };
1707        Object[] finderArgs = new Object[] {
1708                new Long(pk), String.valueOf(start), String.valueOf(end),
1709                String.valueOf(obc)
1710            };
1711
1712        Object result = null;
1713
1714        if (finderClassNameCacheEnabled) {
1715            result = FinderCacheUtil.getResult(finderClassName,
1716                    finderMethodName, finderParams, finderArgs, this);
1717        }
1718
1719        if (result == null) {
1720            Session session = null;
1721
1722            try {
1723                session = openSession();
1724
1725                StringBuilder sb = new StringBuilder();
1726
1727                sb.append(_SQL_GETSCLICENSES);
1728
1729                if (obc != null) {
1730                    sb.append("ORDER BY ");
1731                    sb.append(obc.getOrderBy());
1732                }
1733
1734                else {
1735                    sb.append("ORDER BY ");
1736
1737                    sb.append("SCLicense.name ASC");
1738                }
1739
1740                String sql = sb.toString();
1741
1742                SQLQuery q = session.createSQLQuery(sql);
1743
1744                q.addEntity("SCLicense",
1745                    com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl.class);
1746
1747                QueryPos qPos = QueryPos.getInstance(q);
1748
1749                qPos.add(pk);
1750
1751                List<com.liferay.portlet.softwarecatalog.model.SCLicense> list = (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)QueryUtil.list(q,
1752                        getDialect(), start, end);
1753
1754                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1755                    finderClassName, finderMethodName, finderParams,
1756                    finderArgs, list);
1757
1758                return list;
1759            }
1760            catch (Exception e) {
1761                throw processException(e);
1762            }
1763            finally {
1764                closeSession(session);
1765            }
1766        }
1767        else {
1768            return (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)result;
1769        }
1770    }
1771
1772    public int getSCLicensesSize(long pk) throws SystemException {
1773        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1774
1775        String finderClassName = "SCLicenses_SCProductEntries";
1776
1777        String finderMethodName = "getSCLicensesSize";
1778        String[] finderParams = new String[] { Long.class.getName() };
1779        Object[] finderArgs = new Object[] { new Long(pk) };
1780
1781        Object result = null;
1782
1783        if (finderClassNameCacheEnabled) {
1784            result = FinderCacheUtil.getResult(finderClassName,
1785                    finderMethodName, finderParams, finderArgs, this);
1786        }
1787
1788        if (result == null) {
1789            Session session = null;
1790
1791            try {
1792                session = openSession();
1793
1794                SQLQuery q = session.createSQLQuery(_SQL_GETSCLICENSESSIZE);
1795
1796                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1797
1798                QueryPos qPos = QueryPos.getInstance(q);
1799
1800                qPos.add(pk);
1801
1802                Long count = null;
1803
1804                Iterator<Long> itr = q.list().iterator();
1805
1806                if (itr.hasNext()) {
1807                    count = itr.next();
1808                }
1809
1810                if (count == null) {
1811                    count = new Long(0);
1812                }
1813
1814                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1815                    finderClassName, finderMethodName, finderParams,
1816                    finderArgs, count);
1817
1818                return count.intValue();
1819            }
1820            catch (Exception e) {
1821                throw processException(e);
1822            }
1823            finally {
1824                closeSession(session);
1825            }
1826        }
1827        else {
1828            return ((Long)result).intValue();
1829        }
1830    }
1831
1832    public boolean containsSCLicense(long pk, long scLicensePK)
1833        throws SystemException {
1834        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1835
1836        String finderClassName = "SCLicenses_SCProductEntries";
1837
1838        String finderMethodName = "containsSCLicenses";
1839        String[] finderParams = new String[] {
1840                Long.class.getName(),
1841                
1842                Long.class.getName()
1843            };
1844        Object[] finderArgs = new Object[] { new Long(pk), new Long(scLicensePK) };
1845
1846        Object result = null;
1847
1848        if (finderClassNameCacheEnabled) {
1849            result = FinderCacheUtil.getResult(finderClassName,
1850                    finderMethodName, finderParams, finderArgs, this);
1851        }
1852
1853        if (result == null) {
1854            try {
1855                Boolean value = Boolean.valueOf(containsSCLicense.contains(pk,
1856                            scLicensePK));
1857
1858                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1859                    finderClassName, finderMethodName, finderParams,
1860                    finderArgs, value);
1861
1862                return value.booleanValue();
1863            }
1864            catch (Exception e) {
1865                throw processException(e);
1866            }
1867        }
1868        else {
1869            return ((Boolean)result).booleanValue();
1870        }
1871    }
1872
1873    public boolean containsSCLicenses(long pk) throws SystemException {
1874        if (getSCLicensesSize(pk) > 0) {
1875            return true;
1876        }
1877        else {
1878            return false;
1879        }
1880    }
1881
1882    public void addSCLicense(long pk, long scLicensePK)
1883        throws SystemException {
1884        try {
1885            addSCLicense.add(pk, scLicensePK);
1886        }
1887        catch (Exception e) {
1888            throw processException(e);
1889        }
1890        finally {
1891            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1892        }
1893    }
1894
1895    public void addSCLicense(long pk,
1896        com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
1897        throws SystemException {
1898        try {
1899            addSCLicense.add(pk, scLicense.getPrimaryKey());
1900        }
1901        catch (Exception e) {
1902            throw processException(e);
1903        }
1904        finally {
1905            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1906        }
1907    }
1908
1909    public void addSCLicenses(long pk, long[] scLicensePKs)
1910        throws SystemException {
1911        try {
1912            for (long scLicensePK : scLicensePKs) {
1913                addSCLicense.add(pk, scLicensePK);
1914            }
1915        }
1916        catch (Exception e) {
1917            throw processException(e);
1918        }
1919        finally {
1920            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1921        }
1922    }
1923
1924    public void addSCLicenses(long pk,
1925        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
1926        throws SystemException {
1927        try {
1928            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
1929                addSCLicense.add(pk, scLicense.getPrimaryKey());
1930            }
1931        }
1932        catch (Exception e) {
1933            throw processException(e);
1934        }
1935        finally {
1936            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1937        }
1938    }
1939
1940    public void clearSCLicenses(long pk) throws SystemException {
1941        try {
1942            clearSCLicenses.clear(pk);
1943        }
1944        catch (Exception e) {
1945            throw processException(e);
1946        }
1947        finally {
1948            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1949        }
1950    }
1951
1952    public void removeSCLicense(long pk, long scLicensePK)
1953        throws SystemException {
1954        try {
1955            removeSCLicense.remove(pk, scLicensePK);
1956        }
1957        catch (Exception e) {
1958            throw processException(e);
1959        }
1960        finally {
1961            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1962        }
1963    }
1964
1965    public void removeSCLicense(long pk,
1966        com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
1967        throws SystemException {
1968        try {
1969            removeSCLicense.remove(pk, scLicense.getPrimaryKey());
1970        }
1971        catch (Exception e) {
1972            throw processException(e);
1973        }
1974        finally {
1975            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1976        }
1977    }
1978
1979    public void removeSCLicenses(long pk, long[] scLicensePKs)
1980        throws SystemException {
1981        try {
1982            for (long scLicensePK : scLicensePKs) {
1983                removeSCLicense.remove(pk, scLicensePK);
1984            }
1985        }
1986        catch (Exception e) {
1987            throw processException(e);
1988        }
1989        finally {
1990            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1991        }
1992    }
1993
1994    public void removeSCLicenses(long pk,
1995        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
1996        throws SystemException {
1997        try {
1998            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
1999                removeSCLicense.remove(pk, scLicense.getPrimaryKey());
2000            }
2001        }
2002        catch (Exception e) {
2003            throw processException(e);
2004        }
2005        finally {
2006            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2007        }
2008    }
2009
2010    public void setSCLicenses(long pk, long[] scLicensePKs)
2011        throws SystemException {
2012        try {
2013            clearSCLicenses.clear(pk);
2014
2015            for (long scLicensePK : scLicensePKs) {
2016                addSCLicense.add(pk, scLicensePK);
2017            }
2018        }
2019        catch (Exception e) {
2020            throw processException(e);
2021        }
2022        finally {
2023            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2024        }
2025    }
2026
2027    public void setSCLicenses(long pk,
2028        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
2029        throws SystemException {
2030        try {
2031            clearSCLicenses.clear(pk);
2032
2033            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
2034                addSCLicense.add(pk, scLicense.getPrimaryKey());
2035            }
2036        }
2037        catch (Exception e) {
2038            throw processException(e);
2039        }
2040        finally {
2041            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2042        }
2043    }
2044
2045    public void registerListener(ModelListener listener) {
2046        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2047
2048        listeners.add(listener);
2049
2050        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2051    }
2052
2053    public void unregisterListener(ModelListener listener) {
2054        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2055
2056        listeners.remove(listener);
2057
2058        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2059    }
2060
2061    public void afterPropertiesSet() {
2062        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2063                    com.liferay.portal.util.PropsUtil.get(
2064                        "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductEntry")));
2065
2066        if (listenerClassNames.length > 0) {
2067            try {
2068                List<ModelListener> listeners = new ArrayList<ModelListener>();
2069
2070                for (String listenerClassName : listenerClassNames) {
2071                    listeners.add((ModelListener)Class.forName(
2072                            listenerClassName).newInstance());
2073                }
2074
2075                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2076            }
2077            catch (Exception e) {
2078                _log.error(e);
2079            }
2080        }
2081
2082        containsSCLicense = new ContainsSCLicense(this);
2083
2084        addSCLicense = new AddSCLicense(this);
2085        clearSCLicenses = new ClearSCLicenses(this);
2086        removeSCLicense = new RemoveSCLicense(this);
2087    }
2088
2089    protected ContainsSCLicense containsSCLicense;
2090    protected AddSCLicense addSCLicense;
2091    protected ClearSCLicenses clearSCLicenses;
2092    protected RemoveSCLicense removeSCLicense;
2093
2094    protected class ContainsSCLicense {
2095        protected ContainsSCLicense(
2096            SCProductEntryPersistenceImpl persistenceImpl) {
2097            super();
2098
2099            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2100                    _SQL_CONTAINSSCLICENSE,
2101                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2102        }
2103
2104        protected boolean contains(long productEntryId, long licenseId) {
2105            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2106                        new Long(productEntryId), new Long(licenseId)
2107                    });
2108
2109            if (results.size() > 0) {
2110                Integer count = results.get(0);
2111
2112                if (count.intValue() > 0) {
2113                    return true;
2114                }
2115            }
2116
2117            return false;
2118        }
2119
2120        private MappingSqlQuery _mappingSqlQuery;
2121    }
2122
2123    protected class AddSCLicense {
2124        protected AddSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2125            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2126                    "INSERT INTO SCLicenses_SCProductEntries (productEntryId, licenseId) VALUES (?, ?)",
2127                    new int[] { Types.BIGINT, Types.BIGINT });
2128            _persistenceImpl = persistenceImpl;
2129        }
2130
2131        protected void add(long productEntryId, long licenseId) {
2132            if (!_persistenceImpl.containsSCLicense.contains(productEntryId,
2133                        licenseId)) {
2134                _sqlUpdate.update(new Object[] {
2135                        new Long(productEntryId), new Long(licenseId)
2136                    });
2137            }
2138        }
2139
2140        private SqlUpdate _sqlUpdate;
2141        private SCProductEntryPersistenceImpl _persistenceImpl;
2142    }
2143
2144    protected class ClearSCLicenses {
2145        protected ClearSCLicenses(SCProductEntryPersistenceImpl persistenceImpl) {
2146            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2147                    "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?",
2148                    new int[] { Types.BIGINT });
2149        }
2150
2151        protected void clear(long productEntryId) {
2152            _sqlUpdate.update(new Object[] { new Long(productEntryId) });
2153        }
2154
2155        private SqlUpdate _sqlUpdate;
2156    }
2157
2158    protected class RemoveSCLicense {
2159        protected RemoveSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2160            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2161                    "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?",
2162                    new int[] { Types.BIGINT, Types.BIGINT });
2163        }
2164
2165        protected void remove(long productEntryId, long licenseId) {
2166            _sqlUpdate.update(new Object[] {
2167                    new Long(productEntryId), new Long(licenseId)
2168                });
2169        }
2170
2171        private SqlUpdate _sqlUpdate;
2172    }
2173
2174    private static final String _SQL_GETSCLICENSES = "SELECT {SCLicense.*} FROM SCLicense INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.licenseId = SCLicense.licenseId) WHERE (SCLicenses_SCProductEntries.productEntryId = ?)";
2175    private static final String _SQL_GETSCLICENSESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?";
2176    private static final String _SQL_CONTAINSSCLICENSE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?";
2177    private static Log _log = LogFactory.getLog(SCProductEntryPersistenceImpl.class);
2178    private ModelListener[] _listeners = new ModelListener[0];
2179}