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