001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.softwarecatalog.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderPath;
028    import com.liferay.portal.kernel.dao.orm.Query;
029    import com.liferay.portal.kernel.dao.orm.QueryPos;
030    import com.liferay.portal.kernel.dao.orm.QueryUtil;
031    import com.liferay.portal.kernel.dao.orm.SQLQuery;
032    import com.liferay.portal.kernel.dao.orm.Session;
033    import com.liferay.portal.kernel.exception.SystemException;
034    import com.liferay.portal.kernel.log.Log;
035    import com.liferay.portal.kernel.log.LogFactoryUtil;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.SetUtil;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.kernel.util.StringUtil;
043    import com.liferay.portal.kernel.util.Validator;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047    import com.liferay.portal.service.persistence.GroupPersistence;
048    import com.liferay.portal.service.persistence.ImagePersistence;
049    import com.liferay.portal.service.persistence.SubscriptionPersistence;
050    import com.liferay.portal.service.persistence.UserPersistence;
051    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
052    
053    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
054    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
055    import com.liferay.portlet.softwarecatalog.NoSuchProductEntryException;
056    import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
057    import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryImpl;
058    import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl;
059    
060    import java.io.Serializable;
061    
062    import java.util.ArrayList;
063    import java.util.Collections;
064    import java.util.List;
065    import java.util.Set;
066    
067    /**
068     * The persistence implementation for the s c product entry service.
069     *
070     * <p>
071     * Caching information and settings can be found in <code>portal.properties</code>
072     * </p>
073     *
074     * @author Brian Wing Shun Chan
075     * @see SCProductEntryPersistence
076     * @see SCProductEntryUtil
077     * @generated
078     */
079    public class SCProductEntryPersistenceImpl extends BasePersistenceImpl<SCProductEntry>
080            implements SCProductEntryPersistence {
081            /*
082             * NOTE FOR DEVELOPERS:
083             *
084             * Never modify or reference this class directly. Always use {@link SCProductEntryUtil} to access the s c product entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
085             */
086            public static final String FINDER_CLASS_NAME_ENTITY = SCProductEntryImpl.class.getName();
087            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
088                    ".List1";
089            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
090                    ".List2";
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
092                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
093                            SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
094                            "findByGroupId",
095                            new String[] {
096                                    Long.class.getName(),
097                                    
098                            "java.lang.Integer", "java.lang.Integer",
099                                    "com.liferay.portal.kernel.util.OrderByComparator"
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
102                    new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
103                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
104                            SCProductEntryImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
106                            new String[] { Long.class.getName() },
107                            SCProductEntryModelImpl.GROUPID_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
109                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
111                            new String[] { Long.class.getName() });
112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
113                    new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
114                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
115                            SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
116                            "findByCompanyId",
117                            new String[] {
118                                    Long.class.getName(),
119                                    
120                            "java.lang.Integer", "java.lang.Integer",
121                                    "com.liferay.portal.kernel.util.OrderByComparator"
122                            });
123            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
124                    new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
125                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
126                            SCProductEntryImpl.class,
127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
128                            new String[] { Long.class.getName() },
129                            SCProductEntryModelImpl.COMPANYID_COLUMN_BITMASK);
130            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
131                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
132                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
133                            new String[] { Long.class.getName() });
134            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
135                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
136                            SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
137                            "findByG_U",
138                            new String[] {
139                                    Long.class.getName(), Long.class.getName(),
140                                    
141                            "java.lang.Integer", "java.lang.Integer",
142                                    "com.liferay.portal.kernel.util.OrderByComparator"
143                            });
144            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
145                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
146                            SCProductEntryImpl.class,
147                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
148                            new String[] { Long.class.getName(), Long.class.getName() },
149                            SCProductEntryModelImpl.GROUPID_COLUMN_BITMASK |
150                            SCProductEntryModelImpl.USERID_COLUMN_BITMASK);
151            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
152                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
153                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
154                            new String[] { Long.class.getName(), Long.class.getName() });
155            public static final FinderPath FINDER_PATH_FETCH_BY_RG_RA = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
156                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
157                            SCProductEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByRG_RA",
158                            new String[] { String.class.getName(), String.class.getName() },
159                            SCProductEntryModelImpl.REPOGROUPID_COLUMN_BITMASK |
160                            SCProductEntryModelImpl.REPOARTIFACTID_COLUMN_BITMASK);
161            public static final FinderPath FINDER_PATH_COUNT_BY_RG_RA = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
162                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
163                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRG_RA",
164                            new String[] { String.class.getName(), String.class.getName() });
165            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
166                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
167                            SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
168                            "findAll", new String[0]);
169            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
170                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
171                            SCProductEntryImpl.class,
172                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
173            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
174                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
175                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
176    
177            /**
178             * Caches the s c product entry in the entity cache if it is enabled.
179             *
180             * @param scProductEntry the s c product entry
181             */
182            public void cacheResult(SCProductEntry scProductEntry) {
183                    EntityCacheUtil.putResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
184                            SCProductEntryImpl.class, scProductEntry.getPrimaryKey(),
185                            scProductEntry);
186    
187                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
188                            new Object[] {
189                                    scProductEntry.getRepoGroupId(),
190                                    
191                            scProductEntry.getRepoArtifactId()
192                            }, scProductEntry);
193    
194                    scProductEntry.resetOriginalValues();
195            }
196    
197            /**
198             * Caches the s c product entries in the entity cache if it is enabled.
199             *
200             * @param scProductEntries the s c product entries
201             */
202            public void cacheResult(List<SCProductEntry> scProductEntries) {
203                    for (SCProductEntry scProductEntry : scProductEntries) {
204                            if (EntityCacheUtil.getResult(
205                                                    SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
206                                                    SCProductEntryImpl.class, scProductEntry.getPrimaryKey()) == null) {
207                                    cacheResult(scProductEntry);
208                            }
209                            else {
210                                    scProductEntry.resetOriginalValues();
211                            }
212                    }
213            }
214    
215            /**
216             * Clears the cache for all s c product entries.
217             *
218             * <p>
219             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
220             * </p>
221             */
222            @Override
223            public void clearCache() {
224                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
225                            CacheRegistryUtil.clear(SCProductEntryImpl.class.getName());
226                    }
227    
228                    EntityCacheUtil.clearCache(SCProductEntryImpl.class.getName());
229    
230                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
231                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
233            }
234    
235            /**
236             * Clears the cache for the s c product entry.
237             *
238             * <p>
239             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
240             * </p>
241             */
242            @Override
243            public void clearCache(SCProductEntry scProductEntry) {
244                    EntityCacheUtil.removeResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
245                            SCProductEntryImpl.class, scProductEntry.getPrimaryKey());
246    
247                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
248                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
249    
250                    clearUniqueFindersCache(scProductEntry);
251            }
252    
253            @Override
254            public void clearCache(List<SCProductEntry> scProductEntries) {
255                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
256                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
257    
258                    for (SCProductEntry scProductEntry : scProductEntries) {
259                            EntityCacheUtil.removeResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
260                                    SCProductEntryImpl.class, scProductEntry.getPrimaryKey());
261    
262                            clearUniqueFindersCache(scProductEntry);
263                    }
264            }
265    
266            protected void clearUniqueFindersCache(SCProductEntry scProductEntry) {
267                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_RG_RA,
268                            new Object[] {
269                                    scProductEntry.getRepoGroupId(),
270                                    
271                            scProductEntry.getRepoArtifactId()
272                            });
273            }
274    
275            /**
276             * Creates a new s c product entry with the primary key. Does not add the s c product entry to the database.
277             *
278             * @param productEntryId the primary key for the new s c product entry
279             * @return the new s c product entry
280             */
281            public SCProductEntry create(long productEntryId) {
282                    SCProductEntry scProductEntry = new SCProductEntryImpl();
283    
284                    scProductEntry.setNew(true);
285                    scProductEntry.setPrimaryKey(productEntryId);
286    
287                    return scProductEntry;
288            }
289    
290            /**
291             * Removes the s c product entry with the primary key from the database. Also notifies the appropriate model listeners.
292             *
293             * @param productEntryId the primary key of the s c product entry
294             * @return the s c product entry that was removed
295             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
296             * @throws SystemException if a system exception occurred
297             */
298            public SCProductEntry remove(long productEntryId)
299                    throws NoSuchProductEntryException, SystemException {
300                    return remove(Long.valueOf(productEntryId));
301            }
302    
303            /**
304             * Removes the s c product entry with the primary key from the database. Also notifies the appropriate model listeners.
305             *
306             * @param primaryKey the primary key of the s c product entry
307             * @return the s c product entry that was removed
308             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
309             * @throws SystemException if a system exception occurred
310             */
311            @Override
312            public SCProductEntry remove(Serializable primaryKey)
313                    throws NoSuchProductEntryException, SystemException {
314                    Session session = null;
315    
316                    try {
317                            session = openSession();
318    
319                            SCProductEntry scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
320                                            primaryKey);
321    
322                            if (scProductEntry == null) {
323                                    if (_log.isWarnEnabled()) {
324                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
325                                    }
326    
327                                    throw new NoSuchProductEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
328                                            primaryKey);
329                            }
330    
331                            return remove(scProductEntry);
332                    }
333                    catch (NoSuchProductEntryException nsee) {
334                            throw nsee;
335                    }
336                    catch (Exception e) {
337                            throw processException(e);
338                    }
339                    finally {
340                            closeSession(session);
341                    }
342            }
343    
344            @Override
345            protected SCProductEntry removeImpl(SCProductEntry scProductEntry)
346                    throws SystemException {
347                    scProductEntry = toUnwrappedModel(scProductEntry);
348    
349                    try {
350                            clearSCLicenses.clear(scProductEntry.getPrimaryKey());
351                    }
352                    catch (Exception e) {
353                            throw processException(e);
354                    }
355                    finally {
356                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
357                    }
358    
359                    Session session = null;
360    
361                    try {
362                            session = openSession();
363    
364                            if (scProductEntry.isCachedModel()) {
365                                    scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
366                                                    scProductEntry.getPrimaryKeyObj());
367                            }
368    
369                            session.delete(scProductEntry);
370                    }
371                    catch (Exception e) {
372                            throw processException(e);
373                    }
374                    finally {
375                            closeSession(session);
376                    }
377    
378                    clearCache(scProductEntry);
379    
380                    return scProductEntry;
381            }
382    
383            @Override
384            public SCProductEntry updateImpl(
385                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry)
386                    throws SystemException {
387                    scProductEntry = toUnwrappedModel(scProductEntry);
388    
389                    boolean isNew = scProductEntry.isNew();
390    
391                    SCProductEntryModelImpl scProductEntryModelImpl = (SCProductEntryModelImpl)scProductEntry;
392    
393                    Session session = null;
394    
395                    try {
396                            session = openSession();
397    
398                            if (scProductEntry.isNew()) {
399                                    session.save(scProductEntry);
400    
401                                    scProductEntry.setNew(false);
402                            }
403                            else {
404                                    session.merge(scProductEntry);
405                            }
406                    }
407                    catch (Exception e) {
408                            throw processException(e);
409                    }
410                    finally {
411                            closeSession(session);
412                    }
413    
414                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
415    
416                    if (isNew || !SCProductEntryModelImpl.COLUMN_BITMASK_ENABLED) {
417                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
418                    }
419    
420                    else {
421                            if ((scProductEntryModelImpl.getColumnBitmask() &
422                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
423                                    Object[] args = new Object[] {
424                                                    Long.valueOf(scProductEntryModelImpl.getOriginalGroupId())
425                                            };
426    
427                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
428                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
429                                            args);
430    
431                                    args = new Object[] {
432                                                    Long.valueOf(scProductEntryModelImpl.getGroupId())
433                                            };
434    
435                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
436                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
437                                            args);
438                            }
439    
440                            if ((scProductEntryModelImpl.getColumnBitmask() &
441                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
442                                    Object[] args = new Object[] {
443                                                    Long.valueOf(scProductEntryModelImpl.getOriginalCompanyId())
444                                            };
445    
446                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
447                                            args);
448                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
449                                            args);
450    
451                                    args = new Object[] {
452                                                    Long.valueOf(scProductEntryModelImpl.getCompanyId())
453                                            };
454    
455                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
456                                            args);
457                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
458                                            args);
459                            }
460    
461                            if ((scProductEntryModelImpl.getColumnBitmask() &
462                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
463                                    Object[] args = new Object[] {
464                                                    Long.valueOf(scProductEntryModelImpl.getOriginalGroupId()),
465                                                    Long.valueOf(scProductEntryModelImpl.getOriginalUserId())
466                                            };
467    
468                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
469                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
470                                            args);
471    
472                                    args = new Object[] {
473                                                    Long.valueOf(scProductEntryModelImpl.getGroupId()),
474                                                    Long.valueOf(scProductEntryModelImpl.getUserId())
475                                            };
476    
477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
479                                            args);
480                            }
481                    }
482    
483                    EntityCacheUtil.putResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
484                            SCProductEntryImpl.class, scProductEntry.getPrimaryKey(),
485                            scProductEntry);
486    
487                    if (isNew) {
488                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
489                                    new Object[] {
490                                            scProductEntry.getRepoGroupId(),
491                                            
492                                    scProductEntry.getRepoArtifactId()
493                                    }, scProductEntry);
494                    }
495                    else {
496                            if ((scProductEntryModelImpl.getColumnBitmask() &
497                                            FINDER_PATH_FETCH_BY_RG_RA.getColumnBitmask()) != 0) {
498                                    Object[] args = new Object[] {
499                                                    scProductEntryModelImpl.getOriginalRepoGroupId(),
500                                                    
501                                                    scProductEntryModelImpl.getOriginalRepoArtifactId()
502                                            };
503    
504                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RG_RA, args);
505    
506                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_RG_RA, args);
507    
508                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
509                                            new Object[] {
510                                                    scProductEntry.getRepoGroupId(),
511                                                    
512                                            scProductEntry.getRepoArtifactId()
513                                            }, scProductEntry);
514                            }
515                    }
516    
517                    return scProductEntry;
518            }
519    
520            protected SCProductEntry toUnwrappedModel(SCProductEntry scProductEntry) {
521                    if (scProductEntry instanceof SCProductEntryImpl) {
522                            return scProductEntry;
523                    }
524    
525                    SCProductEntryImpl scProductEntryImpl = new SCProductEntryImpl();
526    
527                    scProductEntryImpl.setNew(scProductEntry.isNew());
528                    scProductEntryImpl.setPrimaryKey(scProductEntry.getPrimaryKey());
529    
530                    scProductEntryImpl.setProductEntryId(scProductEntry.getProductEntryId());
531                    scProductEntryImpl.setGroupId(scProductEntry.getGroupId());
532                    scProductEntryImpl.setCompanyId(scProductEntry.getCompanyId());
533                    scProductEntryImpl.setUserId(scProductEntry.getUserId());
534                    scProductEntryImpl.setUserName(scProductEntry.getUserName());
535                    scProductEntryImpl.setCreateDate(scProductEntry.getCreateDate());
536                    scProductEntryImpl.setModifiedDate(scProductEntry.getModifiedDate());
537                    scProductEntryImpl.setName(scProductEntry.getName());
538                    scProductEntryImpl.setType(scProductEntry.getType());
539                    scProductEntryImpl.setTags(scProductEntry.getTags());
540                    scProductEntryImpl.setShortDescription(scProductEntry.getShortDescription());
541                    scProductEntryImpl.setLongDescription(scProductEntry.getLongDescription());
542                    scProductEntryImpl.setPageURL(scProductEntry.getPageURL());
543                    scProductEntryImpl.setAuthor(scProductEntry.getAuthor());
544                    scProductEntryImpl.setRepoGroupId(scProductEntry.getRepoGroupId());
545                    scProductEntryImpl.setRepoArtifactId(scProductEntry.getRepoArtifactId());
546    
547                    return scProductEntryImpl;
548            }
549    
550            /**
551             * Returns the s c product entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
552             *
553             * @param primaryKey the primary key of the s c product entry
554             * @return the s c product entry
555             * @throws com.liferay.portal.NoSuchModelException if a s c product entry with the primary key could not be found
556             * @throws SystemException if a system exception occurred
557             */
558            @Override
559            public SCProductEntry findByPrimaryKey(Serializable primaryKey)
560                    throws NoSuchModelException, SystemException {
561                    return findByPrimaryKey(((Long)primaryKey).longValue());
562            }
563    
564            /**
565             * Returns the s c product entry with the primary key or throws a {@link com.liferay.portlet.softwarecatalog.NoSuchProductEntryException} if it could not be found.
566             *
567             * @param productEntryId the primary key of the s c product entry
568             * @return the s c product entry
569             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
570             * @throws SystemException if a system exception occurred
571             */
572            public SCProductEntry findByPrimaryKey(long productEntryId)
573                    throws NoSuchProductEntryException, SystemException {
574                    SCProductEntry scProductEntry = fetchByPrimaryKey(productEntryId);
575    
576                    if (scProductEntry == null) {
577                            if (_log.isWarnEnabled()) {
578                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + productEntryId);
579                            }
580    
581                            throw new NoSuchProductEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
582                                    productEntryId);
583                    }
584    
585                    return scProductEntry;
586            }
587    
588            /**
589             * Returns the s c product entry with the primary key or returns <code>null</code> if it could not be found.
590             *
591             * @param primaryKey the primary key of the s c product entry
592             * @return the s c product entry, or <code>null</code> if a s c product entry with the primary key could not be found
593             * @throws SystemException if a system exception occurred
594             */
595            @Override
596            public SCProductEntry fetchByPrimaryKey(Serializable primaryKey)
597                    throws SystemException {
598                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
599            }
600    
601            /**
602             * Returns the s c product entry with the primary key or returns <code>null</code> if it could not be found.
603             *
604             * @param productEntryId the primary key of the s c product entry
605             * @return the s c product entry, or <code>null</code> if a s c product entry with the primary key could not be found
606             * @throws SystemException if a system exception occurred
607             */
608            public SCProductEntry fetchByPrimaryKey(long productEntryId)
609                    throws SystemException {
610                    SCProductEntry scProductEntry = (SCProductEntry)EntityCacheUtil.getResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
611                                    SCProductEntryImpl.class, productEntryId);
612    
613                    if (scProductEntry == _nullSCProductEntry) {
614                            return null;
615                    }
616    
617                    if (scProductEntry == null) {
618                            Session session = null;
619    
620                            boolean hasException = false;
621    
622                            try {
623                                    session = openSession();
624    
625                                    scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
626                                                    Long.valueOf(productEntryId));
627                            }
628                            catch (Exception e) {
629                                    hasException = true;
630    
631                                    throw processException(e);
632                            }
633                            finally {
634                                    if (scProductEntry != null) {
635                                            cacheResult(scProductEntry);
636                                    }
637                                    else if (!hasException) {
638                                            EntityCacheUtil.putResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
639                                                    SCProductEntryImpl.class, productEntryId,
640                                                    _nullSCProductEntry);
641                                    }
642    
643                                    closeSession(session);
644                            }
645                    }
646    
647                    return scProductEntry;
648            }
649    
650            /**
651             * Returns all the s c product entries where groupId = &#63;.
652             *
653             * @param groupId the group ID
654             * @return the matching s c product entries
655             * @throws SystemException if a system exception occurred
656             */
657            public List<SCProductEntry> findByGroupId(long groupId)
658                    throws SystemException {
659                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
660            }
661    
662            /**
663             * Returns a range of all the s c product entries where groupId = &#63;.
664             *
665             * <p>
666             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
667             * </p>
668             *
669             * @param groupId the group ID
670             * @param start the lower bound of the range of s c product entries
671             * @param end the upper bound of the range of s c product entries (not inclusive)
672             * @return the range of matching s c product entries
673             * @throws SystemException if a system exception occurred
674             */
675            public List<SCProductEntry> findByGroupId(long groupId, int start, int end)
676                    throws SystemException {
677                    return findByGroupId(groupId, start, end, null);
678            }
679    
680            /**
681             * Returns an ordered range of all the s c product entries where groupId = &#63;.
682             *
683             * <p>
684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
685             * </p>
686             *
687             * @param groupId the group ID
688             * @param start the lower bound of the range of s c product entries
689             * @param end the upper bound of the range of s c product entries (not inclusive)
690             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
691             * @return the ordered range of matching s c product entries
692             * @throws SystemException if a system exception occurred
693             */
694            public List<SCProductEntry> findByGroupId(long groupId, int start, int end,
695                    OrderByComparator orderByComparator) throws SystemException {
696                    FinderPath finderPath = null;
697                    Object[] finderArgs = null;
698    
699                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
700                                    (orderByComparator == null)) {
701                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
702                            finderArgs = new Object[] { groupId };
703                    }
704                    else {
705                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
706                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
707                    }
708    
709                    List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
710                                    finderArgs, this);
711    
712                    if ((list != null) && !list.isEmpty()) {
713                            for (SCProductEntry scProductEntry : list) {
714                                    if ((groupId != scProductEntry.getGroupId())) {
715                                            list = null;
716    
717                                            break;
718                                    }
719                            }
720                    }
721    
722                    if (list == null) {
723                            StringBundler query = null;
724    
725                            if (orderByComparator != null) {
726                                    query = new StringBundler(3 +
727                                                    (orderByComparator.getOrderByFields().length * 3));
728                            }
729                            else {
730                                    query = new StringBundler(3);
731                            }
732    
733                            query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
734    
735                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
736    
737                            if (orderByComparator != null) {
738                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
739                                            orderByComparator);
740                            }
741    
742                            else {
743                                    query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
744                            }
745    
746                            String sql = query.toString();
747    
748                            Session session = null;
749    
750                            try {
751                                    session = openSession();
752    
753                                    Query q = session.createQuery(sql);
754    
755                                    QueryPos qPos = QueryPos.getInstance(q);
756    
757                                    qPos.add(groupId);
758    
759                                    list = (List<SCProductEntry>)QueryUtil.list(q, getDialect(),
760                                                    start, end);
761                            }
762                            catch (Exception e) {
763                                    throw processException(e);
764                            }
765                            finally {
766                                    if (list == null) {
767                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
768                                    }
769                                    else {
770                                            cacheResult(list);
771    
772                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
773                                    }
774    
775                                    closeSession(session);
776                            }
777                    }
778    
779                    return list;
780            }
781    
782            /**
783             * Returns the first s c product entry in the ordered set where groupId = &#63;.
784             *
785             * @param groupId the group ID
786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
787             * @return the first matching s c product entry
788             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a matching s c product entry could not be found
789             * @throws SystemException if a system exception occurred
790             */
791            public SCProductEntry findByGroupId_First(long groupId,
792                    OrderByComparator orderByComparator)
793                    throws NoSuchProductEntryException, SystemException {
794                    SCProductEntry scProductEntry = fetchByGroupId_First(groupId,
795                                    orderByComparator);
796    
797                    if (scProductEntry != null) {
798                            return scProductEntry;
799                    }
800    
801                    StringBundler msg = new StringBundler(4);
802    
803                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
804    
805                    msg.append("groupId=");
806                    msg.append(groupId);
807    
808                    msg.append(StringPool.CLOSE_CURLY_BRACE);
809    
810                    throw new NoSuchProductEntryException(msg.toString());
811            }
812    
813            /**
814             * Returns the first s c product entry in the ordered set where groupId = &#63;.
815             *
816             * @param groupId the group ID
817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
818             * @return the first matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
819             * @throws SystemException if a system exception occurred
820             */
821            public SCProductEntry fetchByGroupId_First(long groupId,
822                    OrderByComparator orderByComparator) throws SystemException {
823                    List<SCProductEntry> list = findByGroupId(groupId, 0, 1,
824                                    orderByComparator);
825    
826                    if (!list.isEmpty()) {
827                            return list.get(0);
828                    }
829    
830                    return null;
831            }
832    
833            /**
834             * Returns the last s c product entry in the ordered set where groupId = &#63;.
835             *
836             * @param groupId the group ID
837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
838             * @return the last matching s c product entry
839             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a matching s c product entry could not be found
840             * @throws SystemException if a system exception occurred
841             */
842            public SCProductEntry findByGroupId_Last(long groupId,
843                    OrderByComparator orderByComparator)
844                    throws NoSuchProductEntryException, SystemException {
845                    SCProductEntry scProductEntry = fetchByGroupId_Last(groupId,
846                                    orderByComparator);
847    
848                    if (scProductEntry != null) {
849                            return scProductEntry;
850                    }
851    
852                    StringBundler msg = new StringBundler(4);
853    
854                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
855    
856                    msg.append("groupId=");
857                    msg.append(groupId);
858    
859                    msg.append(StringPool.CLOSE_CURLY_BRACE);
860    
861                    throw new NoSuchProductEntryException(msg.toString());
862            }
863    
864            /**
865             * Returns the last s c product entry in the ordered set where groupId = &#63;.
866             *
867             * @param groupId the group ID
868             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
869             * @return the last matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
870             * @throws SystemException if a system exception occurred
871             */
872            public SCProductEntry fetchByGroupId_Last(long groupId,
873                    OrderByComparator orderByComparator) throws SystemException {
874                    int count = countByGroupId(groupId);
875    
876                    List<SCProductEntry> list = findByGroupId(groupId, count - 1, count,
877                                    orderByComparator);
878    
879                    if (!list.isEmpty()) {
880                            return list.get(0);
881                    }
882    
883                    return null;
884            }
885    
886            /**
887             * Returns the s c product entries before and after the current s c product entry in the ordered set where groupId = &#63;.
888             *
889             * @param productEntryId the primary key of the current s c product entry
890             * @param groupId the group ID
891             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
892             * @return the previous, current, and next s c product entry
893             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
894             * @throws SystemException if a system exception occurred
895             */
896            public SCProductEntry[] findByGroupId_PrevAndNext(long productEntryId,
897                    long groupId, OrderByComparator orderByComparator)
898                    throws NoSuchProductEntryException, SystemException {
899                    SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
900    
901                    Session session = null;
902    
903                    try {
904                            session = openSession();
905    
906                            SCProductEntry[] array = new SCProductEntryImpl[3];
907    
908                            array[0] = getByGroupId_PrevAndNext(session, scProductEntry,
909                                            groupId, orderByComparator, true);
910    
911                            array[1] = scProductEntry;
912    
913                            array[2] = getByGroupId_PrevAndNext(session, scProductEntry,
914                                            groupId, orderByComparator, false);
915    
916                            return array;
917                    }
918                    catch (Exception e) {
919                            throw processException(e);
920                    }
921                    finally {
922                            closeSession(session);
923                    }
924            }
925    
926            protected SCProductEntry getByGroupId_PrevAndNext(Session session,
927                    SCProductEntry scProductEntry, long groupId,
928                    OrderByComparator orderByComparator, boolean previous) {
929                    StringBundler query = null;
930    
931                    if (orderByComparator != null) {
932                            query = new StringBundler(6 +
933                                            (orderByComparator.getOrderByFields().length * 6));
934                    }
935                    else {
936                            query = new StringBundler(3);
937                    }
938    
939                    query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
940    
941                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
942    
943                    if (orderByComparator != null) {
944                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
945    
946                            if (orderByConditionFields.length > 0) {
947                                    query.append(WHERE_AND);
948                            }
949    
950                            for (int i = 0; i < orderByConditionFields.length; i++) {
951                                    query.append(_ORDER_BY_ENTITY_ALIAS);
952                                    query.append(orderByConditionFields[i]);
953    
954                                    if ((i + 1) < orderByConditionFields.length) {
955                                            if (orderByComparator.isAscending() ^ previous) {
956                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
957                                            }
958                                            else {
959                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
960                                            }
961                                    }
962                                    else {
963                                            if (orderByComparator.isAscending() ^ previous) {
964                                                    query.append(WHERE_GREATER_THAN);
965                                            }
966                                            else {
967                                                    query.append(WHERE_LESSER_THAN);
968                                            }
969                                    }
970                            }
971    
972                            query.append(ORDER_BY_CLAUSE);
973    
974                            String[] orderByFields = orderByComparator.getOrderByFields();
975    
976                            for (int i = 0; i < orderByFields.length; i++) {
977                                    query.append(_ORDER_BY_ENTITY_ALIAS);
978                                    query.append(orderByFields[i]);
979    
980                                    if ((i + 1) < orderByFields.length) {
981                                            if (orderByComparator.isAscending() ^ previous) {
982                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
983                                            }
984                                            else {
985                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
986                                            }
987                                    }
988                                    else {
989                                            if (orderByComparator.isAscending() ^ previous) {
990                                                    query.append(ORDER_BY_ASC);
991                                            }
992                                            else {
993                                                    query.append(ORDER_BY_DESC);
994                                            }
995                                    }
996                            }
997                    }
998    
999                    else {
1000                            query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1001                    }
1002    
1003                    String sql = query.toString();
1004    
1005                    Query q = session.createQuery(sql);
1006    
1007                    q.setFirstResult(0);
1008                    q.setMaxResults(2);
1009    
1010                    QueryPos qPos = QueryPos.getInstance(q);
1011    
1012                    qPos.add(groupId);
1013    
1014                    if (orderByComparator != null) {
1015                            Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
1016    
1017                            for (Object value : values) {
1018                                    qPos.add(value);
1019                            }
1020                    }
1021    
1022                    List<SCProductEntry> list = q.list();
1023    
1024                    if (list.size() == 2) {
1025                            return list.get(1);
1026                    }
1027                    else {
1028                            return null;
1029                    }
1030            }
1031    
1032            /**
1033             * Returns all the s c product entries that the user has permission to view where groupId = &#63;.
1034             *
1035             * @param groupId the group ID
1036             * @return the matching s c product entries that the user has permission to view
1037             * @throws SystemException if a system exception occurred
1038             */
1039            public List<SCProductEntry> filterFindByGroupId(long groupId)
1040                    throws SystemException {
1041                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1042                            QueryUtil.ALL_POS, null);
1043            }
1044    
1045            /**
1046             * Returns a range of all the s c product entries that the user has permission to view where groupId = &#63;.
1047             *
1048             * <p>
1049             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1050             * </p>
1051             *
1052             * @param groupId the group ID
1053             * @param start the lower bound of the range of s c product entries
1054             * @param end the upper bound of the range of s c product entries (not inclusive)
1055             * @return the range of matching s c product entries that the user has permission to view
1056             * @throws SystemException if a system exception occurred
1057             */
1058            public List<SCProductEntry> filterFindByGroupId(long groupId, int start,
1059                    int end) throws SystemException {
1060                    return filterFindByGroupId(groupId, start, end, null);
1061            }
1062    
1063            /**
1064             * Returns an ordered range of all the s c product entries that the user has permissions to view where groupId = &#63;.
1065             *
1066             * <p>
1067             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1068             * </p>
1069             *
1070             * @param groupId the group ID
1071             * @param start the lower bound of the range of s c product entries
1072             * @param end the upper bound of the range of s c product entries (not inclusive)
1073             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1074             * @return the ordered range of matching s c product entries that the user has permission to view
1075             * @throws SystemException if a system exception occurred
1076             */
1077            public List<SCProductEntry> filterFindByGroupId(long groupId, int start,
1078                    int end, OrderByComparator orderByComparator) throws SystemException {
1079                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1080                            return findByGroupId(groupId, start, end, orderByComparator);
1081                    }
1082    
1083                    StringBundler query = null;
1084    
1085                    if (orderByComparator != null) {
1086                            query = new StringBundler(3 +
1087                                            (orderByComparator.getOrderByFields().length * 3));
1088                    }
1089                    else {
1090                            query = new StringBundler(3);
1091                    }
1092    
1093                    if (getDB().isSupportsInlineDistinct()) {
1094                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1095                    }
1096                    else {
1097                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
1098                    }
1099    
1100                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1101    
1102                    if (!getDB().isSupportsInlineDistinct()) {
1103                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
1104                    }
1105    
1106                    if (orderByComparator != null) {
1107                            if (getDB().isSupportsInlineDistinct()) {
1108                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1109                                            orderByComparator);
1110                            }
1111                            else {
1112                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1113                                            orderByComparator);
1114                            }
1115                    }
1116    
1117                    else {
1118                            if (getDB().isSupportsInlineDistinct()) {
1119                                    query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1120                            }
1121                            else {
1122                                    query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
1123                            }
1124                    }
1125    
1126                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1127                                    SCProductEntry.class.getName(),
1128                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1129    
1130                    Session session = null;
1131    
1132                    try {
1133                            session = openSession();
1134    
1135                            SQLQuery q = session.createSQLQuery(sql);
1136    
1137                            if (getDB().isSupportsInlineDistinct()) {
1138                                    q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
1139                            }
1140                            else {
1141                                    q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
1142                            }
1143    
1144                            QueryPos qPos = QueryPos.getInstance(q);
1145    
1146                            qPos.add(groupId);
1147    
1148                            return (List<SCProductEntry>)QueryUtil.list(q, getDialect(), start,
1149                                    end);
1150                    }
1151                    catch (Exception e) {
1152                            throw processException(e);
1153                    }
1154                    finally {
1155                            closeSession(session);
1156                    }
1157            }
1158    
1159            /**
1160             * Returns the s c product entries before and after the current s c product entry in the ordered set of s c product entries that the user has permission to view where groupId = &#63;.
1161             *
1162             * @param productEntryId the primary key of the current s c product entry
1163             * @param groupId the group ID
1164             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1165             * @return the previous, current, and next s c product entry
1166             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
1167             * @throws SystemException if a system exception occurred
1168             */
1169            public SCProductEntry[] filterFindByGroupId_PrevAndNext(
1170                    long productEntryId, long groupId, OrderByComparator orderByComparator)
1171                    throws NoSuchProductEntryException, SystemException {
1172                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1173                            return findByGroupId_PrevAndNext(productEntryId, groupId,
1174                                    orderByComparator);
1175                    }
1176    
1177                    SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
1178    
1179                    Session session = null;
1180    
1181                    try {
1182                            session = openSession();
1183    
1184                            SCProductEntry[] array = new SCProductEntryImpl[3];
1185    
1186                            array[0] = filterGetByGroupId_PrevAndNext(session, scProductEntry,
1187                                            groupId, orderByComparator, true);
1188    
1189                            array[1] = scProductEntry;
1190    
1191                            array[2] = filterGetByGroupId_PrevAndNext(session, scProductEntry,
1192                                            groupId, orderByComparator, false);
1193    
1194                            return array;
1195                    }
1196                    catch (Exception e) {
1197                            throw processException(e);
1198                    }
1199                    finally {
1200                            closeSession(session);
1201                    }
1202            }
1203    
1204            protected SCProductEntry filterGetByGroupId_PrevAndNext(Session session,
1205                    SCProductEntry scProductEntry, long groupId,
1206                    OrderByComparator orderByComparator, boolean previous) {
1207                    StringBundler query = null;
1208    
1209                    if (orderByComparator != null) {
1210                            query = new StringBundler(6 +
1211                                            (orderByComparator.getOrderByFields().length * 6));
1212                    }
1213                    else {
1214                            query = new StringBundler(3);
1215                    }
1216    
1217                    if (getDB().isSupportsInlineDistinct()) {
1218                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1219                    }
1220                    else {
1221                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
1222                    }
1223    
1224                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1225    
1226                    if (!getDB().isSupportsInlineDistinct()) {
1227                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
1228                    }
1229    
1230                    if (orderByComparator != null) {
1231                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1232    
1233                            if (orderByConditionFields.length > 0) {
1234                                    query.append(WHERE_AND);
1235                            }
1236    
1237                            for (int i = 0; i < orderByConditionFields.length; i++) {
1238                                    if (getDB().isSupportsInlineDistinct()) {
1239                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1240                                    }
1241                                    else {
1242                                            query.append(_ORDER_BY_ENTITY_TABLE);
1243                                    }
1244    
1245                                    query.append(orderByConditionFields[i]);
1246    
1247                                    if ((i + 1) < orderByConditionFields.length) {
1248                                            if (orderByComparator.isAscending() ^ previous) {
1249                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1250                                            }
1251                                            else {
1252                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1253                                            }
1254                                    }
1255                                    else {
1256                                            if (orderByComparator.isAscending() ^ previous) {
1257                                                    query.append(WHERE_GREATER_THAN);
1258                                            }
1259                                            else {
1260                                                    query.append(WHERE_LESSER_THAN);
1261                                            }
1262                                    }
1263                            }
1264    
1265                            query.append(ORDER_BY_CLAUSE);
1266    
1267                            String[] orderByFields = orderByComparator.getOrderByFields();
1268    
1269                            for (int i = 0; i < orderByFields.length; i++) {
1270                                    if (getDB().isSupportsInlineDistinct()) {
1271                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1272                                    }
1273                                    else {
1274                                            query.append(_ORDER_BY_ENTITY_TABLE);
1275                                    }
1276    
1277                                    query.append(orderByFields[i]);
1278    
1279                                    if ((i + 1) < orderByFields.length) {
1280                                            if (orderByComparator.isAscending() ^ previous) {
1281                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1282                                            }
1283                                            else {
1284                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1285                                            }
1286                                    }
1287                                    else {
1288                                            if (orderByComparator.isAscending() ^ previous) {
1289                                                    query.append(ORDER_BY_ASC);
1290                                            }
1291                                            else {
1292                                                    query.append(ORDER_BY_DESC);
1293                                            }
1294                                    }
1295                            }
1296                    }
1297    
1298                    else {
1299                            if (getDB().isSupportsInlineDistinct()) {
1300                                    query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1301                            }
1302                            else {
1303                                    query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
1304                            }
1305                    }
1306    
1307                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1308                                    SCProductEntry.class.getName(),
1309                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1310    
1311                    SQLQuery q = session.createSQLQuery(sql);
1312    
1313                    q.setFirstResult(0);
1314                    q.setMaxResults(2);
1315    
1316                    if (getDB().isSupportsInlineDistinct()) {
1317                            q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
1318                    }
1319                    else {
1320                            q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
1321                    }
1322    
1323                    QueryPos qPos = QueryPos.getInstance(q);
1324    
1325                    qPos.add(groupId);
1326    
1327                    if (orderByComparator != null) {
1328                            Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
1329    
1330                            for (Object value : values) {
1331                                    qPos.add(value);
1332                            }
1333                    }
1334    
1335                    List<SCProductEntry> list = q.list();
1336    
1337                    if (list.size() == 2) {
1338                            return list.get(1);
1339                    }
1340                    else {
1341                            return null;
1342                    }
1343            }
1344    
1345            /**
1346             * Returns all the s c product entries where companyId = &#63;.
1347             *
1348             * @param companyId the company ID
1349             * @return the matching s c product entries
1350             * @throws SystemException if a system exception occurred
1351             */
1352            public List<SCProductEntry> findByCompanyId(long companyId)
1353                    throws SystemException {
1354                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1355                            null);
1356            }
1357    
1358            /**
1359             * Returns a range of all the s c product entries where companyId = &#63;.
1360             *
1361             * <p>
1362             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1363             * </p>
1364             *
1365             * @param companyId the company ID
1366             * @param start the lower bound of the range of s c product entries
1367             * @param end the upper bound of the range of s c product entries (not inclusive)
1368             * @return the range of matching s c product entries
1369             * @throws SystemException if a system exception occurred
1370             */
1371            public List<SCProductEntry> findByCompanyId(long companyId, int start,
1372                    int end) throws SystemException {
1373                    return findByCompanyId(companyId, start, end, null);
1374            }
1375    
1376            /**
1377             * Returns an ordered range of all the s c product entries where companyId = &#63;.
1378             *
1379             * <p>
1380             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1381             * </p>
1382             *
1383             * @param companyId the company ID
1384             * @param start the lower bound of the range of s c product entries
1385             * @param end the upper bound of the range of s c product entries (not inclusive)
1386             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1387             * @return the ordered range of matching s c product entries
1388             * @throws SystemException if a system exception occurred
1389             */
1390            public List<SCProductEntry> findByCompanyId(long companyId, int start,
1391                    int end, OrderByComparator orderByComparator) throws SystemException {
1392                    FinderPath finderPath = null;
1393                    Object[] finderArgs = null;
1394    
1395                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1396                                    (orderByComparator == null)) {
1397                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1398                            finderArgs = new Object[] { companyId };
1399                    }
1400                    else {
1401                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1402                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1403                    }
1404    
1405                    List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
1406                                    finderArgs, this);
1407    
1408                    if ((list != null) && !list.isEmpty()) {
1409                            for (SCProductEntry scProductEntry : list) {
1410                                    if ((companyId != scProductEntry.getCompanyId())) {
1411                                            list = null;
1412    
1413                                            break;
1414                                    }
1415                            }
1416                    }
1417    
1418                    if (list == null) {
1419                            StringBundler query = null;
1420    
1421                            if (orderByComparator != null) {
1422                                    query = new StringBundler(3 +
1423                                                    (orderByComparator.getOrderByFields().length * 3));
1424                            }
1425                            else {
1426                                    query = new StringBundler(3);
1427                            }
1428    
1429                            query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1430    
1431                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1432    
1433                            if (orderByComparator != null) {
1434                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1435                                            orderByComparator);
1436                            }
1437    
1438                            else {
1439                                    query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1440                            }
1441    
1442                            String sql = query.toString();
1443    
1444                            Session session = null;
1445    
1446                            try {
1447                                    session = openSession();
1448    
1449                                    Query q = session.createQuery(sql);
1450    
1451                                    QueryPos qPos = QueryPos.getInstance(q);
1452    
1453                                    qPos.add(companyId);
1454    
1455                                    list = (List<SCProductEntry>)QueryUtil.list(q, getDialect(),
1456                                                    start, end);
1457                            }
1458                            catch (Exception e) {
1459                                    throw processException(e);
1460                            }
1461                            finally {
1462                                    if (list == null) {
1463                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1464                                    }
1465                                    else {
1466                                            cacheResult(list);
1467    
1468                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1469                                    }
1470    
1471                                    closeSession(session);
1472                            }
1473                    }
1474    
1475                    return list;
1476            }
1477    
1478            /**
1479             * Returns the first s c product entry in the ordered set where companyId = &#63;.
1480             *
1481             * @param companyId the company ID
1482             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1483             * @return the first matching s c product entry
1484             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a matching s c product entry could not be found
1485             * @throws SystemException if a system exception occurred
1486             */
1487            public SCProductEntry findByCompanyId_First(long companyId,
1488                    OrderByComparator orderByComparator)
1489                    throws NoSuchProductEntryException, SystemException {
1490                    SCProductEntry scProductEntry = fetchByCompanyId_First(companyId,
1491                                    orderByComparator);
1492    
1493                    if (scProductEntry != null) {
1494                            return scProductEntry;
1495                    }
1496    
1497                    StringBundler msg = new StringBundler(4);
1498    
1499                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1500    
1501                    msg.append("companyId=");
1502                    msg.append(companyId);
1503    
1504                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1505    
1506                    throw new NoSuchProductEntryException(msg.toString());
1507            }
1508    
1509            /**
1510             * Returns the first s c product entry in the ordered set where companyId = &#63;.
1511             *
1512             * @param companyId the company ID
1513             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1514             * @return the first matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
1515             * @throws SystemException if a system exception occurred
1516             */
1517            public SCProductEntry fetchByCompanyId_First(long companyId,
1518                    OrderByComparator orderByComparator) throws SystemException {
1519                    List<SCProductEntry> list = findByCompanyId(companyId, 0, 1,
1520                                    orderByComparator);
1521    
1522                    if (!list.isEmpty()) {
1523                            return list.get(0);
1524                    }
1525    
1526                    return null;
1527            }
1528    
1529            /**
1530             * Returns the last s c product entry in the ordered set where companyId = &#63;.
1531             *
1532             * @param companyId the company ID
1533             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1534             * @return the last matching s c product entry
1535             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a matching s c product entry could not be found
1536             * @throws SystemException if a system exception occurred
1537             */
1538            public SCProductEntry findByCompanyId_Last(long companyId,
1539                    OrderByComparator orderByComparator)
1540                    throws NoSuchProductEntryException, SystemException {
1541                    SCProductEntry scProductEntry = fetchByCompanyId_Last(companyId,
1542                                    orderByComparator);
1543    
1544                    if (scProductEntry != null) {
1545                            return scProductEntry;
1546                    }
1547    
1548                    StringBundler msg = new StringBundler(4);
1549    
1550                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1551    
1552                    msg.append("companyId=");
1553                    msg.append(companyId);
1554    
1555                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1556    
1557                    throw new NoSuchProductEntryException(msg.toString());
1558            }
1559    
1560            /**
1561             * Returns the last s c product entry in the ordered set where companyId = &#63;.
1562             *
1563             * @param companyId the company ID
1564             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1565             * @return the last matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
1566             * @throws SystemException if a system exception occurred
1567             */
1568            public SCProductEntry fetchByCompanyId_Last(long companyId,
1569                    OrderByComparator orderByComparator) throws SystemException {
1570                    int count = countByCompanyId(companyId);
1571    
1572                    List<SCProductEntry> list = findByCompanyId(companyId, count - 1,
1573                                    count, orderByComparator);
1574    
1575                    if (!list.isEmpty()) {
1576                            return list.get(0);
1577                    }
1578    
1579                    return null;
1580            }
1581    
1582            /**
1583             * Returns the s c product entries before and after the current s c product entry in the ordered set where companyId = &#63;.
1584             *
1585             * @param productEntryId the primary key of the current s c product entry
1586             * @param companyId the company ID
1587             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1588             * @return the previous, current, and next s c product entry
1589             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
1590             * @throws SystemException if a system exception occurred
1591             */
1592            public SCProductEntry[] findByCompanyId_PrevAndNext(long productEntryId,
1593                    long companyId, OrderByComparator orderByComparator)
1594                    throws NoSuchProductEntryException, SystemException {
1595                    SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
1596    
1597                    Session session = null;
1598    
1599                    try {
1600                            session = openSession();
1601    
1602                            SCProductEntry[] array = new SCProductEntryImpl[3];
1603    
1604                            array[0] = getByCompanyId_PrevAndNext(session, scProductEntry,
1605                                            companyId, orderByComparator, true);
1606    
1607                            array[1] = scProductEntry;
1608    
1609                            array[2] = getByCompanyId_PrevAndNext(session, scProductEntry,
1610                                            companyId, orderByComparator, false);
1611    
1612                            return array;
1613                    }
1614                    catch (Exception e) {
1615                            throw processException(e);
1616                    }
1617                    finally {
1618                            closeSession(session);
1619                    }
1620            }
1621    
1622            protected SCProductEntry getByCompanyId_PrevAndNext(Session session,
1623                    SCProductEntry scProductEntry, long companyId,
1624                    OrderByComparator orderByComparator, boolean previous) {
1625                    StringBundler query = null;
1626    
1627                    if (orderByComparator != null) {
1628                            query = new StringBundler(6 +
1629                                            (orderByComparator.getOrderByFields().length * 6));
1630                    }
1631                    else {
1632                            query = new StringBundler(3);
1633                    }
1634    
1635                    query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1636    
1637                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1638    
1639                    if (orderByComparator != null) {
1640                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1641    
1642                            if (orderByConditionFields.length > 0) {
1643                                    query.append(WHERE_AND);
1644                            }
1645    
1646                            for (int i = 0; i < orderByConditionFields.length; i++) {
1647                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1648                                    query.append(orderByConditionFields[i]);
1649    
1650                                    if ((i + 1) < orderByConditionFields.length) {
1651                                            if (orderByComparator.isAscending() ^ previous) {
1652                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1653                                            }
1654                                            else {
1655                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1656                                            }
1657                                    }
1658                                    else {
1659                                            if (orderByComparator.isAscending() ^ previous) {
1660                                                    query.append(WHERE_GREATER_THAN);
1661                                            }
1662                                            else {
1663                                                    query.append(WHERE_LESSER_THAN);
1664                                            }
1665                                    }
1666                            }
1667    
1668                            query.append(ORDER_BY_CLAUSE);
1669    
1670                            String[] orderByFields = orderByComparator.getOrderByFields();
1671    
1672                            for (int i = 0; i < orderByFields.length; i++) {
1673                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1674                                    query.append(orderByFields[i]);
1675    
1676                                    if ((i + 1) < orderByFields.length) {
1677                                            if (orderByComparator.isAscending() ^ previous) {
1678                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1679                                            }
1680                                            else {
1681                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1682                                            }
1683                                    }
1684                                    else {
1685                                            if (orderByComparator.isAscending() ^ previous) {
1686                                                    query.append(ORDER_BY_ASC);
1687                                            }
1688                                            else {
1689                                                    query.append(ORDER_BY_DESC);
1690                                            }
1691                                    }
1692                            }
1693                    }
1694    
1695                    else {
1696                            query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1697                    }
1698    
1699                    String sql = query.toString();
1700    
1701                    Query q = session.createQuery(sql);
1702    
1703                    q.setFirstResult(0);
1704                    q.setMaxResults(2);
1705    
1706                    QueryPos qPos = QueryPos.getInstance(q);
1707    
1708                    qPos.add(companyId);
1709    
1710                    if (orderByComparator != null) {
1711                            Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
1712    
1713                            for (Object value : values) {
1714                                    qPos.add(value);
1715                            }
1716                    }
1717    
1718                    List<SCProductEntry> list = q.list();
1719    
1720                    if (list.size() == 2) {
1721                            return list.get(1);
1722                    }
1723                    else {
1724                            return null;
1725                    }
1726            }
1727    
1728            /**
1729             * Returns all the s c product entries where groupId = &#63; and userId = &#63;.
1730             *
1731             * @param groupId the group ID
1732             * @param userId the user ID
1733             * @return the matching s c product entries
1734             * @throws SystemException if a system exception occurred
1735             */
1736            public List<SCProductEntry> findByG_U(long groupId, long userId)
1737                    throws SystemException {
1738                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1739                            null);
1740            }
1741    
1742            /**
1743             * Returns a range of all the s c product entries where groupId = &#63; and userId = &#63;.
1744             *
1745             * <p>
1746             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1747             * </p>
1748             *
1749             * @param groupId the group ID
1750             * @param userId the user ID
1751             * @param start the lower bound of the range of s c product entries
1752             * @param end the upper bound of the range of s c product entries (not inclusive)
1753             * @return the range of matching s c product entries
1754             * @throws SystemException if a system exception occurred
1755             */
1756            public List<SCProductEntry> findByG_U(long groupId, long userId, int start,
1757                    int end) throws SystemException {
1758                    return findByG_U(groupId, userId, start, end, null);
1759            }
1760    
1761            /**
1762             * Returns an ordered range of all the s c product entries where groupId = &#63; and userId = &#63;.
1763             *
1764             * <p>
1765             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1766             * </p>
1767             *
1768             * @param groupId the group ID
1769             * @param userId the user ID
1770             * @param start the lower bound of the range of s c product entries
1771             * @param end the upper bound of the range of s c product entries (not inclusive)
1772             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1773             * @return the ordered range of matching s c product entries
1774             * @throws SystemException if a system exception occurred
1775             */
1776            public List<SCProductEntry> findByG_U(long groupId, long userId, int start,
1777                    int end, OrderByComparator orderByComparator) throws SystemException {
1778                    FinderPath finderPath = null;
1779                    Object[] finderArgs = null;
1780    
1781                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1782                                    (orderByComparator == null)) {
1783                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
1784                            finderArgs = new Object[] { groupId, userId };
1785                    }
1786                    else {
1787                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
1788                            finderArgs = new Object[] {
1789                                            groupId, userId,
1790                                            
1791                                            start, end, orderByComparator
1792                                    };
1793                    }
1794    
1795                    List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
1796                                    finderArgs, this);
1797    
1798                    if ((list != null) && !list.isEmpty()) {
1799                            for (SCProductEntry scProductEntry : list) {
1800                                    if ((groupId != scProductEntry.getGroupId()) ||
1801                                                    (userId != scProductEntry.getUserId())) {
1802                                            list = null;
1803    
1804                                            break;
1805                                    }
1806                            }
1807                    }
1808    
1809                    if (list == null) {
1810                            StringBundler query = null;
1811    
1812                            if (orderByComparator != null) {
1813                                    query = new StringBundler(4 +
1814                                                    (orderByComparator.getOrderByFields().length * 3));
1815                            }
1816                            else {
1817                                    query = new StringBundler(4);
1818                            }
1819    
1820                            query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1821    
1822                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1823    
1824                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1825    
1826                            if (orderByComparator != null) {
1827                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1828                                            orderByComparator);
1829                            }
1830    
1831                            else {
1832                                    query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1833                            }
1834    
1835                            String sql = query.toString();
1836    
1837                            Session session = null;
1838    
1839                            try {
1840                                    session = openSession();
1841    
1842                                    Query q = session.createQuery(sql);
1843    
1844                                    QueryPos qPos = QueryPos.getInstance(q);
1845    
1846                                    qPos.add(groupId);
1847    
1848                                    qPos.add(userId);
1849    
1850                                    list = (List<SCProductEntry>)QueryUtil.list(q, getDialect(),
1851                                                    start, end);
1852                            }
1853                            catch (Exception e) {
1854                                    throw processException(e);
1855                            }
1856                            finally {
1857                                    if (list == null) {
1858                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1859                                    }
1860                                    else {
1861                                            cacheResult(list);
1862    
1863                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1864                                    }
1865    
1866                                    closeSession(session);
1867                            }
1868                    }
1869    
1870                    return list;
1871            }
1872    
1873            /**
1874             * Returns the first s c product entry in the ordered set where groupId = &#63; and userId = &#63;.
1875             *
1876             * @param groupId the group ID
1877             * @param userId the user ID
1878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1879             * @return the first matching s c product entry
1880             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a matching s c product entry could not be found
1881             * @throws SystemException if a system exception occurred
1882             */
1883            public SCProductEntry findByG_U_First(long groupId, long userId,
1884                    OrderByComparator orderByComparator)
1885                    throws NoSuchProductEntryException, SystemException {
1886                    SCProductEntry scProductEntry = fetchByG_U_First(groupId, userId,
1887                                    orderByComparator);
1888    
1889                    if (scProductEntry != null) {
1890                            return scProductEntry;
1891                    }
1892    
1893                    StringBundler msg = new StringBundler(6);
1894    
1895                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1896    
1897                    msg.append("groupId=");
1898                    msg.append(groupId);
1899    
1900                    msg.append(", userId=");
1901                    msg.append(userId);
1902    
1903                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1904    
1905                    throw new NoSuchProductEntryException(msg.toString());
1906            }
1907    
1908            /**
1909             * Returns the first s c product entry in the ordered set where groupId = &#63; and userId = &#63;.
1910             *
1911             * @param groupId the group ID
1912             * @param userId the user ID
1913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1914             * @return the first matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
1915             * @throws SystemException if a system exception occurred
1916             */
1917            public SCProductEntry fetchByG_U_First(long groupId, long userId,
1918                    OrderByComparator orderByComparator) throws SystemException {
1919                    List<SCProductEntry> list = findByG_U(groupId, userId, 0, 1,
1920                                    orderByComparator);
1921    
1922                    if (!list.isEmpty()) {
1923                            return list.get(0);
1924                    }
1925    
1926                    return null;
1927            }
1928    
1929            /**
1930             * Returns the last s c product entry in the ordered set where groupId = &#63; and userId = &#63;.
1931             *
1932             * @param groupId the group ID
1933             * @param userId the user ID
1934             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1935             * @return the last matching s c product entry
1936             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a matching s c product entry could not be found
1937             * @throws SystemException if a system exception occurred
1938             */
1939            public SCProductEntry findByG_U_Last(long groupId, long userId,
1940                    OrderByComparator orderByComparator)
1941                    throws NoSuchProductEntryException, SystemException {
1942                    SCProductEntry scProductEntry = fetchByG_U_Last(groupId, userId,
1943                                    orderByComparator);
1944    
1945                    if (scProductEntry != null) {
1946                            return scProductEntry;
1947                    }
1948    
1949                    StringBundler msg = new StringBundler(6);
1950    
1951                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1952    
1953                    msg.append("groupId=");
1954                    msg.append(groupId);
1955    
1956                    msg.append(", userId=");
1957                    msg.append(userId);
1958    
1959                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1960    
1961                    throw new NoSuchProductEntryException(msg.toString());
1962            }
1963    
1964            /**
1965             * Returns the last s c product entry in the ordered set where groupId = &#63; and userId = &#63;.
1966             *
1967             * @param groupId the group ID
1968             * @param userId the user ID
1969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1970             * @return the last matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
1971             * @throws SystemException if a system exception occurred
1972             */
1973            public SCProductEntry fetchByG_U_Last(long groupId, long userId,
1974                    OrderByComparator orderByComparator) throws SystemException {
1975                    int count = countByG_U(groupId, userId);
1976    
1977                    List<SCProductEntry> list = findByG_U(groupId, userId, count - 1,
1978                                    count, orderByComparator);
1979    
1980                    if (!list.isEmpty()) {
1981                            return list.get(0);
1982                    }
1983    
1984                    return null;
1985            }
1986    
1987            /**
1988             * Returns the s c product entries before and after the current s c product entry in the ordered set where groupId = &#63; and userId = &#63;.
1989             *
1990             * @param productEntryId the primary key of the current s c product entry
1991             * @param groupId the group ID
1992             * @param userId the user ID
1993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1994             * @return the previous, current, and next s c product entry
1995             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
1996             * @throws SystemException if a system exception occurred
1997             */
1998            public SCProductEntry[] findByG_U_PrevAndNext(long productEntryId,
1999                    long groupId, long userId, OrderByComparator orderByComparator)
2000                    throws NoSuchProductEntryException, SystemException {
2001                    SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
2002    
2003                    Session session = null;
2004    
2005                    try {
2006                            session = openSession();
2007    
2008                            SCProductEntry[] array = new SCProductEntryImpl[3];
2009    
2010                            array[0] = getByG_U_PrevAndNext(session, scProductEntry, groupId,
2011                                            userId, orderByComparator, true);
2012    
2013                            array[1] = scProductEntry;
2014    
2015                            array[2] = getByG_U_PrevAndNext(session, scProductEntry, groupId,
2016                                            userId, orderByComparator, false);
2017    
2018                            return array;
2019                    }
2020                    catch (Exception e) {
2021                            throw processException(e);
2022                    }
2023                    finally {
2024                            closeSession(session);
2025                    }
2026            }
2027    
2028            protected SCProductEntry getByG_U_PrevAndNext(Session session,
2029                    SCProductEntry scProductEntry, long groupId, long userId,
2030                    OrderByComparator orderByComparator, boolean previous) {
2031                    StringBundler query = null;
2032    
2033                    if (orderByComparator != null) {
2034                            query = new StringBundler(6 +
2035                                            (orderByComparator.getOrderByFields().length * 6));
2036                    }
2037                    else {
2038                            query = new StringBundler(3);
2039                    }
2040    
2041                    query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
2042    
2043                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2044    
2045                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2046    
2047                    if (orderByComparator != null) {
2048                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2049    
2050                            if (orderByConditionFields.length > 0) {
2051                                    query.append(WHERE_AND);
2052                            }
2053    
2054                            for (int i = 0; i < orderByConditionFields.length; i++) {
2055                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2056                                    query.append(orderByConditionFields[i]);
2057    
2058                                    if ((i + 1) < orderByConditionFields.length) {
2059                                            if (orderByComparator.isAscending() ^ previous) {
2060                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2061                                            }
2062                                            else {
2063                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2064                                            }
2065                                    }
2066                                    else {
2067                                            if (orderByComparator.isAscending() ^ previous) {
2068                                                    query.append(WHERE_GREATER_THAN);
2069                                            }
2070                                            else {
2071                                                    query.append(WHERE_LESSER_THAN);
2072                                            }
2073                                    }
2074                            }
2075    
2076                            query.append(ORDER_BY_CLAUSE);
2077    
2078                            String[] orderByFields = orderByComparator.getOrderByFields();
2079    
2080                            for (int i = 0; i < orderByFields.length; i++) {
2081                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2082                                    query.append(orderByFields[i]);
2083    
2084                                    if ((i + 1) < orderByFields.length) {
2085                                            if (orderByComparator.isAscending() ^ previous) {
2086                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2087                                            }
2088                                            else {
2089                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2090                                            }
2091                                    }
2092                                    else {
2093                                            if (orderByComparator.isAscending() ^ previous) {
2094                                                    query.append(ORDER_BY_ASC);
2095                                            }
2096                                            else {
2097                                                    query.append(ORDER_BY_DESC);
2098                                            }
2099                                    }
2100                            }
2101                    }
2102    
2103                    else {
2104                            query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
2105                    }
2106    
2107                    String sql = query.toString();
2108    
2109                    Query q = session.createQuery(sql);
2110    
2111                    q.setFirstResult(0);
2112                    q.setMaxResults(2);
2113    
2114                    QueryPos qPos = QueryPos.getInstance(q);
2115    
2116                    qPos.add(groupId);
2117    
2118                    qPos.add(userId);
2119    
2120                    if (orderByComparator != null) {
2121                            Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
2122    
2123                            for (Object value : values) {
2124                                    qPos.add(value);
2125                            }
2126                    }
2127    
2128                    List<SCProductEntry> list = q.list();
2129    
2130                    if (list.size() == 2) {
2131                            return list.get(1);
2132                    }
2133                    else {
2134                            return null;
2135                    }
2136            }
2137    
2138            /**
2139             * Returns all the s c product entries that the user has permission to view where groupId = &#63; and userId = &#63;.
2140             *
2141             * @param groupId the group ID
2142             * @param userId the user ID
2143             * @return the matching s c product entries that the user has permission to view
2144             * @throws SystemException if a system exception occurred
2145             */
2146            public List<SCProductEntry> filterFindByG_U(long groupId, long userId)
2147                    throws SystemException {
2148                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
2149                            QueryUtil.ALL_POS, null);
2150            }
2151    
2152            /**
2153             * Returns a range of all the s c product entries that the user has permission to view where groupId = &#63; and userId = &#63;.
2154             *
2155             * <p>
2156             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2157             * </p>
2158             *
2159             * @param groupId the group ID
2160             * @param userId the user ID
2161             * @param start the lower bound of the range of s c product entries
2162             * @param end the upper bound of the range of s c product entries (not inclusive)
2163             * @return the range of matching s c product entries that the user has permission to view
2164             * @throws SystemException if a system exception occurred
2165             */
2166            public List<SCProductEntry> filterFindByG_U(long groupId, long userId,
2167                    int start, int end) throws SystemException {
2168                    return filterFindByG_U(groupId, userId, start, end, null);
2169            }
2170    
2171            /**
2172             * Returns an ordered range of all the s c product entries that the user has permissions to view where groupId = &#63; and userId = &#63;.
2173             *
2174             * <p>
2175             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2176             * </p>
2177             *
2178             * @param groupId the group ID
2179             * @param userId the user ID
2180             * @param start the lower bound of the range of s c product entries
2181             * @param end the upper bound of the range of s c product entries (not inclusive)
2182             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2183             * @return the ordered range of matching s c product entries that the user has permission to view
2184             * @throws SystemException if a system exception occurred
2185             */
2186            public List<SCProductEntry> filterFindByG_U(long groupId, long userId,
2187                    int start, int end, OrderByComparator orderByComparator)
2188                    throws SystemException {
2189                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2190                            return findByG_U(groupId, userId, start, end, orderByComparator);
2191                    }
2192    
2193                    StringBundler query = null;
2194    
2195                    if (orderByComparator != null) {
2196                            query = new StringBundler(4 +
2197                                            (orderByComparator.getOrderByFields().length * 3));
2198                    }
2199                    else {
2200                            query = new StringBundler(4);
2201                    }
2202    
2203                    if (getDB().isSupportsInlineDistinct()) {
2204                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
2205                    }
2206                    else {
2207                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
2208                    }
2209    
2210                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2211    
2212                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2213    
2214                    if (!getDB().isSupportsInlineDistinct()) {
2215                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
2216                    }
2217    
2218                    if (orderByComparator != null) {
2219                            if (getDB().isSupportsInlineDistinct()) {
2220                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2221                                            orderByComparator);
2222                            }
2223                            else {
2224                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2225                                            orderByComparator);
2226                            }
2227                    }
2228    
2229                    else {
2230                            if (getDB().isSupportsInlineDistinct()) {
2231                                    query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
2232                            }
2233                            else {
2234                                    query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
2235                            }
2236                    }
2237    
2238                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2239                                    SCProductEntry.class.getName(),
2240                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2241    
2242                    Session session = null;
2243    
2244                    try {
2245                            session = openSession();
2246    
2247                            SQLQuery q = session.createSQLQuery(sql);
2248    
2249                            if (getDB().isSupportsInlineDistinct()) {
2250                                    q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
2251                            }
2252                            else {
2253                                    q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
2254                            }
2255    
2256                            QueryPos qPos = QueryPos.getInstance(q);
2257    
2258                            qPos.add(groupId);
2259    
2260                            qPos.add(userId);
2261    
2262                            return (List<SCProductEntry>)QueryUtil.list(q, getDialect(), start,
2263                                    end);
2264                    }
2265                    catch (Exception e) {
2266                            throw processException(e);
2267                    }
2268                    finally {
2269                            closeSession(session);
2270                    }
2271            }
2272    
2273            /**
2274             * Returns the s c product entries before and after the current s c product entry in the ordered set of s c product entries that the user has permission to view where groupId = &#63; and userId = &#63;.
2275             *
2276             * @param productEntryId the primary key of the current s c product entry
2277             * @param groupId the group ID
2278             * @param userId the user ID
2279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2280             * @return the previous, current, and next s c product entry
2281             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a s c product entry with the primary key could not be found
2282             * @throws SystemException if a system exception occurred
2283             */
2284            public SCProductEntry[] filterFindByG_U_PrevAndNext(long productEntryId,
2285                    long groupId, long userId, OrderByComparator orderByComparator)
2286                    throws NoSuchProductEntryException, SystemException {
2287                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2288                            return findByG_U_PrevAndNext(productEntryId, groupId, userId,
2289                                    orderByComparator);
2290                    }
2291    
2292                    SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
2293    
2294                    Session session = null;
2295    
2296                    try {
2297                            session = openSession();
2298    
2299                            SCProductEntry[] array = new SCProductEntryImpl[3];
2300    
2301                            array[0] = filterGetByG_U_PrevAndNext(session, scProductEntry,
2302                                            groupId, userId, orderByComparator, true);
2303    
2304                            array[1] = scProductEntry;
2305    
2306                            array[2] = filterGetByG_U_PrevAndNext(session, scProductEntry,
2307                                            groupId, userId, orderByComparator, false);
2308    
2309                            return array;
2310                    }
2311                    catch (Exception e) {
2312                            throw processException(e);
2313                    }
2314                    finally {
2315                            closeSession(session);
2316                    }
2317            }
2318    
2319            protected SCProductEntry filterGetByG_U_PrevAndNext(Session session,
2320                    SCProductEntry scProductEntry, long groupId, long userId,
2321                    OrderByComparator orderByComparator, boolean previous) {
2322                    StringBundler query = null;
2323    
2324                    if (orderByComparator != null) {
2325                            query = new StringBundler(6 +
2326                                            (orderByComparator.getOrderByFields().length * 6));
2327                    }
2328                    else {
2329                            query = new StringBundler(3);
2330                    }
2331    
2332                    if (getDB().isSupportsInlineDistinct()) {
2333                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
2334                    }
2335                    else {
2336                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
2337                    }
2338    
2339                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2340    
2341                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2342    
2343                    if (!getDB().isSupportsInlineDistinct()) {
2344                            query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
2345                    }
2346    
2347                    if (orderByComparator != null) {
2348                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2349    
2350                            if (orderByConditionFields.length > 0) {
2351                                    query.append(WHERE_AND);
2352                            }
2353    
2354                            for (int i = 0; i < orderByConditionFields.length; i++) {
2355                                    if (getDB().isSupportsInlineDistinct()) {
2356                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2357                                    }
2358                                    else {
2359                                            query.append(_ORDER_BY_ENTITY_TABLE);
2360                                    }
2361    
2362                                    query.append(orderByConditionFields[i]);
2363    
2364                                    if ((i + 1) < orderByConditionFields.length) {
2365                                            if (orderByComparator.isAscending() ^ previous) {
2366                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2367                                            }
2368                                            else {
2369                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2370                                            }
2371                                    }
2372                                    else {
2373                                            if (orderByComparator.isAscending() ^ previous) {
2374                                                    query.append(WHERE_GREATER_THAN);
2375                                            }
2376                                            else {
2377                                                    query.append(WHERE_LESSER_THAN);
2378                                            }
2379                                    }
2380                            }
2381    
2382                            query.append(ORDER_BY_CLAUSE);
2383    
2384                            String[] orderByFields = orderByComparator.getOrderByFields();
2385    
2386                            for (int i = 0; i < orderByFields.length; i++) {
2387                                    if (getDB().isSupportsInlineDistinct()) {
2388                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2389                                    }
2390                                    else {
2391                                            query.append(_ORDER_BY_ENTITY_TABLE);
2392                                    }
2393    
2394                                    query.append(orderByFields[i]);
2395    
2396                                    if ((i + 1) < orderByFields.length) {
2397                                            if (orderByComparator.isAscending() ^ previous) {
2398                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2399                                            }
2400                                            else {
2401                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2402                                            }
2403                                    }
2404                                    else {
2405                                            if (orderByComparator.isAscending() ^ previous) {
2406                                                    query.append(ORDER_BY_ASC);
2407                                            }
2408                                            else {
2409                                                    query.append(ORDER_BY_DESC);
2410                                            }
2411                                    }
2412                            }
2413                    }
2414    
2415                    else {
2416                            if (getDB().isSupportsInlineDistinct()) {
2417                                    query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
2418                            }
2419                            else {
2420                                    query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
2421                            }
2422                    }
2423    
2424                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2425                                    SCProductEntry.class.getName(),
2426                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2427    
2428                    SQLQuery q = session.createSQLQuery(sql);
2429    
2430                    q.setFirstResult(0);
2431                    q.setMaxResults(2);
2432    
2433                    if (getDB().isSupportsInlineDistinct()) {
2434                            q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
2435                    }
2436                    else {
2437                            q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
2438                    }
2439    
2440                    QueryPos qPos = QueryPos.getInstance(q);
2441    
2442                    qPos.add(groupId);
2443    
2444                    qPos.add(userId);
2445    
2446                    if (orderByComparator != null) {
2447                            Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
2448    
2449                            for (Object value : values) {
2450                                    qPos.add(value);
2451                            }
2452                    }
2453    
2454                    List<SCProductEntry> list = q.list();
2455    
2456                    if (list.size() == 2) {
2457                            return list.get(1);
2458                    }
2459                    else {
2460                            return null;
2461                    }
2462            }
2463    
2464            /**
2465             * Returns the s c product entry where repoGroupId = &#63; and repoArtifactId = &#63; or throws a {@link com.liferay.portlet.softwarecatalog.NoSuchProductEntryException} if it could not be found.
2466             *
2467             * @param repoGroupId the repo group ID
2468             * @param repoArtifactId the repo artifact ID
2469             * @return the matching s c product entry
2470             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductEntryException if a matching s c product entry could not be found
2471             * @throws SystemException if a system exception occurred
2472             */
2473            public SCProductEntry findByRG_RA(String repoGroupId, String repoArtifactId)
2474                    throws NoSuchProductEntryException, SystemException {
2475                    SCProductEntry scProductEntry = fetchByRG_RA(repoGroupId, repoArtifactId);
2476    
2477                    if (scProductEntry == null) {
2478                            StringBundler msg = new StringBundler(6);
2479    
2480                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2481    
2482                            msg.append("repoGroupId=");
2483                            msg.append(repoGroupId);
2484    
2485                            msg.append(", repoArtifactId=");
2486                            msg.append(repoArtifactId);
2487    
2488                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2489    
2490                            if (_log.isWarnEnabled()) {
2491                                    _log.warn(msg.toString());
2492                            }
2493    
2494                            throw new NoSuchProductEntryException(msg.toString());
2495                    }
2496    
2497                    return scProductEntry;
2498            }
2499    
2500            /**
2501             * Returns the s c product entry where repoGroupId = &#63; and repoArtifactId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2502             *
2503             * @param repoGroupId the repo group ID
2504             * @param repoArtifactId the repo artifact ID
2505             * @return the matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
2506             * @throws SystemException if a system exception occurred
2507             */
2508            public SCProductEntry fetchByRG_RA(String repoGroupId, String repoArtifactId)
2509                    throws SystemException {
2510                    return fetchByRG_RA(repoGroupId, repoArtifactId, true);
2511            }
2512    
2513            /**
2514             * Returns the s c product entry where repoGroupId = &#63; and repoArtifactId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2515             *
2516             * @param repoGroupId the repo group ID
2517             * @param repoArtifactId the repo artifact ID
2518             * @param retrieveFromCache whether to use the finder cache
2519             * @return the matching s c product entry, or <code>null</code> if a matching s c product entry could not be found
2520             * @throws SystemException if a system exception occurred
2521             */
2522            public SCProductEntry fetchByRG_RA(String repoGroupId,
2523                    String repoArtifactId, boolean retrieveFromCache)
2524                    throws SystemException {
2525                    Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
2526    
2527                    Object result = null;
2528    
2529                    if (retrieveFromCache) {
2530                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_RG_RA,
2531                                            finderArgs, this);
2532                    }
2533    
2534                    if (result instanceof SCProductEntry) {
2535                            SCProductEntry scProductEntry = (SCProductEntry)result;
2536    
2537                            if (!Validator.equals(repoGroupId, scProductEntry.getRepoGroupId()) ||
2538                                            !Validator.equals(repoArtifactId,
2539                                                    scProductEntry.getRepoArtifactId())) {
2540                                    result = null;
2541                            }
2542                    }
2543    
2544                    if (result == null) {
2545                            StringBundler query = new StringBundler(4);
2546    
2547                            query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
2548    
2549                            if (repoGroupId == null) {
2550                                    query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_1);
2551                            }
2552                            else {
2553                                    if (repoGroupId.equals(StringPool.BLANK)) {
2554                                            query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_3);
2555                                    }
2556                                    else {
2557                                            query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_2);
2558                                    }
2559                            }
2560    
2561                            if (repoArtifactId == null) {
2562                                    query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_1);
2563                            }
2564                            else {
2565                                    if (repoArtifactId.equals(StringPool.BLANK)) {
2566                                            query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_3);
2567                                    }
2568                                    else {
2569                                            query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_2);
2570                                    }
2571                            }
2572    
2573                            query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
2574    
2575                            String sql = query.toString();
2576    
2577                            Session session = null;
2578    
2579                            try {
2580                                    session = openSession();
2581    
2582                                    Query q = session.createQuery(sql);
2583    
2584                                    QueryPos qPos = QueryPos.getInstance(q);
2585    
2586                                    if (repoGroupId != null) {
2587                                            qPos.add(repoGroupId);
2588                                    }
2589    
2590                                    if (repoArtifactId != null) {
2591                                            qPos.add(repoArtifactId);
2592                                    }
2593    
2594                                    List<SCProductEntry> list = q.list();
2595    
2596                                    result = list;
2597    
2598                                    SCProductEntry scProductEntry = null;
2599    
2600                                    if (list.isEmpty()) {
2601                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
2602                                                    finderArgs, list);
2603                                    }
2604                                    else {
2605                                            scProductEntry = list.get(0);
2606    
2607                                            cacheResult(scProductEntry);
2608    
2609                                            if ((scProductEntry.getRepoGroupId() == null) ||
2610                                                            !scProductEntry.getRepoGroupId().equals(repoGroupId) ||
2611                                                            (scProductEntry.getRepoArtifactId() == null) ||
2612                                                            !scProductEntry.getRepoArtifactId()
2613                                                                                               .equals(repoArtifactId)) {
2614                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
2615                                                            finderArgs, scProductEntry);
2616                                            }
2617                                    }
2618    
2619                                    return scProductEntry;
2620                            }
2621                            catch (Exception e) {
2622                                    throw processException(e);
2623                            }
2624                            finally {
2625                                    if (result == null) {
2626                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_RG_RA,
2627                                                    finderArgs);
2628                                    }
2629    
2630                                    closeSession(session);
2631                            }
2632                    }
2633                    else {
2634                            if (result instanceof List<?>) {
2635                                    return null;
2636                            }
2637                            else {
2638                                    return (SCProductEntry)result;
2639                            }
2640                    }
2641            }
2642    
2643            /**
2644             * Returns all the s c product entries.
2645             *
2646             * @return the s c product entries
2647             * @throws SystemException if a system exception occurred
2648             */
2649            public List<SCProductEntry> findAll() throws SystemException {
2650                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2651            }
2652    
2653            /**
2654             * Returns a range of all the s c product entries.
2655             *
2656             * <p>
2657             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2658             * </p>
2659             *
2660             * @param start the lower bound of the range of s c product entries
2661             * @param end the upper bound of the range of s c product entries (not inclusive)
2662             * @return the range of s c product entries
2663             * @throws SystemException if a system exception occurred
2664             */
2665            public List<SCProductEntry> findAll(int start, int end)
2666                    throws SystemException {
2667                    return findAll(start, end, null);
2668            }
2669    
2670            /**
2671             * Returns an ordered range of all the s c product entries.
2672             *
2673             * <p>
2674             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2675             * </p>
2676             *
2677             * @param start the lower bound of the range of s c product entries
2678             * @param end the upper bound of the range of s c product entries (not inclusive)
2679             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2680             * @return the ordered range of s c product entries
2681             * @throws SystemException if a system exception occurred
2682             */
2683            public List<SCProductEntry> findAll(int start, int end,
2684                    OrderByComparator orderByComparator) throws SystemException {
2685                    FinderPath finderPath = null;
2686                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2687    
2688                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2689                                    (orderByComparator == null)) {
2690                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2691                            finderArgs = FINDER_ARGS_EMPTY;
2692                    }
2693                    else {
2694                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2695                            finderArgs = new Object[] { start, end, orderByComparator };
2696                    }
2697    
2698                    List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
2699                                    finderArgs, this);
2700    
2701                    if (list == null) {
2702                            StringBundler query = null;
2703                            String sql = null;
2704    
2705                            if (orderByComparator != null) {
2706                                    query = new StringBundler(2 +
2707                                                    (orderByComparator.getOrderByFields().length * 3));
2708    
2709                                    query.append(_SQL_SELECT_SCPRODUCTENTRY);
2710    
2711                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2712                                            orderByComparator);
2713    
2714                                    sql = query.toString();
2715                            }
2716                            else {
2717                                    sql = _SQL_SELECT_SCPRODUCTENTRY.concat(SCProductEntryModelImpl.ORDER_BY_JPQL);
2718                            }
2719    
2720                            Session session = null;
2721    
2722                            try {
2723                                    session = openSession();
2724    
2725                                    Query q = session.createQuery(sql);
2726    
2727                                    if (orderByComparator == null) {
2728                                            list = (List<SCProductEntry>)QueryUtil.list(q,
2729                                                            getDialect(), start, end, false);
2730    
2731                                            Collections.sort(list);
2732                                    }
2733                                    else {
2734                                            list = (List<SCProductEntry>)QueryUtil.list(q,
2735                                                            getDialect(), start, end);
2736                                    }
2737                            }
2738                            catch (Exception e) {
2739                                    throw processException(e);
2740                            }
2741                            finally {
2742                                    if (list == null) {
2743                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2744                                    }
2745                                    else {
2746                                            cacheResult(list);
2747    
2748                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2749                                    }
2750    
2751                                    closeSession(session);
2752                            }
2753                    }
2754    
2755                    return list;
2756            }
2757    
2758            /**
2759             * Removes all the s c product entries where groupId = &#63; from the database.
2760             *
2761             * @param groupId the group ID
2762             * @throws SystemException if a system exception occurred
2763             */
2764            public void removeByGroupId(long groupId) throws SystemException {
2765                    for (SCProductEntry scProductEntry : findByGroupId(groupId)) {
2766                            remove(scProductEntry);
2767                    }
2768            }
2769    
2770            /**
2771             * Removes all the s c product entries where companyId = &#63; from the database.
2772             *
2773             * @param companyId the company ID
2774             * @throws SystemException if a system exception occurred
2775             */
2776            public void removeByCompanyId(long companyId) throws SystemException {
2777                    for (SCProductEntry scProductEntry : findByCompanyId(companyId)) {
2778                            remove(scProductEntry);
2779                    }
2780            }
2781    
2782            /**
2783             * Removes all the s c product entries where groupId = &#63; and userId = &#63; from the database.
2784             *
2785             * @param groupId the group ID
2786             * @param userId the user ID
2787             * @throws SystemException if a system exception occurred
2788             */
2789            public void removeByG_U(long groupId, long userId)
2790                    throws SystemException {
2791                    for (SCProductEntry scProductEntry : findByG_U(groupId, userId)) {
2792                            remove(scProductEntry);
2793                    }
2794            }
2795    
2796            /**
2797             * Removes the s c product entry where repoGroupId = &#63; and repoArtifactId = &#63; from the database.
2798             *
2799             * @param repoGroupId the repo group ID
2800             * @param repoArtifactId the repo artifact ID
2801             * @return the s c product entry that was removed
2802             * @throws SystemException if a system exception occurred
2803             */
2804            public SCProductEntry removeByRG_RA(String repoGroupId,
2805                    String repoArtifactId)
2806                    throws NoSuchProductEntryException, SystemException {
2807                    SCProductEntry scProductEntry = findByRG_RA(repoGroupId, repoArtifactId);
2808    
2809                    return remove(scProductEntry);
2810            }
2811    
2812            /**
2813             * Removes all the s c product entries from the database.
2814             *
2815             * @throws SystemException if a system exception occurred
2816             */
2817            public void removeAll() throws SystemException {
2818                    for (SCProductEntry scProductEntry : findAll()) {
2819                            remove(scProductEntry);
2820                    }
2821            }
2822    
2823            /**
2824             * Returns the number of s c product entries where groupId = &#63;.
2825             *
2826             * @param groupId the group ID
2827             * @return the number of matching s c product entries
2828             * @throws SystemException if a system exception occurred
2829             */
2830            public int countByGroupId(long groupId) throws SystemException {
2831                    Object[] finderArgs = new Object[] { groupId };
2832    
2833                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2834                                    finderArgs, this);
2835    
2836                    if (count == null) {
2837                            StringBundler query = new StringBundler(2);
2838    
2839                            query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
2840    
2841                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2842    
2843                            String sql = query.toString();
2844    
2845                            Session session = null;
2846    
2847                            try {
2848                                    session = openSession();
2849    
2850                                    Query q = session.createQuery(sql);
2851    
2852                                    QueryPos qPos = QueryPos.getInstance(q);
2853    
2854                                    qPos.add(groupId);
2855    
2856                                    count = (Long)q.uniqueResult();
2857                            }
2858                            catch (Exception e) {
2859                                    throw processException(e);
2860                            }
2861                            finally {
2862                                    if (count == null) {
2863                                            count = Long.valueOf(0);
2864                                    }
2865    
2866                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2867                                            finderArgs, count);
2868    
2869                                    closeSession(session);
2870                            }
2871                    }
2872    
2873                    return count.intValue();
2874            }
2875    
2876            /**
2877             * Returns the number of s c product entries that the user has permission to view where groupId = &#63;.
2878             *
2879             * @param groupId the group ID
2880             * @return the number of matching s c product entries that the user has permission to view
2881             * @throws SystemException if a system exception occurred
2882             */
2883            public int filterCountByGroupId(long groupId) throws SystemException {
2884                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2885                            return countByGroupId(groupId);
2886                    }
2887    
2888                    StringBundler query = new StringBundler(2);
2889    
2890                    query.append(_FILTER_SQL_COUNT_SCPRODUCTENTRY_WHERE);
2891    
2892                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2893    
2894                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2895                                    SCProductEntry.class.getName(),
2896                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2897    
2898                    Session session = null;
2899    
2900                    try {
2901                            session = openSession();
2902    
2903                            SQLQuery q = session.createSQLQuery(sql);
2904    
2905                            q.addScalar(COUNT_COLUMN_NAME,
2906                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2907    
2908                            QueryPos qPos = QueryPos.getInstance(q);
2909    
2910                            qPos.add(groupId);
2911    
2912                            Long count = (Long)q.uniqueResult();
2913    
2914                            return count.intValue();
2915                    }
2916                    catch (Exception e) {
2917                            throw processException(e);
2918                    }
2919                    finally {
2920                            closeSession(session);
2921                    }
2922            }
2923    
2924            /**
2925             * Returns the number of s c product entries where companyId = &#63;.
2926             *
2927             * @param companyId the company ID
2928             * @return the number of matching s c product entries
2929             * @throws SystemException if a system exception occurred
2930             */
2931            public int countByCompanyId(long companyId) throws SystemException {
2932                    Object[] finderArgs = new Object[] { companyId };
2933    
2934                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2935                                    finderArgs, this);
2936    
2937                    if (count == null) {
2938                            StringBundler query = new StringBundler(2);
2939    
2940                            query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
2941    
2942                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2943    
2944                            String sql = query.toString();
2945    
2946                            Session session = null;
2947    
2948                            try {
2949                                    session = openSession();
2950    
2951                                    Query q = session.createQuery(sql);
2952    
2953                                    QueryPos qPos = QueryPos.getInstance(q);
2954    
2955                                    qPos.add(companyId);
2956    
2957                                    count = (Long)q.uniqueResult();
2958                            }
2959                            catch (Exception e) {
2960                                    throw processException(e);
2961                            }
2962                            finally {
2963                                    if (count == null) {
2964                                            count = Long.valueOf(0);
2965                                    }
2966    
2967                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2968                                            finderArgs, count);
2969    
2970                                    closeSession(session);
2971                            }
2972                    }
2973    
2974                    return count.intValue();
2975            }
2976    
2977            /**
2978             * Returns the number of s c product entries where groupId = &#63; and userId = &#63;.
2979             *
2980             * @param groupId the group ID
2981             * @param userId the user ID
2982             * @return the number of matching s c product entries
2983             * @throws SystemException if a system exception occurred
2984             */
2985            public int countByG_U(long groupId, long userId) throws SystemException {
2986                    Object[] finderArgs = new Object[] { groupId, userId };
2987    
2988                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2989                                    finderArgs, this);
2990    
2991                    if (count == null) {
2992                            StringBundler query = new StringBundler(3);
2993    
2994                            query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
2995    
2996                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2997    
2998                            query.append(_FINDER_COLUMN_G_U_USERID_2);
2999    
3000                            String sql = query.toString();
3001    
3002                            Session session = null;
3003    
3004                            try {
3005                                    session = openSession();
3006    
3007                                    Query q = session.createQuery(sql);
3008    
3009                                    QueryPos qPos = QueryPos.getInstance(q);
3010    
3011                                    qPos.add(groupId);
3012    
3013                                    qPos.add(userId);
3014    
3015                                    count = (Long)q.uniqueResult();
3016                            }
3017                            catch (Exception e) {
3018                                    throw processException(e);
3019                            }
3020                            finally {
3021                                    if (count == null) {
3022                                            count = Long.valueOf(0);
3023                                    }
3024    
3025                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
3026                                            count);
3027    
3028                                    closeSession(session);
3029                            }
3030                    }
3031    
3032                    return count.intValue();
3033            }
3034    
3035            /**
3036             * Returns the number of s c product entries that the user has permission to view where groupId = &#63; and userId = &#63;.
3037             *
3038             * @param groupId the group ID
3039             * @param userId the user ID
3040             * @return the number of matching s c product entries that the user has permission to view
3041             * @throws SystemException if a system exception occurred
3042             */
3043            public int filterCountByG_U(long groupId, long userId)
3044                    throws SystemException {
3045                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3046                            return countByG_U(groupId, userId);
3047                    }
3048    
3049                    StringBundler query = new StringBundler(3);
3050    
3051                    query.append(_FILTER_SQL_COUNT_SCPRODUCTENTRY_WHERE);
3052    
3053                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3054    
3055                    query.append(_FINDER_COLUMN_G_U_USERID_2);
3056    
3057                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3058                                    SCProductEntry.class.getName(),
3059                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3060    
3061                    Session session = null;
3062    
3063                    try {
3064                            session = openSession();
3065    
3066                            SQLQuery q = session.createSQLQuery(sql);
3067    
3068                            q.addScalar(COUNT_COLUMN_NAME,
3069                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3070    
3071                            QueryPos qPos = QueryPos.getInstance(q);
3072    
3073                            qPos.add(groupId);
3074    
3075                            qPos.add(userId);
3076    
3077                            Long count = (Long)q.uniqueResult();
3078    
3079                            return count.intValue();
3080                    }
3081                    catch (Exception e) {
3082                            throw processException(e);
3083                    }
3084                    finally {
3085                            closeSession(session);
3086                    }
3087            }
3088    
3089            /**
3090             * Returns the number of s c product entries where repoGroupId = &#63; and repoArtifactId = &#63;.
3091             *
3092             * @param repoGroupId the repo group ID
3093             * @param repoArtifactId the repo artifact ID
3094             * @return the number of matching s c product entries
3095             * @throws SystemException if a system exception occurred
3096             */
3097            public int countByRG_RA(String repoGroupId, String repoArtifactId)
3098                    throws SystemException {
3099                    Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
3100    
3101                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RG_RA,
3102                                    finderArgs, this);
3103    
3104                    if (count == null) {
3105                            StringBundler query = new StringBundler(3);
3106    
3107                            query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
3108    
3109                            if (repoGroupId == null) {
3110                                    query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_1);
3111                            }
3112                            else {
3113                                    if (repoGroupId.equals(StringPool.BLANK)) {
3114                                            query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_3);
3115                                    }
3116                                    else {
3117                                            query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_2);
3118                                    }
3119                            }
3120    
3121                            if (repoArtifactId == null) {
3122                                    query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_1);
3123                            }
3124                            else {
3125                                    if (repoArtifactId.equals(StringPool.BLANK)) {
3126                                            query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_3);
3127                                    }
3128                                    else {
3129                                            query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_2);
3130                                    }
3131                            }
3132    
3133                            String sql = query.toString();
3134    
3135                            Session session = null;
3136    
3137                            try {
3138                                    session = openSession();
3139    
3140                                    Query q = session.createQuery(sql);
3141    
3142                                    QueryPos qPos = QueryPos.getInstance(q);
3143    
3144                                    if (repoGroupId != null) {
3145                                            qPos.add(repoGroupId);
3146                                    }
3147    
3148                                    if (repoArtifactId != null) {
3149                                            qPos.add(repoArtifactId);
3150                                    }
3151    
3152                                    count = (Long)q.uniqueResult();
3153                            }
3154                            catch (Exception e) {
3155                                    throw processException(e);
3156                            }
3157                            finally {
3158                                    if (count == null) {
3159                                            count = Long.valueOf(0);
3160                                    }
3161    
3162                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RG_RA,
3163                                            finderArgs, count);
3164    
3165                                    closeSession(session);
3166                            }
3167                    }
3168    
3169                    return count.intValue();
3170            }
3171    
3172            /**
3173             * Returns the number of s c product entries.
3174             *
3175             * @return the number of s c product entries
3176             * @throws SystemException if a system exception occurred
3177             */
3178            public int countAll() throws SystemException {
3179                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3180                                    FINDER_ARGS_EMPTY, this);
3181    
3182                    if (count == null) {
3183                            Session session = null;
3184    
3185                            try {
3186                                    session = openSession();
3187    
3188                                    Query q = session.createQuery(_SQL_COUNT_SCPRODUCTENTRY);
3189    
3190                                    count = (Long)q.uniqueResult();
3191                            }
3192                            catch (Exception e) {
3193                                    throw processException(e);
3194                            }
3195                            finally {
3196                                    if (count == null) {
3197                                            count = Long.valueOf(0);
3198                                    }
3199    
3200                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3201                                            FINDER_ARGS_EMPTY, count);
3202    
3203                                    closeSession(session);
3204                            }
3205                    }
3206    
3207                    return count.intValue();
3208            }
3209    
3210            /**
3211             * Returns all the s c licenses associated with the s c product entry.
3212             *
3213             * @param pk the primary key of the s c product entry
3214             * @return the s c licenses associated with the s c product entry
3215             * @throws SystemException if a system exception occurred
3216             */
3217            public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
3218                    long pk) throws SystemException {
3219                    return getSCLicenses(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3220            }
3221    
3222            /**
3223             * Returns a range of all the s c licenses associated with the s c product entry.
3224             *
3225             * <p>
3226             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3227             * </p>
3228             *
3229             * @param pk the primary key of the s c product entry
3230             * @param start the lower bound of the range of s c product entries
3231             * @param end the upper bound of the range of s c product entries (not inclusive)
3232             * @return the range of s c licenses associated with the s c product entry
3233             * @throws SystemException if a system exception occurred
3234             */
3235            public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
3236                    long pk, int start, int end) throws SystemException {
3237                    return getSCLicenses(pk, start, end, null);
3238            }
3239    
3240            public static final FinderPath FINDER_PATH_GET_SCLICENSES = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
3241                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
3242                            com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl.class,
3243                            SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
3244                            "getSCLicenses",
3245                            new String[] {
3246                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3247                                    "com.liferay.portal.kernel.util.OrderByComparator"
3248                            });
3249    
3250            static {
3251                    FINDER_PATH_GET_SCLICENSES.setCacheKeyGeneratorCacheName(null);
3252            }
3253    
3254            /**
3255             * Returns an ordered range of all the s c licenses associated with the s c product entry.
3256             *
3257             * <p>
3258             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3259             * </p>
3260             *
3261             * @param pk the primary key of the s c product entry
3262             * @param start the lower bound of the range of s c product entries
3263             * @param end the upper bound of the range of s c product entries (not inclusive)
3264             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3265             * @return the ordered range of s c licenses associated with the s c product entry
3266             * @throws SystemException if a system exception occurred
3267             */
3268            public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
3269                    long pk, int start, int end, OrderByComparator orderByComparator)
3270                    throws SystemException {
3271                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
3272    
3273                    List<com.liferay.portlet.softwarecatalog.model.SCLicense> list = (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_GET_SCLICENSES,
3274                                    finderArgs, this);
3275    
3276                    if (list == null) {
3277                            Session session = null;
3278    
3279                            try {
3280                                    session = openSession();
3281    
3282                                    String sql = null;
3283    
3284                                    if (orderByComparator != null) {
3285                                            sql = _SQL_GETSCLICENSES.concat(ORDER_BY_CLAUSE)
3286                                                                                            .concat(orderByComparator.getOrderBy());
3287                                    }
3288                                    else {
3289                                            sql = _SQL_GETSCLICENSES.concat(com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl.ORDER_BY_SQL);
3290                                    }
3291    
3292                                    SQLQuery q = session.createSQLQuery(sql);
3293    
3294                                    q.addEntity("SCLicense",
3295                                            com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl.class);
3296    
3297                                    QueryPos qPos = QueryPos.getInstance(q);
3298    
3299                                    qPos.add(pk);
3300    
3301                                    list = (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)QueryUtil.list(q,
3302                                                    getDialect(), start, end);
3303                            }
3304                            catch (Exception e) {
3305                                    throw processException(e);
3306                            }
3307                            finally {
3308                                    if (list == null) {
3309                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_SCLICENSES,
3310                                                    finderArgs);
3311                                    }
3312                                    else {
3313                                            scLicensePersistence.cacheResult(list);
3314    
3315                                            FinderCacheUtil.putResult(FINDER_PATH_GET_SCLICENSES,
3316                                                    finderArgs, list);
3317                                    }
3318    
3319                                    closeSession(session);
3320                            }
3321                    }
3322    
3323                    return list;
3324            }
3325    
3326            public static final FinderPath FINDER_PATH_GET_SCLICENSES_SIZE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
3327                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
3328                            Long.class,
3329                            SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
3330                            "getSCLicensesSize", new String[] { Long.class.getName() });
3331    
3332            static {
3333                    FINDER_PATH_GET_SCLICENSES_SIZE.setCacheKeyGeneratorCacheName(null);
3334            }
3335    
3336            /**
3337             * Returns the number of s c licenses associated with the s c product entry.
3338             *
3339             * @param pk the primary key of the s c product entry
3340             * @return the number of s c licenses associated with the s c product entry
3341             * @throws SystemException if a system exception occurred
3342             */
3343            public int getSCLicensesSize(long pk) throws SystemException {
3344                    Object[] finderArgs = new Object[] { pk };
3345    
3346                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SCLICENSES_SIZE,
3347                                    finderArgs, this);
3348    
3349                    if (count == null) {
3350                            Session session = null;
3351    
3352                            try {
3353                                    session = openSession();
3354    
3355                                    SQLQuery q = session.createSQLQuery(_SQL_GETSCLICENSESSIZE);
3356    
3357                                    q.addScalar(COUNT_COLUMN_NAME,
3358                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
3359    
3360                                    QueryPos qPos = QueryPos.getInstance(q);
3361    
3362                                    qPos.add(pk);
3363    
3364                                    count = (Long)q.uniqueResult();
3365                            }
3366                            catch (Exception e) {
3367                                    throw processException(e);
3368                            }
3369                            finally {
3370                                    if (count == null) {
3371                                            count = Long.valueOf(0);
3372                                    }
3373    
3374                                    FinderCacheUtil.putResult(FINDER_PATH_GET_SCLICENSES_SIZE,
3375                                            finderArgs, count);
3376    
3377                                    closeSession(session);
3378                            }
3379                    }
3380    
3381                    return count.intValue();
3382            }
3383    
3384            public static final FinderPath FINDER_PATH_CONTAINS_SCLICENSE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
3385                            SCProductEntryModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
3386                            Boolean.class,
3387                            SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
3388                            "containsSCLicense",
3389                            new String[] { Long.class.getName(), Long.class.getName() });
3390    
3391            /**
3392             * Returns <code>true</code> if the s c license is associated with the s c product entry.
3393             *
3394             * @param pk the primary key of the s c product entry
3395             * @param scLicensePK the primary key of the s c license
3396             * @return <code>true</code> if the s c license is associated with the s c product entry; <code>false</code> otherwise
3397             * @throws SystemException if a system exception occurred
3398             */
3399            public boolean containsSCLicense(long pk, long scLicensePK)
3400                    throws SystemException {
3401                    Object[] finderArgs = new Object[] { pk, scLicensePK };
3402    
3403                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SCLICENSE,
3404                                    finderArgs, this);
3405    
3406                    if (value == null) {
3407                            try {
3408                                    value = Boolean.valueOf(containsSCLicense.contains(pk,
3409                                                            scLicensePK));
3410                            }
3411                            catch (Exception e) {
3412                                    throw processException(e);
3413                            }
3414                            finally {
3415                                    if (value == null) {
3416                                            value = Boolean.FALSE;
3417                                    }
3418    
3419                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SCLICENSE,
3420                                            finderArgs, value);
3421                            }
3422                    }
3423    
3424                    return value.booleanValue();
3425            }
3426    
3427            /**
3428             * Returns <code>true</code> if the s c product entry has any s c licenses associated with it.
3429             *
3430             * @param pk the primary key of the s c product entry to check for associations with s c licenses
3431             * @return <code>true</code> if the s c product entry has any s c licenses associated with it; <code>false</code> otherwise
3432             * @throws SystemException if a system exception occurred
3433             */
3434            public boolean containsSCLicenses(long pk) throws SystemException {
3435                    if (getSCLicensesSize(pk) > 0) {
3436                            return true;
3437                    }
3438                    else {
3439                            return false;
3440                    }
3441            }
3442    
3443            /**
3444             * Adds an association between the s c product entry and the s c license. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3445             *
3446             * @param pk the primary key of the s c product entry
3447             * @param scLicensePK the primary key of the s c license
3448             * @throws SystemException if a system exception occurred
3449             */
3450            public void addSCLicense(long pk, long scLicensePK)
3451                    throws SystemException {
3452                    try {
3453                            addSCLicense.add(pk, scLicensePK);
3454                    }
3455                    catch (Exception e) {
3456                            throw processException(e);
3457                    }
3458                    finally {
3459                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3460                    }
3461            }
3462    
3463            /**
3464             * Adds an association between the s c product entry and the s c license. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3465             *
3466             * @param pk the primary key of the s c product entry
3467             * @param scLicense the s c license
3468             * @throws SystemException if a system exception occurred
3469             */
3470            public void addSCLicense(long pk,
3471                    com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
3472                    throws SystemException {
3473                    try {
3474                            addSCLicense.add(pk, scLicense.getPrimaryKey());
3475                    }
3476                    catch (Exception e) {
3477                            throw processException(e);
3478                    }
3479                    finally {
3480                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3481                    }
3482            }
3483    
3484            /**
3485             * Adds an association between the s c product entry and the s c licenses. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3486             *
3487             * @param pk the primary key of the s c product entry
3488             * @param scLicensePKs the primary keys of the s c licenses
3489             * @throws SystemException if a system exception occurred
3490             */
3491            public void addSCLicenses(long pk, long[] scLicensePKs)
3492                    throws SystemException {
3493                    try {
3494                            for (long scLicensePK : scLicensePKs) {
3495                                    addSCLicense.add(pk, scLicensePK);
3496                            }
3497                    }
3498                    catch (Exception e) {
3499                            throw processException(e);
3500                    }
3501                    finally {
3502                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3503                    }
3504            }
3505    
3506            /**
3507             * Adds an association between the s c product entry and the s c licenses. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3508             *
3509             * @param pk the primary key of the s c product entry
3510             * @param scLicenses the s c licenses
3511             * @throws SystemException if a system exception occurred
3512             */
3513            public void addSCLicenses(long pk,
3514                    List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
3515                    throws SystemException {
3516                    try {
3517                            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
3518                                    addSCLicense.add(pk, scLicense.getPrimaryKey());
3519                            }
3520                    }
3521                    catch (Exception e) {
3522                            throw processException(e);
3523                    }
3524                    finally {
3525                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3526                    }
3527            }
3528    
3529            /**
3530             * Clears all associations between the s c product entry and its s c licenses. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3531             *
3532             * @param pk the primary key of the s c product entry to clear the associated s c licenses from
3533             * @throws SystemException if a system exception occurred
3534             */
3535            public void clearSCLicenses(long pk) throws SystemException {
3536                    try {
3537                            clearSCLicenses.clear(pk);
3538                    }
3539                    catch (Exception e) {
3540                            throw processException(e);
3541                    }
3542                    finally {
3543                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3544                    }
3545            }
3546    
3547            /**
3548             * Removes the association between the s c product entry and the s c license. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3549             *
3550             * @param pk the primary key of the s c product entry
3551             * @param scLicensePK the primary key of the s c license
3552             * @throws SystemException if a system exception occurred
3553             */
3554            public void removeSCLicense(long pk, long scLicensePK)
3555                    throws SystemException {
3556                    try {
3557                            removeSCLicense.remove(pk, scLicensePK);
3558                    }
3559                    catch (Exception e) {
3560                            throw processException(e);
3561                    }
3562                    finally {
3563                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3564                    }
3565            }
3566    
3567            /**
3568             * Removes the association between the s c product entry and the s c license. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3569             *
3570             * @param pk the primary key of the s c product entry
3571             * @param scLicense the s c license
3572             * @throws SystemException if a system exception occurred
3573             */
3574            public void removeSCLicense(long pk,
3575                    com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
3576                    throws SystemException {
3577                    try {
3578                            removeSCLicense.remove(pk, scLicense.getPrimaryKey());
3579                    }
3580                    catch (Exception e) {
3581                            throw processException(e);
3582                    }
3583                    finally {
3584                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3585                    }
3586            }
3587    
3588            /**
3589             * Removes the association between the s c product entry and the s c licenses. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3590             *
3591             * @param pk the primary key of the s c product entry
3592             * @param scLicensePKs the primary keys of the s c licenses
3593             * @throws SystemException if a system exception occurred
3594             */
3595            public void removeSCLicenses(long pk, long[] scLicensePKs)
3596                    throws SystemException {
3597                    try {
3598                            for (long scLicensePK : scLicensePKs) {
3599                                    removeSCLicense.remove(pk, scLicensePK);
3600                            }
3601                    }
3602                    catch (Exception e) {
3603                            throw processException(e);
3604                    }
3605                    finally {
3606                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3607                    }
3608            }
3609    
3610            /**
3611             * Removes the association between the s c product entry and the s c licenses. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3612             *
3613             * @param pk the primary key of the s c product entry
3614             * @param scLicenses the s c licenses
3615             * @throws SystemException if a system exception occurred
3616             */
3617            public void removeSCLicenses(long pk,
3618                    List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
3619                    throws SystemException {
3620                    try {
3621                            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
3622                                    removeSCLicense.remove(pk, scLicense.getPrimaryKey());
3623                            }
3624                    }
3625                    catch (Exception e) {
3626                            throw processException(e);
3627                    }
3628                    finally {
3629                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3630                    }
3631            }
3632    
3633            /**
3634             * Sets the s c licenses associated with the s c product entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3635             *
3636             * @param pk the primary key of the s c product entry
3637             * @param scLicensePKs the primary keys of the s c licenses to be associated with the s c product entry
3638             * @throws SystemException if a system exception occurred
3639             */
3640            public void setSCLicenses(long pk, long[] scLicensePKs)
3641                    throws SystemException {
3642                    try {
3643                            Set<Long> scLicensePKSet = SetUtil.fromArray(scLicensePKs);
3644    
3645                            List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses =
3646                                    getSCLicenses(pk);
3647    
3648                            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
3649                                    if (!scLicensePKSet.remove(scLicense.getPrimaryKey())) {
3650                                            removeSCLicense.remove(pk, scLicense.getPrimaryKey());
3651                                    }
3652                            }
3653    
3654                            for (Long scLicensePK : scLicensePKSet) {
3655                                    addSCLicense.add(pk, scLicensePK);
3656                            }
3657                    }
3658                    catch (Exception e) {
3659                            throw processException(e);
3660                    }
3661                    finally {
3662                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3663                    }
3664            }
3665    
3666            /**
3667             * Sets the s c licenses associated with the s c product entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3668             *
3669             * @param pk the primary key of the s c product entry
3670             * @param scLicenses the s c licenses to be associated with the s c product entry
3671             * @throws SystemException if a system exception occurred
3672             */
3673            public void setSCLicenses(long pk,
3674                    List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
3675                    throws SystemException {
3676                    try {
3677                            long[] scLicensePKs = new long[scLicenses.size()];
3678    
3679                            for (int i = 0; i < scLicenses.size(); i++) {
3680                                    com.liferay.portlet.softwarecatalog.model.SCLicense scLicense = scLicenses.get(i);
3681    
3682                                    scLicensePKs[i] = scLicense.getPrimaryKey();
3683                            }
3684    
3685                            setSCLicenses(pk, scLicensePKs);
3686                    }
3687                    catch (Exception e) {
3688                            throw processException(e);
3689                    }
3690                    finally {
3691                            FinderCacheUtil.clearCache(SCProductEntryModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
3692                    }
3693            }
3694    
3695            /**
3696             * Initializes the s c product entry persistence.
3697             */
3698            public void afterPropertiesSet() {
3699                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3700                                            com.liferay.portal.util.PropsUtil.get(
3701                                                    "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductEntry")));
3702    
3703                    if (listenerClassNames.length > 0) {
3704                            try {
3705                                    List<ModelListener<SCProductEntry>> listenersList = new ArrayList<ModelListener<SCProductEntry>>();
3706    
3707                                    for (String listenerClassName : listenerClassNames) {
3708                                            listenersList.add((ModelListener<SCProductEntry>)InstanceFactory.newInstance(
3709                                                            listenerClassName));
3710                                    }
3711    
3712                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3713                            }
3714                            catch (Exception e) {
3715                                    _log.error(e);
3716                            }
3717                    }
3718    
3719                    containsSCLicense = new ContainsSCLicense();
3720    
3721                    addSCLicense = new AddSCLicense();
3722                    clearSCLicenses = new ClearSCLicenses();
3723                    removeSCLicense = new RemoveSCLicense();
3724            }
3725    
3726            public void destroy() {
3727                    EntityCacheUtil.removeCache(SCProductEntryImpl.class.getName());
3728                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3729                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3730            }
3731    
3732            @BeanReference(type = SCFrameworkVersionPersistence.class)
3733            protected SCFrameworkVersionPersistence scFrameworkVersionPersistence;
3734            @BeanReference(type = SCLicensePersistence.class)
3735            protected SCLicensePersistence scLicensePersistence;
3736            @BeanReference(type = SCProductEntryPersistence.class)
3737            protected SCProductEntryPersistence scProductEntryPersistence;
3738            @BeanReference(type = SCProductScreenshotPersistence.class)
3739            protected SCProductScreenshotPersistence scProductScreenshotPersistence;
3740            @BeanReference(type = SCProductVersionPersistence.class)
3741            protected SCProductVersionPersistence scProductVersionPersistence;
3742            @BeanReference(type = GroupPersistence.class)
3743            protected GroupPersistence groupPersistence;
3744            @BeanReference(type = ImagePersistence.class)
3745            protected ImagePersistence imagePersistence;
3746            @BeanReference(type = SubscriptionPersistence.class)
3747            protected SubscriptionPersistence subscriptionPersistence;
3748            @BeanReference(type = UserPersistence.class)
3749            protected UserPersistence userPersistence;
3750            @BeanReference(type = MBMessagePersistence.class)
3751            protected MBMessagePersistence mbMessagePersistence;
3752            @BeanReference(type = RatingsStatsPersistence.class)
3753            protected RatingsStatsPersistence ratingsStatsPersistence;
3754            protected ContainsSCLicense containsSCLicense;
3755            protected AddSCLicense addSCLicense;
3756            protected ClearSCLicenses clearSCLicenses;
3757            protected RemoveSCLicense removeSCLicense;
3758    
3759            protected class ContainsSCLicense {
3760                    protected ContainsSCLicense() {
3761                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3762                                            _SQL_CONTAINSSCLICENSE,
3763                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3764                                            RowMapper.COUNT);
3765                    }
3766    
3767                    protected boolean contains(long productEntryId, long licenseId) {
3768                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3769                                                    new Long(productEntryId), new Long(licenseId)
3770                                            });
3771    
3772                            if (results.size() > 0) {
3773                                    Integer count = results.get(0);
3774    
3775                                    if (count.intValue() > 0) {
3776                                            return true;
3777                                    }
3778                            }
3779    
3780                            return false;
3781                    }
3782    
3783                    private MappingSqlQuery<Integer> _mappingSqlQuery;
3784            }
3785    
3786            protected class AddSCLicense {
3787                    protected AddSCLicense() {
3788                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3789                                            "INSERT INTO SCLicenses_SCProductEntries (productEntryId, licenseId) VALUES (?, ?)",
3790                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3791                    }
3792    
3793                    protected void add(long productEntryId, long licenseId)
3794                            throws SystemException {
3795                            if (!containsSCLicense.contains(productEntryId, licenseId)) {
3796                                    ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense>[] scLicenseListeners =
3797                                            scLicensePersistence.getListeners();
3798    
3799                                    for (ModelListener<SCProductEntry> listener : listeners) {
3800                                            listener.onBeforeAddAssociation(productEntryId,
3801                                                    com.liferay.portlet.softwarecatalog.model.SCLicense.class.getName(),
3802                                                    licenseId);
3803                                    }
3804    
3805                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense> listener : scLicenseListeners) {
3806                                            listener.onBeforeAddAssociation(licenseId,
3807                                                    SCProductEntry.class.getName(), productEntryId);
3808                                    }
3809    
3810                                    _sqlUpdate.update(new Object[] {
3811                                                    new Long(productEntryId), new Long(licenseId)
3812                                            });
3813    
3814                                    for (ModelListener<SCProductEntry> listener : listeners) {
3815                                            listener.onAfterAddAssociation(productEntryId,
3816                                                    com.liferay.portlet.softwarecatalog.model.SCLicense.class.getName(),
3817                                                    licenseId);
3818                                    }
3819    
3820                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense> listener : scLicenseListeners) {
3821                                            listener.onAfterAddAssociation(licenseId,
3822                                                    SCProductEntry.class.getName(), productEntryId);
3823                                    }
3824                            }
3825                    }
3826    
3827                    private SqlUpdate _sqlUpdate;
3828            }
3829    
3830            protected class ClearSCLicenses {
3831                    protected ClearSCLicenses() {
3832                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3833                                            "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?",
3834                                            new int[] { java.sql.Types.BIGINT });
3835                    }
3836    
3837                    protected void clear(long productEntryId) throws SystemException {
3838                            ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense>[] scLicenseListeners =
3839                                    scLicensePersistence.getListeners();
3840    
3841                            List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses =
3842                                    null;
3843    
3844                            if ((listeners.length > 0) || (scLicenseListeners.length > 0)) {
3845                                    scLicenses = getSCLicenses(productEntryId);
3846    
3847                                    for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
3848                                            for (ModelListener<SCProductEntry> listener : listeners) {
3849                                                    listener.onBeforeRemoveAssociation(productEntryId,
3850                                                            com.liferay.portlet.softwarecatalog.model.SCLicense.class.getName(),
3851                                                            scLicense.getPrimaryKey());
3852                                            }
3853    
3854                                            for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense> listener : scLicenseListeners) {
3855                                                    listener.onBeforeRemoveAssociation(scLicense.getPrimaryKey(),
3856                                                            SCProductEntry.class.getName(), productEntryId);
3857                                            }
3858                                    }
3859                            }
3860    
3861                            _sqlUpdate.update(new Object[] { new Long(productEntryId) });
3862    
3863                            if ((listeners.length > 0) || (scLicenseListeners.length > 0)) {
3864                                    for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
3865                                            for (ModelListener<SCProductEntry> listener : listeners) {
3866                                                    listener.onAfterRemoveAssociation(productEntryId,
3867                                                            com.liferay.portlet.softwarecatalog.model.SCLicense.class.getName(),
3868                                                            scLicense.getPrimaryKey());
3869                                            }
3870    
3871                                            for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense> listener : scLicenseListeners) {
3872                                                    listener.onAfterRemoveAssociation(scLicense.getPrimaryKey(),
3873                                                            SCProductEntry.class.getName(), productEntryId);
3874                                            }
3875                                    }
3876                            }
3877                    }
3878    
3879                    private SqlUpdate _sqlUpdate;
3880            }
3881    
3882            protected class RemoveSCLicense {
3883                    protected RemoveSCLicense() {
3884                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3885                                            "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?",
3886                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3887                    }
3888    
3889                    protected void remove(long productEntryId, long licenseId)
3890                            throws SystemException {
3891                            if (containsSCLicense.contains(productEntryId, licenseId)) {
3892                                    ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense>[] scLicenseListeners =
3893                                            scLicensePersistence.getListeners();
3894    
3895                                    for (ModelListener<SCProductEntry> listener : listeners) {
3896                                            listener.onBeforeRemoveAssociation(productEntryId,
3897                                                    com.liferay.portlet.softwarecatalog.model.SCLicense.class.getName(),
3898                                                    licenseId);
3899                                    }
3900    
3901                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense> listener : scLicenseListeners) {
3902                                            listener.onBeforeRemoveAssociation(licenseId,
3903                                                    SCProductEntry.class.getName(), productEntryId);
3904                                    }
3905    
3906                                    _sqlUpdate.update(new Object[] {
3907                                                    new Long(productEntryId), new Long(licenseId)
3908                                            });
3909    
3910                                    for (ModelListener<SCProductEntry> listener : listeners) {
3911                                            listener.onAfterRemoveAssociation(productEntryId,
3912                                                    com.liferay.portlet.softwarecatalog.model.SCLicense.class.getName(),
3913                                                    licenseId);
3914                                    }
3915    
3916                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCLicense> listener : scLicenseListeners) {
3917                                            listener.onAfterRemoveAssociation(licenseId,
3918                                                    SCProductEntry.class.getName(), productEntryId);
3919                                    }
3920                            }
3921                    }
3922    
3923                    private SqlUpdate _sqlUpdate;
3924            }
3925    
3926            private static final String _SQL_SELECT_SCPRODUCTENTRY = "SELECT scProductEntry FROM SCProductEntry scProductEntry";
3927            private static final String _SQL_SELECT_SCPRODUCTENTRY_WHERE = "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ";
3928            private static final String _SQL_COUNT_SCPRODUCTENTRY = "SELECT COUNT(scProductEntry) FROM SCProductEntry scProductEntry";
3929            private static final String _SQL_COUNT_SCPRODUCTENTRY_WHERE = "SELECT COUNT(scProductEntry) FROM SCProductEntry scProductEntry WHERE ";
3930            private static final String _SQL_GETSCLICENSES = "SELECT {SCLicense.*} FROM SCLicense INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.licenseId = SCLicense.licenseId) WHERE (SCLicenses_SCProductEntries.productEntryId = ?)";
3931            private static final String _SQL_GETSCLICENSESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?";
3932            private static final String _SQL_CONTAINSSCLICENSE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?";
3933            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "scProductEntry.groupId = ?";
3934            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "scProductEntry.companyId = ?";
3935            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "scProductEntry.groupId = ? AND ";
3936            private static final String _FINDER_COLUMN_G_U_USERID_2 = "scProductEntry.userId = ?";
3937            private static final String _FINDER_COLUMN_RG_RA_REPOGROUPID_1 = "scProductEntry.repoGroupId IS NULL AND ";
3938            private static final String _FINDER_COLUMN_RG_RA_REPOGROUPID_2 = "lower(scProductEntry.repoGroupId) = lower(CAST_TEXT(?)) AND ";
3939            private static final String _FINDER_COLUMN_RG_RA_REPOGROUPID_3 = "(scProductEntry.repoGroupId IS NULL OR lower(scProductEntry.repoGroupId) = lower(CAST_TEXT(?))) AND ";
3940            private static final String _FINDER_COLUMN_RG_RA_REPOARTIFACTID_1 = "scProductEntry.repoArtifactId IS NULL";
3941            private static final String _FINDER_COLUMN_RG_RA_REPOARTIFACTID_2 = "lower(scProductEntry.repoArtifactId) = lower(CAST_TEXT(?))";
3942            private static final String _FINDER_COLUMN_RG_RA_REPOARTIFACTID_3 = "(scProductEntry.repoArtifactId IS NULL OR lower(scProductEntry.repoArtifactId) = lower(CAST_TEXT(?)))";
3943            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "scProductEntry.productEntryId";
3944            private static final String _FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE = "SELECT DISTINCT {scProductEntry.*} FROM SCProductEntry scProductEntry WHERE ";
3945            private static final String _FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1 =
3946                    "SELECT {SCProductEntry.*} FROM (SELECT DISTINCT scProductEntry.productEntryId FROM SCProductEntry scProductEntry WHERE ";
3947            private static final String _FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2 =
3948                    ") TEMP_TABLE INNER JOIN SCProductEntry ON TEMP_TABLE.productEntryId = SCProductEntry.productEntryId";
3949            private static final String _FILTER_SQL_COUNT_SCPRODUCTENTRY_WHERE = "SELECT COUNT(DISTINCT scProductEntry.productEntryId) AS COUNT_VALUE FROM SCProductEntry scProductEntry WHERE ";
3950            private static final String _FILTER_ENTITY_ALIAS = "scProductEntry";
3951            private static final String _FILTER_ENTITY_TABLE = "SCProductEntry";
3952            private static final String _ORDER_BY_ENTITY_ALIAS = "scProductEntry.";
3953            private static final String _ORDER_BY_ENTITY_TABLE = "SCProductEntry.";
3954            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCProductEntry exists with the primary key ";
3955            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCProductEntry exists with the key {";
3956            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3957            private static Log _log = LogFactoryUtil.getLog(SCProductEntryPersistenceImpl.class);
3958            private static SCProductEntry _nullSCProductEntry = new SCProductEntryImpl() {
3959                            @Override
3960                            public Object clone() {
3961                                    return this;
3962                            }
3963    
3964                            @Override
3965                            public CacheModel<SCProductEntry> toCacheModel() {
3966                                    return _nullSCProductEntryCacheModel;
3967                            }
3968                    };
3969    
3970            private static CacheModel<SCProductEntry> _nullSCProductEntryCacheModel = new CacheModel<SCProductEntry>() {
3971                            public SCProductEntry toEntityModel() {
3972                                    return _nullSCProductEntry;
3973                            }
3974                    };
3975    }