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