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