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