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.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.SetUtil;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
036    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
037    import com.liferay.portal.service.persistence.impl.TableMapper;
038    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
039    
040    import com.liferay.portlet.softwarecatalog.NoSuchLicenseException;
041    import com.liferay.portlet.softwarecatalog.model.SCLicense;
042    import com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl;
043    import com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl;
044    import com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence;
045    import com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence;
046    
047    import java.io.Serializable;
048    
049    import java.util.Collections;
050    import java.util.HashMap;
051    import java.util.HashSet;
052    import java.util.Iterator;
053    import java.util.List;
054    import java.util.Map;
055    import java.util.Set;
056    
057    /**
058     * The persistence implementation for the s c license service.
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see SCLicensePersistence
066     * @see com.liferay.portlet.softwarecatalog.service.persistence.SCLicenseUtil
067     * @generated
068     */
069    @ProviderType
070    public class SCLicensePersistenceImpl extends BasePersistenceImpl<SCLicense>
071            implements SCLicensePersistence {
072            /*
073             * NOTE FOR DEVELOPERS:
074             *
075             * Never modify or reference this class directly. Always use {@link SCLicenseUtil} to access the s c license persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
076             */
077            public static final String FINDER_CLASS_NAME_ENTITY = SCLicenseImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List1";
080            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List2";
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
083                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, SCLicenseImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
086                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, SCLicenseImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
089                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
092                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, SCLicenseImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
094                            new String[] {
095                                    Boolean.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
101                    new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
102                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, SCLicenseImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
104                            new String[] { Boolean.class.getName() },
105                            SCLicenseModelImpl.ACTIVE_COLUMN_BITMASK |
106                            SCLicenseModelImpl.NAME_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
108                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
110                            new String[] { Boolean.class.getName() });
111    
112            /**
113             * Returns all the s c licenses where active = &#63;.
114             *
115             * @param active the active
116             * @return the matching s c licenses
117             */
118            @Override
119            public List<SCLicense> findByActive(boolean active) {
120                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the s c licenses where active = &#63;.
125             *
126             * <p>
127             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
128             * </p>
129             *
130             * @param active the active
131             * @param start the lower bound of the range of s c licenses
132             * @param end the upper bound of the range of s c licenses (not inclusive)
133             * @return the range of matching s c licenses
134             */
135            @Override
136            public List<SCLicense> findByActive(boolean active, int start, int end) {
137                    return findByActive(active, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the s c licenses where active = &#63;.
142             *
143             * <p>
144             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
145             * </p>
146             *
147             * @param active the active
148             * @param start the lower bound of the range of s c licenses
149             * @param end the upper bound of the range of s c licenses (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching s c licenses
152             */
153            @Override
154            public List<SCLicense> findByActive(boolean active, int start, int end,
155                    OrderByComparator<SCLicense> orderByComparator) {
156                    boolean pagination = true;
157                    FinderPath finderPath = null;
158                    Object[] finderArgs = null;
159    
160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161                                    (orderByComparator == null)) {
162                            pagination = false;
163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
164                            finderArgs = new Object[] { active };
165                    }
166                    else {
167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
168                            finderArgs = new Object[] { active, start, end, orderByComparator };
169                    }
170    
171                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(finderPath,
172                                    finderArgs, this);
173    
174                    if ((list != null) && !list.isEmpty()) {
175                            for (SCLicense scLicense : list) {
176                                    if ((active != scLicense.getActive())) {
177                                            list = null;
178    
179                                            break;
180                                    }
181                            }
182                    }
183    
184                    if (list == null) {
185                            StringBundler query = null;
186    
187                            if (orderByComparator != null) {
188                                    query = new StringBundler(3 +
189                                                    (orderByComparator.getOrderByFields().length * 3));
190                            }
191                            else {
192                                    query = new StringBundler(3);
193                            }
194    
195                            query.append(_SQL_SELECT_SCLICENSE_WHERE);
196    
197                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
198    
199                            if (orderByComparator != null) {
200                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
201                                            orderByComparator);
202                            }
203                            else
204                             if (pagination) {
205                                    query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
206                            }
207    
208                            String sql = query.toString();
209    
210                            Session session = null;
211    
212                            try {
213                                    session = openSession();
214    
215                                    Query q = session.createQuery(sql);
216    
217                                    QueryPos qPos = QueryPos.getInstance(q);
218    
219                                    qPos.add(active);
220    
221                                    if (!pagination) {
222                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
223                                                            start, end, false);
224    
225                                            Collections.sort(list);
226    
227                                            list = Collections.unmodifiableList(list);
228                                    }
229                                    else {
230                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
231                                                            start, end);
232                                    }
233    
234                                    cacheResult(list);
235    
236                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
237                            }
238                            catch (Exception e) {
239                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
240    
241                                    throw processException(e);
242                            }
243                            finally {
244                                    closeSession(session);
245                            }
246                    }
247    
248                    return list;
249            }
250    
251            /**
252             * Returns the first s c license in the ordered set where active = &#63;.
253             *
254             * @param active the active
255             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
256             * @return the first matching s c license
257             * @throws NoSuchLicenseException if a matching s c license could not be found
258             */
259            @Override
260            public SCLicense findByActive_First(boolean active,
261                    OrderByComparator<SCLicense> orderByComparator)
262                    throws NoSuchLicenseException {
263                    SCLicense scLicense = fetchByActive_First(active, orderByComparator);
264    
265                    if (scLicense != null) {
266                            return scLicense;
267                    }
268    
269                    StringBundler msg = new StringBundler(4);
270    
271                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272    
273                    msg.append("active=");
274                    msg.append(active);
275    
276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
277    
278                    throw new NoSuchLicenseException(msg.toString());
279            }
280    
281            /**
282             * Returns the first s c license in the ordered set where active = &#63;.
283             *
284             * @param active the active
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching s c license, or <code>null</code> if a matching s c license could not be found
287             */
288            @Override
289            public SCLicense fetchByActive_First(boolean active,
290                    OrderByComparator<SCLicense> orderByComparator) {
291                    List<SCLicense> list = findByActive(active, 0, 1, orderByComparator);
292    
293                    if (!list.isEmpty()) {
294                            return list.get(0);
295                    }
296    
297                    return null;
298            }
299    
300            /**
301             * Returns the last s c license in the ordered set where active = &#63;.
302             *
303             * @param active the active
304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
305             * @return the last matching s c license
306             * @throws NoSuchLicenseException if a matching s c license could not be found
307             */
308            @Override
309            public SCLicense findByActive_Last(boolean active,
310                    OrderByComparator<SCLicense> orderByComparator)
311                    throws NoSuchLicenseException {
312                    SCLicense scLicense = fetchByActive_Last(active, orderByComparator);
313    
314                    if (scLicense != null) {
315                            return scLicense;
316                    }
317    
318                    StringBundler msg = new StringBundler(4);
319    
320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321    
322                    msg.append("active=");
323                    msg.append(active);
324    
325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
326    
327                    throw new NoSuchLicenseException(msg.toString());
328            }
329    
330            /**
331             * Returns the last s c license in the ordered set where active = &#63;.
332             *
333             * @param active the active
334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
335             * @return the last matching s c license, or <code>null</code> if a matching s c license could not be found
336             */
337            @Override
338            public SCLicense fetchByActive_Last(boolean active,
339                    OrderByComparator<SCLicense> orderByComparator) {
340                    int count = countByActive(active);
341    
342                    if (count == 0) {
343                            return null;
344                    }
345    
346                    List<SCLicense> list = findByActive(active, count - 1, count,
347                                    orderByComparator);
348    
349                    if (!list.isEmpty()) {
350                            return list.get(0);
351                    }
352    
353                    return null;
354            }
355    
356            /**
357             * Returns the s c licenses before and after the current s c license in the ordered set where active = &#63;.
358             *
359             * @param licenseId the primary key of the current s c license
360             * @param active the active
361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
362             * @return the previous, current, and next s c license
363             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
364             */
365            @Override
366            public SCLicense[] findByActive_PrevAndNext(long licenseId, boolean active,
367                    OrderByComparator<SCLicense> orderByComparator)
368                    throws NoSuchLicenseException {
369                    SCLicense scLicense = findByPrimaryKey(licenseId);
370    
371                    Session session = null;
372    
373                    try {
374                            session = openSession();
375    
376                            SCLicense[] array = new SCLicenseImpl[3];
377    
378                            array[0] = getByActive_PrevAndNext(session, scLicense, active,
379                                            orderByComparator, true);
380    
381                            array[1] = scLicense;
382    
383                            array[2] = getByActive_PrevAndNext(session, scLicense, active,
384                                            orderByComparator, false);
385    
386                            return array;
387                    }
388                    catch (Exception e) {
389                            throw processException(e);
390                    }
391                    finally {
392                            closeSession(session);
393                    }
394            }
395    
396            protected SCLicense getByActive_PrevAndNext(Session session,
397                    SCLicense scLicense, boolean active,
398                    OrderByComparator<SCLicense> orderByComparator, boolean previous) {
399                    StringBundler query = null;
400    
401                    if (orderByComparator != null) {
402                            query = new StringBundler(6 +
403                                            (orderByComparator.getOrderByFields().length * 6));
404                    }
405                    else {
406                            query = new StringBundler(3);
407                    }
408    
409                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
410    
411                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
412    
413                    if (orderByComparator != null) {
414                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
415    
416                            if (orderByConditionFields.length > 0) {
417                                    query.append(WHERE_AND);
418                            }
419    
420                            for (int i = 0; i < orderByConditionFields.length; i++) {
421                                    query.append(_ORDER_BY_ENTITY_ALIAS);
422                                    query.append(orderByConditionFields[i]);
423    
424                                    if ((i + 1) < orderByConditionFields.length) {
425                                            if (orderByComparator.isAscending() ^ previous) {
426                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
427                                            }
428                                            else {
429                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
430                                            }
431                                    }
432                                    else {
433                                            if (orderByComparator.isAscending() ^ previous) {
434                                                    query.append(WHERE_GREATER_THAN);
435                                            }
436                                            else {
437                                                    query.append(WHERE_LESSER_THAN);
438                                            }
439                                    }
440                            }
441    
442                            query.append(ORDER_BY_CLAUSE);
443    
444                            String[] orderByFields = orderByComparator.getOrderByFields();
445    
446                            for (int i = 0; i < orderByFields.length; i++) {
447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
448                                    query.append(orderByFields[i]);
449    
450                                    if ((i + 1) < orderByFields.length) {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
453                                            }
454                                            else {
455                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
456                                            }
457                                    }
458                                    else {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(ORDER_BY_ASC);
461                                            }
462                                            else {
463                                                    query.append(ORDER_BY_DESC);
464                                            }
465                                    }
466                            }
467                    }
468                    else {
469                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
470                    }
471    
472                    String sql = query.toString();
473    
474                    Query q = session.createQuery(sql);
475    
476                    q.setFirstResult(0);
477                    q.setMaxResults(2);
478    
479                    QueryPos qPos = QueryPos.getInstance(q);
480    
481                    qPos.add(active);
482    
483                    if (orderByComparator != null) {
484                            Object[] values = orderByComparator.getOrderByConditionValues(scLicense);
485    
486                            for (Object value : values) {
487                                    qPos.add(value);
488                            }
489                    }
490    
491                    List<SCLicense> list = q.list();
492    
493                    if (list.size() == 2) {
494                            return list.get(1);
495                    }
496                    else {
497                            return null;
498                    }
499            }
500    
501            /**
502             * Returns all the s c licenses that the user has permission to view where active = &#63;.
503             *
504             * @param active the active
505             * @return the matching s c licenses that the user has permission to view
506             */
507            @Override
508            public List<SCLicense> filterFindByActive(boolean active) {
509                    return filterFindByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
510                            null);
511            }
512    
513            /**
514             * Returns a range of all the s c licenses that the user has permission to view where active = &#63;.
515             *
516             * <p>
517             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
518             * </p>
519             *
520             * @param active the active
521             * @param start the lower bound of the range of s c licenses
522             * @param end the upper bound of the range of s c licenses (not inclusive)
523             * @return the range of matching s c licenses that the user has permission to view
524             */
525            @Override
526            public List<SCLicense> filterFindByActive(boolean active, int start, int end) {
527                    return filterFindByActive(active, start, end, null);
528            }
529    
530            /**
531             * Returns an ordered range of all the s c licenses that the user has permissions to view where active = &#63;.
532             *
533             * <p>
534             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
535             * </p>
536             *
537             * @param active the active
538             * @param start the lower bound of the range of s c licenses
539             * @param end the upper bound of the range of s c licenses (not inclusive)
540             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
541             * @return the ordered range of matching s c licenses that the user has permission to view
542             */
543            @Override
544            public List<SCLicense> filterFindByActive(boolean active, int start,
545                    int end, OrderByComparator<SCLicense> orderByComparator) {
546                    if (!InlineSQLHelperUtil.isEnabled()) {
547                            return findByActive(active, start, end, orderByComparator);
548                    }
549    
550                    StringBundler query = null;
551    
552                    if (orderByComparator != null) {
553                            query = new StringBundler(3 +
554                                            (orderByComparator.getOrderByFields().length * 3));
555                    }
556                    else {
557                            query = new StringBundler(3);
558                    }
559    
560                    if (getDB().isSupportsInlineDistinct()) {
561                            query.append(_FILTER_SQL_SELECT_SCLICENSE_WHERE);
562                    }
563                    else {
564                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_1);
565                    }
566    
567                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2_SQL);
568    
569                    if (!getDB().isSupportsInlineDistinct()) {
570                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_2);
571                    }
572    
573                    if (orderByComparator != null) {
574                            if (getDB().isSupportsInlineDistinct()) {
575                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
576                                            orderByComparator, true);
577                            }
578                            else {
579                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
580                                            orderByComparator, true);
581                            }
582                    }
583                    else {
584                            if (getDB().isSupportsInlineDistinct()) {
585                                    query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
586                            }
587                            else {
588                                    query.append(SCLicenseModelImpl.ORDER_BY_SQL);
589                            }
590                    }
591    
592                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
593                                    SCLicense.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
594    
595                    Session session = null;
596    
597                    try {
598                            session = openSession();
599    
600                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
601    
602                            if (getDB().isSupportsInlineDistinct()) {
603                                    q.addEntity(_FILTER_ENTITY_ALIAS, SCLicenseImpl.class);
604                            }
605                            else {
606                                    q.addEntity(_FILTER_ENTITY_TABLE, SCLicenseImpl.class);
607                            }
608    
609                            QueryPos qPos = QueryPos.getInstance(q);
610    
611                            qPos.add(active);
612    
613                            return (List<SCLicense>)QueryUtil.list(q, getDialect(), start, end);
614                    }
615                    catch (Exception e) {
616                            throw processException(e);
617                    }
618                    finally {
619                            closeSession(session);
620                    }
621            }
622    
623            /**
624             * Returns the s c licenses before and after the current s c license in the ordered set of s c licenses that the user has permission to view where active = &#63;.
625             *
626             * @param licenseId the primary key of the current s c license
627             * @param active the active
628             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
629             * @return the previous, current, and next s c license
630             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
631             */
632            @Override
633            public SCLicense[] filterFindByActive_PrevAndNext(long licenseId,
634                    boolean active, OrderByComparator<SCLicense> orderByComparator)
635                    throws NoSuchLicenseException {
636                    if (!InlineSQLHelperUtil.isEnabled()) {
637                            return findByActive_PrevAndNext(licenseId, active, orderByComparator);
638                    }
639    
640                    SCLicense scLicense = findByPrimaryKey(licenseId);
641    
642                    Session session = null;
643    
644                    try {
645                            session = openSession();
646    
647                            SCLicense[] array = new SCLicenseImpl[3];
648    
649                            array[0] = filterGetByActive_PrevAndNext(session, scLicense,
650                                            active, orderByComparator, true);
651    
652                            array[1] = scLicense;
653    
654                            array[2] = filterGetByActive_PrevAndNext(session, scLicense,
655                                            active, orderByComparator, false);
656    
657                            return array;
658                    }
659                    catch (Exception e) {
660                            throw processException(e);
661                    }
662                    finally {
663                            closeSession(session);
664                    }
665            }
666    
667            protected SCLicense filterGetByActive_PrevAndNext(Session session,
668                    SCLicense scLicense, boolean active,
669                    OrderByComparator<SCLicense> orderByComparator, boolean previous) {
670                    StringBundler query = null;
671    
672                    if (orderByComparator != null) {
673                            query = new StringBundler(6 +
674                                            (orderByComparator.getOrderByFields().length * 6));
675                    }
676                    else {
677                            query = new StringBundler(3);
678                    }
679    
680                    if (getDB().isSupportsInlineDistinct()) {
681                            query.append(_FILTER_SQL_SELECT_SCLICENSE_WHERE);
682                    }
683                    else {
684                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_1);
685                    }
686    
687                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2_SQL);
688    
689                    if (!getDB().isSupportsInlineDistinct()) {
690                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_2);
691                    }
692    
693                    if (orderByComparator != null) {
694                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
695    
696                            if (orderByConditionFields.length > 0) {
697                                    query.append(WHERE_AND);
698                            }
699    
700                            for (int i = 0; i < orderByConditionFields.length; i++) {
701                                    if (getDB().isSupportsInlineDistinct()) {
702                                            query.append(_ORDER_BY_ENTITY_ALIAS);
703                                    }
704                                    else {
705                                            query.append(_ORDER_BY_ENTITY_TABLE);
706                                    }
707    
708                                    query.append(orderByConditionFields[i]);
709    
710                                    if ((i + 1) < orderByConditionFields.length) {
711                                            if (orderByComparator.isAscending() ^ previous) {
712                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
713                                            }
714                                            else {
715                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
716                                            }
717                                    }
718                                    else {
719                                            if (orderByComparator.isAscending() ^ previous) {
720                                                    query.append(WHERE_GREATER_THAN);
721                                            }
722                                            else {
723                                                    query.append(WHERE_LESSER_THAN);
724                                            }
725                                    }
726                            }
727    
728                            query.append(ORDER_BY_CLAUSE);
729    
730                            String[] orderByFields = orderByComparator.getOrderByFields();
731    
732                            for (int i = 0; i < orderByFields.length; i++) {
733                                    if (getDB().isSupportsInlineDistinct()) {
734                                            query.append(_ORDER_BY_ENTITY_ALIAS);
735                                    }
736                                    else {
737                                            query.append(_ORDER_BY_ENTITY_TABLE);
738                                    }
739    
740                                    query.append(orderByFields[i]);
741    
742                                    if ((i + 1) < orderByFields.length) {
743                                            if (orderByComparator.isAscending() ^ previous) {
744                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
745                                            }
746                                            else {
747                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
748                                            }
749                                    }
750                                    else {
751                                            if (orderByComparator.isAscending() ^ previous) {
752                                                    query.append(ORDER_BY_ASC);
753                                            }
754                                            else {
755                                                    query.append(ORDER_BY_DESC);
756                                            }
757                                    }
758                            }
759                    }
760                    else {
761                            if (getDB().isSupportsInlineDistinct()) {
762                                    query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
763                            }
764                            else {
765                                    query.append(SCLicenseModelImpl.ORDER_BY_SQL);
766                            }
767                    }
768    
769                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
770                                    SCLicense.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
771    
772                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
773    
774                    q.setFirstResult(0);
775                    q.setMaxResults(2);
776    
777                    if (getDB().isSupportsInlineDistinct()) {
778                            q.addEntity(_FILTER_ENTITY_ALIAS, SCLicenseImpl.class);
779                    }
780                    else {
781                            q.addEntity(_FILTER_ENTITY_TABLE, SCLicenseImpl.class);
782                    }
783    
784                    QueryPos qPos = QueryPos.getInstance(q);
785    
786                    qPos.add(active);
787    
788                    if (orderByComparator != null) {
789                            Object[] values = orderByComparator.getOrderByConditionValues(scLicense);
790    
791                            for (Object value : values) {
792                                    qPos.add(value);
793                            }
794                    }
795    
796                    List<SCLicense> list = q.list();
797    
798                    if (list.size() == 2) {
799                            return list.get(1);
800                    }
801                    else {
802                            return null;
803                    }
804            }
805    
806            /**
807             * Removes all the s c licenses where active = &#63; from the database.
808             *
809             * @param active the active
810             */
811            @Override
812            public void removeByActive(boolean active) {
813                    for (SCLicense scLicense : findByActive(active, QueryUtil.ALL_POS,
814                                    QueryUtil.ALL_POS, null)) {
815                            remove(scLicense);
816                    }
817            }
818    
819            /**
820             * Returns the number of s c licenses where active = &#63;.
821             *
822             * @param active the active
823             * @return the number of matching s c licenses
824             */
825            @Override
826            public int countByActive(boolean active) {
827                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
828    
829                    Object[] finderArgs = new Object[] { active };
830    
831                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
832                                    this);
833    
834                    if (count == null) {
835                            StringBundler query = new StringBundler(2);
836    
837                            query.append(_SQL_COUNT_SCLICENSE_WHERE);
838    
839                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
840    
841                            String sql = query.toString();
842    
843                            Session session = null;
844    
845                            try {
846                                    session = openSession();
847    
848                                    Query q = session.createQuery(sql);
849    
850                                    QueryPos qPos = QueryPos.getInstance(q);
851    
852                                    qPos.add(active);
853    
854                                    count = (Long)q.uniqueResult();
855    
856                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
857                            }
858                            catch (Exception e) {
859                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
860    
861                                    throw processException(e);
862                            }
863                            finally {
864                                    closeSession(session);
865                            }
866                    }
867    
868                    return count.intValue();
869            }
870    
871            /**
872             * Returns the number of s c licenses that the user has permission to view where active = &#63;.
873             *
874             * @param active the active
875             * @return the number of matching s c licenses that the user has permission to view
876             */
877            @Override
878            public int filterCountByActive(boolean active) {
879                    if (!InlineSQLHelperUtil.isEnabled()) {
880                            return countByActive(active);
881                    }
882    
883                    StringBundler query = new StringBundler(2);
884    
885                    query.append(_FILTER_SQL_COUNT_SCLICENSE_WHERE);
886    
887                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2_SQL);
888    
889                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
890                                    SCLicense.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
891    
892                    Session session = null;
893    
894                    try {
895                            session = openSession();
896    
897                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
898    
899                            q.addScalar(COUNT_COLUMN_NAME,
900                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
901    
902                            QueryPos qPos = QueryPos.getInstance(q);
903    
904                            qPos.add(active);
905    
906                            Long count = (Long)q.uniqueResult();
907    
908                            return count.intValue();
909                    }
910                    catch (Exception e) {
911                            throw processException(e);
912                    }
913                    finally {
914                            closeSession(session);
915                    }
916            }
917    
918            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "scLicense.active = ?";
919            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2_SQL = "scLicense.active_ = ?";
920            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_A_R = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
921                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, SCLicenseImpl.class,
922                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByA_R",
923                            new String[] {
924                                    Boolean.class.getName(), Boolean.class.getName(),
925                                    
926                            Integer.class.getName(), Integer.class.getName(),
927                                    OrderByComparator.class.getName()
928                            });
929            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_A_R = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
930                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, SCLicenseImpl.class,
931                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByA_R",
932                            new String[] { Boolean.class.getName(), Boolean.class.getName() },
933                            SCLicenseModelImpl.ACTIVE_COLUMN_BITMASK |
934                            SCLicenseModelImpl.RECOMMENDED_COLUMN_BITMASK |
935                            SCLicenseModelImpl.NAME_COLUMN_BITMASK);
936            public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
937                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, Long.class,
938                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA_R",
939                            new String[] { Boolean.class.getName(), Boolean.class.getName() });
940    
941            /**
942             * Returns all the s c licenses where active = &#63; and recommended = &#63;.
943             *
944             * @param active the active
945             * @param recommended the recommended
946             * @return the matching s c licenses
947             */
948            @Override
949            public List<SCLicense> findByA_R(boolean active, boolean recommended) {
950                    return findByA_R(active, recommended, QueryUtil.ALL_POS,
951                            QueryUtil.ALL_POS, null);
952            }
953    
954            /**
955             * Returns a range of all the s c licenses where active = &#63; and recommended = &#63;.
956             *
957             * <p>
958             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
959             * </p>
960             *
961             * @param active the active
962             * @param recommended the recommended
963             * @param start the lower bound of the range of s c licenses
964             * @param end the upper bound of the range of s c licenses (not inclusive)
965             * @return the range of matching s c licenses
966             */
967            @Override
968            public List<SCLicense> findByA_R(boolean active, boolean recommended,
969                    int start, int end) {
970                    return findByA_R(active, recommended, start, end, null);
971            }
972    
973            /**
974             * Returns an ordered range of all the s c licenses where active = &#63; and recommended = &#63;.
975             *
976             * <p>
977             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
978             * </p>
979             *
980             * @param active the active
981             * @param recommended the recommended
982             * @param start the lower bound of the range of s c licenses
983             * @param end the upper bound of the range of s c licenses (not inclusive)
984             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
985             * @return the ordered range of matching s c licenses
986             */
987            @Override
988            public List<SCLicense> findByA_R(boolean active, boolean recommended,
989                    int start, int end, OrderByComparator<SCLicense> orderByComparator) {
990                    boolean pagination = true;
991                    FinderPath finderPath = null;
992                    Object[] finderArgs = null;
993    
994                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
995                                    (orderByComparator == null)) {
996                            pagination = false;
997                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_A_R;
998                            finderArgs = new Object[] { active, recommended };
999                    }
1000                    else {
1001                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_A_R;
1002                            finderArgs = new Object[] {
1003                                            active, recommended,
1004                                            
1005                                            start, end, orderByComparator
1006                                    };
1007                    }
1008    
1009                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(finderPath,
1010                                    finderArgs, this);
1011    
1012                    if ((list != null) && !list.isEmpty()) {
1013                            for (SCLicense scLicense : list) {
1014                                    if ((active != scLicense.getActive()) ||
1015                                                    (recommended != scLicense.getRecommended())) {
1016                                            list = null;
1017    
1018                                            break;
1019                                    }
1020                            }
1021                    }
1022    
1023                    if (list == null) {
1024                            StringBundler query = null;
1025    
1026                            if (orderByComparator != null) {
1027                                    query = new StringBundler(4 +
1028                                                    (orderByComparator.getOrderByFields().length * 3));
1029                            }
1030                            else {
1031                                    query = new StringBundler(4);
1032                            }
1033    
1034                            query.append(_SQL_SELECT_SCLICENSE_WHERE);
1035    
1036                            query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
1037    
1038                            query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1039    
1040                            if (orderByComparator != null) {
1041                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1042                                            orderByComparator);
1043                            }
1044                            else
1045                             if (pagination) {
1046                                    query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
1047                            }
1048    
1049                            String sql = query.toString();
1050    
1051                            Session session = null;
1052    
1053                            try {
1054                                    session = openSession();
1055    
1056                                    Query q = session.createQuery(sql);
1057    
1058                                    QueryPos qPos = QueryPos.getInstance(q);
1059    
1060                                    qPos.add(active);
1061    
1062                                    qPos.add(recommended);
1063    
1064                                    if (!pagination) {
1065                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
1066                                                            start, end, false);
1067    
1068                                            Collections.sort(list);
1069    
1070                                            list = Collections.unmodifiableList(list);
1071                                    }
1072                                    else {
1073                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
1074                                                            start, end);
1075                                    }
1076    
1077                                    cacheResult(list);
1078    
1079                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1080                            }
1081                            catch (Exception e) {
1082                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1083    
1084                                    throw processException(e);
1085                            }
1086                            finally {
1087                                    closeSession(session);
1088                            }
1089                    }
1090    
1091                    return list;
1092            }
1093    
1094            /**
1095             * Returns the first s c license in the ordered set where active = &#63; and recommended = &#63;.
1096             *
1097             * @param active the active
1098             * @param recommended the recommended
1099             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1100             * @return the first matching s c license
1101             * @throws NoSuchLicenseException if a matching s c license could not be found
1102             */
1103            @Override
1104            public SCLicense findByA_R_First(boolean active, boolean recommended,
1105                    OrderByComparator<SCLicense> orderByComparator)
1106                    throws NoSuchLicenseException {
1107                    SCLicense scLicense = fetchByA_R_First(active, recommended,
1108                                    orderByComparator);
1109    
1110                    if (scLicense != null) {
1111                            return scLicense;
1112                    }
1113    
1114                    StringBundler msg = new StringBundler(6);
1115    
1116                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1117    
1118                    msg.append("active=");
1119                    msg.append(active);
1120    
1121                    msg.append(", recommended=");
1122                    msg.append(recommended);
1123    
1124                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1125    
1126                    throw new NoSuchLicenseException(msg.toString());
1127            }
1128    
1129            /**
1130             * Returns the first s c license in the ordered set where active = &#63; and recommended = &#63;.
1131             *
1132             * @param active the active
1133             * @param recommended the recommended
1134             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1135             * @return the first matching s c license, or <code>null</code> if a matching s c license could not be found
1136             */
1137            @Override
1138            public SCLicense fetchByA_R_First(boolean active, boolean recommended,
1139                    OrderByComparator<SCLicense> orderByComparator) {
1140                    List<SCLicense> list = findByA_R(active, recommended, 0, 1,
1141                                    orderByComparator);
1142    
1143                    if (!list.isEmpty()) {
1144                            return list.get(0);
1145                    }
1146    
1147                    return null;
1148            }
1149    
1150            /**
1151             * Returns the last s c license in the ordered set where active = &#63; and recommended = &#63;.
1152             *
1153             * @param active the active
1154             * @param recommended the recommended
1155             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1156             * @return the last matching s c license
1157             * @throws NoSuchLicenseException if a matching s c license could not be found
1158             */
1159            @Override
1160            public SCLicense findByA_R_Last(boolean active, boolean recommended,
1161                    OrderByComparator<SCLicense> orderByComparator)
1162                    throws NoSuchLicenseException {
1163                    SCLicense scLicense = fetchByA_R_Last(active, recommended,
1164                                    orderByComparator);
1165    
1166                    if (scLicense != null) {
1167                            return scLicense;
1168                    }
1169    
1170                    StringBundler msg = new StringBundler(6);
1171    
1172                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1173    
1174                    msg.append("active=");
1175                    msg.append(active);
1176    
1177                    msg.append(", recommended=");
1178                    msg.append(recommended);
1179    
1180                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1181    
1182                    throw new NoSuchLicenseException(msg.toString());
1183            }
1184    
1185            /**
1186             * Returns the last s c license in the ordered set where active = &#63; and recommended = &#63;.
1187             *
1188             * @param active the active
1189             * @param recommended the recommended
1190             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1191             * @return the last matching s c license, or <code>null</code> if a matching s c license could not be found
1192             */
1193            @Override
1194            public SCLicense fetchByA_R_Last(boolean active, boolean recommended,
1195                    OrderByComparator<SCLicense> orderByComparator) {
1196                    int count = countByA_R(active, recommended);
1197    
1198                    if (count == 0) {
1199                            return null;
1200                    }
1201    
1202                    List<SCLicense> list = findByA_R(active, recommended, count - 1, count,
1203                                    orderByComparator);
1204    
1205                    if (!list.isEmpty()) {
1206                            return list.get(0);
1207                    }
1208    
1209                    return null;
1210            }
1211    
1212            /**
1213             * Returns the s c licenses before and after the current s c license in the ordered set where active = &#63; and recommended = &#63;.
1214             *
1215             * @param licenseId the primary key of the current s c license
1216             * @param active the active
1217             * @param recommended the recommended
1218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1219             * @return the previous, current, and next s c license
1220             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
1221             */
1222            @Override
1223            public SCLicense[] findByA_R_PrevAndNext(long licenseId, boolean active,
1224                    boolean recommended, OrderByComparator<SCLicense> orderByComparator)
1225                    throws NoSuchLicenseException {
1226                    SCLicense scLicense = findByPrimaryKey(licenseId);
1227    
1228                    Session session = null;
1229    
1230                    try {
1231                            session = openSession();
1232    
1233                            SCLicense[] array = new SCLicenseImpl[3];
1234    
1235                            array[0] = getByA_R_PrevAndNext(session, scLicense, active,
1236                                            recommended, orderByComparator, true);
1237    
1238                            array[1] = scLicense;
1239    
1240                            array[2] = getByA_R_PrevAndNext(session, scLicense, active,
1241                                            recommended, orderByComparator, false);
1242    
1243                            return array;
1244                    }
1245                    catch (Exception e) {
1246                            throw processException(e);
1247                    }
1248                    finally {
1249                            closeSession(session);
1250                    }
1251            }
1252    
1253            protected SCLicense getByA_R_PrevAndNext(Session session,
1254                    SCLicense scLicense, boolean active, boolean recommended,
1255                    OrderByComparator<SCLicense> orderByComparator, boolean previous) {
1256                    StringBundler query = null;
1257    
1258                    if (orderByComparator != null) {
1259                            query = new StringBundler(6 +
1260                                            (orderByComparator.getOrderByFields().length * 6));
1261                    }
1262                    else {
1263                            query = new StringBundler(3);
1264                    }
1265    
1266                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
1267    
1268                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
1269    
1270                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1271    
1272                    if (orderByComparator != null) {
1273                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1274    
1275                            if (orderByConditionFields.length > 0) {
1276                                    query.append(WHERE_AND);
1277                            }
1278    
1279                            for (int i = 0; i < orderByConditionFields.length; i++) {
1280                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1281                                    query.append(orderByConditionFields[i]);
1282    
1283                                    if ((i + 1) < orderByConditionFields.length) {
1284                                            if (orderByComparator.isAscending() ^ previous) {
1285                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1286                                            }
1287                                            else {
1288                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1289                                            }
1290                                    }
1291                                    else {
1292                                            if (orderByComparator.isAscending() ^ previous) {
1293                                                    query.append(WHERE_GREATER_THAN);
1294                                            }
1295                                            else {
1296                                                    query.append(WHERE_LESSER_THAN);
1297                                            }
1298                                    }
1299                            }
1300    
1301                            query.append(ORDER_BY_CLAUSE);
1302    
1303                            String[] orderByFields = orderByComparator.getOrderByFields();
1304    
1305                            for (int i = 0; i < orderByFields.length; i++) {
1306                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1307                                    query.append(orderByFields[i]);
1308    
1309                                    if ((i + 1) < orderByFields.length) {
1310                                            if (orderByComparator.isAscending() ^ previous) {
1311                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1312                                            }
1313                                            else {
1314                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1315                                            }
1316                                    }
1317                                    else {
1318                                            if (orderByComparator.isAscending() ^ previous) {
1319                                                    query.append(ORDER_BY_ASC);
1320                                            }
1321                                            else {
1322                                                    query.append(ORDER_BY_DESC);
1323                                            }
1324                                    }
1325                            }
1326                    }
1327                    else {
1328                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
1329                    }
1330    
1331                    String sql = query.toString();
1332    
1333                    Query q = session.createQuery(sql);
1334    
1335                    q.setFirstResult(0);
1336                    q.setMaxResults(2);
1337    
1338                    QueryPos qPos = QueryPos.getInstance(q);
1339    
1340                    qPos.add(active);
1341    
1342                    qPos.add(recommended);
1343    
1344                    if (orderByComparator != null) {
1345                            Object[] values = orderByComparator.getOrderByConditionValues(scLicense);
1346    
1347                            for (Object value : values) {
1348                                    qPos.add(value);
1349                            }
1350                    }
1351    
1352                    List<SCLicense> list = q.list();
1353    
1354                    if (list.size() == 2) {
1355                            return list.get(1);
1356                    }
1357                    else {
1358                            return null;
1359                    }
1360            }
1361    
1362            /**
1363             * Returns all the s c licenses that the user has permission to view where active = &#63; and recommended = &#63;.
1364             *
1365             * @param active the active
1366             * @param recommended the recommended
1367             * @return the matching s c licenses that the user has permission to view
1368             */
1369            @Override
1370            public List<SCLicense> filterFindByA_R(boolean active, boolean recommended) {
1371                    return filterFindByA_R(active, recommended, QueryUtil.ALL_POS,
1372                            QueryUtil.ALL_POS, null);
1373            }
1374    
1375            /**
1376             * Returns a range of all the s c licenses that the user has permission to view where active = &#63; and recommended = &#63;.
1377             *
1378             * <p>
1379             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
1380             * </p>
1381             *
1382             * @param active the active
1383             * @param recommended the recommended
1384             * @param start the lower bound of the range of s c licenses
1385             * @param end the upper bound of the range of s c licenses (not inclusive)
1386             * @return the range of matching s c licenses that the user has permission to view
1387             */
1388            @Override
1389            public List<SCLicense> filterFindByA_R(boolean active, boolean recommended,
1390                    int start, int end) {
1391                    return filterFindByA_R(active, recommended, start, end, null);
1392            }
1393    
1394            /**
1395             * Returns an ordered range of all the s c licenses that the user has permissions to view where active = &#63; and recommended = &#63;.
1396             *
1397             * <p>
1398             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
1399             * </p>
1400             *
1401             * @param active the active
1402             * @param recommended the recommended
1403             * @param start the lower bound of the range of s c licenses
1404             * @param end the upper bound of the range of s c licenses (not inclusive)
1405             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1406             * @return the ordered range of matching s c licenses that the user has permission to view
1407             */
1408            @Override
1409            public List<SCLicense> filterFindByA_R(boolean active, boolean recommended,
1410                    int start, int end, OrderByComparator<SCLicense> orderByComparator) {
1411                    if (!InlineSQLHelperUtil.isEnabled()) {
1412                            return findByA_R(active, recommended, start, end, orderByComparator);
1413                    }
1414    
1415                    StringBundler query = null;
1416    
1417                    if (orderByComparator != null) {
1418                            query = new StringBundler(4 +
1419                                            (orderByComparator.getOrderByFields().length * 3));
1420                    }
1421                    else {
1422                            query = new StringBundler(4);
1423                    }
1424    
1425                    if (getDB().isSupportsInlineDistinct()) {
1426                            query.append(_FILTER_SQL_SELECT_SCLICENSE_WHERE);
1427                    }
1428                    else {
1429                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_1);
1430                    }
1431    
1432                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2_SQL);
1433    
1434                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1435    
1436                    if (!getDB().isSupportsInlineDistinct()) {
1437                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_2);
1438                    }
1439    
1440                    if (orderByComparator != null) {
1441                            if (getDB().isSupportsInlineDistinct()) {
1442                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1443                                            orderByComparator, true);
1444                            }
1445                            else {
1446                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1447                                            orderByComparator, true);
1448                            }
1449                    }
1450                    else {
1451                            if (getDB().isSupportsInlineDistinct()) {
1452                                    query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
1453                            }
1454                            else {
1455                                    query.append(SCLicenseModelImpl.ORDER_BY_SQL);
1456                            }
1457                    }
1458    
1459                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1460                                    SCLicense.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1461    
1462                    Session session = null;
1463    
1464                    try {
1465                            session = openSession();
1466    
1467                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1468    
1469                            if (getDB().isSupportsInlineDistinct()) {
1470                                    q.addEntity(_FILTER_ENTITY_ALIAS, SCLicenseImpl.class);
1471                            }
1472                            else {
1473                                    q.addEntity(_FILTER_ENTITY_TABLE, SCLicenseImpl.class);
1474                            }
1475    
1476                            QueryPos qPos = QueryPos.getInstance(q);
1477    
1478                            qPos.add(active);
1479    
1480                            qPos.add(recommended);
1481    
1482                            return (List<SCLicense>)QueryUtil.list(q, getDialect(), start, end);
1483                    }
1484                    catch (Exception e) {
1485                            throw processException(e);
1486                    }
1487                    finally {
1488                            closeSession(session);
1489                    }
1490            }
1491    
1492            /**
1493             * Returns the s c licenses before and after the current s c license in the ordered set of s c licenses that the user has permission to view where active = &#63; and recommended = &#63;.
1494             *
1495             * @param licenseId the primary key of the current s c license
1496             * @param active the active
1497             * @param recommended the recommended
1498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1499             * @return the previous, current, and next s c license
1500             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
1501             */
1502            @Override
1503            public SCLicense[] filterFindByA_R_PrevAndNext(long licenseId,
1504                    boolean active, boolean recommended,
1505                    OrderByComparator<SCLicense> orderByComparator)
1506                    throws NoSuchLicenseException {
1507                    if (!InlineSQLHelperUtil.isEnabled()) {
1508                            return findByA_R_PrevAndNext(licenseId, active, recommended,
1509                                    orderByComparator);
1510                    }
1511    
1512                    SCLicense scLicense = findByPrimaryKey(licenseId);
1513    
1514                    Session session = null;
1515    
1516                    try {
1517                            session = openSession();
1518    
1519                            SCLicense[] array = new SCLicenseImpl[3];
1520    
1521                            array[0] = filterGetByA_R_PrevAndNext(session, scLicense, active,
1522                                            recommended, orderByComparator, true);
1523    
1524                            array[1] = scLicense;
1525    
1526                            array[2] = filterGetByA_R_PrevAndNext(session, scLicense, active,
1527                                            recommended, orderByComparator, false);
1528    
1529                            return array;
1530                    }
1531                    catch (Exception e) {
1532                            throw processException(e);
1533                    }
1534                    finally {
1535                            closeSession(session);
1536                    }
1537            }
1538    
1539            protected SCLicense filterGetByA_R_PrevAndNext(Session session,
1540                    SCLicense scLicense, boolean active, boolean recommended,
1541                    OrderByComparator<SCLicense> orderByComparator, boolean previous) {
1542                    StringBundler query = null;
1543    
1544                    if (orderByComparator != null) {
1545                            query = new StringBundler(6 +
1546                                            (orderByComparator.getOrderByFields().length * 6));
1547                    }
1548                    else {
1549                            query = new StringBundler(3);
1550                    }
1551    
1552                    if (getDB().isSupportsInlineDistinct()) {
1553                            query.append(_FILTER_SQL_SELECT_SCLICENSE_WHERE);
1554                    }
1555                    else {
1556                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_1);
1557                    }
1558    
1559                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2_SQL);
1560    
1561                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1562    
1563                    if (!getDB().isSupportsInlineDistinct()) {
1564                            query.append(_FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_2);
1565                    }
1566    
1567                    if (orderByComparator != null) {
1568                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1569    
1570                            if (orderByConditionFields.length > 0) {
1571                                    query.append(WHERE_AND);
1572                            }
1573    
1574                            for (int i = 0; i < orderByConditionFields.length; i++) {
1575                                    if (getDB().isSupportsInlineDistinct()) {
1576                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1577                                    }
1578                                    else {
1579                                            query.append(_ORDER_BY_ENTITY_TABLE);
1580                                    }
1581    
1582                                    query.append(orderByConditionFields[i]);
1583    
1584                                    if ((i + 1) < orderByConditionFields.length) {
1585                                            if (orderByComparator.isAscending() ^ previous) {
1586                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1587                                            }
1588                                            else {
1589                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1590                                            }
1591                                    }
1592                                    else {
1593                                            if (orderByComparator.isAscending() ^ previous) {
1594                                                    query.append(WHERE_GREATER_THAN);
1595                                            }
1596                                            else {
1597                                                    query.append(WHERE_LESSER_THAN);
1598                                            }
1599                                    }
1600                            }
1601    
1602                            query.append(ORDER_BY_CLAUSE);
1603    
1604                            String[] orderByFields = orderByComparator.getOrderByFields();
1605    
1606                            for (int i = 0; i < orderByFields.length; i++) {
1607                                    if (getDB().isSupportsInlineDistinct()) {
1608                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1609                                    }
1610                                    else {
1611                                            query.append(_ORDER_BY_ENTITY_TABLE);
1612                                    }
1613    
1614                                    query.append(orderByFields[i]);
1615    
1616                                    if ((i + 1) < orderByFields.length) {
1617                                            if (orderByComparator.isAscending() ^ previous) {
1618                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1619                                            }
1620                                            else {
1621                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1622                                            }
1623                                    }
1624                                    else {
1625                                            if (orderByComparator.isAscending() ^ previous) {
1626                                                    query.append(ORDER_BY_ASC);
1627                                            }
1628                                            else {
1629                                                    query.append(ORDER_BY_DESC);
1630                                            }
1631                                    }
1632                            }
1633                    }
1634                    else {
1635                            if (getDB().isSupportsInlineDistinct()) {
1636                                    query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
1637                            }
1638                            else {
1639                                    query.append(SCLicenseModelImpl.ORDER_BY_SQL);
1640                            }
1641                    }
1642    
1643                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1644                                    SCLicense.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1645    
1646                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
1647    
1648                    q.setFirstResult(0);
1649                    q.setMaxResults(2);
1650    
1651                    if (getDB().isSupportsInlineDistinct()) {
1652                            q.addEntity(_FILTER_ENTITY_ALIAS, SCLicenseImpl.class);
1653                    }
1654                    else {
1655                            q.addEntity(_FILTER_ENTITY_TABLE, SCLicenseImpl.class);
1656                    }
1657    
1658                    QueryPos qPos = QueryPos.getInstance(q);
1659    
1660                    qPos.add(active);
1661    
1662                    qPos.add(recommended);
1663    
1664                    if (orderByComparator != null) {
1665                            Object[] values = orderByComparator.getOrderByConditionValues(scLicense);
1666    
1667                            for (Object value : values) {
1668                                    qPos.add(value);
1669                            }
1670                    }
1671    
1672                    List<SCLicense> list = q.list();
1673    
1674                    if (list.size() == 2) {
1675                            return list.get(1);
1676                    }
1677                    else {
1678                            return null;
1679                    }
1680            }
1681    
1682            /**
1683             * Removes all the s c licenses where active = &#63; and recommended = &#63; from the database.
1684             *
1685             * @param active the active
1686             * @param recommended the recommended
1687             */
1688            @Override
1689            public void removeByA_R(boolean active, boolean recommended) {
1690                    for (SCLicense scLicense : findByA_R(active, recommended,
1691                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1692                            remove(scLicense);
1693                    }
1694            }
1695    
1696            /**
1697             * Returns the number of s c licenses where active = &#63; and recommended = &#63;.
1698             *
1699             * @param active the active
1700             * @param recommended the recommended
1701             * @return the number of matching s c licenses
1702             */
1703            @Override
1704            public int countByA_R(boolean active, boolean recommended) {
1705                    FinderPath finderPath = FINDER_PATH_COUNT_BY_A_R;
1706    
1707                    Object[] finderArgs = new Object[] { active, recommended };
1708    
1709                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1710                                    this);
1711    
1712                    if (count == null) {
1713                            StringBundler query = new StringBundler(3);
1714    
1715                            query.append(_SQL_COUNT_SCLICENSE_WHERE);
1716    
1717                            query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
1718    
1719                            query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1720    
1721                            String sql = query.toString();
1722    
1723                            Session session = null;
1724    
1725                            try {
1726                                    session = openSession();
1727    
1728                                    Query q = session.createQuery(sql);
1729    
1730                                    QueryPos qPos = QueryPos.getInstance(q);
1731    
1732                                    qPos.add(active);
1733    
1734                                    qPos.add(recommended);
1735    
1736                                    count = (Long)q.uniqueResult();
1737    
1738                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1739                            }
1740                            catch (Exception e) {
1741                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1742    
1743                                    throw processException(e);
1744                            }
1745                            finally {
1746                                    closeSession(session);
1747                            }
1748                    }
1749    
1750                    return count.intValue();
1751            }
1752    
1753            /**
1754             * Returns the number of s c licenses that the user has permission to view where active = &#63; and recommended = &#63;.
1755             *
1756             * @param active the active
1757             * @param recommended the recommended
1758             * @return the number of matching s c licenses that the user has permission to view
1759             */
1760            @Override
1761            public int filterCountByA_R(boolean active, boolean recommended) {
1762                    if (!InlineSQLHelperUtil.isEnabled()) {
1763                            return countByA_R(active, recommended);
1764                    }
1765    
1766                    StringBundler query = new StringBundler(3);
1767    
1768                    query.append(_FILTER_SQL_COUNT_SCLICENSE_WHERE);
1769    
1770                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2_SQL);
1771    
1772                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1773    
1774                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1775                                    SCLicense.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1776    
1777                    Session session = null;
1778    
1779                    try {
1780                            session = openSession();
1781    
1782                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1783    
1784                            q.addScalar(COUNT_COLUMN_NAME,
1785                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1786    
1787                            QueryPos qPos = QueryPos.getInstance(q);
1788    
1789                            qPos.add(active);
1790    
1791                            qPos.add(recommended);
1792    
1793                            Long count = (Long)q.uniqueResult();
1794    
1795                            return count.intValue();
1796                    }
1797                    catch (Exception e) {
1798                            throw processException(e);
1799                    }
1800                    finally {
1801                            closeSession(session);
1802                    }
1803            }
1804    
1805            private static final String _FINDER_COLUMN_A_R_ACTIVE_2 = "scLicense.active = ? AND ";
1806            private static final String _FINDER_COLUMN_A_R_ACTIVE_2_SQL = "scLicense.active_ = ? AND ";
1807            private static final String _FINDER_COLUMN_A_R_RECOMMENDED_2 = "scLicense.recommended = ?";
1808    
1809            public SCLicensePersistenceImpl() {
1810                    setModelClass(SCLicense.class);
1811            }
1812    
1813            /**
1814             * Caches the s c license in the entity cache if it is enabled.
1815             *
1816             * @param scLicense the s c license
1817             */
1818            @Override
1819            public void cacheResult(SCLicense scLicense) {
1820                    EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
1821                            SCLicenseImpl.class, scLicense.getPrimaryKey(), scLicense);
1822    
1823                    scLicense.resetOriginalValues();
1824            }
1825    
1826            /**
1827             * Caches the s c licenses in the entity cache if it is enabled.
1828             *
1829             * @param scLicenses the s c licenses
1830             */
1831            @Override
1832            public void cacheResult(List<SCLicense> scLicenses) {
1833                    for (SCLicense scLicense : scLicenses) {
1834                            if (EntityCacheUtil.getResult(
1835                                                    SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
1836                                                    SCLicenseImpl.class, scLicense.getPrimaryKey()) == null) {
1837                                    cacheResult(scLicense);
1838                            }
1839                            else {
1840                                    scLicense.resetOriginalValues();
1841                            }
1842                    }
1843            }
1844    
1845            /**
1846             * Clears the cache for all s c licenses.
1847             *
1848             * <p>
1849             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1850             * </p>
1851             */
1852            @Override
1853            public void clearCache() {
1854                    EntityCacheUtil.clearCache(SCLicenseImpl.class);
1855    
1856                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1857                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1858                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1859            }
1860    
1861            /**
1862             * Clears the cache for the s c license.
1863             *
1864             * <p>
1865             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1866             * </p>
1867             */
1868            @Override
1869            public void clearCache(SCLicense scLicense) {
1870                    EntityCacheUtil.removeResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
1871                            SCLicenseImpl.class, scLicense.getPrimaryKey());
1872    
1873                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1874                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1875            }
1876    
1877            @Override
1878            public void clearCache(List<SCLicense> scLicenses) {
1879                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1880                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1881    
1882                    for (SCLicense scLicense : scLicenses) {
1883                            EntityCacheUtil.removeResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
1884                                    SCLicenseImpl.class, scLicense.getPrimaryKey());
1885                    }
1886            }
1887    
1888            /**
1889             * Creates a new s c license with the primary key. Does not add the s c license to the database.
1890             *
1891             * @param licenseId the primary key for the new s c license
1892             * @return the new s c license
1893             */
1894            @Override
1895            public SCLicense create(long licenseId) {
1896                    SCLicense scLicense = new SCLicenseImpl();
1897    
1898                    scLicense.setNew(true);
1899                    scLicense.setPrimaryKey(licenseId);
1900    
1901                    return scLicense;
1902            }
1903    
1904            /**
1905             * Removes the s c license with the primary key from the database. Also notifies the appropriate model listeners.
1906             *
1907             * @param licenseId the primary key of the s c license
1908             * @return the s c license that was removed
1909             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
1910             */
1911            @Override
1912            public SCLicense remove(long licenseId) throws NoSuchLicenseException {
1913                    return remove((Serializable)licenseId);
1914            }
1915    
1916            /**
1917             * Removes the s c license with the primary key from the database. Also notifies the appropriate model listeners.
1918             *
1919             * @param primaryKey the primary key of the s c license
1920             * @return the s c license that was removed
1921             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
1922             */
1923            @Override
1924            public SCLicense remove(Serializable primaryKey)
1925                    throws NoSuchLicenseException {
1926                    Session session = null;
1927    
1928                    try {
1929                            session = openSession();
1930    
1931                            SCLicense scLicense = (SCLicense)session.get(SCLicenseImpl.class,
1932                                            primaryKey);
1933    
1934                            if (scLicense == null) {
1935                                    if (_log.isWarnEnabled()) {
1936                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1937                                    }
1938    
1939                                    throw new NoSuchLicenseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1940                                            primaryKey);
1941                            }
1942    
1943                            return remove(scLicense);
1944                    }
1945                    catch (NoSuchLicenseException nsee) {
1946                            throw nsee;
1947                    }
1948                    catch (Exception e) {
1949                            throw processException(e);
1950                    }
1951                    finally {
1952                            closeSession(session);
1953                    }
1954            }
1955    
1956            @Override
1957            protected SCLicense removeImpl(SCLicense scLicense) {
1958                    scLicense = toUnwrappedModel(scLicense);
1959    
1960                    scLicenseToSCProductEntryTableMapper.deleteLeftPrimaryKeyTableMappings(scLicense.getPrimaryKey());
1961    
1962                    Session session = null;
1963    
1964                    try {
1965                            session = openSession();
1966    
1967                            if (!session.contains(scLicense)) {
1968                                    scLicense = (SCLicense)session.get(SCLicenseImpl.class,
1969                                                    scLicense.getPrimaryKeyObj());
1970                            }
1971    
1972                            if (scLicense != null) {
1973                                    session.delete(scLicense);
1974                            }
1975                    }
1976                    catch (Exception e) {
1977                            throw processException(e);
1978                    }
1979                    finally {
1980                            closeSession(session);
1981                    }
1982    
1983                    if (scLicense != null) {
1984                            clearCache(scLicense);
1985                    }
1986    
1987                    return scLicense;
1988            }
1989    
1990            @Override
1991            public SCLicense updateImpl(SCLicense scLicense) {
1992                    scLicense = toUnwrappedModel(scLicense);
1993    
1994                    boolean isNew = scLicense.isNew();
1995    
1996                    SCLicenseModelImpl scLicenseModelImpl = (SCLicenseModelImpl)scLicense;
1997    
1998                    Session session = null;
1999    
2000                    try {
2001                            session = openSession();
2002    
2003                            if (scLicense.isNew()) {
2004                                    session.save(scLicense);
2005    
2006                                    scLicense.setNew(false);
2007                            }
2008                            else {
2009                                    session.merge(scLicense);
2010                            }
2011                    }
2012                    catch (Exception e) {
2013                            throw processException(e);
2014                    }
2015                    finally {
2016                            closeSession(session);
2017                    }
2018    
2019                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2020    
2021                    if (isNew || !SCLicenseModelImpl.COLUMN_BITMASK_ENABLED) {
2022                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2023                    }
2024    
2025                    else {
2026                            if ((scLicenseModelImpl.getColumnBitmask() &
2027                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
2028                                    Object[] args = new Object[] {
2029                                                    scLicenseModelImpl.getOriginalActive()
2030                                            };
2031    
2032                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2033                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2034                                            args);
2035    
2036                                    args = new Object[] { scLicenseModelImpl.getActive() };
2037    
2038                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2039                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2040                                            args);
2041                            }
2042    
2043                            if ((scLicenseModelImpl.getColumnBitmask() &
2044                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_A_R.getColumnBitmask()) != 0) {
2045                                    Object[] args = new Object[] {
2046                                                    scLicenseModelImpl.getOriginalActive(),
2047                                                    scLicenseModelImpl.getOriginalRecommended()
2048                                            };
2049    
2050                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A_R, args);
2051                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_A_R,
2052                                            args);
2053    
2054                                    args = new Object[] {
2055                                                    scLicenseModelImpl.getActive(),
2056                                                    scLicenseModelImpl.getRecommended()
2057                                            };
2058    
2059                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A_R, args);
2060                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_A_R,
2061                                            args);
2062                            }
2063                    }
2064    
2065                    EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
2066                            SCLicenseImpl.class, scLicense.getPrimaryKey(), scLicense, false);
2067    
2068                    scLicense.resetOriginalValues();
2069    
2070                    return scLicense;
2071            }
2072    
2073            protected SCLicense toUnwrappedModel(SCLicense scLicense) {
2074                    if (scLicense instanceof SCLicenseImpl) {
2075                            return scLicense;
2076                    }
2077    
2078                    SCLicenseImpl scLicenseImpl = new SCLicenseImpl();
2079    
2080                    scLicenseImpl.setNew(scLicense.isNew());
2081                    scLicenseImpl.setPrimaryKey(scLicense.getPrimaryKey());
2082    
2083                    scLicenseImpl.setLicenseId(scLicense.getLicenseId());
2084                    scLicenseImpl.setName(scLicense.getName());
2085                    scLicenseImpl.setUrl(scLicense.getUrl());
2086                    scLicenseImpl.setOpenSource(scLicense.isOpenSource());
2087                    scLicenseImpl.setActive(scLicense.isActive());
2088                    scLicenseImpl.setRecommended(scLicense.isRecommended());
2089    
2090                    return scLicenseImpl;
2091            }
2092    
2093            /**
2094             * Returns the s c license with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2095             *
2096             * @param primaryKey the primary key of the s c license
2097             * @return the s c license
2098             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
2099             */
2100            @Override
2101            public SCLicense findByPrimaryKey(Serializable primaryKey)
2102                    throws NoSuchLicenseException {
2103                    SCLicense scLicense = fetchByPrimaryKey(primaryKey);
2104    
2105                    if (scLicense == null) {
2106                            if (_log.isWarnEnabled()) {
2107                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2108                            }
2109    
2110                            throw new NoSuchLicenseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2111                                    primaryKey);
2112                    }
2113    
2114                    return scLicense;
2115            }
2116    
2117            /**
2118             * Returns the s c license with the primary key or throws a {@link NoSuchLicenseException} if it could not be found.
2119             *
2120             * @param licenseId the primary key of the s c license
2121             * @return the s c license
2122             * @throws NoSuchLicenseException if a s c license with the primary key could not be found
2123             */
2124            @Override
2125            public SCLicense findByPrimaryKey(long licenseId)
2126                    throws NoSuchLicenseException {
2127                    return findByPrimaryKey((Serializable)licenseId);
2128            }
2129    
2130            /**
2131             * Returns the s c license with the primary key or returns <code>null</code> if it could not be found.
2132             *
2133             * @param primaryKey the primary key of the s c license
2134             * @return the s c license, or <code>null</code> if a s c license with the primary key could not be found
2135             */
2136            @Override
2137            public SCLicense fetchByPrimaryKey(Serializable primaryKey) {
2138                    SCLicense scLicense = (SCLicense)EntityCacheUtil.getResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
2139                                    SCLicenseImpl.class, primaryKey);
2140    
2141                    if (scLicense == _nullSCLicense) {
2142                            return null;
2143                    }
2144    
2145                    if (scLicense == null) {
2146                            Session session = null;
2147    
2148                            try {
2149                                    session = openSession();
2150    
2151                                    scLicense = (SCLicense)session.get(SCLicenseImpl.class,
2152                                                    primaryKey);
2153    
2154                                    if (scLicense != null) {
2155                                            cacheResult(scLicense);
2156                                    }
2157                                    else {
2158                                            EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
2159                                                    SCLicenseImpl.class, primaryKey, _nullSCLicense);
2160                                    }
2161                            }
2162                            catch (Exception e) {
2163                                    EntityCacheUtil.removeResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
2164                                            SCLicenseImpl.class, primaryKey);
2165    
2166                                    throw processException(e);
2167                            }
2168                            finally {
2169                                    closeSession(session);
2170                            }
2171                    }
2172    
2173                    return scLicense;
2174            }
2175    
2176            /**
2177             * Returns the s c license with the primary key or returns <code>null</code> if it could not be found.
2178             *
2179             * @param licenseId the primary key of the s c license
2180             * @return the s c license, or <code>null</code> if a s c license with the primary key could not be found
2181             */
2182            @Override
2183            public SCLicense fetchByPrimaryKey(long licenseId) {
2184                    return fetchByPrimaryKey((Serializable)licenseId);
2185            }
2186    
2187            @Override
2188            public Map<Serializable, SCLicense> fetchByPrimaryKeys(
2189                    Set<Serializable> primaryKeys) {
2190                    if (primaryKeys.isEmpty()) {
2191                            return Collections.emptyMap();
2192                    }
2193    
2194                    Map<Serializable, SCLicense> map = new HashMap<Serializable, SCLicense>();
2195    
2196                    if (primaryKeys.size() == 1) {
2197                            Iterator<Serializable> iterator = primaryKeys.iterator();
2198    
2199                            Serializable primaryKey = iterator.next();
2200    
2201                            SCLicense scLicense = fetchByPrimaryKey(primaryKey);
2202    
2203                            if (scLicense != null) {
2204                                    map.put(primaryKey, scLicense);
2205                            }
2206    
2207                            return map;
2208                    }
2209    
2210                    Set<Serializable> uncachedPrimaryKeys = null;
2211    
2212                    for (Serializable primaryKey : primaryKeys) {
2213                            SCLicense scLicense = (SCLicense)EntityCacheUtil.getResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
2214                                            SCLicenseImpl.class, primaryKey);
2215    
2216                            if (scLicense == null) {
2217                                    if (uncachedPrimaryKeys == null) {
2218                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2219                                    }
2220    
2221                                    uncachedPrimaryKeys.add(primaryKey);
2222                            }
2223                            else {
2224                                    map.put(primaryKey, scLicense);
2225                            }
2226                    }
2227    
2228                    if (uncachedPrimaryKeys == null) {
2229                            return map;
2230                    }
2231    
2232                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2233                                    1);
2234    
2235                    query.append(_SQL_SELECT_SCLICENSE_WHERE_PKS_IN);
2236    
2237                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2238                            query.append(String.valueOf(primaryKey));
2239    
2240                            query.append(StringPool.COMMA);
2241                    }
2242    
2243                    query.setIndex(query.index() - 1);
2244    
2245                    query.append(StringPool.CLOSE_PARENTHESIS);
2246    
2247                    String sql = query.toString();
2248    
2249                    Session session = null;
2250    
2251                    try {
2252                            session = openSession();
2253    
2254                            Query q = session.createQuery(sql);
2255    
2256                            for (SCLicense scLicense : (List<SCLicense>)q.list()) {
2257                                    map.put(scLicense.getPrimaryKeyObj(), scLicense);
2258    
2259                                    cacheResult(scLicense);
2260    
2261                                    uncachedPrimaryKeys.remove(scLicense.getPrimaryKeyObj());
2262                            }
2263    
2264                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2265                                    EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
2266                                            SCLicenseImpl.class, primaryKey, _nullSCLicense);
2267                            }
2268                    }
2269                    catch (Exception e) {
2270                            throw processException(e);
2271                    }
2272                    finally {
2273                            closeSession(session);
2274                    }
2275    
2276                    return map;
2277            }
2278    
2279            /**
2280             * Returns all the s c licenses.
2281             *
2282             * @return the s c licenses
2283             */
2284            @Override
2285            public List<SCLicense> findAll() {
2286                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2287            }
2288    
2289            /**
2290             * Returns a range of all the s c licenses.
2291             *
2292             * <p>
2293             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
2294             * </p>
2295             *
2296             * @param start the lower bound of the range of s c licenses
2297             * @param end the upper bound of the range of s c licenses (not inclusive)
2298             * @return the range of s c licenses
2299             */
2300            @Override
2301            public List<SCLicense> findAll(int start, int end) {
2302                    return findAll(start, end, null);
2303            }
2304    
2305            /**
2306             * Returns an ordered range of all the s c licenses.
2307             *
2308             * <p>
2309             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
2310             * </p>
2311             *
2312             * @param start the lower bound of the range of s c licenses
2313             * @param end the upper bound of the range of s c licenses (not inclusive)
2314             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2315             * @return the ordered range of s c licenses
2316             */
2317            @Override
2318            public List<SCLicense> findAll(int start, int end,
2319                    OrderByComparator<SCLicense> orderByComparator) {
2320                    boolean pagination = true;
2321                    FinderPath finderPath = null;
2322                    Object[] finderArgs = null;
2323    
2324                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2325                                    (orderByComparator == null)) {
2326                            pagination = false;
2327                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2328                            finderArgs = FINDER_ARGS_EMPTY;
2329                    }
2330                    else {
2331                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2332                            finderArgs = new Object[] { start, end, orderByComparator };
2333                    }
2334    
2335                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(finderPath,
2336                                    finderArgs, this);
2337    
2338                    if (list == null) {
2339                            StringBundler query = null;
2340                            String sql = null;
2341    
2342                            if (orderByComparator != null) {
2343                                    query = new StringBundler(2 +
2344                                                    (orderByComparator.getOrderByFields().length * 3));
2345    
2346                                    query.append(_SQL_SELECT_SCLICENSE);
2347    
2348                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2349                                            orderByComparator);
2350    
2351                                    sql = query.toString();
2352                            }
2353                            else {
2354                                    sql = _SQL_SELECT_SCLICENSE;
2355    
2356                                    if (pagination) {
2357                                            sql = sql.concat(SCLicenseModelImpl.ORDER_BY_JPQL);
2358                                    }
2359                            }
2360    
2361                            Session session = null;
2362    
2363                            try {
2364                                    session = openSession();
2365    
2366                                    Query q = session.createQuery(sql);
2367    
2368                                    if (!pagination) {
2369                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
2370                                                            start, end, false);
2371    
2372                                            Collections.sort(list);
2373    
2374                                            list = Collections.unmodifiableList(list);
2375                                    }
2376                                    else {
2377                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
2378                                                            start, end);
2379                                    }
2380    
2381                                    cacheResult(list);
2382    
2383                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2384                            }
2385                            catch (Exception e) {
2386                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2387    
2388                                    throw processException(e);
2389                            }
2390                            finally {
2391                                    closeSession(session);
2392                            }
2393                    }
2394    
2395                    return list;
2396            }
2397    
2398            /**
2399             * Removes all the s c licenses from the database.
2400             *
2401             */
2402            @Override
2403            public void removeAll() {
2404                    for (SCLicense scLicense : findAll()) {
2405                            remove(scLicense);
2406                    }
2407            }
2408    
2409            /**
2410             * Returns the number of s c licenses.
2411             *
2412             * @return the number of s c licenses
2413             */
2414            @Override
2415            public int countAll() {
2416                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2417                                    FINDER_ARGS_EMPTY, this);
2418    
2419                    if (count == null) {
2420                            Session session = null;
2421    
2422                            try {
2423                                    session = openSession();
2424    
2425                                    Query q = session.createQuery(_SQL_COUNT_SCLICENSE);
2426    
2427                                    count = (Long)q.uniqueResult();
2428    
2429                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2430                                            FINDER_ARGS_EMPTY, count);
2431                            }
2432                            catch (Exception e) {
2433                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2434                                            FINDER_ARGS_EMPTY);
2435    
2436                                    throw processException(e);
2437                            }
2438                            finally {
2439                                    closeSession(session);
2440                            }
2441                    }
2442    
2443                    return count.intValue();
2444            }
2445    
2446            /**
2447             * Returns the primaryKeys of s c product entries associated with the s c license.
2448             *
2449             * @param pk the primary key of the s c license
2450             * @return long[] of the primaryKeys of s c product entries associated with the s c license
2451             */
2452            @Override
2453            public long[] getSCProductEntryPrimaryKeys(long pk) {
2454                    long[] pks = scLicenseToSCProductEntryTableMapper.getRightPrimaryKeys(pk);
2455    
2456                    return pks.clone();
2457            }
2458    
2459            /**
2460             * Returns all the s c product entries associated with the s c license.
2461             *
2462             * @param pk the primary key of the s c license
2463             * @return the s c product entries associated with the s c license
2464             */
2465            @Override
2466            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
2467                    long pk) {
2468                    return getSCProductEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2469            }
2470    
2471            /**
2472             * Returns a range of all the s c product entries associated with the s c license.
2473             *
2474             * <p>
2475             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
2476             * </p>
2477             *
2478             * @param pk the primary key of the s c license
2479             * @param start the lower bound of the range of s c licenses
2480             * @param end the upper bound of the range of s c licenses (not inclusive)
2481             * @return the range of s c product entries associated with the s c license
2482             */
2483            @Override
2484            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
2485                    long pk, int start, int end) {
2486                    return getSCProductEntries(pk, start, end, null);
2487            }
2488    
2489            /**
2490             * Returns an ordered range of all the s c product entries associated with the s c license.
2491             *
2492             * <p>
2493             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SCLicenseModelImpl}. 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.
2494             * </p>
2495             *
2496             * @param pk the primary key of the s c license
2497             * @param start the lower bound of the range of s c licenses
2498             * @param end the upper bound of the range of s c licenses (not inclusive)
2499             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2500             * @return the ordered range of s c product entries associated with the s c license
2501             */
2502            @Override
2503            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
2504                    long pk, int start, int end,
2505                    OrderByComparator<com.liferay.portlet.softwarecatalog.model.SCProductEntry> orderByComparator) {
2506                    return scLicenseToSCProductEntryTableMapper.getRightBaseModels(pk,
2507                            start, end, orderByComparator);
2508            }
2509    
2510            /**
2511             * Returns the number of s c product entries associated with the s c license.
2512             *
2513             * @param pk the primary key of the s c license
2514             * @return the number of s c product entries associated with the s c license
2515             */
2516            @Override
2517            public int getSCProductEntriesSize(long pk) {
2518                    long[] pks = scLicenseToSCProductEntryTableMapper.getRightPrimaryKeys(pk);
2519    
2520                    return pks.length;
2521            }
2522    
2523            /**
2524             * Returns <code>true</code> if the s c product entry is associated with the s c license.
2525             *
2526             * @param pk the primary key of the s c license
2527             * @param scProductEntryPK the primary key of the s c product entry
2528             * @return <code>true</code> if the s c product entry is associated with the s c license; <code>false</code> otherwise
2529             */
2530            @Override
2531            public boolean containsSCProductEntry(long pk, long scProductEntryPK) {
2532                    return scLicenseToSCProductEntryTableMapper.containsTableMapping(pk,
2533                            scProductEntryPK);
2534            }
2535    
2536            /**
2537             * Returns <code>true</code> if the s c license has any s c product entries associated with it.
2538             *
2539             * @param pk the primary key of the s c license to check for associations with s c product entries
2540             * @return <code>true</code> if the s c license has any s c product entries associated with it; <code>false</code> otherwise
2541             */
2542            @Override
2543            public boolean containsSCProductEntries(long pk) {
2544                    if (getSCProductEntriesSize(pk) > 0) {
2545                            return true;
2546                    }
2547                    else {
2548                            return false;
2549                    }
2550            }
2551    
2552            /**
2553             * Adds an association between the s c license and the s c product entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2554             *
2555             * @param pk the primary key of the s c license
2556             * @param scProductEntryPK the primary key of the s c product entry
2557             */
2558            @Override
2559            public void addSCProductEntry(long pk, long scProductEntryPK) {
2560                    scLicenseToSCProductEntryTableMapper.addTableMapping(pk,
2561                            scProductEntryPK);
2562            }
2563    
2564            /**
2565             * Adds an association between the s c license and the s c product entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2566             *
2567             * @param pk the primary key of the s c license
2568             * @param scProductEntry the s c product entry
2569             */
2570            @Override
2571            public void addSCProductEntry(long pk,
2572                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry) {
2573                    scLicenseToSCProductEntryTableMapper.addTableMapping(pk,
2574                            scProductEntry.getPrimaryKey());
2575            }
2576    
2577            /**
2578             * Adds an association between the s c license and the s c product entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2579             *
2580             * @param pk the primary key of the s c license
2581             * @param scProductEntryPKs the primary keys of the s c product entries
2582             */
2583            @Override
2584            public void addSCProductEntries(long pk, long[] scProductEntryPKs) {
2585                    for (long scProductEntryPK : scProductEntryPKs) {
2586                            scLicenseToSCProductEntryTableMapper.addTableMapping(pk,
2587                                    scProductEntryPK);
2588                    }
2589            }
2590    
2591            /**
2592             * Adds an association between the s c license and the s c product entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2593             *
2594             * @param pk the primary key of the s c license
2595             * @param scProductEntries the s c product entries
2596             */
2597            @Override
2598            public void addSCProductEntries(long pk,
2599                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries) {
2600                    for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
2601                            scLicenseToSCProductEntryTableMapper.addTableMapping(pk,
2602                                    scProductEntry.getPrimaryKey());
2603                    }
2604            }
2605    
2606            /**
2607             * Clears all associations between the s c license and its s c product entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2608             *
2609             * @param pk the primary key of the s c license to clear the associated s c product entries from
2610             */
2611            @Override
2612            public void clearSCProductEntries(long pk) {
2613                    scLicenseToSCProductEntryTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
2614            }
2615    
2616            /**
2617             * Removes the association between the s c license and the s c product entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2618             *
2619             * @param pk the primary key of the s c license
2620             * @param scProductEntryPK the primary key of the s c product entry
2621             */
2622            @Override
2623            public void removeSCProductEntry(long pk, long scProductEntryPK) {
2624                    scLicenseToSCProductEntryTableMapper.deleteTableMapping(pk,
2625                            scProductEntryPK);
2626            }
2627    
2628            /**
2629             * Removes the association between the s c license and the s c product entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2630             *
2631             * @param pk the primary key of the s c license
2632             * @param scProductEntry the s c product entry
2633             */
2634            @Override
2635            public void removeSCProductEntry(long pk,
2636                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry) {
2637                    scLicenseToSCProductEntryTableMapper.deleteTableMapping(pk,
2638                            scProductEntry.getPrimaryKey());
2639            }
2640    
2641            /**
2642             * Removes the association between the s c license and the s c product entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2643             *
2644             * @param pk the primary key of the s c license
2645             * @param scProductEntryPKs the primary keys of the s c product entries
2646             */
2647            @Override
2648            public void removeSCProductEntries(long pk, long[] scProductEntryPKs) {
2649                    for (long scProductEntryPK : scProductEntryPKs) {
2650                            scLicenseToSCProductEntryTableMapper.deleteTableMapping(pk,
2651                                    scProductEntryPK);
2652                    }
2653            }
2654    
2655            /**
2656             * Removes the association between the s c license and the s c product entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2657             *
2658             * @param pk the primary key of the s c license
2659             * @param scProductEntries the s c product entries
2660             */
2661            @Override
2662            public void removeSCProductEntries(long pk,
2663                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries) {
2664                    for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
2665                            scLicenseToSCProductEntryTableMapper.deleteTableMapping(pk,
2666                                    scProductEntry.getPrimaryKey());
2667                    }
2668            }
2669    
2670            /**
2671             * Sets the s c product entries associated with the s c license, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2672             *
2673             * @param pk the primary key of the s c license
2674             * @param scProductEntryPKs the primary keys of the s c product entries to be associated with the s c license
2675             */
2676            @Override
2677            public void setSCProductEntries(long pk, long[] scProductEntryPKs) {
2678                    Set<Long> newSCProductEntryPKsSet = SetUtil.fromArray(scProductEntryPKs);
2679                    Set<Long> oldSCProductEntryPKsSet = SetUtil.fromArray(scLicenseToSCProductEntryTableMapper.getRightPrimaryKeys(
2680                                            pk));
2681    
2682                    Set<Long> removeSCProductEntryPKsSet = new HashSet<Long>(oldSCProductEntryPKsSet);
2683    
2684                    removeSCProductEntryPKsSet.removeAll(newSCProductEntryPKsSet);
2685    
2686                    for (long removeSCProductEntryPK : removeSCProductEntryPKsSet) {
2687                            scLicenseToSCProductEntryTableMapper.deleteTableMapping(pk,
2688                                    removeSCProductEntryPK);
2689                    }
2690    
2691                    newSCProductEntryPKsSet.removeAll(oldSCProductEntryPKsSet);
2692    
2693                    for (long newSCProductEntryPK : newSCProductEntryPKsSet) {
2694                            scLicenseToSCProductEntryTableMapper.addTableMapping(pk,
2695                                    newSCProductEntryPK);
2696                    }
2697            }
2698    
2699            /**
2700             * Sets the s c product entries associated with the s c license, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2701             *
2702             * @param pk the primary key of the s c license
2703             * @param scProductEntries the s c product entries to be associated with the s c license
2704             */
2705            @Override
2706            public void setSCProductEntries(long pk,
2707                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries) {
2708                    try {
2709                            long[] scProductEntryPKs = new long[scProductEntries.size()];
2710    
2711                            for (int i = 0; i < scProductEntries.size(); i++) {
2712                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry =
2713                                            scProductEntries.get(i);
2714    
2715                                    scProductEntryPKs[i] = scProductEntry.getPrimaryKey();
2716                            }
2717    
2718                            setSCProductEntries(pk, scProductEntryPKs);
2719                    }
2720                    catch (Exception e) {
2721                            throw processException(e);
2722                    }
2723            }
2724    
2725            @Override
2726            protected Set<String> getBadColumnNames() {
2727                    return _badColumnNames;
2728            }
2729    
2730            /**
2731             * Initializes the s c license persistence.
2732             */
2733            public void afterPropertiesSet() {
2734                    scLicenseToSCProductEntryTableMapper = TableMapperFactory.getTableMapper("SCLicenses_SCProductEntries",
2735                                    "licenseId", "productEntryId", this, scProductEntryPersistence);
2736            }
2737    
2738            public void destroy() {
2739                    EntityCacheUtil.removeCache(SCLicenseImpl.class.getName());
2740                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2741                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2742                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2743    
2744                    TableMapperFactory.removeTableMapper("SCLicenses_SCProductEntries");
2745            }
2746    
2747            @BeanReference(type = SCProductEntryPersistence.class)
2748            protected SCProductEntryPersistence scProductEntryPersistence;
2749            protected TableMapper<SCLicense, com.liferay.portlet.softwarecatalog.model.SCProductEntry> scLicenseToSCProductEntryTableMapper;
2750            private static final String _SQL_SELECT_SCLICENSE = "SELECT scLicense FROM SCLicense scLicense";
2751            private static final String _SQL_SELECT_SCLICENSE_WHERE_PKS_IN = "SELECT scLicense FROM SCLicense scLicense WHERE licenseId IN (";
2752            private static final String _SQL_SELECT_SCLICENSE_WHERE = "SELECT scLicense FROM SCLicense scLicense WHERE ";
2753            private static final String _SQL_COUNT_SCLICENSE = "SELECT COUNT(scLicense) FROM SCLicense scLicense";
2754            private static final String _SQL_COUNT_SCLICENSE_WHERE = "SELECT COUNT(scLicense) FROM SCLicense scLicense WHERE ";
2755            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "scLicense.licenseId";
2756            private static final String _FILTER_SQL_SELECT_SCLICENSE_WHERE = "SELECT DISTINCT {scLicense.*} FROM SCLicense scLicense WHERE ";
2757            private static final String _FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_1 =
2758                    "SELECT {SCLicense.*} FROM (SELECT DISTINCT scLicense.licenseId FROM SCLicense scLicense WHERE ";
2759            private static final String _FILTER_SQL_SELECT_SCLICENSE_NO_INLINE_DISTINCT_WHERE_2 =
2760                    ") TEMP_TABLE INNER JOIN SCLicense ON TEMP_TABLE.licenseId = SCLicense.licenseId";
2761            private static final String _FILTER_SQL_COUNT_SCLICENSE_WHERE = "SELECT COUNT(DISTINCT scLicense.licenseId) AS COUNT_VALUE FROM SCLicense scLicense WHERE ";
2762            private static final String _FILTER_ENTITY_ALIAS = "scLicense";
2763            private static final String _FILTER_ENTITY_TABLE = "SCLicense";
2764            private static final String _ORDER_BY_ENTITY_ALIAS = "scLicense.";
2765            private static final String _ORDER_BY_ENTITY_TABLE = "SCLicense.";
2766            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCLicense exists with the primary key ";
2767            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCLicense exists with the key {";
2768            private static final Log _log = LogFactoryUtil.getLog(SCLicensePersistenceImpl.class);
2769            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2770                                    "active"
2771                            });
2772            private static final SCLicense _nullSCLicense = new SCLicenseImpl() {
2773                            @Override
2774                            public Object clone() {
2775                                    return this;
2776                            }
2777    
2778                            @Override
2779                            public CacheModel<SCLicense> toCacheModel() {
2780                                    return _nullSCLicenseCacheModel;
2781                            }
2782                    };
2783    
2784            private static final CacheModel<SCLicense> _nullSCLicenseCacheModel = new CacheModel<SCLicense>() {
2785                            @Override
2786                            public SCLicense toEntityModel() {
2787                                    return _nullSCLicense;
2788                            }
2789                    };
2790    }