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                     "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
460 
461                 query.append("scProductEntry.groupId = ?");
462 
463                 query.append(" ");
464 
465                 query.append("ORDER BY ");
466 
467                 query.append("scProductEntry.modifiedDate DESC, ");
468                 query.append("scProductEntry.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                     "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
524 
525                 query.append("scProductEntry.groupId = ?");
526 
527                 query.append(" ");
528 
529                 if (obc != null) {
530                     query.append("ORDER BY ");
531 
532                     String[] orderByFields = obc.getOrderByFields();
533 
534                     for (int i = 0; i < orderByFields.length; i++) {
535                         query.append("scProductEntry.");
536                         query.append(orderByFields[i]);
537 
538                         if (obc.isAscending()) {
539                             query.append(" ASC");
540                         }
541                         else {
542                             query.append(" DESC");
543                         }
544 
545                         if ((i + 1) < orderByFields.length) {
546                             query.append(", ");
547                         }
548                     }
549                 }
550 
551                 else {
552                     query.append("ORDER BY ");
553 
554                     query.append("scProductEntry.modifiedDate DESC, ");
555                     query.append("scProductEntry.name DESC");
556                 }
557 
558                 Query q = session.createQuery(query.toString());
559 
560                 QueryPos qPos = QueryPos.getInstance(q);
561 
562                 qPos.add(groupId);
563 
564                 list = (List<SCProductEntry>)QueryUtil.list(q, getDialect(),
565                         start, end);
566             }
567             catch (Exception e) {
568                 throw processException(e);
569             }
570             finally {
571                 if (list == null) {
572                     list = new ArrayList<SCProductEntry>();
573                 }
574 
575                 cacheResult(list);
576 
577                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
578                     finderArgs, list);
579 
580                 closeSession(session);
581             }
582         }
583 
584         return list;
585     }
586 
587     public SCProductEntry findByGroupId_First(long groupId,
588         OrderByComparator obc)
589         throws NoSuchProductEntryException, SystemException {
590         List<SCProductEntry> list = findByGroupId(groupId, 0, 1, obc);
591 
592         if (list.isEmpty()) {
593             StringBuilder msg = new StringBuilder();
594 
595             msg.append("No SCProductEntry exists with the key {");
596 
597             msg.append("groupId=" + groupId);
598 
599             msg.append(StringPool.CLOSE_CURLY_BRACE);
600 
601             throw new NoSuchProductEntryException(msg.toString());
602         }
603         else {
604             return list.get(0);
605         }
606     }
607 
608     public SCProductEntry findByGroupId_Last(long groupId, OrderByComparator obc)
609         throws NoSuchProductEntryException, SystemException {
610         int count = countByGroupId(groupId);
611 
612         List<SCProductEntry> list = findByGroupId(groupId, count - 1, count, obc);
613 
614         if (list.isEmpty()) {
615             StringBuilder msg = new StringBuilder();
616 
617             msg.append("No SCProductEntry exists with the key {");
618 
619             msg.append("groupId=" + groupId);
620 
621             msg.append(StringPool.CLOSE_CURLY_BRACE);
622 
623             throw new NoSuchProductEntryException(msg.toString());
624         }
625         else {
626             return list.get(0);
627         }
628     }
629 
630     public SCProductEntry[] findByGroupId_PrevAndNext(long productEntryId,
631         long groupId, OrderByComparator obc)
632         throws NoSuchProductEntryException, SystemException {
633         SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
634 
635         int count = countByGroupId(groupId);
636 
637         Session session = null;
638 
639         try {
640             session = openSession();
641 
642             StringBuilder query = new StringBuilder();
643 
644             query.append(
645                 "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
646 
647             query.append("scProductEntry.groupId = ?");
648 
649             query.append(" ");
650 
651             if (obc != null) {
652                 query.append("ORDER BY ");
653 
654                 String[] orderByFields = obc.getOrderByFields();
655 
656                 for (int i = 0; i < orderByFields.length; i++) {
657                     query.append("scProductEntry.");
658                     query.append(orderByFields[i]);
659 
660                     if (obc.isAscending()) {
661                         query.append(" ASC");
662                     }
663                     else {
664                         query.append(" DESC");
665                     }
666 
667                     if ((i + 1) < orderByFields.length) {
668                         query.append(", ");
669                     }
670                 }
671             }
672 
673             else {
674                 query.append("ORDER BY ");
675 
676                 query.append("scProductEntry.modifiedDate DESC, ");
677                 query.append("scProductEntry.name DESC");
678             }
679 
680             Query q = session.createQuery(query.toString());
681 
682             QueryPos qPos = QueryPos.getInstance(q);
683 
684             qPos.add(groupId);
685 
686             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
687                     scProductEntry);
688 
689             SCProductEntry[] array = new SCProductEntryImpl[3];
690 
691             array[0] = (SCProductEntry)objArray[0];
692             array[1] = (SCProductEntry)objArray[1];
693             array[2] = (SCProductEntry)objArray[2];
694 
695             return array;
696         }
697         catch (Exception e) {
698             throw processException(e);
699         }
700         finally {
701             closeSession(session);
702         }
703     }
704 
705     public List<SCProductEntry> findByCompanyId(long companyId)
706         throws SystemException {
707         Object[] finderArgs = new Object[] { new Long(companyId) };
708 
709         List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
710                 finderArgs, this);
711 
712         if (list == null) {
713             Session session = null;
714 
715             try {
716                 session = openSession();
717 
718                 StringBuilder query = new StringBuilder();
719 
720                 query.append(
721                     "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
722 
723                 query.append("scProductEntry.companyId = ?");
724 
725                 query.append(" ");
726 
727                 query.append("ORDER BY ");
728 
729                 query.append("scProductEntry.modifiedDate DESC, ");
730                 query.append("scProductEntry.name DESC");
731 
732                 Query q = session.createQuery(query.toString());
733 
734                 QueryPos qPos = QueryPos.getInstance(q);
735 
736                 qPos.add(companyId);
737 
738                 list = q.list();
739             }
740             catch (Exception e) {
741                 throw processException(e);
742             }
743             finally {
744                 if (list == null) {
745                     list = new ArrayList<SCProductEntry>();
746                 }
747 
748                 cacheResult(list);
749 
750                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
751                     finderArgs, list);
752 
753                 closeSession(session);
754             }
755         }
756 
757         return list;
758     }
759 
760     public List<SCProductEntry> findByCompanyId(long companyId, int start,
761         int end) throws SystemException {
762         return findByCompanyId(companyId, start, end, null);
763     }
764 
765     public List<SCProductEntry> findByCompanyId(long companyId, int start,
766         int end, OrderByComparator obc) throws SystemException {
767         Object[] finderArgs = new Object[] {
768                 new Long(companyId),
769                 
770                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
771             };
772 
773         List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
774                 finderArgs, this);
775 
776         if (list == null) {
777             Session session = null;
778 
779             try {
780                 session = openSession();
781 
782                 StringBuilder query = new StringBuilder();
783 
784                 query.append(
785                     "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
786 
787                 query.append("scProductEntry.companyId = ?");
788 
789                 query.append(" ");
790 
791                 if (obc != null) {
792                     query.append("ORDER BY ");
793 
794                     String[] orderByFields = obc.getOrderByFields();
795 
796                     for (int i = 0; i < orderByFields.length; i++) {
797                         query.append("scProductEntry.");
798                         query.append(orderByFields[i]);
799 
800                         if (obc.isAscending()) {
801                             query.append(" ASC");
802                         }
803                         else {
804                             query.append(" DESC");
805                         }
806 
807                         if ((i + 1) < orderByFields.length) {
808                             query.append(", ");
809                         }
810                     }
811                 }
812 
813                 else {
814                     query.append("ORDER BY ");
815 
816                     query.append("scProductEntry.modifiedDate DESC, ");
817                     query.append("scProductEntry.name DESC");
818                 }
819 
820                 Query q = session.createQuery(query.toString());
821 
822                 QueryPos qPos = QueryPos.getInstance(q);
823 
824                 qPos.add(companyId);
825 
826                 list = (List<SCProductEntry>)QueryUtil.list(q, getDialect(),
827                         start, end);
828             }
829             catch (Exception e) {
830                 throw processException(e);
831             }
832             finally {
833                 if (list == null) {
834                     list = new ArrayList<SCProductEntry>();
835                 }
836 
837                 cacheResult(list);
838 
839                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
840                     finderArgs, list);
841 
842                 closeSession(session);
843             }
844         }
845 
846         return list;
847     }
848 
849     public SCProductEntry findByCompanyId_First(long companyId,
850         OrderByComparator obc)
851         throws NoSuchProductEntryException, SystemException {
852         List<SCProductEntry> list = findByCompanyId(companyId, 0, 1, obc);
853 
854         if (list.isEmpty()) {
855             StringBuilder msg = new StringBuilder();
856 
857             msg.append("No SCProductEntry exists with the key {");
858 
859             msg.append("companyId=" + companyId);
860 
861             msg.append(StringPool.CLOSE_CURLY_BRACE);
862 
863             throw new NoSuchProductEntryException(msg.toString());
864         }
865         else {
866             return list.get(0);
867         }
868     }
869 
870     public SCProductEntry findByCompanyId_Last(long companyId,
871         OrderByComparator obc)
872         throws NoSuchProductEntryException, SystemException {
873         int count = countByCompanyId(companyId);
874 
875         List<SCProductEntry> list = findByCompanyId(companyId, count - 1,
876                 count, obc);
877 
878         if (list.isEmpty()) {
879             StringBuilder msg = new StringBuilder();
880 
881             msg.append("No SCProductEntry exists with the key {");
882 
883             msg.append("companyId=" + companyId);
884 
885             msg.append(StringPool.CLOSE_CURLY_BRACE);
886 
887             throw new NoSuchProductEntryException(msg.toString());
888         }
889         else {
890             return list.get(0);
891         }
892     }
893 
894     public SCProductEntry[] findByCompanyId_PrevAndNext(long productEntryId,
895         long companyId, OrderByComparator obc)
896         throws NoSuchProductEntryException, SystemException {
897         SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
898 
899         int count = countByCompanyId(companyId);
900 
901         Session session = null;
902 
903         try {
904             session = openSession();
905 
906             StringBuilder query = new StringBuilder();
907 
908             query.append(
909                 "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
910 
911             query.append("scProductEntry.companyId = ?");
912 
913             query.append(" ");
914 
915             if (obc != null) {
916                 query.append("ORDER BY ");
917 
918                 String[] orderByFields = obc.getOrderByFields();
919 
920                 for (int i = 0; i < orderByFields.length; i++) {
921                     query.append("scProductEntry.");
922                     query.append(orderByFields[i]);
923 
924                     if (obc.isAscending()) {
925                         query.append(" ASC");
926                     }
927                     else {
928                         query.append(" DESC");
929                     }
930 
931                     if ((i + 1) < orderByFields.length) {
932                         query.append(", ");
933                     }
934                 }
935             }
936 
937             else {
938                 query.append("ORDER BY ");
939 
940                 query.append("scProductEntry.modifiedDate DESC, ");
941                 query.append("scProductEntry.name DESC");
942             }
943 
944             Query q = session.createQuery(query.toString());
945 
946             QueryPos qPos = QueryPos.getInstance(q);
947 
948             qPos.add(companyId);
949 
950             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
951                     scProductEntry);
952 
953             SCProductEntry[] array = new SCProductEntryImpl[3];
954 
955             array[0] = (SCProductEntry)objArray[0];
956             array[1] = (SCProductEntry)objArray[1];
957             array[2] = (SCProductEntry)objArray[2];
958 
959             return array;
960         }
961         catch (Exception e) {
962             throw processException(e);
963         }
964         finally {
965             closeSession(session);
966         }
967     }
968 
969     public List<SCProductEntry> findByG_U(long groupId, long userId)
970         throws SystemException {
971         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
972 
973         List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
974                 finderArgs, this);
975 
976         if (list == null) {
977             Session session = null;
978 
979             try {
980                 session = openSession();
981 
982                 StringBuilder query = new StringBuilder();
983 
984                 query.append(
985                     "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
986 
987                 query.append("scProductEntry.groupId = ?");
988 
989                 query.append(" AND ");
990 
991                 query.append("scProductEntry.userId = ?");
992 
993                 query.append(" ");
994 
995                 query.append("ORDER BY ");
996 
997                 query.append("scProductEntry.modifiedDate DESC, ");
998                 query.append("scProductEntry.name DESC");
999 
1000                Query q = session.createQuery(query.toString());
1001
1002                QueryPos qPos = QueryPos.getInstance(q);
1003
1004                qPos.add(groupId);
1005
1006                qPos.add(userId);
1007
1008                list = q.list();
1009            }
1010            catch (Exception e) {
1011                throw processException(e);
1012            }
1013            finally {
1014                if (list == null) {
1015                    list = new ArrayList<SCProductEntry>();
1016                }
1017
1018                cacheResult(list);
1019
1020                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
1021                    list);
1022
1023                closeSession(session);
1024            }
1025        }
1026
1027        return list;
1028    }
1029
1030    public List<SCProductEntry> findByG_U(long groupId, long userId, int start,
1031        int end) throws SystemException {
1032        return findByG_U(groupId, userId, start, end, null);
1033    }
1034
1035    public List<SCProductEntry> findByG_U(long groupId, long userId, int start,
1036        int end, OrderByComparator obc) throws SystemException {
1037        Object[] finderArgs = new Object[] {
1038                new Long(groupId), new Long(userId),
1039                
1040                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1041            };
1042
1043        List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_U,
1044                finderArgs, this);
1045
1046        if (list == null) {
1047            Session session = null;
1048
1049            try {
1050                session = openSession();
1051
1052                StringBuilder query = new StringBuilder();
1053
1054                query.append(
1055                    "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
1056
1057                query.append("scProductEntry.groupId = ?");
1058
1059                query.append(" AND ");
1060
1061                query.append("scProductEntry.userId = ?");
1062
1063                query.append(" ");
1064
1065                if (obc != null) {
1066                    query.append("ORDER BY ");
1067
1068                    String[] orderByFields = obc.getOrderByFields();
1069
1070                    for (int i = 0; i < orderByFields.length; i++) {
1071                        query.append("scProductEntry.");
1072                        query.append(orderByFields[i]);
1073
1074                        if (obc.isAscending()) {
1075                            query.append(" ASC");
1076                        }
1077                        else {
1078                            query.append(" DESC");
1079                        }
1080
1081                        if ((i + 1) < orderByFields.length) {
1082                            query.append(", ");
1083                        }
1084                    }
1085                }
1086
1087                else {
1088                    query.append("ORDER BY ");
1089
1090                    query.append("scProductEntry.modifiedDate DESC, ");
1091                    query.append("scProductEntry.name DESC");
1092                }
1093
1094                Query q = session.createQuery(query.toString());
1095
1096                QueryPos qPos = QueryPos.getInstance(q);
1097
1098                qPos.add(groupId);
1099
1100                qPos.add(userId);
1101
1102                list = (List<SCProductEntry>)QueryUtil.list(q, getDialect(),
1103                        start, end);
1104            }
1105            catch (Exception e) {
1106                throw processException(e);
1107            }
1108            finally {
1109                if (list == null) {
1110                    list = new ArrayList<SCProductEntry>();
1111                }
1112
1113                cacheResult(list);
1114
1115                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_U,
1116                    finderArgs, list);
1117
1118                closeSession(session);
1119            }
1120        }
1121
1122        return list;
1123    }
1124
1125    public SCProductEntry findByG_U_First(long groupId, long userId,
1126        OrderByComparator obc)
1127        throws NoSuchProductEntryException, SystemException {
1128        List<SCProductEntry> list = findByG_U(groupId, userId, 0, 1, obc);
1129
1130        if (list.isEmpty()) {
1131            StringBuilder msg = new StringBuilder();
1132
1133            msg.append("No SCProductEntry exists with the key {");
1134
1135            msg.append("groupId=" + groupId);
1136
1137            msg.append(", ");
1138            msg.append("userId=" + userId);
1139
1140            msg.append(StringPool.CLOSE_CURLY_BRACE);
1141
1142            throw new NoSuchProductEntryException(msg.toString());
1143        }
1144        else {
1145            return list.get(0);
1146        }
1147    }
1148
1149    public SCProductEntry findByG_U_Last(long groupId, long userId,
1150        OrderByComparator obc)
1151        throws NoSuchProductEntryException, SystemException {
1152        int count = countByG_U(groupId, userId);
1153
1154        List<SCProductEntry> list = findByG_U(groupId, userId, count - 1,
1155                count, obc);
1156
1157        if (list.isEmpty()) {
1158            StringBuilder msg = new StringBuilder();
1159
1160            msg.append("No SCProductEntry exists with the key {");
1161
1162            msg.append("groupId=" + groupId);
1163
1164            msg.append(", ");
1165            msg.append("userId=" + userId);
1166
1167            msg.append(StringPool.CLOSE_CURLY_BRACE);
1168
1169            throw new NoSuchProductEntryException(msg.toString());
1170        }
1171        else {
1172            return list.get(0);
1173        }
1174    }
1175
1176    public SCProductEntry[] findByG_U_PrevAndNext(long productEntryId,
1177        long groupId, long userId, OrderByComparator obc)
1178        throws NoSuchProductEntryException, SystemException {
1179        SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
1180
1181        int count = countByG_U(groupId, userId);
1182
1183        Session session = null;
1184
1185        try {
1186            session = openSession();
1187
1188            StringBuilder query = new StringBuilder();
1189
1190            query.append(
1191                "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
1192
1193            query.append("scProductEntry.groupId = ?");
1194
1195            query.append(" AND ");
1196
1197            query.append("scProductEntry.userId = ?");
1198
1199            query.append(" ");
1200
1201            if (obc != null) {
1202                query.append("ORDER BY ");
1203
1204                String[] orderByFields = obc.getOrderByFields();
1205
1206                for (int i = 0; i < orderByFields.length; i++) {
1207                    query.append("scProductEntry.");
1208                    query.append(orderByFields[i]);
1209
1210                    if (obc.isAscending()) {
1211                        query.append(" ASC");
1212                    }
1213                    else {
1214                        query.append(" DESC");
1215                    }
1216
1217                    if ((i + 1) < orderByFields.length) {
1218                        query.append(", ");
1219                    }
1220                }
1221            }
1222
1223            else {
1224                query.append("ORDER BY ");
1225
1226                query.append("scProductEntry.modifiedDate DESC, ");
1227                query.append("scProductEntry.name DESC");
1228            }
1229
1230            Query q = session.createQuery(query.toString());
1231
1232            QueryPos qPos = QueryPos.getInstance(q);
1233
1234            qPos.add(groupId);
1235
1236            qPos.add(userId);
1237
1238            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1239                    scProductEntry);
1240
1241            SCProductEntry[] array = new SCProductEntryImpl[3];
1242
1243            array[0] = (SCProductEntry)objArray[0];
1244            array[1] = (SCProductEntry)objArray[1];
1245            array[2] = (SCProductEntry)objArray[2];
1246
1247            return array;
1248        }
1249        catch (Exception e) {
1250            throw processException(e);
1251        }
1252        finally {
1253            closeSession(session);
1254        }
1255    }
1256
1257    public SCProductEntry findByRG_RA(String repoGroupId, String repoArtifactId)
1258        throws NoSuchProductEntryException, SystemException {
1259        SCProductEntry scProductEntry = fetchByRG_RA(repoGroupId, repoArtifactId);
1260
1261        if (scProductEntry == null) {
1262            StringBuilder msg = new StringBuilder();
1263
1264            msg.append("No SCProductEntry exists with the key {");
1265
1266            msg.append("repoGroupId=" + repoGroupId);
1267
1268            msg.append(", ");
1269            msg.append("repoArtifactId=" + repoArtifactId);
1270
1271            msg.append(StringPool.CLOSE_CURLY_BRACE);
1272
1273            if (_log.isWarnEnabled()) {
1274                _log.warn(msg.toString());
1275            }
1276
1277            throw new NoSuchProductEntryException(msg.toString());
1278        }
1279
1280        return scProductEntry;
1281    }
1282
1283    public SCProductEntry fetchByRG_RA(String repoGroupId, String repoArtifactId)
1284        throws SystemException {
1285        return fetchByRG_RA(repoGroupId, repoArtifactId, true);
1286    }
1287
1288    public SCProductEntry fetchByRG_RA(String repoGroupId,
1289        String repoArtifactId, boolean retrieveFromCache)
1290        throws SystemException {
1291        Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
1292
1293        Object result = null;
1294
1295        if (retrieveFromCache) {
1296            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_RG_RA,
1297                    finderArgs, this);
1298        }
1299
1300        if (result == null) {
1301            Session session = null;
1302
1303            try {
1304                session = openSession();
1305
1306                StringBuilder query = new StringBuilder();
1307
1308                query.append(
1309                    "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ");
1310
1311                if (repoGroupId == null) {
1312                    query.append("scProductEntry.repoGroupId IS NULL");
1313                }
1314                else {
1315                    query.append("scProductEntry.lower(repoGroupId) = ?");
1316                }
1317
1318                query.append(" AND ");
1319
1320                if (repoArtifactId == null) {
1321                    query.append("scProductEntry.repoArtifactId IS NULL");
1322                }
1323                else {
1324                    query.append("scProductEntry.lower(repoArtifactId) = ?");
1325                }
1326
1327                query.append(" ");
1328
1329                query.append("ORDER BY ");
1330
1331                query.append("scProductEntry.modifiedDate DESC, ");
1332                query.append("scProductEntry.name DESC");
1333
1334                Query q = session.createQuery(query.toString());
1335
1336                QueryPos qPos = QueryPos.getInstance(q);
1337
1338                if (repoGroupId != null) {
1339                    qPos.add(repoGroupId);
1340                }
1341
1342                if (repoArtifactId != null) {
1343                    qPos.add(repoArtifactId);
1344                }
1345
1346                List<SCProductEntry> list = q.list();
1347
1348                result = list;
1349
1350                SCProductEntry scProductEntry = null;
1351
1352                if (list.isEmpty()) {
1353                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
1354                        finderArgs, list);
1355                }
1356                else {
1357                    scProductEntry = list.get(0);
1358
1359                    cacheResult(scProductEntry);
1360
1361                    if ((scProductEntry.getRepoGroupId() == null) ||
1362                            !scProductEntry.getRepoGroupId().equals(repoGroupId) ||
1363                            (scProductEntry.getRepoArtifactId() == null) ||
1364                            !scProductEntry.getRepoArtifactId()
1365                                               .equals(repoArtifactId)) {
1366                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
1367                            finderArgs, scProductEntry);
1368                    }
1369                }
1370
1371                return scProductEntry;
1372            }
1373            catch (Exception e) {
1374                throw processException(e);
1375            }
1376            finally {
1377                if (result == null) {
1378                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
1379                        finderArgs, new ArrayList<SCProductEntry>());
1380                }
1381
1382                closeSession(session);
1383            }
1384        }
1385        else {
1386            if (result instanceof List) {
1387                return null;
1388            }
1389            else {
1390                return (SCProductEntry)result;
1391            }
1392        }
1393    }
1394
1395    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1396        throws SystemException {
1397        Session session = null;
1398
1399        try {
1400            session = openSession();
1401
1402            dynamicQuery.compile(session);
1403
1404            return dynamicQuery.list();
1405        }
1406        catch (Exception e) {
1407            throw processException(e);
1408        }
1409        finally {
1410            closeSession(session);
1411        }
1412    }
1413
1414    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1415        int start, int end) throws SystemException {
1416        Session session = null;
1417
1418        try {
1419            session = openSession();
1420
1421            dynamicQuery.setLimit(start, end);
1422
1423            dynamicQuery.compile(session);
1424
1425            return dynamicQuery.list();
1426        }
1427        catch (Exception e) {
1428            throw processException(e);
1429        }
1430        finally {
1431            closeSession(session);
1432        }
1433    }
1434
1435    public List<SCProductEntry> findAll() throws SystemException {
1436        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1437    }
1438
1439    public List<SCProductEntry> findAll(int start, int end)
1440        throws SystemException {
1441        return findAll(start, end, null);
1442    }
1443
1444    public List<SCProductEntry> findAll(int start, int end,
1445        OrderByComparator obc) throws SystemException {
1446        Object[] finderArgs = new Object[] {
1447                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1448            };
1449
1450        List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1451                finderArgs, this);
1452
1453        if (list == null) {
1454            Session session = null;
1455
1456            try {
1457                session = openSession();
1458
1459                StringBuilder query = new StringBuilder();
1460
1461                query.append(
1462                    "SELECT scProductEntry FROM SCProductEntry scProductEntry ");
1463
1464                if (obc != null) {
1465                    query.append("ORDER BY ");
1466
1467                    String[] orderByFields = obc.getOrderByFields();
1468
1469                    for (int i = 0; i < orderByFields.length; i++) {
1470                        query.append("scProductEntry.");
1471                        query.append(orderByFields[i]);
1472
1473                        if (obc.isAscending()) {
1474                            query.append(" ASC");
1475                        }
1476                        else {
1477                            query.append(" DESC");
1478                        }
1479
1480                        if ((i + 1) < orderByFields.length) {
1481                            query.append(", ");
1482                        }
1483                    }
1484                }
1485
1486                else {
1487                    query.append("ORDER BY ");
1488
1489                    query.append("scProductEntry.modifiedDate DESC, ");
1490                    query.append("scProductEntry.name DESC");
1491                }
1492
1493                Query q = session.createQuery(query.toString());
1494
1495                if (obc == null) {
1496                    list = (List<SCProductEntry>)QueryUtil.list(q,
1497                            getDialect(), start, end, false);
1498
1499                    Collections.sort(list);
1500                }
1501                else {
1502                    list = (List<SCProductEntry>)QueryUtil.list(q,
1503                            getDialect(), start, end);
1504                }
1505            }
1506            catch (Exception e) {
1507                throw processException(e);
1508            }
1509            finally {
1510                if (list == null) {
1511                    list = new ArrayList<SCProductEntry>();
1512                }
1513
1514                cacheResult(list);
1515
1516                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1517
1518                closeSession(session);
1519            }
1520        }
1521
1522        return list;
1523    }
1524
1525    public void removeByGroupId(long groupId) throws SystemException {
1526        for (SCProductEntry scProductEntry : findByGroupId(groupId)) {
1527            remove(scProductEntry);
1528        }
1529    }
1530
1531    public void removeByCompanyId(long companyId) throws SystemException {
1532        for (SCProductEntry scProductEntry : findByCompanyId(companyId)) {
1533            remove(scProductEntry);
1534        }
1535    }
1536
1537    public void removeByG_U(long groupId, long userId)
1538        throws SystemException {
1539        for (SCProductEntry scProductEntry : findByG_U(groupId, userId)) {
1540            remove(scProductEntry);
1541        }
1542    }
1543
1544    public void removeByRG_RA(String repoGroupId, String repoArtifactId)
1545        throws NoSuchProductEntryException, SystemException {
1546        SCProductEntry scProductEntry = findByRG_RA(repoGroupId, repoArtifactId);
1547
1548        remove(scProductEntry);
1549    }
1550
1551    public void removeAll() throws SystemException {
1552        for (SCProductEntry scProductEntry : findAll()) {
1553            remove(scProductEntry);
1554        }
1555    }
1556
1557    public int countByGroupId(long groupId) throws SystemException {
1558        Object[] finderArgs = new Object[] { new Long(groupId) };
1559
1560        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1561                finderArgs, this);
1562
1563        if (count == null) {
1564            Session session = null;
1565
1566            try {
1567                session = openSession();
1568
1569                StringBuilder query = new StringBuilder();
1570
1571                query.append("SELECT COUNT(scProductEntry) ");
1572                query.append("FROM SCProductEntry scProductEntry WHERE ");
1573
1574                query.append("scProductEntry.groupId = ?");
1575
1576                query.append(" ");
1577
1578                Query q = session.createQuery(query.toString());
1579
1580                QueryPos qPos = QueryPos.getInstance(q);
1581
1582                qPos.add(groupId);
1583
1584                count = (Long)q.uniqueResult();
1585            }
1586            catch (Exception e) {
1587                throw processException(e);
1588            }
1589            finally {
1590                if (count == null) {
1591                    count = Long.valueOf(0);
1592                }
1593
1594                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1595                    finderArgs, count);
1596
1597                closeSession(session);
1598            }
1599        }
1600
1601        return count.intValue();
1602    }
1603
1604    public int countByCompanyId(long companyId) throws SystemException {
1605        Object[] finderArgs = new Object[] { new Long(companyId) };
1606
1607        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1608                finderArgs, this);
1609
1610        if (count == null) {
1611            Session session = null;
1612
1613            try {
1614                session = openSession();
1615
1616                StringBuilder query = new StringBuilder();
1617
1618                query.append("SELECT COUNT(scProductEntry) ");
1619                query.append("FROM SCProductEntry scProductEntry WHERE ");
1620
1621                query.append("scProductEntry.companyId = ?");
1622
1623                query.append(" ");
1624
1625                Query q = session.createQuery(query.toString());
1626
1627                QueryPos qPos = QueryPos.getInstance(q);
1628
1629                qPos.add(companyId);
1630
1631                count = (Long)q.uniqueResult();
1632            }
1633            catch (Exception e) {
1634                throw processException(e);
1635            }
1636            finally {
1637                if (count == null) {
1638                    count = Long.valueOf(0);
1639                }
1640
1641                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1642                    finderArgs, count);
1643
1644                closeSession(session);
1645            }
1646        }
1647
1648        return count.intValue();
1649    }
1650
1651    public int countByG_U(long groupId, long userId) throws SystemException {
1652        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1653
1654        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1655                finderArgs, this);
1656
1657        if (count == null) {
1658            Session session = null;
1659
1660            try {
1661                session = openSession();
1662
1663                StringBuilder query = new StringBuilder();
1664
1665                query.append("SELECT COUNT(scProductEntry) ");
1666                query.append("FROM SCProductEntry scProductEntry WHERE ");
1667
1668                query.append("scProductEntry.groupId = ?");
1669
1670                query.append(" AND ");
1671
1672                query.append("scProductEntry.userId = ?");
1673
1674                query.append(" ");
1675
1676                Query q = session.createQuery(query.toString());
1677
1678                QueryPos qPos = QueryPos.getInstance(q);
1679
1680                qPos.add(groupId);
1681
1682                qPos.add(userId);
1683
1684                count = (Long)q.uniqueResult();
1685            }
1686            catch (Exception e) {
1687                throw processException(e);
1688            }
1689            finally {
1690                if (count == null) {
1691                    count = Long.valueOf(0);
1692                }
1693
1694                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1695                    count);
1696
1697                closeSession(session);
1698            }
1699        }
1700
1701        return count.intValue();
1702    }
1703
1704    public int countByRG_RA(String repoGroupId, String repoArtifactId)
1705        throws SystemException {
1706        Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
1707
1708        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RG_RA,
1709                finderArgs, this);
1710
1711        if (count == null) {
1712            Session session = null;
1713
1714            try {
1715                session = openSession();
1716
1717                StringBuilder query = new StringBuilder();
1718
1719                query.append("SELECT COUNT(scProductEntry) ");
1720                query.append("FROM SCProductEntry scProductEntry WHERE ");
1721
1722                if (repoGroupId == null) {
1723                    query.append("scProductEntry.repoGroupId IS NULL");
1724                }
1725                else {
1726                    query.append("scProductEntry.lower(repoGroupId) = ?");
1727                }
1728
1729                query.append(" AND ");
1730
1731                if (repoArtifactId == null) {
1732                    query.append("scProductEntry.repoArtifactId IS NULL");
1733                }
1734                else {
1735                    query.append("scProductEntry.lower(repoArtifactId) = ?");
1736                }
1737
1738                query.append(" ");
1739
1740                Query q = session.createQuery(query.toString());
1741
1742                QueryPos qPos = QueryPos.getInstance(q);
1743
1744                if (repoGroupId != null) {
1745                    qPos.add(repoGroupId);
1746                }
1747
1748                if (repoArtifactId != null) {
1749                    qPos.add(repoArtifactId);
1750                }
1751
1752                count = (Long)q.uniqueResult();
1753            }
1754            catch (Exception e) {
1755                throw processException(e);
1756            }
1757            finally {
1758                if (count == null) {
1759                    count = Long.valueOf(0);
1760                }
1761
1762                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RG_RA,
1763                    finderArgs, count);
1764
1765                closeSession(session);
1766            }
1767        }
1768
1769        return count.intValue();
1770    }
1771
1772    public int countAll() throws SystemException {
1773        Object[] finderArgs = new Object[0];
1774
1775        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1776                finderArgs, this);
1777
1778        if (count == null) {
1779            Session session = null;
1780
1781            try {
1782                session = openSession();
1783
1784                Query q = session.createQuery(
1785                        "SELECT COUNT(scProductEntry) FROM SCProductEntry scProductEntry");
1786
1787                count = (Long)q.uniqueResult();
1788            }
1789            catch (Exception e) {
1790                throw processException(e);
1791            }
1792            finally {
1793                if (count == null) {
1794                    count = Long.valueOf(0);
1795                }
1796
1797                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1798                    count);
1799
1800                closeSession(session);
1801            }
1802        }
1803
1804        return count.intValue();
1805    }
1806
1807    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1808        long pk) throws SystemException {
1809        return getSCLicenses(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1810    }
1811
1812    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1813        long pk, int start, int end) throws SystemException {
1814        return getSCLicenses(pk, start, end, null);
1815    }
1816
1817    public static final FinderPath FINDER_PATH_GET_SCLICENSES = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
1818            SCProductEntryModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1819            "SCLicenses_SCProductEntries", "getSCLicenses",
1820            new String[] {
1821                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1822                "com.liferay.portal.kernel.util.OrderByComparator"
1823            });
1824
1825    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1826        long pk, int start, int end, OrderByComparator obc)
1827        throws SystemException {
1828        Object[] finderArgs = new Object[] {
1829                new Long(pk), String.valueOf(start), String.valueOf(end),
1830                String.valueOf(obc)
1831            };
1832
1833        List<com.liferay.portlet.softwarecatalog.model.SCLicense> list = (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_GET_SCLICENSES,
1834                finderArgs, this);
1835
1836        if (list == null) {
1837            Session session = null;
1838
1839            try {
1840                session = openSession();
1841
1842                StringBuilder sb = new StringBuilder();
1843
1844                sb.append(_SQL_GETSCLICENSES);
1845
1846                if (obc != null) {
1847                    sb.append("ORDER BY ");
1848                    sb.append(obc.getOrderBy());
1849                }
1850
1851                else {
1852                    sb.append("ORDER BY ");
1853
1854                    sb.append("SCLicense.name ASC");
1855                }
1856
1857                String sql = sb.toString();
1858
1859                SQLQuery q = session.createSQLQuery(sql);
1860
1861                q.addEntity("SCLicense",
1862                    com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl.class);
1863
1864                QueryPos qPos = QueryPos.getInstance(q);
1865
1866                qPos.add(pk);
1867
1868                list = (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)QueryUtil.list(q,
1869                        getDialect(), start, end);
1870            }
1871            catch (Exception e) {
1872                throw processException(e);
1873            }
1874            finally {
1875                if (list == null) {
1876                    list = new ArrayList<com.liferay.portlet.softwarecatalog.model.SCLicense>();
1877                }
1878
1879                scLicensePersistence.cacheResult(list);
1880
1881                FinderCacheUtil.putResult(FINDER_PATH_GET_SCLICENSES,
1882                    finderArgs, list);
1883
1884                closeSession(session);
1885            }
1886        }
1887
1888        return list;
1889    }
1890
1891    public static final FinderPath FINDER_PATH_GET_SCLICENSES_SIZE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
1892            SCProductEntryModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1893            "SCLicenses_SCProductEntries", "getSCLicensesSize",
1894            new String[] { Long.class.getName() });
1895
1896    public int getSCLicensesSize(long pk) throws SystemException {
1897        Object[] finderArgs = new Object[] { new Long(pk) };
1898
1899        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SCLICENSES_SIZE,
1900                finderArgs, this);
1901
1902        if (count == null) {
1903            Session session = null;
1904
1905            try {
1906                session = openSession();
1907
1908                SQLQuery q = session.createSQLQuery(_SQL_GETSCLICENSESSIZE);
1909
1910                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1911
1912                QueryPos qPos = QueryPos.getInstance(q);
1913
1914                qPos.add(pk);
1915
1916                count = (Long)q.uniqueResult();
1917            }
1918            catch (Exception e) {
1919                throw processException(e);
1920            }
1921            finally {
1922                if (count == null) {
1923                    count = Long.valueOf(0);
1924                }
1925
1926                FinderCacheUtil.putResult(FINDER_PATH_GET_SCLICENSES_SIZE,
1927                    finderArgs, count);
1928
1929                closeSession(session);
1930            }
1931        }
1932
1933        return count.intValue();
1934    }
1935
1936    public static final FinderPath FINDER_PATH_CONTAINS_SCLICENSE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
1937            SCProductEntryModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1938            "SCLicenses_SCProductEntries", "containsSCLicense",
1939            new String[] { Long.class.getName(), Long.class.getName() });
1940
1941    public boolean containsSCLicense(long pk, long scLicensePK)
1942        throws SystemException {
1943        Object[] finderArgs = new Object[] { new Long(pk), new Long(scLicensePK) };
1944
1945        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SCLICENSE,
1946                finderArgs, this);
1947
1948        if (value == null) {
1949            try {
1950                value = Boolean.valueOf(containsSCLicense.contains(pk,
1951                            scLicensePK));
1952            }
1953            catch (Exception e) {
1954                throw processException(e);
1955            }
1956            finally {
1957                if (value == null) {
1958                    value = Boolean.FALSE;
1959                }
1960
1961                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SCLICENSE,
1962                    finderArgs, value);
1963            }
1964        }
1965
1966        return value.booleanValue();
1967    }
1968
1969    public boolean containsSCLicenses(long pk) throws SystemException {
1970        if (getSCLicensesSize(pk) > 0) {
1971            return true;
1972        }
1973        else {
1974            return false;
1975        }
1976    }
1977
1978    public void addSCLicense(long pk, long scLicensePK)
1979        throws SystemException {
1980        try {
1981            addSCLicense.add(pk, scLicensePK);
1982        }
1983        catch (Exception e) {
1984            throw processException(e);
1985        }
1986        finally {
1987            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1988        }
1989    }
1990
1991    public void addSCLicense(long pk,
1992        com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
1993        throws SystemException {
1994        try {
1995            addSCLicense.add(pk, scLicense.getPrimaryKey());
1996        }
1997        catch (Exception e) {
1998            throw processException(e);
1999        }
2000        finally {
2001            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2002        }
2003    }
2004
2005    public void addSCLicenses(long pk, long[] scLicensePKs)
2006        throws SystemException {
2007        try {
2008            for (long scLicensePK : scLicensePKs) {
2009                addSCLicense.add(pk, scLicensePK);
2010            }
2011        }
2012        catch (Exception e) {
2013            throw processException(e);
2014        }
2015        finally {
2016            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2017        }
2018    }
2019
2020    public void addSCLicenses(long pk,
2021        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
2022        throws SystemException {
2023        try {
2024            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
2025                addSCLicense.add(pk, scLicense.getPrimaryKey());
2026            }
2027        }
2028        catch (Exception e) {
2029            throw processException(e);
2030        }
2031        finally {
2032            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2033        }
2034    }
2035
2036    public void clearSCLicenses(long pk) throws SystemException {
2037        try {
2038            clearSCLicenses.clear(pk);
2039        }
2040        catch (Exception e) {
2041            throw processException(e);
2042        }
2043        finally {
2044            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2045        }
2046    }
2047
2048    public void removeSCLicense(long pk, long scLicensePK)
2049        throws SystemException {
2050        try {
2051            removeSCLicense.remove(pk, scLicensePK);
2052        }
2053        catch (Exception e) {
2054            throw processException(e);
2055        }
2056        finally {
2057            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2058        }
2059    }
2060
2061    public void removeSCLicense(long pk,
2062        com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
2063        throws SystemException {
2064        try {
2065            removeSCLicense.remove(pk, scLicense.getPrimaryKey());
2066        }
2067        catch (Exception e) {
2068            throw processException(e);
2069        }
2070        finally {
2071            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2072        }
2073    }
2074
2075    public void removeSCLicenses(long pk, long[] scLicensePKs)
2076        throws SystemException {
2077        try {
2078            for (long scLicensePK : scLicensePKs) {
2079                removeSCLicense.remove(pk, scLicensePK);
2080            }
2081        }
2082        catch (Exception e) {
2083            throw processException(e);
2084        }
2085        finally {
2086            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2087        }
2088    }
2089
2090    public void removeSCLicenses(long pk,
2091        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
2092        throws SystemException {
2093        try {
2094            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
2095                removeSCLicense.remove(pk, scLicense.getPrimaryKey());
2096            }
2097        }
2098        catch (Exception e) {
2099            throw processException(e);
2100        }
2101        finally {
2102            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2103        }
2104    }
2105
2106    public void setSCLicenses(long pk, long[] scLicensePKs)
2107        throws SystemException {
2108        try {
2109            clearSCLicenses.clear(pk);
2110
2111            for (long scLicensePK : scLicensePKs) {
2112                addSCLicense.add(pk, scLicensePK);
2113            }
2114        }
2115        catch (Exception e) {
2116            throw processException(e);
2117        }
2118        finally {
2119            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2120        }
2121    }
2122
2123    public void setSCLicenses(long pk,
2124        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
2125        throws SystemException {
2126        try {
2127            clearSCLicenses.clear(pk);
2128
2129            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
2130                addSCLicense.add(pk, scLicense.getPrimaryKey());
2131            }
2132        }
2133        catch (Exception e) {
2134            throw processException(e);
2135        }
2136        finally {
2137            FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
2138        }
2139    }
2140
2141    public void afterPropertiesSet() {
2142        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2143                    com.liferay.portal.util.PropsUtil.get(
2144                        "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductEntry")));
2145
2146        if (listenerClassNames.length > 0) {
2147            try {
2148                List<ModelListener<SCProductEntry>> listenersList = new ArrayList<ModelListener<SCProductEntry>>();
2149
2150                for (String listenerClassName : listenerClassNames) {
2151                    listenersList.add((ModelListener<SCProductEntry>)Class.forName(
2152                            listenerClassName).newInstance());
2153                }
2154
2155                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2156            }
2157            catch (Exception e) {
2158                _log.error(e);
2159            }
2160        }
2161
2162        containsSCLicense = new ContainsSCLicense(this);
2163
2164        addSCLicense = new AddSCLicense(this);
2165        clearSCLicenses = new ClearSCLicenses(this);
2166        removeSCLicense = new RemoveSCLicense(this);
2167    }
2168
2169    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence.impl")
2170    protected com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence scLicensePersistence;
2171    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence.impl")
2172    protected com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence scFrameworkVersionPersistence;
2173    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence.impl")
2174    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence scProductEntryPersistence;
2175    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductScreenshotPersistence.impl")
2176    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductScreenshotPersistence scProductScreenshotPersistence;
2177    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductVersionPersistence.impl")
2178    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductVersionPersistence scProductVersionPersistence;
2179    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
2180    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
2181    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2182    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2183    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2184    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2185    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
2186    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
2187    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence.impl")
2188    protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
2189    protected ContainsSCLicense containsSCLicense;
2190    protected AddSCLicense addSCLicense;
2191    protected ClearSCLicenses clearSCLicenses;
2192    protected RemoveSCLicense removeSCLicense;
2193
2194    protected class ContainsSCLicense {
2195        protected ContainsSCLicense(
2196            SCProductEntryPersistenceImpl persistenceImpl) {
2197            super();
2198
2199            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2200                    _SQL_CONTAINSSCLICENSE,
2201                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2202        }
2203
2204        protected boolean contains(long productEntryId, long licenseId) {
2205            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2206                        new Long(productEntryId), new Long(licenseId)
2207                    });
2208
2209            if (results.size() > 0) {
2210                Integer count = results.get(0);
2211
2212                if (count.intValue() > 0) {
2213                    return true;
2214                }
2215            }
2216
2217            return false;
2218        }
2219
2220        private MappingSqlQuery _mappingSqlQuery;
2221    }
2222
2223    protected class AddSCLicense {
2224        protected AddSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2225            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2226                    "INSERT INTO SCLicenses_SCProductEntries (productEntryId, licenseId) VALUES (?, ?)",
2227                    new int[] { Types.BIGINT, Types.BIGINT });
2228            _persistenceImpl = persistenceImpl;
2229        }
2230
2231        protected void add(long productEntryId, long licenseId) {
2232            if (!_persistenceImpl.containsSCLicense.contains(productEntryId,
2233                        licenseId)) {
2234                _sqlUpdate.update(new Object[] {
2235                        new Long(productEntryId), new Long(licenseId)
2236                    });
2237            }
2238        }
2239
2240        private SqlUpdate _sqlUpdate;
2241        private SCProductEntryPersistenceImpl _persistenceImpl;
2242    }
2243
2244    protected class ClearSCLicenses {
2245        protected ClearSCLicenses(SCProductEntryPersistenceImpl persistenceImpl) {
2246            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2247                    "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?",
2248                    new int[] { Types.BIGINT });
2249        }
2250
2251        protected void clear(long productEntryId) {
2252            _sqlUpdate.update(new Object[] { new Long(productEntryId) });
2253        }
2254
2255        private SqlUpdate _sqlUpdate;
2256    }
2257
2258    protected class RemoveSCLicense {
2259        protected RemoveSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2260            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2261                    "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?",
2262                    new int[] { Types.BIGINT, Types.BIGINT });
2263        }
2264
2265        protected void remove(long productEntryId, long licenseId) {
2266            _sqlUpdate.update(new Object[] {
2267                    new Long(productEntryId), new Long(licenseId)
2268                });
2269        }
2270
2271        private SqlUpdate _sqlUpdate;
2272    }
2273
2274    private static final String _SQL_GETSCLICENSES = "SELECT {SCLicense.*} FROM SCLicense INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.licenseId = SCLicense.licenseId) WHERE (SCLicenses_SCProductEntries.productEntryId = ?)";
2275    private static final String _SQL_GETSCLICENSESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?";
2276    private static final String _SQL_CONTAINSSCLICENSE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?";
2277    private static Log _log = LogFactoryUtil.getLog(SCProductEntryPersistenceImpl.class);
2278}