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