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