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