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