001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.softwarecatalog.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderPath;
028    import com.liferay.portal.kernel.dao.orm.Query;
029    import com.liferay.portal.kernel.dao.orm.QueryPos;
030    import com.liferay.portal.kernel.dao.orm.QueryUtil;
031    import com.liferay.portal.kernel.dao.orm.SQLQuery;
032    import com.liferay.portal.kernel.dao.orm.Session;
033    import com.liferay.portal.kernel.exception.SystemException;
034    import com.liferay.portal.kernel.log.Log;
035    import com.liferay.portal.kernel.log.LogFactoryUtil;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.SetUtil;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.kernel.util.StringUtil;
043    import com.liferay.portal.model.ModelListener;
044    import com.liferay.portal.service.persistence.BatchSessionUtil;
045    import com.liferay.portal.service.persistence.ResourcePersistence;
046    import com.liferay.portal.service.persistence.UserPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.softwarecatalog.NoSuchLicenseException;
050    import com.liferay.portlet.softwarecatalog.model.SCLicense;
051    import com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl;
052    import com.liferay.portlet.softwarecatalog.model.impl.SCLicenseModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    import java.util.Set;
060    
061    /**
062     * The persistence implementation for the s c license service.
063     *
064     * <p>
065     * 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.
066     * </p>
067     *
068     * <p>
069     * Caching information and settings can be found in <code>portal.properties</code>
070     * </p>
071     *
072     * @author Brian Wing Shun Chan
073     * @see SCLicensePersistence
074     * @see SCLicenseUtil
075     * @generated
076     */
077    public class SCLicensePersistenceImpl extends BasePersistenceImpl<SCLicense>
078            implements SCLicensePersistence {
079            public static final String FINDER_CLASS_NAME_ENTITY = SCLicenseImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
081                    ".List";
082            public static final FinderPath FINDER_PATH_FIND_BY_ACTIVE = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
083                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084                            "findByActive",
085                            new String[] {
086                                    Boolean.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
092                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "countByActive", new String[] { Boolean.class.getName() });
094            public static final FinderPath FINDER_PATH_FIND_BY_A_R = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
095                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096                            "findByA_R",
097                            new String[] {
098                                    Boolean.class.getName(), Boolean.class.getName(),
099                                    
100                            "java.lang.Integer", "java.lang.Integer",
101                                    "com.liferay.portal.kernel.util.OrderByComparator"
102                            });
103            public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
104                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105                            "countByA_R",
106                            new String[] { Boolean.class.getName(), Boolean.class.getName() });
107            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
108                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109                            "findAll", new String[0]);
110            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
111                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112                            "countAll", new String[0]);
113    
114            /**
115             * Caches the s c license in the entity cache if it is enabled.
116             *
117             * @param scLicense the s c license to cache
118             */
119            public void cacheResult(SCLicense scLicense) {
120                    EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
121                            SCLicenseImpl.class, scLicense.getPrimaryKey(), scLicense);
122            }
123    
124            /**
125             * Caches the s c licenses in the entity cache if it is enabled.
126             *
127             * @param scLicenses the s c licenses to cache
128             */
129            public void cacheResult(List<SCLicense> scLicenses) {
130                    for (SCLicense scLicense : scLicenses) {
131                            if (EntityCacheUtil.getResult(
132                                                    SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
133                                                    SCLicenseImpl.class, scLicense.getPrimaryKey(), this) == null) {
134                                    cacheResult(scLicense);
135                            }
136                    }
137            }
138    
139            /**
140             * Clears the cache for all s c licenses.
141             *
142             * <p>
143             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
144             * </p>
145             */
146            public void clearCache() {
147                    CacheRegistryUtil.clear(SCLicenseImpl.class.getName());
148                    EntityCacheUtil.clearCache(SCLicenseImpl.class.getName());
149                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
151            }
152    
153            /**
154             * Clears the cache for the s c license.
155             *
156             * <p>
157             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
158             * </p>
159             */
160            public void clearCache(SCLicense scLicense) {
161                    EntityCacheUtil.removeResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
162                            SCLicenseImpl.class, scLicense.getPrimaryKey());
163            }
164    
165            /**
166             * Creates a new s c license with the primary key. Does not add the s c license to the database.
167             *
168             * @param licenseId the primary key for the new s c license
169             * @return the new s c license
170             */
171            public SCLicense create(long licenseId) {
172                    SCLicense scLicense = new SCLicenseImpl();
173    
174                    scLicense.setNew(true);
175                    scLicense.setPrimaryKey(licenseId);
176    
177                    return scLicense;
178            }
179    
180            /**
181             * Removes the s c license with the primary key from the database. Also notifies the appropriate model listeners.
182             *
183             * @param primaryKey the primary key of the s c license to remove
184             * @return the s c license that was removed
185             * @throws com.liferay.portal.NoSuchModelException if a s c license with the primary key could not be found
186             * @throws SystemException if a system exception occurred
187             */
188            public SCLicense remove(Serializable primaryKey)
189                    throws NoSuchModelException, SystemException {
190                    return remove(((Long)primaryKey).longValue());
191            }
192    
193            /**
194             * Removes the s c license with the primary key from the database. Also notifies the appropriate model listeners.
195             *
196             * @param licenseId the primary key of the s c license to remove
197             * @return the s c license that was removed
198             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a s c license with the primary key could not be found
199             * @throws SystemException if a system exception occurred
200             */
201            public SCLicense remove(long licenseId)
202                    throws NoSuchLicenseException, SystemException {
203                    Session session = null;
204    
205                    try {
206                            session = openSession();
207    
208                            SCLicense scLicense = (SCLicense)session.get(SCLicenseImpl.class,
209                                            new Long(licenseId));
210    
211                            if (scLicense == null) {
212                                    if (_log.isWarnEnabled()) {
213                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + licenseId);
214                                    }
215    
216                                    throw new NoSuchLicenseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
217                                            licenseId);
218                            }
219    
220                            return remove(scLicense);
221                    }
222                    catch (NoSuchLicenseException nsee) {
223                            throw nsee;
224                    }
225                    catch (Exception e) {
226                            throw processException(e);
227                    }
228                    finally {
229                            closeSession(session);
230                    }
231            }
232    
233            protected SCLicense removeImpl(SCLicense scLicense)
234                    throws SystemException {
235                    scLicense = toUnwrappedModel(scLicense);
236    
237                    try {
238                            clearSCProductEntries.clear(scLicense.getPrimaryKey());
239                    }
240                    catch (Exception e) {
241                            throw processException(e);
242                    }
243                    finally {
244                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
245                    }
246    
247                    Session session = null;
248    
249                    try {
250                            session = openSession();
251    
252                            BatchSessionUtil.delete(session, scLicense);
253                    }
254                    catch (Exception e) {
255                            throw processException(e);
256                    }
257                    finally {
258                            closeSession(session);
259                    }
260    
261                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
262    
263                    EntityCacheUtil.removeResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
264                            SCLicenseImpl.class, scLicense.getPrimaryKey());
265    
266                    return scLicense;
267            }
268    
269            public SCLicense updateImpl(
270                    com.liferay.portlet.softwarecatalog.model.SCLicense scLicense,
271                    boolean merge) throws SystemException {
272                    scLicense = toUnwrappedModel(scLicense);
273    
274                    Session session = null;
275    
276                    try {
277                            session = openSession();
278    
279                            BatchSessionUtil.update(session, scLicense, merge);
280    
281                            scLicense.setNew(false);
282                    }
283                    catch (Exception e) {
284                            throw processException(e);
285                    }
286                    finally {
287                            closeSession(session);
288                    }
289    
290                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
291    
292                    EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
293                            SCLicenseImpl.class, scLicense.getPrimaryKey(), scLicense);
294    
295                    return scLicense;
296            }
297    
298            protected SCLicense toUnwrappedModel(SCLicense scLicense) {
299                    if (scLicense instanceof SCLicenseImpl) {
300                            return scLicense;
301                    }
302    
303                    SCLicenseImpl scLicenseImpl = new SCLicenseImpl();
304    
305                    scLicenseImpl.setNew(scLicense.isNew());
306                    scLicenseImpl.setPrimaryKey(scLicense.getPrimaryKey());
307    
308                    scLicenseImpl.setLicenseId(scLicense.getLicenseId());
309                    scLicenseImpl.setName(scLicense.getName());
310                    scLicenseImpl.setUrl(scLicense.getUrl());
311                    scLicenseImpl.setOpenSource(scLicense.isOpenSource());
312                    scLicenseImpl.setActive(scLicense.isActive());
313                    scLicenseImpl.setRecommended(scLicense.isRecommended());
314    
315                    return scLicenseImpl;
316            }
317    
318            /**
319             * Finds the s c license with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
320             *
321             * @param primaryKey the primary key of the s c license to find
322             * @return the s c license
323             * @throws com.liferay.portal.NoSuchModelException if a s c license with the primary key could not be found
324             * @throws SystemException if a system exception occurred
325             */
326            public SCLicense findByPrimaryKey(Serializable primaryKey)
327                    throws NoSuchModelException, SystemException {
328                    return findByPrimaryKey(((Long)primaryKey).longValue());
329            }
330    
331            /**
332             * Finds the s c license with the primary key or throws a {@link com.liferay.portlet.softwarecatalog.NoSuchLicenseException} if it could not be found.
333             *
334             * @param licenseId the primary key of the s c license to find
335             * @return the s c license
336             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a s c license with the primary key could not be found
337             * @throws SystemException if a system exception occurred
338             */
339            public SCLicense findByPrimaryKey(long licenseId)
340                    throws NoSuchLicenseException, SystemException {
341                    SCLicense scLicense = fetchByPrimaryKey(licenseId);
342    
343                    if (scLicense == null) {
344                            if (_log.isWarnEnabled()) {
345                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + licenseId);
346                            }
347    
348                            throw new NoSuchLicenseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
349                                    licenseId);
350                    }
351    
352                    return scLicense;
353            }
354    
355            /**
356             * Finds the s c license with the primary key or returns <code>null</code> if it could not be found.
357             *
358             * @param primaryKey the primary key of the s c license to find
359             * @return the s c license, or <code>null</code> if a s c license with the primary key could not be found
360             * @throws SystemException if a system exception occurred
361             */
362            public SCLicense fetchByPrimaryKey(Serializable primaryKey)
363                    throws SystemException {
364                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
365            }
366    
367            /**
368             * Finds the s c license with the primary key or returns <code>null</code> if it could not be found.
369             *
370             * @param licenseId the primary key of the s c license to find
371             * @return the s c license, or <code>null</code> if a s c license with the primary key could not be found
372             * @throws SystemException if a system exception occurred
373             */
374            public SCLicense fetchByPrimaryKey(long licenseId)
375                    throws SystemException {
376                    SCLicense scLicense = (SCLicense)EntityCacheUtil.getResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
377                                    SCLicenseImpl.class, licenseId, this);
378    
379                    if (scLicense == null) {
380                            Session session = null;
381    
382                            try {
383                                    session = openSession();
384    
385                                    scLicense = (SCLicense)session.get(SCLicenseImpl.class,
386                                                    new Long(licenseId));
387                            }
388                            catch (Exception e) {
389                                    throw processException(e);
390                            }
391                            finally {
392                                    if (scLicense != null) {
393                                            cacheResult(scLicense);
394                                    }
395    
396                                    closeSession(session);
397                            }
398                    }
399    
400                    return scLicense;
401            }
402    
403            /**
404             * Finds all the s c licenses where active = &#63;.
405             *
406             * @param active the active to search with
407             * @return the matching s c licenses
408             * @throws SystemException if a system exception occurred
409             */
410            public List<SCLicense> findByActive(boolean active)
411                    throws SystemException {
412                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
413            }
414    
415            /**
416             * Finds a range of all the s c licenses where active = &#63;.
417             *
418             * <p>
419             * 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.
420             * </p>
421             *
422             * @param active the active to search with
423             * @param start the lower bound of the range of s c licenses to return
424             * @param end the upper bound of the range of s c licenses to return (not inclusive)
425             * @return the range of matching s c licenses
426             * @throws SystemException if a system exception occurred
427             */
428            public List<SCLicense> findByActive(boolean active, int start, int end)
429                    throws SystemException {
430                    return findByActive(active, start, end, null);
431            }
432    
433            /**
434             * Finds an ordered range of all the s c licenses where active = &#63;.
435             *
436             * <p>
437             * 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.
438             * </p>
439             *
440             * @param active the active to search with
441             * @param start the lower bound of the range of s c licenses to return
442             * @param end the upper bound of the range of s c licenses to return (not inclusive)
443             * @param orderByComparator the comparator to order the results by
444             * @return the ordered range of matching s c licenses
445             * @throws SystemException if a system exception occurred
446             */
447            public List<SCLicense> findByActive(boolean active, int start, int end,
448                    OrderByComparator orderByComparator) throws SystemException {
449                    Object[] finderArgs = new Object[] {
450                                    active,
451                                    
452                                    String.valueOf(start), String.valueOf(end),
453                                    String.valueOf(orderByComparator)
454                            };
455    
456                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
457                                    finderArgs, this);
458    
459                    if (list == null) {
460                            Session session = null;
461    
462                            try {
463                                    session = openSession();
464    
465                                    StringBundler query = null;
466    
467                                    if (orderByComparator != null) {
468                                            query = new StringBundler(3 +
469                                                            (orderByComparator.getOrderByFields().length * 3));
470                                    }
471                                    else {
472                                            query = new StringBundler(3);
473                                    }
474    
475                                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
476    
477                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
478    
479                                    if (orderByComparator != null) {
480                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
481                                                    orderByComparator);
482                                    }
483    
484                                    else {
485                                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
486                                    }
487    
488                                    String sql = query.toString();
489    
490                                    Query q = session.createQuery(sql);
491    
492                                    QueryPos qPos = QueryPos.getInstance(q);
493    
494                                    qPos.add(active);
495    
496                                    list = (List<SCLicense>)QueryUtil.list(q, getDialect(), start,
497                                                    end);
498                            }
499                            catch (Exception e) {
500                                    throw processException(e);
501                            }
502                            finally {
503                                    if (list == null) {
504                                            list = new ArrayList<SCLicense>();
505                                    }
506    
507                                    cacheResult(list);
508    
509                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
510                                            finderArgs, list);
511    
512                                    closeSession(session);
513                            }
514                    }
515    
516                    return list;
517            }
518    
519            /**
520             * Finds the first s c license in the ordered set where active = &#63;.
521             *
522             * <p>
523             * 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.
524             * </p>
525             *
526             * @param active the active to search with
527             * @param orderByComparator the comparator to order the set by
528             * @return the first matching s c license
529             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a matching s c license could not be found
530             * @throws SystemException if a system exception occurred
531             */
532            public SCLicense findByActive_First(boolean active,
533                    OrderByComparator orderByComparator)
534                    throws NoSuchLicenseException, SystemException {
535                    List<SCLicense> list = findByActive(active, 0, 1, orderByComparator);
536    
537                    if (list.isEmpty()) {
538                            StringBundler msg = new StringBundler(4);
539    
540                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
541    
542                            msg.append("active=");
543                            msg.append(active);
544    
545                            msg.append(StringPool.CLOSE_CURLY_BRACE);
546    
547                            throw new NoSuchLicenseException(msg.toString());
548                    }
549                    else {
550                            return list.get(0);
551                    }
552            }
553    
554            /**
555             * Finds the last s c license in the ordered set where active = &#63;.
556             *
557             * <p>
558             * 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.
559             * </p>
560             *
561             * @param active the active to search with
562             * @param orderByComparator the comparator to order the set by
563             * @return the last matching s c license
564             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a matching s c license could not be found
565             * @throws SystemException if a system exception occurred
566             */
567            public SCLicense findByActive_Last(boolean active,
568                    OrderByComparator orderByComparator)
569                    throws NoSuchLicenseException, SystemException {
570                    int count = countByActive(active);
571    
572                    List<SCLicense> list = findByActive(active, count - 1, count,
573                                    orderByComparator);
574    
575                    if (list.isEmpty()) {
576                            StringBundler msg = new StringBundler(4);
577    
578                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
579    
580                            msg.append("active=");
581                            msg.append(active);
582    
583                            msg.append(StringPool.CLOSE_CURLY_BRACE);
584    
585                            throw new NoSuchLicenseException(msg.toString());
586                    }
587                    else {
588                            return list.get(0);
589                    }
590            }
591    
592            /**
593             * Finds the s c licenses before and after the current s c license in the ordered set where active = &#63;.
594             *
595             * <p>
596             * 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.
597             * </p>
598             *
599             * @param licenseId the primary key of the current s c license
600             * @param active the active to search with
601             * @param orderByComparator the comparator to order the set by
602             * @return the previous, current, and next s c license
603             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a s c license with the primary key could not be found
604             * @throws SystemException if a system exception occurred
605             */
606            public SCLicense[] findByActive_PrevAndNext(long licenseId, boolean active,
607                    OrderByComparator orderByComparator)
608                    throws NoSuchLicenseException, SystemException {
609                    SCLicense scLicense = findByPrimaryKey(licenseId);
610    
611                    Session session = null;
612    
613                    try {
614                            session = openSession();
615    
616                            SCLicense[] array = new SCLicenseImpl[3];
617    
618                            array[0] = getByActive_PrevAndNext(session, scLicense, active,
619                                            orderByComparator, true);
620    
621                            array[1] = scLicense;
622    
623                            array[2] = getByActive_PrevAndNext(session, scLicense, active,
624                                            orderByComparator, false);
625    
626                            return array;
627                    }
628                    catch (Exception e) {
629                            throw processException(e);
630                    }
631                    finally {
632                            closeSession(session);
633                    }
634            }
635    
636            protected SCLicense getByActive_PrevAndNext(Session session,
637                    SCLicense scLicense, boolean active,
638                    OrderByComparator orderByComparator, boolean previous) {
639                    StringBundler query = null;
640    
641                    if (orderByComparator != null) {
642                            query = new StringBundler(6 +
643                                            (orderByComparator.getOrderByFields().length * 6));
644                    }
645                    else {
646                            query = new StringBundler(3);
647                    }
648    
649                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
650    
651                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
652    
653                    if (orderByComparator != null) {
654                            String[] orderByFields = orderByComparator.getOrderByFields();
655    
656                            if (orderByFields.length > 0) {
657                                    query.append(WHERE_AND);
658                            }
659    
660                            for (int i = 0; i < orderByFields.length; i++) {
661                                    query.append(_ORDER_BY_ENTITY_ALIAS);
662                                    query.append(orderByFields[i]);
663    
664                                    if ((i + 1) < orderByFields.length) {
665                                            if (orderByComparator.isAscending() ^ previous) {
666                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
667                                            }
668                                            else {
669                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
670                                            }
671                                    }
672                                    else {
673                                            if (orderByComparator.isAscending() ^ previous) {
674                                                    query.append(WHERE_GREATER_THAN);
675                                            }
676                                            else {
677                                                    query.append(WHERE_LESSER_THAN);
678                                            }
679                                    }
680                            }
681    
682                            query.append(ORDER_BY_CLAUSE);
683    
684                            for (int i = 0; i < orderByFields.length; i++) {
685                                    query.append(_ORDER_BY_ENTITY_ALIAS);
686                                    query.append(orderByFields[i]);
687    
688                                    if ((i + 1) < orderByFields.length) {
689                                            if (orderByComparator.isAscending() ^ previous) {
690                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
691                                            }
692                                            else {
693                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
694                                            }
695                                    }
696                                    else {
697                                            if (orderByComparator.isAscending() ^ previous) {
698                                                    query.append(ORDER_BY_ASC);
699                                            }
700                                            else {
701                                                    query.append(ORDER_BY_DESC);
702                                            }
703                                    }
704                            }
705                    }
706    
707                    else {
708                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
709                    }
710    
711                    String sql = query.toString();
712    
713                    Query q = session.createQuery(sql);
714    
715                    q.setFirstResult(0);
716                    q.setMaxResults(2);
717    
718                    QueryPos qPos = QueryPos.getInstance(q);
719    
720                    qPos.add(active);
721    
722                    if (orderByComparator != null) {
723                            Object[] values = orderByComparator.getOrderByValues(scLicense);
724    
725                            for (Object value : values) {
726                                    qPos.add(value);
727                            }
728                    }
729    
730                    List<SCLicense> list = q.list();
731    
732                    if (list.size() == 2) {
733                            return list.get(1);
734                    }
735                    else {
736                            return null;
737                    }
738            }
739    
740            /**
741             * Finds all the s c licenses where active = &#63; and recommended = &#63;.
742             *
743             * @param active the active to search with
744             * @param recommended the recommended to search with
745             * @return the matching s c licenses
746             * @throws SystemException if a system exception occurred
747             */
748            public List<SCLicense> findByA_R(boolean active, boolean recommended)
749                    throws SystemException {
750                    return findByA_R(active, recommended, QueryUtil.ALL_POS,
751                            QueryUtil.ALL_POS, null);
752            }
753    
754            /**
755             * Finds a range of all the s c licenses where active = &#63; and recommended = &#63;.
756             *
757             * <p>
758             * 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.
759             * </p>
760             *
761             * @param active the active to search with
762             * @param recommended the recommended to search with
763             * @param start the lower bound of the range of s c licenses to return
764             * @param end the upper bound of the range of s c licenses to return (not inclusive)
765             * @return the range of matching s c licenses
766             * @throws SystemException if a system exception occurred
767             */
768            public List<SCLicense> findByA_R(boolean active, boolean recommended,
769                    int start, int end) throws SystemException {
770                    return findByA_R(active, recommended, start, end, null);
771            }
772    
773            /**
774             * Finds an ordered range of all the s c licenses where active = &#63; and recommended = &#63;.
775             *
776             * <p>
777             * 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.
778             * </p>
779             *
780             * @param active the active to search with
781             * @param recommended the recommended to search with
782             * @param start the lower bound of the range of s c licenses to return
783             * @param end the upper bound of the range of s c licenses to return (not inclusive)
784             * @param orderByComparator the comparator to order the results by
785             * @return the ordered range of matching s c licenses
786             * @throws SystemException if a system exception occurred
787             */
788            public List<SCLicense> findByA_R(boolean active, boolean recommended,
789                    int start, int end, OrderByComparator orderByComparator)
790                    throws SystemException {
791                    Object[] finderArgs = new Object[] {
792                                    active, recommended,
793                                    
794                                    String.valueOf(start), String.valueOf(end),
795                                    String.valueOf(orderByComparator)
796                            };
797    
798                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_A_R,
799                                    finderArgs, this);
800    
801                    if (list == null) {
802                            Session session = null;
803    
804                            try {
805                                    session = openSession();
806    
807                                    StringBundler query = null;
808    
809                                    if (orderByComparator != null) {
810                                            query = new StringBundler(4 +
811                                                            (orderByComparator.getOrderByFields().length * 3));
812                                    }
813                                    else {
814                                            query = new StringBundler(4);
815                                    }
816    
817                                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
818    
819                                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
820    
821                                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
822    
823                                    if (orderByComparator != null) {
824                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
825                                                    orderByComparator);
826                                    }
827    
828                                    else {
829                                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
830                                    }
831    
832                                    String sql = query.toString();
833    
834                                    Query q = session.createQuery(sql);
835    
836                                    QueryPos qPos = QueryPos.getInstance(q);
837    
838                                    qPos.add(active);
839    
840                                    qPos.add(recommended);
841    
842                                    list = (List<SCLicense>)QueryUtil.list(q, getDialect(), start,
843                                                    end);
844                            }
845                            catch (Exception e) {
846                                    throw processException(e);
847                            }
848                            finally {
849                                    if (list == null) {
850                                            list = new ArrayList<SCLicense>();
851                                    }
852    
853                                    cacheResult(list);
854    
855                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_A_R, finderArgs,
856                                            list);
857    
858                                    closeSession(session);
859                            }
860                    }
861    
862                    return list;
863            }
864    
865            /**
866             * Finds the first s c license in the ordered set where active = &#63; and recommended = &#63;.
867             *
868             * <p>
869             * 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.
870             * </p>
871             *
872             * @param active the active to search with
873             * @param recommended the recommended to search with
874             * @param orderByComparator the comparator to order the set by
875             * @return the first matching s c license
876             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a matching s c license could not be found
877             * @throws SystemException if a system exception occurred
878             */
879            public SCLicense findByA_R_First(boolean active, boolean recommended,
880                    OrderByComparator orderByComparator)
881                    throws NoSuchLicenseException, SystemException {
882                    List<SCLicense> list = findByA_R(active, recommended, 0, 1,
883                                    orderByComparator);
884    
885                    if (list.isEmpty()) {
886                            StringBundler msg = new StringBundler(6);
887    
888                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
889    
890                            msg.append("active=");
891                            msg.append(active);
892    
893                            msg.append(", recommended=");
894                            msg.append(recommended);
895    
896                            msg.append(StringPool.CLOSE_CURLY_BRACE);
897    
898                            throw new NoSuchLicenseException(msg.toString());
899                    }
900                    else {
901                            return list.get(0);
902                    }
903            }
904    
905            /**
906             * Finds the last s c license in the ordered set where active = &#63; and recommended = &#63;.
907             *
908             * <p>
909             * 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.
910             * </p>
911             *
912             * @param active the active to search with
913             * @param recommended the recommended to search with
914             * @param orderByComparator the comparator to order the set by
915             * @return the last matching s c license
916             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a matching s c license could not be found
917             * @throws SystemException if a system exception occurred
918             */
919            public SCLicense findByA_R_Last(boolean active, boolean recommended,
920                    OrderByComparator orderByComparator)
921                    throws NoSuchLicenseException, SystemException {
922                    int count = countByA_R(active, recommended);
923    
924                    List<SCLicense> list = findByA_R(active, recommended, count - 1, count,
925                                    orderByComparator);
926    
927                    if (list.isEmpty()) {
928                            StringBundler msg = new StringBundler(6);
929    
930                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
931    
932                            msg.append("active=");
933                            msg.append(active);
934    
935                            msg.append(", recommended=");
936                            msg.append(recommended);
937    
938                            msg.append(StringPool.CLOSE_CURLY_BRACE);
939    
940                            throw new NoSuchLicenseException(msg.toString());
941                    }
942                    else {
943                            return list.get(0);
944                    }
945            }
946    
947            /**
948             * Finds the s c licenses before and after the current s c license in the ordered set where active = &#63; and recommended = &#63;.
949             *
950             * <p>
951             * 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.
952             * </p>
953             *
954             * @param licenseId the primary key of the current s c license
955             * @param active the active to search with
956             * @param recommended the recommended to search with
957             * @param orderByComparator the comparator to order the set by
958             * @return the previous, current, and next s c license
959             * @throws com.liferay.portlet.softwarecatalog.NoSuchLicenseException if a s c license with the primary key could not be found
960             * @throws SystemException if a system exception occurred
961             */
962            public SCLicense[] findByA_R_PrevAndNext(long licenseId, boolean active,
963                    boolean recommended, OrderByComparator orderByComparator)
964                    throws NoSuchLicenseException, SystemException {
965                    SCLicense scLicense = findByPrimaryKey(licenseId);
966    
967                    Session session = null;
968    
969                    try {
970                            session = openSession();
971    
972                            SCLicense[] array = new SCLicenseImpl[3];
973    
974                            array[0] = getByA_R_PrevAndNext(session, scLicense, active,
975                                            recommended, orderByComparator, true);
976    
977                            array[1] = scLicense;
978    
979                            array[2] = getByA_R_PrevAndNext(session, scLicense, active,
980                                            recommended, orderByComparator, false);
981    
982                            return array;
983                    }
984                    catch (Exception e) {
985                            throw processException(e);
986                    }
987                    finally {
988                            closeSession(session);
989                    }
990            }
991    
992            protected SCLicense getByA_R_PrevAndNext(Session session,
993                    SCLicense scLicense, boolean active, boolean recommended,
994                    OrderByComparator orderByComparator, boolean previous) {
995                    StringBundler query = null;
996    
997                    if (orderByComparator != null) {
998                            query = new StringBundler(6 +
999                                            (orderByComparator.getOrderByFields().length * 6));
1000                    }
1001                    else {
1002                            query = new StringBundler(3);
1003                    }
1004    
1005                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
1006    
1007                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
1008    
1009                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1010    
1011                    if (orderByComparator != null) {
1012                            String[] orderByFields = orderByComparator.getOrderByFields();
1013    
1014                            if (orderByFields.length > 0) {
1015                                    query.append(WHERE_AND);
1016                            }
1017    
1018                            for (int i = 0; i < orderByFields.length; i++) {
1019                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1020                                    query.append(orderByFields[i]);
1021    
1022                                    if ((i + 1) < orderByFields.length) {
1023                                            if (orderByComparator.isAscending() ^ previous) {
1024                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1025                                            }
1026                                            else {
1027                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1028                                            }
1029                                    }
1030                                    else {
1031                                            if (orderByComparator.isAscending() ^ previous) {
1032                                                    query.append(WHERE_GREATER_THAN);
1033                                            }
1034                                            else {
1035                                                    query.append(WHERE_LESSER_THAN);
1036                                            }
1037                                    }
1038                            }
1039    
1040                            query.append(ORDER_BY_CLAUSE);
1041    
1042                            for (int i = 0; i < orderByFields.length; i++) {
1043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1044                                    query.append(orderByFields[i]);
1045    
1046                                    if ((i + 1) < orderByFields.length) {
1047                                            if (orderByComparator.isAscending() ^ previous) {
1048                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1049                                            }
1050                                            else {
1051                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1052                                            }
1053                                    }
1054                                    else {
1055                                            if (orderByComparator.isAscending() ^ previous) {
1056                                                    query.append(ORDER_BY_ASC);
1057                                            }
1058                                            else {
1059                                                    query.append(ORDER_BY_DESC);
1060                                            }
1061                                    }
1062                            }
1063                    }
1064    
1065                    else {
1066                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
1067                    }
1068    
1069                    String sql = query.toString();
1070    
1071                    Query q = session.createQuery(sql);
1072    
1073                    q.setFirstResult(0);
1074                    q.setMaxResults(2);
1075    
1076                    QueryPos qPos = QueryPos.getInstance(q);
1077    
1078                    qPos.add(active);
1079    
1080                    qPos.add(recommended);
1081    
1082                    if (orderByComparator != null) {
1083                            Object[] values = orderByComparator.getOrderByValues(scLicense);
1084    
1085                            for (Object value : values) {
1086                                    qPos.add(value);
1087                            }
1088                    }
1089    
1090                    List<SCLicense> list = q.list();
1091    
1092                    if (list.size() == 2) {
1093                            return list.get(1);
1094                    }
1095                    else {
1096                            return null;
1097                    }
1098            }
1099    
1100            /**
1101             * Finds all the s c licenses.
1102             *
1103             * @return the s c licenses
1104             * @throws SystemException if a system exception occurred
1105             */
1106            public List<SCLicense> findAll() throws SystemException {
1107                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1108            }
1109    
1110            /**
1111             * Finds a range of all the s c licenses.
1112             *
1113             * <p>
1114             * 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.
1115             * </p>
1116             *
1117             * @param start the lower bound of the range of s c licenses to return
1118             * @param end the upper bound of the range of s c licenses to return (not inclusive)
1119             * @return the range of s c licenses
1120             * @throws SystemException if a system exception occurred
1121             */
1122            public List<SCLicense> findAll(int start, int end)
1123                    throws SystemException {
1124                    return findAll(start, end, null);
1125            }
1126    
1127            /**
1128             * Finds an ordered range of all the s c licenses.
1129             *
1130             * <p>
1131             * 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.
1132             * </p>
1133             *
1134             * @param start the lower bound of the range of s c licenses to return
1135             * @param end the upper bound of the range of s c licenses to return (not inclusive)
1136             * @param orderByComparator the comparator to order the results by
1137             * @return the ordered range of s c licenses
1138             * @throws SystemException if a system exception occurred
1139             */
1140            public List<SCLicense> findAll(int start, int end,
1141                    OrderByComparator orderByComparator) throws SystemException {
1142                    Object[] finderArgs = new Object[] {
1143                                    String.valueOf(start), String.valueOf(end),
1144                                    String.valueOf(orderByComparator)
1145                            };
1146    
1147                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1148                                    finderArgs, this);
1149    
1150                    if (list == null) {
1151                            Session session = null;
1152    
1153                            try {
1154                                    session = openSession();
1155    
1156                                    StringBundler query = null;
1157                                    String sql = null;
1158    
1159                                    if (orderByComparator != null) {
1160                                            query = new StringBundler(2 +
1161                                                            (orderByComparator.getOrderByFields().length * 3));
1162    
1163                                            query.append(_SQL_SELECT_SCLICENSE);
1164    
1165                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1166                                                    orderByComparator);
1167    
1168                                            sql = query.toString();
1169                                    }
1170                                    else {
1171                                            sql = _SQL_SELECT_SCLICENSE.concat(SCLicenseModelImpl.ORDER_BY_JPQL);
1172                                    }
1173    
1174                                    Query q = session.createQuery(sql);
1175    
1176                                    if (orderByComparator == null) {
1177                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
1178                                                            start, end, false);
1179    
1180                                            Collections.sort(list);
1181                                    }
1182                                    else {
1183                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
1184                                                            start, end);
1185                                    }
1186                            }
1187                            catch (Exception e) {
1188                                    throw processException(e);
1189                            }
1190                            finally {
1191                                    if (list == null) {
1192                                            list = new ArrayList<SCLicense>();
1193                                    }
1194    
1195                                    cacheResult(list);
1196    
1197                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1198    
1199                                    closeSession(session);
1200                            }
1201                    }
1202    
1203                    return list;
1204            }
1205    
1206            /**
1207             * Removes all the s c licenses where active = &#63; from the database.
1208             *
1209             * @param active the active to search with
1210             * @throws SystemException if a system exception occurred
1211             */
1212            public void removeByActive(boolean active) throws SystemException {
1213                    for (SCLicense scLicense : findByActive(active)) {
1214                            remove(scLicense);
1215                    }
1216            }
1217    
1218            /**
1219             * Removes all the s c licenses where active = &#63; and recommended = &#63; from the database.
1220             *
1221             * @param active the active to search with
1222             * @param recommended the recommended to search with
1223             * @throws SystemException if a system exception occurred
1224             */
1225            public void removeByA_R(boolean active, boolean recommended)
1226                    throws SystemException {
1227                    for (SCLicense scLicense : findByA_R(active, recommended)) {
1228                            remove(scLicense);
1229                    }
1230            }
1231    
1232            /**
1233             * Removes all the s c licenses from the database.
1234             *
1235             * @throws SystemException if a system exception occurred
1236             */
1237            public void removeAll() throws SystemException {
1238                    for (SCLicense scLicense : findAll()) {
1239                            remove(scLicense);
1240                    }
1241            }
1242    
1243            /**
1244             * Counts all the s c licenses where active = &#63;.
1245             *
1246             * @param active the active to search with
1247             * @return the number of matching s c licenses
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public int countByActive(boolean active) throws SystemException {
1251                    Object[] finderArgs = new Object[] { active };
1252    
1253                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1254                                    finderArgs, this);
1255    
1256                    if (count == null) {
1257                            Session session = null;
1258    
1259                            try {
1260                                    session = openSession();
1261    
1262                                    StringBundler query = new StringBundler(2);
1263    
1264                                    query.append(_SQL_COUNT_SCLICENSE_WHERE);
1265    
1266                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1267    
1268                                    String sql = query.toString();
1269    
1270                                    Query q = session.createQuery(sql);
1271    
1272                                    QueryPos qPos = QueryPos.getInstance(q);
1273    
1274                                    qPos.add(active);
1275    
1276                                    count = (Long)q.uniqueResult();
1277                            }
1278                            catch (Exception e) {
1279                                    throw processException(e);
1280                            }
1281                            finally {
1282                                    if (count == null) {
1283                                            count = Long.valueOf(0);
1284                                    }
1285    
1286                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1287                                            finderArgs, count);
1288    
1289                                    closeSession(session);
1290                            }
1291                    }
1292    
1293                    return count.intValue();
1294            }
1295    
1296            /**
1297             * Counts all the s c licenses where active = &#63; and recommended = &#63;.
1298             *
1299             * @param active the active to search with
1300             * @param recommended the recommended to search with
1301             * @return the number of matching s c licenses
1302             * @throws SystemException if a system exception occurred
1303             */
1304            public int countByA_R(boolean active, boolean recommended)
1305                    throws SystemException {
1306                    Object[] finderArgs = new Object[] { active, recommended };
1307    
1308                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
1309                                    finderArgs, this);
1310    
1311                    if (count == null) {
1312                            Session session = null;
1313    
1314                            try {
1315                                    session = openSession();
1316    
1317                                    StringBundler query = new StringBundler(3);
1318    
1319                                    query.append(_SQL_COUNT_SCLICENSE_WHERE);
1320    
1321                                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
1322    
1323                                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1324    
1325                                    String sql = query.toString();
1326    
1327                                    Query q = session.createQuery(sql);
1328    
1329                                    QueryPos qPos = QueryPos.getInstance(q);
1330    
1331                                    qPos.add(active);
1332    
1333                                    qPos.add(recommended);
1334    
1335                                    count = (Long)q.uniqueResult();
1336                            }
1337                            catch (Exception e) {
1338                                    throw processException(e);
1339                            }
1340                            finally {
1341                                    if (count == null) {
1342                                            count = Long.valueOf(0);
1343                                    }
1344    
1345                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
1346                                            count);
1347    
1348                                    closeSession(session);
1349                            }
1350                    }
1351    
1352                    return count.intValue();
1353            }
1354    
1355            /**
1356             * Counts all the s c licenses.
1357             *
1358             * @return the number of s c licenses
1359             * @throws SystemException if a system exception occurred
1360             */
1361            public int countAll() throws SystemException {
1362                    Object[] finderArgs = new Object[0];
1363    
1364                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1365                                    finderArgs, this);
1366    
1367                    if (count == null) {
1368                            Session session = null;
1369    
1370                            try {
1371                                    session = openSession();
1372    
1373                                    Query q = session.createQuery(_SQL_COUNT_SCLICENSE);
1374    
1375                                    count = (Long)q.uniqueResult();
1376                            }
1377                            catch (Exception e) {
1378                                    throw processException(e);
1379                            }
1380                            finally {
1381                                    if (count == null) {
1382                                            count = Long.valueOf(0);
1383                                    }
1384    
1385                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1386                                            count);
1387    
1388                                    closeSession(session);
1389                            }
1390                    }
1391    
1392                    return count.intValue();
1393            }
1394    
1395            /**
1396             * Gets all the s c product entries associated with the s c license.
1397             *
1398             * @param pk the primary key of the s c license to get the associated s c product entries for
1399             * @return the s c product entries associated with the s c license
1400             * @throws SystemException if a system exception occurred
1401             */
1402            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1403                    long pk) throws SystemException {
1404                    return getSCProductEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1405            }
1406    
1407            /**
1408             * Gets a range of all the s c product entries associated with the s c license.
1409             *
1410             * <p>
1411             * 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.
1412             * </p>
1413             *
1414             * @param pk the primary key of the s c license to get the associated s c product entries for
1415             * @param start the lower bound of the range of s c licenses to return
1416             * @param end the upper bound of the range of s c licenses to return (not inclusive)
1417             * @return the range of s c product entries associated with the s c license
1418             * @throws SystemException if a system exception occurred
1419             */
1420            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1421                    long pk, int start, int end) throws SystemException {
1422                    return getSCProductEntries(pk, start, end, null);
1423            }
1424    
1425            public static final FinderPath FINDER_PATH_GET_SCPRODUCTENTRIES = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1426                            SCLicenseModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1427                            SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
1428                            "getSCProductEntries",
1429                            new String[] {
1430                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1431                                    "com.liferay.portal.kernel.util.OrderByComparator"
1432                            });
1433    
1434            /**
1435             * Gets an ordered range of all the s c product entries associated with the s c license.
1436             *
1437             * <p>
1438             * 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.
1439             * </p>
1440             *
1441             * @param pk the primary key of the s c license to get the associated s c product entries for
1442             * @param start the lower bound of the range of s c licenses to return
1443             * @param end the upper bound of the range of s c licenses to return (not inclusive)
1444             * @param orderByComparator the comparator to order the results by
1445             * @return the ordered range of s c product entries associated with the s c license
1446             * @throws SystemException if a system exception occurred
1447             */
1448            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1449                    long pk, int start, int end, OrderByComparator orderByComparator)
1450                    throws SystemException {
1451                    Object[] finderArgs = new Object[] {
1452                                    pk, String.valueOf(start), String.valueOf(end),
1453                                    String.valueOf(orderByComparator)
1454                            };
1455    
1456                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> list = (List<com.liferay.portlet.softwarecatalog.model.SCProductEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_SCPRODUCTENTRIES,
1457                                    finderArgs, this);
1458    
1459                    if (list == null) {
1460                            Session session = null;
1461    
1462                            try {
1463                                    session = openSession();
1464    
1465                                    String sql = null;
1466    
1467                                    if (orderByComparator != null) {
1468                                            sql = _SQL_GETSCPRODUCTENTRIES.concat(ORDER_BY_CLAUSE)
1469                                                                                                      .concat(orderByComparator.getOrderBy());
1470                                    }
1471                                    else {
1472                                            sql = _SQL_GETSCPRODUCTENTRIES.concat(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ORDER_BY_SQL);
1473                                    }
1474    
1475                                    SQLQuery q = session.createSQLQuery(sql);
1476    
1477                                    q.addEntity("SCProductEntry",
1478                                            com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryImpl.class);
1479    
1480                                    QueryPos qPos = QueryPos.getInstance(q);
1481    
1482                                    qPos.add(pk);
1483    
1484                                    list = (List<com.liferay.portlet.softwarecatalog.model.SCProductEntry>)QueryUtil.list(q,
1485                                                    getDialect(), start, end);
1486                            }
1487                            catch (Exception e) {
1488                                    throw processException(e);
1489                            }
1490                            finally {
1491                                    if (list == null) {
1492                                            list = new ArrayList<com.liferay.portlet.softwarecatalog.model.SCProductEntry>();
1493                                    }
1494    
1495                                    scProductEntryPersistence.cacheResult(list);
1496    
1497                                    FinderCacheUtil.putResult(FINDER_PATH_GET_SCPRODUCTENTRIES,
1498                                            finderArgs, list);
1499    
1500                                    closeSession(session);
1501                            }
1502                    }
1503    
1504                    return list;
1505            }
1506    
1507            public static final FinderPath FINDER_PATH_GET_SCPRODUCTENTRIES_SIZE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1508                            SCLicenseModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1509                            SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
1510                            "getSCProductEntriesSize", new String[] { Long.class.getName() });
1511    
1512            /**
1513             * Gets the number of s c product entries associated with the s c license.
1514             *
1515             * @param pk the primary key of the s c license to get the number of associated s c product entries for
1516             * @return the number of s c product entries associated with the s c license
1517             * @throws SystemException if a system exception occurred
1518             */
1519            public int getSCProductEntriesSize(long pk) throws SystemException {
1520                    Object[] finderArgs = new Object[] { pk };
1521    
1522                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SCPRODUCTENTRIES_SIZE,
1523                                    finderArgs, this);
1524    
1525                    if (count == null) {
1526                            Session session = null;
1527    
1528                            try {
1529                                    session = openSession();
1530    
1531                                    SQLQuery q = session.createSQLQuery(_SQL_GETSCPRODUCTENTRIESSIZE);
1532    
1533                                    q.addScalar(COUNT_COLUMN_NAME,
1534                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1535    
1536                                    QueryPos qPos = QueryPos.getInstance(q);
1537    
1538                                    qPos.add(pk);
1539    
1540                                    count = (Long)q.uniqueResult();
1541                            }
1542                            catch (Exception e) {
1543                                    throw processException(e);
1544                            }
1545                            finally {
1546                                    if (count == null) {
1547                                            count = Long.valueOf(0);
1548                                    }
1549    
1550                                    FinderCacheUtil.putResult(FINDER_PATH_GET_SCPRODUCTENTRIES_SIZE,
1551                                            finderArgs, count);
1552    
1553                                    closeSession(session);
1554                            }
1555                    }
1556    
1557                    return count.intValue();
1558            }
1559    
1560            public static final FinderPath FINDER_PATH_CONTAINS_SCPRODUCTENTRY = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1561                            SCLicenseModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1562                            SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
1563                            "containsSCProductEntry",
1564                            new String[] { Long.class.getName(), Long.class.getName() });
1565    
1566            /**
1567             * Determines whether the s c product entry is associated with the s c license.
1568             *
1569             * @param pk the primary key of the s c license
1570             * @param scProductEntryPK the primary key of the s c product entry
1571             * @return whether the s c product entry is associated with the s c license
1572             * @throws SystemException if a system exception occurred
1573             */
1574            public boolean containsSCProductEntry(long pk, long scProductEntryPK)
1575                    throws SystemException {
1576                    Object[] finderArgs = new Object[] { pk, scProductEntryPK };
1577    
1578                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SCPRODUCTENTRY,
1579                                    finderArgs, this);
1580    
1581                    if (value == null) {
1582                            try {
1583                                    value = Boolean.valueOf(containsSCProductEntry.contains(pk,
1584                                                            scProductEntryPK));
1585                            }
1586                            catch (Exception e) {
1587                                    throw processException(e);
1588                            }
1589                            finally {
1590                                    if (value == null) {
1591                                            value = Boolean.FALSE;
1592                                    }
1593    
1594                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SCPRODUCTENTRY,
1595                                            finderArgs, value);
1596                            }
1597                    }
1598    
1599                    return value.booleanValue();
1600            }
1601    
1602            /**
1603             * Determines whether the s c license has any s c product entries associated with it.
1604             *
1605             * @param pk the primary key of the s c license to check for associations with s c product entries
1606             * @return whether the s c license has any s c product entries associated with it
1607             * @throws SystemException if a system exception occurred
1608             */
1609            public boolean containsSCProductEntries(long pk) throws SystemException {
1610                    if (getSCProductEntriesSize(pk) > 0) {
1611                            return true;
1612                    }
1613                    else {
1614                            return false;
1615                    }
1616            }
1617    
1618            /**
1619             * 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.
1620             *
1621             * @param pk the primary key of the s c license
1622             * @param scProductEntryPK the primary key of the s c product entry
1623             * @throws SystemException if a system exception occurred
1624             */
1625            public void addSCProductEntry(long pk, long scProductEntryPK)
1626                    throws SystemException {
1627                    try {
1628                            addSCProductEntry.add(pk, scProductEntryPK);
1629                    }
1630                    catch (Exception e) {
1631                            throw processException(e);
1632                    }
1633                    finally {
1634                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1635                    }
1636            }
1637    
1638            /**
1639             * 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.
1640             *
1641             * @param pk the primary key of the s c license
1642             * @param scProductEntry the s c product entry
1643             * @throws SystemException if a system exception occurred
1644             */
1645            public void addSCProductEntry(long pk,
1646                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry)
1647                    throws SystemException {
1648                    try {
1649                            addSCProductEntry.add(pk, scProductEntry.getPrimaryKey());
1650                    }
1651                    catch (Exception e) {
1652                            throw processException(e);
1653                    }
1654                    finally {
1655                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1656                    }
1657            }
1658    
1659            /**
1660             * 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.
1661             *
1662             * @param pk the primary key of the s c license
1663             * @param scProductEntryPKs the primary keys of the s c product entries
1664             * @throws SystemException if a system exception occurred
1665             */
1666            public void addSCProductEntries(long pk, long[] scProductEntryPKs)
1667                    throws SystemException {
1668                    try {
1669                            for (long scProductEntryPK : scProductEntryPKs) {
1670                                    addSCProductEntry.add(pk, scProductEntryPK);
1671                            }
1672                    }
1673                    catch (Exception e) {
1674                            throw processException(e);
1675                    }
1676                    finally {
1677                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1678                    }
1679            }
1680    
1681            /**
1682             * 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.
1683             *
1684             * @param pk the primary key of the s c license
1685             * @param scProductEntries the s c product entries
1686             * @throws SystemException if a system exception occurred
1687             */
1688            public void addSCProductEntries(long pk,
1689                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1690                    throws SystemException {
1691                    try {
1692                            for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1693                                    addSCProductEntry.add(pk, scProductEntry.getPrimaryKey());
1694                            }
1695                    }
1696                    catch (Exception e) {
1697                            throw processException(e);
1698                    }
1699                    finally {
1700                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1701                    }
1702            }
1703    
1704            /**
1705             * 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.
1706             *
1707             * @param pk the primary key of the s c license to clear the associated s c product entries from
1708             * @throws SystemException if a system exception occurred
1709             */
1710            public void clearSCProductEntries(long pk) throws SystemException {
1711                    try {
1712                            clearSCProductEntries.clear(pk);
1713                    }
1714                    catch (Exception e) {
1715                            throw processException(e);
1716                    }
1717                    finally {
1718                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1719                    }
1720            }
1721    
1722            /**
1723             * 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.
1724             *
1725             * @param pk the primary key of the s c license
1726             * @param scProductEntryPK the primary key of the s c product entry
1727             * @throws SystemException if a system exception occurred
1728             */
1729            public void removeSCProductEntry(long pk, long scProductEntryPK)
1730                    throws SystemException {
1731                    try {
1732                            removeSCProductEntry.remove(pk, scProductEntryPK);
1733                    }
1734                    catch (Exception e) {
1735                            throw processException(e);
1736                    }
1737                    finally {
1738                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1739                    }
1740            }
1741    
1742            /**
1743             * 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.
1744             *
1745             * @param pk the primary key of the s c license
1746             * @param scProductEntry the s c product entry
1747             * @throws SystemException if a system exception occurred
1748             */
1749            public void removeSCProductEntry(long pk,
1750                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry)
1751                    throws SystemException {
1752                    try {
1753                            removeSCProductEntry.remove(pk, scProductEntry.getPrimaryKey());
1754                    }
1755                    catch (Exception e) {
1756                            throw processException(e);
1757                    }
1758                    finally {
1759                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1760                    }
1761            }
1762    
1763            /**
1764             * 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.
1765             *
1766             * @param pk the primary key of the s c license
1767             * @param scProductEntryPKs the primary keys of the s c product entries
1768             * @throws SystemException if a system exception occurred
1769             */
1770            public void removeSCProductEntries(long pk, long[] scProductEntryPKs)
1771                    throws SystemException {
1772                    try {
1773                            for (long scProductEntryPK : scProductEntryPKs) {
1774                                    removeSCProductEntry.remove(pk, scProductEntryPK);
1775                            }
1776                    }
1777                    catch (Exception e) {
1778                            throw processException(e);
1779                    }
1780                    finally {
1781                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1782                    }
1783            }
1784    
1785            /**
1786             * 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.
1787             *
1788             * @param pk the primary key of the s c license
1789             * @param scProductEntries the s c product entries
1790             * @throws SystemException if a system exception occurred
1791             */
1792            public void removeSCProductEntries(long pk,
1793                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1794                    throws SystemException {
1795                    try {
1796                            for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1797                                    removeSCProductEntry.remove(pk, scProductEntry.getPrimaryKey());
1798                            }
1799                    }
1800                    catch (Exception e) {
1801                            throw processException(e);
1802                    }
1803                    finally {
1804                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1805                    }
1806            }
1807    
1808            /**
1809             * 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.
1810             *
1811             * @param pk the primary key of the s c license to set the associations for
1812             * @param scProductEntryPKs the primary keys of the s c product entries to be associated with the s c license
1813             * @throws SystemException if a system exception occurred
1814             */
1815            public void setSCProductEntries(long pk, long[] scProductEntryPKs)
1816                    throws SystemException {
1817                    try {
1818                            Set<Long> scProductEntryPKSet = SetUtil.fromArray(scProductEntryPKs);
1819    
1820                            List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries =
1821                                    getSCProductEntries(pk);
1822    
1823                            for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1824                                    if (!scProductEntryPKSet.remove(scProductEntry.getPrimaryKey())) {
1825                                            removeSCProductEntry.remove(pk,
1826                                                    scProductEntry.getPrimaryKey());
1827                                    }
1828                            }
1829    
1830                            for (Long scProductEntryPK : scProductEntryPKSet) {
1831                                    addSCProductEntry.add(pk, scProductEntryPK);
1832                            }
1833                    }
1834                    catch (Exception e) {
1835                            throw processException(e);
1836                    }
1837                    finally {
1838                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1839                    }
1840            }
1841    
1842            /**
1843             * 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.
1844             *
1845             * @param pk the primary key of the s c license to set the associations for
1846             * @param scProductEntries the s c product entries to be associated with the s c license
1847             * @throws SystemException if a system exception occurred
1848             */
1849            public void setSCProductEntries(long pk,
1850                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1851                    throws SystemException {
1852                    try {
1853                            long[] scProductEntryPKs = new long[scProductEntries.size()];
1854    
1855                            for (int i = 0; i < scProductEntries.size(); i++) {
1856                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry =
1857                                            scProductEntries.get(i);
1858    
1859                                    scProductEntryPKs[i] = scProductEntry.getPrimaryKey();
1860                            }
1861    
1862                            setSCProductEntries(pk, scProductEntryPKs);
1863                    }
1864                    catch (Exception e) {
1865                            throw processException(e);
1866                    }
1867                    finally {
1868                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1869                    }
1870            }
1871    
1872            /**
1873             * Initializes the s c license persistence.
1874             */
1875            public void afterPropertiesSet() {
1876                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1877                                            com.liferay.portal.util.PropsUtil.get(
1878                                                    "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCLicense")));
1879    
1880                    if (listenerClassNames.length > 0) {
1881                            try {
1882                                    List<ModelListener<SCLicense>> listenersList = new ArrayList<ModelListener<SCLicense>>();
1883    
1884                                    for (String listenerClassName : listenerClassNames) {
1885                                            listenersList.add((ModelListener<SCLicense>)InstanceFactory.newInstance(
1886                                                            listenerClassName));
1887                                    }
1888    
1889                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1890                            }
1891                            catch (Exception e) {
1892                                    _log.error(e);
1893                            }
1894                    }
1895    
1896                    containsSCProductEntry = new ContainsSCProductEntry(this);
1897    
1898                    addSCProductEntry = new AddSCProductEntry(this);
1899                    clearSCProductEntries = new ClearSCProductEntries(this);
1900                    removeSCProductEntry = new RemoveSCProductEntry(this);
1901            }
1902    
1903            public void destroy() {
1904                    EntityCacheUtil.removeCache(SCLicenseImpl.class.getName());
1905                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1906                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1907            }
1908    
1909            @BeanReference(type = SCLicensePersistence.class)
1910            protected SCLicensePersistence scLicensePersistence;
1911            @BeanReference(type = SCFrameworkVersionPersistence.class)
1912            protected SCFrameworkVersionPersistence scFrameworkVersionPersistence;
1913            @BeanReference(type = SCProductEntryPersistence.class)
1914            protected SCProductEntryPersistence scProductEntryPersistence;
1915            @BeanReference(type = SCProductScreenshotPersistence.class)
1916            protected SCProductScreenshotPersistence scProductScreenshotPersistence;
1917            @BeanReference(type = SCProductVersionPersistence.class)
1918            protected SCProductVersionPersistence scProductVersionPersistence;
1919            @BeanReference(type = ResourcePersistence.class)
1920            protected ResourcePersistence resourcePersistence;
1921            @BeanReference(type = UserPersistence.class)
1922            protected UserPersistence userPersistence;
1923            protected ContainsSCProductEntry containsSCProductEntry;
1924            protected AddSCProductEntry addSCProductEntry;
1925            protected ClearSCProductEntries clearSCProductEntries;
1926            protected RemoveSCProductEntry removeSCProductEntry;
1927    
1928            protected class ContainsSCProductEntry {
1929                    protected ContainsSCProductEntry(
1930                            SCLicensePersistenceImpl persistenceImpl) {
1931                            super();
1932    
1933                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1934                                            _SQL_CONTAINSSCPRODUCTENTRY,
1935                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
1936                                            RowMapper.COUNT);
1937                    }
1938    
1939                    protected boolean contains(long licenseId, long productEntryId) {
1940                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1941                                                    new Long(licenseId), new Long(productEntryId)
1942                                            });
1943    
1944                            if (results.size() > 0) {
1945                                    Integer count = results.get(0);
1946    
1947                                    if (count.intValue() > 0) {
1948                                            return true;
1949                                    }
1950                            }
1951    
1952                            return false;
1953                    }
1954    
1955                    private MappingSqlQuery<Integer> _mappingSqlQuery;
1956            }
1957    
1958            protected class AddSCProductEntry {
1959                    protected AddSCProductEntry(SCLicensePersistenceImpl persistenceImpl) {
1960                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1961                                            "INSERT INTO SCLicenses_SCProductEntries (licenseId, productEntryId) VALUES (?, ?)",
1962                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
1963                            _persistenceImpl = persistenceImpl;
1964                    }
1965    
1966                    protected void add(long licenseId, long productEntryId)
1967                            throws SystemException {
1968                            if (!_persistenceImpl.containsSCProductEntry.contains(licenseId,
1969                                                    productEntryId)) {
1970                                    ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry>[] scProductEntryListeners =
1971                                            scProductEntryPersistence.getListeners();
1972    
1973                                    for (ModelListener<SCLicense> listener : listeners) {
1974                                            listener.onBeforeAddAssociation(licenseId,
1975                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1976                                                    productEntryId);
1977                                    }
1978    
1979                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1980                                            listener.onBeforeAddAssociation(productEntryId,
1981                                                    SCLicense.class.getName(), licenseId);
1982                                    }
1983    
1984                                    _sqlUpdate.update(new Object[] {
1985                                                    new Long(licenseId), new Long(productEntryId)
1986                                            });
1987    
1988                                    for (ModelListener<SCLicense> listener : listeners) {
1989                                            listener.onAfterAddAssociation(licenseId,
1990                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1991                                                    productEntryId);
1992                                    }
1993    
1994                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1995                                            listener.onAfterAddAssociation(productEntryId,
1996                                                    SCLicense.class.getName(), licenseId);
1997                                    }
1998                            }
1999                    }
2000    
2001                    private SqlUpdate _sqlUpdate;
2002                    private SCLicensePersistenceImpl _persistenceImpl;
2003            }
2004    
2005            protected class ClearSCProductEntries {
2006                    protected ClearSCProductEntries(
2007                            SCLicensePersistenceImpl persistenceImpl) {
2008                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2009                                            "DELETE FROM SCLicenses_SCProductEntries WHERE licenseId = ?",
2010                                            new int[] { java.sql.Types.BIGINT });
2011                    }
2012    
2013                    protected void clear(long licenseId) throws SystemException {
2014                            ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry>[] scProductEntryListeners =
2015                                    scProductEntryPersistence.getListeners();
2016    
2017                            List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries =
2018                                    null;
2019    
2020                            if ((listeners.length > 0) || (scProductEntryListeners.length > 0)) {
2021                                    scProductEntries = getSCProductEntries(licenseId);
2022    
2023                                    for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
2024                                            for (ModelListener<SCLicense> listener : listeners) {
2025                                                    listener.onBeforeRemoveAssociation(licenseId,
2026                                                            com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
2027                                                            scProductEntry.getPrimaryKey());
2028                                            }
2029    
2030                                            for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
2031                                                    listener.onBeforeRemoveAssociation(scProductEntry.getPrimaryKey(),
2032                                                            SCLicense.class.getName(), licenseId);
2033                                            }
2034                                    }
2035                            }
2036    
2037                            _sqlUpdate.update(new Object[] { new Long(licenseId) });
2038    
2039                            if ((listeners.length > 0) || (scProductEntryListeners.length > 0)) {
2040                                    for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
2041                                            for (ModelListener<SCLicense> listener : listeners) {
2042                                                    listener.onAfterRemoveAssociation(licenseId,
2043                                                            com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
2044                                                            scProductEntry.getPrimaryKey());
2045                                            }
2046    
2047                                            for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
2048                                                    listener.onAfterRemoveAssociation(scProductEntry.getPrimaryKey(),
2049                                                            SCLicense.class.getName(), licenseId);
2050                                            }
2051                                    }
2052                            }
2053                    }
2054    
2055                    private SqlUpdate _sqlUpdate;
2056            }
2057    
2058            protected class RemoveSCProductEntry {
2059                    protected RemoveSCProductEntry(SCLicensePersistenceImpl persistenceImpl) {
2060                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2061                                            "DELETE FROM SCLicenses_SCProductEntries WHERE licenseId = ? AND productEntryId = ?",
2062                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2063                            _persistenceImpl = persistenceImpl;
2064                    }
2065    
2066                    protected void remove(long licenseId, long productEntryId)
2067                            throws SystemException {
2068                            if (_persistenceImpl.containsSCProductEntry.contains(licenseId,
2069                                                    productEntryId)) {
2070                                    ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry>[] scProductEntryListeners =
2071                                            scProductEntryPersistence.getListeners();
2072    
2073                                    for (ModelListener<SCLicense> listener : listeners) {
2074                                            listener.onBeforeRemoveAssociation(licenseId,
2075                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
2076                                                    productEntryId);
2077                                    }
2078    
2079                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
2080                                            listener.onBeforeRemoveAssociation(productEntryId,
2081                                                    SCLicense.class.getName(), licenseId);
2082                                    }
2083    
2084                                    _sqlUpdate.update(new Object[] {
2085                                                    new Long(licenseId), new Long(productEntryId)
2086                                            });
2087    
2088                                    for (ModelListener<SCLicense> listener : listeners) {
2089                                            listener.onAfterRemoveAssociation(licenseId,
2090                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
2091                                                    productEntryId);
2092                                    }
2093    
2094                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
2095                                            listener.onAfterRemoveAssociation(productEntryId,
2096                                                    SCLicense.class.getName(), licenseId);
2097                                    }
2098                            }
2099                    }
2100    
2101                    private SqlUpdate _sqlUpdate;
2102                    private SCLicensePersistenceImpl _persistenceImpl;
2103            }
2104    
2105            private static final String _SQL_SELECT_SCLICENSE = "SELECT scLicense FROM SCLicense scLicense";
2106            private static final String _SQL_SELECT_SCLICENSE_WHERE = "SELECT scLicense FROM SCLicense scLicense WHERE ";
2107            private static final String _SQL_COUNT_SCLICENSE = "SELECT COUNT(scLicense) FROM SCLicense scLicense";
2108            private static final String _SQL_COUNT_SCLICENSE_WHERE = "SELECT COUNT(scLicense) FROM SCLicense scLicense WHERE ";
2109            private static final String _SQL_GETSCPRODUCTENTRIES = "SELECT {SCProductEntry.*} FROM SCProductEntry INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.productEntryId = SCProductEntry.productEntryId) WHERE (SCLicenses_SCProductEntries.licenseId = ?)";
2110            private static final String _SQL_GETSCPRODUCTENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE licenseId = ?";
2111            private static final String _SQL_CONTAINSSCPRODUCTENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE licenseId = ? AND productEntryId = ?";
2112            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "scLicense.active = ?";
2113            private static final String _FINDER_COLUMN_A_R_ACTIVE_2 = "scLicense.active = ? AND ";
2114            private static final String _FINDER_COLUMN_A_R_RECOMMENDED_2 = "scLicense.recommended = ?";
2115            private static final String _ORDER_BY_ENTITY_ALIAS = "scLicense.";
2116            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCLicense exists with the primary key ";
2117            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCLicense exists with the key {";
2118            private static Log _log = LogFactoryUtil.getLog(SCLicensePersistenceImpl.class);
2119    }