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