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