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