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