001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.softwarecatalog.service.persistence;
016    
017    import com.liferay.portal.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     * @author    Brian Wing Shun Chan
063     * @see       SCLicensePersistence
064     * @see       SCLicenseUtil
065     * @generated
066     */
067    public class SCLicensePersistenceImpl extends BasePersistenceImpl<SCLicense>
068            implements SCLicensePersistence {
069            public static final String FINDER_CLASS_NAME_ENTITY = SCLicenseImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
071                    ".List";
072            public static final FinderPath FINDER_PATH_FIND_BY_ACTIVE = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
073                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
074                            "findByActive",
075                            new String[] {
076                                    Boolean.class.getName(),
077                                    
078                            "java.lang.Integer", "java.lang.Integer",
079                                    "com.liferay.portal.kernel.util.OrderByComparator"
080                            });
081            public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
082                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
083                            "countByActive", new String[] { Boolean.class.getName() });
084            public static final FinderPath FINDER_PATH_FIND_BY_A_R = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
085                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
086                            "findByA_R",
087                            new String[] {
088                                    Boolean.class.getName(), Boolean.class.getName(),
089                                    
090                            "java.lang.Integer", "java.lang.Integer",
091                                    "com.liferay.portal.kernel.util.OrderByComparator"
092                            });
093            public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
094                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
095                            "countByA_R",
096                            new String[] { Boolean.class.getName(), Boolean.class.getName() });
097            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
098                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099                            "findAll", new String[0]);
100            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
101                            SCLicenseModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "countAll", new String[0]);
103    
104            public void cacheResult(SCLicense scLicense) {
105                    EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
106                            SCLicenseImpl.class, scLicense.getPrimaryKey(), scLicense);
107            }
108    
109            public void cacheResult(List<SCLicense> scLicenses) {
110                    for (SCLicense scLicense : scLicenses) {
111                            if (EntityCacheUtil.getResult(
112                                                    SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
113                                                    SCLicenseImpl.class, scLicense.getPrimaryKey(), this) == null) {
114                                    cacheResult(scLicense);
115                            }
116                    }
117            }
118    
119            public void clearCache() {
120                    CacheRegistryUtil.clear(SCLicenseImpl.class.getName());
121                    EntityCacheUtil.clearCache(SCLicenseImpl.class.getName());
122                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
123                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
124            }
125    
126            public void clearCache(SCLicense scLicense) {
127                    EntityCacheUtil.removeResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
128                            SCLicenseImpl.class, scLicense.getPrimaryKey());
129            }
130    
131            public SCLicense create(long licenseId) {
132                    SCLicense scLicense = new SCLicenseImpl();
133    
134                    scLicense.setNew(true);
135                    scLicense.setPrimaryKey(licenseId);
136    
137                    return scLicense;
138            }
139    
140            public SCLicense remove(Serializable primaryKey)
141                    throws NoSuchModelException, SystemException {
142                    return remove(((Long)primaryKey).longValue());
143            }
144    
145            public SCLicense remove(long licenseId)
146                    throws NoSuchLicenseException, SystemException {
147                    Session session = null;
148    
149                    try {
150                            session = openSession();
151    
152                            SCLicense scLicense = (SCLicense)session.get(SCLicenseImpl.class,
153                                            new Long(licenseId));
154    
155                            if (scLicense == null) {
156                                    if (_log.isWarnEnabled()) {
157                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + licenseId);
158                                    }
159    
160                                    throw new NoSuchLicenseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
161                                            licenseId);
162                            }
163    
164                            return remove(scLicense);
165                    }
166                    catch (NoSuchLicenseException nsee) {
167                            throw nsee;
168                    }
169                    catch (Exception e) {
170                            throw processException(e);
171                    }
172                    finally {
173                            closeSession(session);
174                    }
175            }
176    
177            protected SCLicense removeImpl(SCLicense scLicense)
178                    throws SystemException {
179                    scLicense = toUnwrappedModel(scLicense);
180    
181                    try {
182                            clearSCProductEntries.clear(scLicense.getPrimaryKey());
183                    }
184                    catch (Exception e) {
185                            throw processException(e);
186                    }
187                    finally {
188                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
189                    }
190    
191                    Session session = null;
192    
193                    try {
194                            session = openSession();
195    
196                            if (scLicense.isCachedModel() || BatchSessionUtil.isEnabled()) {
197                                    Object staleObject = session.get(SCLicenseImpl.class,
198                                                    scLicense.getPrimaryKeyObj());
199    
200                                    if (staleObject != null) {
201                                            session.evict(staleObject);
202                                    }
203                            }
204    
205                            session.delete(scLicense);
206    
207                            session.flush();
208                    }
209                    catch (Exception e) {
210                            throw processException(e);
211                    }
212                    finally {
213                            closeSession(session);
214                    }
215    
216                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
217    
218                    EntityCacheUtil.removeResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
219                            SCLicenseImpl.class, scLicense.getPrimaryKey());
220    
221                    return scLicense;
222            }
223    
224            public SCLicense updateImpl(
225                    com.liferay.portlet.softwarecatalog.model.SCLicense scLicense,
226                    boolean merge) throws SystemException {
227                    scLicense = toUnwrappedModel(scLicense);
228    
229                    Session session = null;
230    
231                    try {
232                            session = openSession();
233    
234                            BatchSessionUtil.update(session, scLicense, merge);
235    
236                            scLicense.setNew(false);
237                    }
238                    catch (Exception e) {
239                            throw processException(e);
240                    }
241                    finally {
242                            closeSession(session);
243                    }
244    
245                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
246    
247                    EntityCacheUtil.putResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
248                            SCLicenseImpl.class, scLicense.getPrimaryKey(), scLicense);
249    
250                    return scLicense;
251            }
252    
253            protected SCLicense toUnwrappedModel(SCLicense scLicense) {
254                    if (scLicense instanceof SCLicenseImpl) {
255                            return scLicense;
256                    }
257    
258                    SCLicenseImpl scLicenseImpl = new SCLicenseImpl();
259    
260                    scLicenseImpl.setNew(scLicense.isNew());
261                    scLicenseImpl.setPrimaryKey(scLicense.getPrimaryKey());
262    
263                    scLicenseImpl.setLicenseId(scLicense.getLicenseId());
264                    scLicenseImpl.setName(scLicense.getName());
265                    scLicenseImpl.setUrl(scLicense.getUrl());
266                    scLicenseImpl.setOpenSource(scLicense.isOpenSource());
267                    scLicenseImpl.setActive(scLicense.isActive());
268                    scLicenseImpl.setRecommended(scLicense.isRecommended());
269    
270                    return scLicenseImpl;
271            }
272    
273            public SCLicense findByPrimaryKey(Serializable primaryKey)
274                    throws NoSuchModelException, SystemException {
275                    return findByPrimaryKey(((Long)primaryKey).longValue());
276            }
277    
278            public SCLicense findByPrimaryKey(long licenseId)
279                    throws NoSuchLicenseException, SystemException {
280                    SCLicense scLicense = fetchByPrimaryKey(licenseId);
281    
282                    if (scLicense == null) {
283                            if (_log.isWarnEnabled()) {
284                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + licenseId);
285                            }
286    
287                            throw new NoSuchLicenseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
288                                    licenseId);
289                    }
290    
291                    return scLicense;
292            }
293    
294            public SCLicense fetchByPrimaryKey(Serializable primaryKey)
295                    throws SystemException {
296                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
297            }
298    
299            public SCLicense fetchByPrimaryKey(long licenseId)
300                    throws SystemException {
301                    SCLicense scLicense = (SCLicense)EntityCacheUtil.getResult(SCLicenseModelImpl.ENTITY_CACHE_ENABLED,
302                                    SCLicenseImpl.class, licenseId, this);
303    
304                    if (scLicense == null) {
305                            Session session = null;
306    
307                            try {
308                                    session = openSession();
309    
310                                    scLicense = (SCLicense)session.get(SCLicenseImpl.class,
311                                                    new Long(licenseId));
312                            }
313                            catch (Exception e) {
314                                    throw processException(e);
315                            }
316                            finally {
317                                    if (scLicense != null) {
318                                            cacheResult(scLicense);
319                                    }
320    
321                                    closeSession(session);
322                            }
323                    }
324    
325                    return scLicense;
326            }
327    
328            public List<SCLicense> findByActive(boolean active)
329                    throws SystemException {
330                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
331            }
332    
333            public List<SCLicense> findByActive(boolean active, int start, int end)
334                    throws SystemException {
335                    return findByActive(active, start, end, null);
336            }
337    
338            public List<SCLicense> findByActive(boolean active, int start, int end,
339                    OrderByComparator orderByComparator) throws SystemException {
340                    Object[] finderArgs = new Object[] {
341                                    active,
342                                    
343                                    String.valueOf(start), String.valueOf(end),
344                                    String.valueOf(orderByComparator)
345                            };
346    
347                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
348                                    finderArgs, this);
349    
350                    if (list == null) {
351                            Session session = null;
352    
353                            try {
354                                    session = openSession();
355    
356                                    StringBundler query = null;
357    
358                                    if (orderByComparator != null) {
359                                            query = new StringBundler(3 +
360                                                            (orderByComparator.getOrderByFields().length * 3));
361                                    }
362                                    else {
363                                            query = new StringBundler(3);
364                                    }
365    
366                                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
367    
368                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
369    
370                                    if (orderByComparator != null) {
371                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
372                                                    orderByComparator);
373                                    }
374    
375                                    else {
376                                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
377                                    }
378    
379                                    String sql = query.toString();
380    
381                                    Query q = session.createQuery(sql);
382    
383                                    QueryPos qPos = QueryPos.getInstance(q);
384    
385                                    qPos.add(active);
386    
387                                    list = (List<SCLicense>)QueryUtil.list(q, getDialect(), start,
388                                                    end);
389                            }
390                            catch (Exception e) {
391                                    throw processException(e);
392                            }
393                            finally {
394                                    if (list == null) {
395                                            list = new ArrayList<SCLicense>();
396                                    }
397    
398                                    cacheResult(list);
399    
400                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
401                                            finderArgs, list);
402    
403                                    closeSession(session);
404                            }
405                    }
406    
407                    return list;
408            }
409    
410            public SCLicense findByActive_First(boolean active,
411                    OrderByComparator orderByComparator)
412                    throws NoSuchLicenseException, SystemException {
413                    List<SCLicense> list = findByActive(active, 0, 1, orderByComparator);
414    
415                    if (list.isEmpty()) {
416                            StringBundler msg = new StringBundler(4);
417    
418                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
419    
420                            msg.append("active=");
421                            msg.append(active);
422    
423                            msg.append(StringPool.CLOSE_CURLY_BRACE);
424    
425                            throw new NoSuchLicenseException(msg.toString());
426                    }
427                    else {
428                            return list.get(0);
429                    }
430            }
431    
432            public SCLicense findByActive_Last(boolean active,
433                    OrderByComparator orderByComparator)
434                    throws NoSuchLicenseException, SystemException {
435                    int count = countByActive(active);
436    
437                    List<SCLicense> list = findByActive(active, count - 1, count,
438                                    orderByComparator);
439    
440                    if (list.isEmpty()) {
441                            StringBundler msg = new StringBundler(4);
442    
443                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
444    
445                            msg.append("active=");
446                            msg.append(active);
447    
448                            msg.append(StringPool.CLOSE_CURLY_BRACE);
449    
450                            throw new NoSuchLicenseException(msg.toString());
451                    }
452                    else {
453                            return list.get(0);
454                    }
455            }
456    
457            public SCLicense[] findByActive_PrevAndNext(long licenseId, boolean active,
458                    OrderByComparator orderByComparator)
459                    throws NoSuchLicenseException, SystemException {
460                    SCLicense scLicense = findByPrimaryKey(licenseId);
461    
462                    Session session = null;
463    
464                    try {
465                            session = openSession();
466    
467                            SCLicense[] array = new SCLicenseImpl[3];
468    
469                            array[0] = getByActive_PrevAndNext(session, scLicense, active,
470                                            orderByComparator, true);
471    
472                            array[1] = scLicense;
473    
474                            array[2] = getByActive_PrevAndNext(session, scLicense, active,
475                                            orderByComparator, false);
476    
477                            return array;
478                    }
479                    catch (Exception e) {
480                            throw processException(e);
481                    }
482                    finally {
483                            closeSession(session);
484                    }
485            }
486    
487            protected SCLicense getByActive_PrevAndNext(Session session,
488                    SCLicense scLicense, boolean active,
489                    OrderByComparator orderByComparator, boolean previous) {
490                    StringBundler query = null;
491    
492                    if (orderByComparator != null) {
493                            query = new StringBundler(6 +
494                                            (orderByComparator.getOrderByFields().length * 6));
495                    }
496                    else {
497                            query = new StringBundler(3);
498                    }
499    
500                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
501    
502                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
503    
504                    if (orderByComparator != null) {
505                            String[] orderByFields = orderByComparator.getOrderByFields();
506    
507                            if (orderByFields.length > 0) {
508                                    query.append(WHERE_AND);
509                            }
510    
511                            for (int i = 0; i < orderByFields.length; i++) {
512                                    query.append(_ORDER_BY_ENTITY_ALIAS);
513                                    query.append(orderByFields[i]);
514    
515                                    if ((i + 1) < orderByFields.length) {
516                                            if (orderByComparator.isAscending() ^ previous) {
517                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
518                                            }
519                                            else {
520                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
521                                            }
522                                    }
523                                    else {
524                                            if (orderByComparator.isAscending() ^ previous) {
525                                                    query.append(WHERE_GREATER_THAN);
526                                            }
527                                            else {
528                                                    query.append(WHERE_LESSER_THAN);
529                                            }
530                                    }
531                            }
532    
533                            query.append(ORDER_BY_CLAUSE);
534    
535                            for (int i = 0; i < orderByFields.length; i++) {
536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
537                                    query.append(orderByFields[i]);
538    
539                                    if ((i + 1) < orderByFields.length) {
540                                            if (orderByComparator.isAscending() ^ previous) {
541                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
542                                            }
543                                            else {
544                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
545                                            }
546                                    }
547                                    else {
548                                            if (orderByComparator.isAscending() ^ previous) {
549                                                    query.append(ORDER_BY_ASC);
550                                            }
551                                            else {
552                                                    query.append(ORDER_BY_DESC);
553                                            }
554                                    }
555                            }
556                    }
557    
558                    else {
559                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
560                    }
561    
562                    String sql = query.toString();
563    
564                    Query q = session.createQuery(sql);
565    
566                    q.setFirstResult(0);
567                    q.setMaxResults(2);
568    
569                    QueryPos qPos = QueryPos.getInstance(q);
570    
571                    qPos.add(active);
572    
573                    if (orderByComparator != null) {
574                            Object[] values = orderByComparator.getOrderByValues(scLicense);
575    
576                            for (Object value : values) {
577                                    qPos.add(value);
578                            }
579                    }
580    
581                    List<SCLicense> list = q.list();
582    
583                    if (list.size() == 2) {
584                            return list.get(1);
585                    }
586                    else {
587                            return null;
588                    }
589            }
590    
591            public List<SCLicense> findByA_R(boolean active, boolean recommended)
592                    throws SystemException {
593                    return findByA_R(active, recommended, QueryUtil.ALL_POS,
594                            QueryUtil.ALL_POS, null);
595            }
596    
597            public List<SCLicense> findByA_R(boolean active, boolean recommended,
598                    int start, int end) throws SystemException {
599                    return findByA_R(active, recommended, start, end, null);
600            }
601    
602            public List<SCLicense> findByA_R(boolean active, boolean recommended,
603                    int start, int end, OrderByComparator orderByComparator)
604                    throws SystemException {
605                    Object[] finderArgs = new Object[] {
606                                    active, recommended,
607                                    
608                                    String.valueOf(start), String.valueOf(end),
609                                    String.valueOf(orderByComparator)
610                            };
611    
612                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_A_R,
613                                    finderArgs, this);
614    
615                    if (list == null) {
616                            Session session = null;
617    
618                            try {
619                                    session = openSession();
620    
621                                    StringBundler query = null;
622    
623                                    if (orderByComparator != null) {
624                                            query = new StringBundler(4 +
625                                                            (orderByComparator.getOrderByFields().length * 3));
626                                    }
627                                    else {
628                                            query = new StringBundler(4);
629                                    }
630    
631                                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
632    
633                                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
634    
635                                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
636    
637                                    if (orderByComparator != null) {
638                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
639                                                    orderByComparator);
640                                    }
641    
642                                    else {
643                                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
644                                    }
645    
646                                    String sql = query.toString();
647    
648                                    Query q = session.createQuery(sql);
649    
650                                    QueryPos qPos = QueryPos.getInstance(q);
651    
652                                    qPos.add(active);
653    
654                                    qPos.add(recommended);
655    
656                                    list = (List<SCLicense>)QueryUtil.list(q, getDialect(), start,
657                                                    end);
658                            }
659                            catch (Exception e) {
660                                    throw processException(e);
661                            }
662                            finally {
663                                    if (list == null) {
664                                            list = new ArrayList<SCLicense>();
665                                    }
666    
667                                    cacheResult(list);
668    
669                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_A_R, finderArgs,
670                                            list);
671    
672                                    closeSession(session);
673                            }
674                    }
675    
676                    return list;
677            }
678    
679            public SCLicense findByA_R_First(boolean active, boolean recommended,
680                    OrderByComparator orderByComparator)
681                    throws NoSuchLicenseException, SystemException {
682                    List<SCLicense> list = findByA_R(active, recommended, 0, 1,
683                                    orderByComparator);
684    
685                    if (list.isEmpty()) {
686                            StringBundler msg = new StringBundler(6);
687    
688                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
689    
690                            msg.append("active=");
691                            msg.append(active);
692    
693                            msg.append(", recommended=");
694                            msg.append(recommended);
695    
696                            msg.append(StringPool.CLOSE_CURLY_BRACE);
697    
698                            throw new NoSuchLicenseException(msg.toString());
699                    }
700                    else {
701                            return list.get(0);
702                    }
703            }
704    
705            public SCLicense findByA_R_Last(boolean active, boolean recommended,
706                    OrderByComparator orderByComparator)
707                    throws NoSuchLicenseException, SystemException {
708                    int count = countByA_R(active, recommended);
709    
710                    List<SCLicense> list = findByA_R(active, recommended, count - 1, count,
711                                    orderByComparator);
712    
713                    if (list.isEmpty()) {
714                            StringBundler msg = new StringBundler(6);
715    
716                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
717    
718                            msg.append("active=");
719                            msg.append(active);
720    
721                            msg.append(", recommended=");
722                            msg.append(recommended);
723    
724                            msg.append(StringPool.CLOSE_CURLY_BRACE);
725    
726                            throw new NoSuchLicenseException(msg.toString());
727                    }
728                    else {
729                            return list.get(0);
730                    }
731            }
732    
733            public SCLicense[] findByA_R_PrevAndNext(long licenseId, boolean active,
734                    boolean recommended, OrderByComparator orderByComparator)
735                    throws NoSuchLicenseException, SystemException {
736                    SCLicense scLicense = findByPrimaryKey(licenseId);
737    
738                    Session session = null;
739    
740                    try {
741                            session = openSession();
742    
743                            SCLicense[] array = new SCLicenseImpl[3];
744    
745                            array[0] = getByA_R_PrevAndNext(session, scLicense, active,
746                                            recommended, orderByComparator, true);
747    
748                            array[1] = scLicense;
749    
750                            array[2] = getByA_R_PrevAndNext(session, scLicense, active,
751                                            recommended, orderByComparator, false);
752    
753                            return array;
754                    }
755                    catch (Exception e) {
756                            throw processException(e);
757                    }
758                    finally {
759                            closeSession(session);
760                    }
761            }
762    
763            protected SCLicense getByA_R_PrevAndNext(Session session,
764                    SCLicense scLicense, boolean active, boolean recommended,
765                    OrderByComparator orderByComparator, boolean previous) {
766                    StringBundler query = null;
767    
768                    if (orderByComparator != null) {
769                            query = new StringBundler(6 +
770                                            (orderByComparator.getOrderByFields().length * 6));
771                    }
772                    else {
773                            query = new StringBundler(3);
774                    }
775    
776                    query.append(_SQL_SELECT_SCLICENSE_WHERE);
777    
778                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
779    
780                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
781    
782                    if (orderByComparator != null) {
783                            String[] orderByFields = orderByComparator.getOrderByFields();
784    
785                            if (orderByFields.length > 0) {
786                                    query.append(WHERE_AND);
787                            }
788    
789                            for (int i = 0; i < orderByFields.length; i++) {
790                                    query.append(_ORDER_BY_ENTITY_ALIAS);
791                                    query.append(orderByFields[i]);
792    
793                                    if ((i + 1) < orderByFields.length) {
794                                            if (orderByComparator.isAscending() ^ previous) {
795                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
796                                            }
797                                            else {
798                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
799                                            }
800                                    }
801                                    else {
802                                            if (orderByComparator.isAscending() ^ previous) {
803                                                    query.append(WHERE_GREATER_THAN);
804                                            }
805                                            else {
806                                                    query.append(WHERE_LESSER_THAN);
807                                            }
808                                    }
809                            }
810    
811                            query.append(ORDER_BY_CLAUSE);
812    
813                            for (int i = 0; i < orderByFields.length; i++) {
814                                    query.append(_ORDER_BY_ENTITY_ALIAS);
815                                    query.append(orderByFields[i]);
816    
817                                    if ((i + 1) < orderByFields.length) {
818                                            if (orderByComparator.isAscending() ^ previous) {
819                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
820                                            }
821                                            else {
822                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
823                                            }
824                                    }
825                                    else {
826                                            if (orderByComparator.isAscending() ^ previous) {
827                                                    query.append(ORDER_BY_ASC);
828                                            }
829                                            else {
830                                                    query.append(ORDER_BY_DESC);
831                                            }
832                                    }
833                            }
834                    }
835    
836                    else {
837                            query.append(SCLicenseModelImpl.ORDER_BY_JPQL);
838                    }
839    
840                    String sql = query.toString();
841    
842                    Query q = session.createQuery(sql);
843    
844                    q.setFirstResult(0);
845                    q.setMaxResults(2);
846    
847                    QueryPos qPos = QueryPos.getInstance(q);
848    
849                    qPos.add(active);
850    
851                    qPos.add(recommended);
852    
853                    if (orderByComparator != null) {
854                            Object[] values = orderByComparator.getOrderByValues(scLicense);
855    
856                            for (Object value : values) {
857                                    qPos.add(value);
858                            }
859                    }
860    
861                    List<SCLicense> list = q.list();
862    
863                    if (list.size() == 2) {
864                            return list.get(1);
865                    }
866                    else {
867                            return null;
868                    }
869            }
870    
871            public List<SCLicense> findAll() throws SystemException {
872                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
873            }
874    
875            public List<SCLicense> findAll(int start, int end)
876                    throws SystemException {
877                    return findAll(start, end, null);
878            }
879    
880            public List<SCLicense> findAll(int start, int end,
881                    OrderByComparator orderByComparator) throws SystemException {
882                    Object[] finderArgs = new Object[] {
883                                    String.valueOf(start), String.valueOf(end),
884                                    String.valueOf(orderByComparator)
885                            };
886    
887                    List<SCLicense> list = (List<SCLicense>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
888                                    finderArgs, this);
889    
890                    if (list == null) {
891                            Session session = null;
892    
893                            try {
894                                    session = openSession();
895    
896                                    StringBundler query = null;
897                                    String sql = null;
898    
899                                    if (orderByComparator != null) {
900                                            query = new StringBundler(2 +
901                                                            (orderByComparator.getOrderByFields().length * 3));
902    
903                                            query.append(_SQL_SELECT_SCLICENSE);
904    
905                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
906                                                    orderByComparator);
907    
908                                            sql = query.toString();
909                                    }
910                                    else {
911                                            sql = _SQL_SELECT_SCLICENSE.concat(SCLicenseModelImpl.ORDER_BY_JPQL);
912                                    }
913    
914                                    Query q = session.createQuery(sql);
915    
916                                    if (orderByComparator == null) {
917                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
918                                                            start, end, false);
919    
920                                            Collections.sort(list);
921                                    }
922                                    else {
923                                            list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
924                                                            start, end);
925                                    }
926                            }
927                            catch (Exception e) {
928                                    throw processException(e);
929                            }
930                            finally {
931                                    if (list == null) {
932                                            list = new ArrayList<SCLicense>();
933                                    }
934    
935                                    cacheResult(list);
936    
937                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
938    
939                                    closeSession(session);
940                            }
941                    }
942    
943                    return list;
944            }
945    
946            public void removeByActive(boolean active) throws SystemException {
947                    for (SCLicense scLicense : findByActive(active)) {
948                            remove(scLicense);
949                    }
950            }
951    
952            public void removeByA_R(boolean active, boolean recommended)
953                    throws SystemException {
954                    for (SCLicense scLicense : findByA_R(active, recommended)) {
955                            remove(scLicense);
956                    }
957            }
958    
959            public void removeAll() throws SystemException {
960                    for (SCLicense scLicense : findAll()) {
961                            remove(scLicense);
962                    }
963            }
964    
965            public int countByActive(boolean active) throws SystemException {
966                    Object[] finderArgs = new Object[] { active };
967    
968                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
969                                    finderArgs, this);
970    
971                    if (count == null) {
972                            Session session = null;
973    
974                            try {
975                                    session = openSession();
976    
977                                    StringBundler query = new StringBundler(2);
978    
979                                    query.append(_SQL_COUNT_SCLICENSE_WHERE);
980    
981                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
982    
983                                    String sql = query.toString();
984    
985                                    Query q = session.createQuery(sql);
986    
987                                    QueryPos qPos = QueryPos.getInstance(q);
988    
989                                    qPos.add(active);
990    
991                                    count = (Long)q.uniqueResult();
992                            }
993                            catch (Exception e) {
994                                    throw processException(e);
995                            }
996                            finally {
997                                    if (count == null) {
998                                            count = Long.valueOf(0);
999                                    }
1000    
1001                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1002                                            finderArgs, count);
1003    
1004                                    closeSession(session);
1005                            }
1006                    }
1007    
1008                    return count.intValue();
1009            }
1010    
1011            public int countByA_R(boolean active, boolean recommended)
1012                    throws SystemException {
1013                    Object[] finderArgs = new Object[] { active, recommended };
1014    
1015                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
1016                                    finderArgs, this);
1017    
1018                    if (count == null) {
1019                            Session session = null;
1020    
1021                            try {
1022                                    session = openSession();
1023    
1024                                    StringBundler query = new StringBundler(3);
1025    
1026                                    query.append(_SQL_COUNT_SCLICENSE_WHERE);
1027    
1028                                    query.append(_FINDER_COLUMN_A_R_ACTIVE_2);
1029    
1030                                    query.append(_FINDER_COLUMN_A_R_RECOMMENDED_2);
1031    
1032                                    String sql = query.toString();
1033    
1034                                    Query q = session.createQuery(sql);
1035    
1036                                    QueryPos qPos = QueryPos.getInstance(q);
1037    
1038                                    qPos.add(active);
1039    
1040                                    qPos.add(recommended);
1041    
1042                                    count = (Long)q.uniqueResult();
1043                            }
1044                            catch (Exception e) {
1045                                    throw processException(e);
1046                            }
1047                            finally {
1048                                    if (count == null) {
1049                                            count = Long.valueOf(0);
1050                                    }
1051    
1052                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
1053                                            count);
1054    
1055                                    closeSession(session);
1056                            }
1057                    }
1058    
1059                    return count.intValue();
1060            }
1061    
1062            public int countAll() throws SystemException {
1063                    Object[] finderArgs = new Object[0];
1064    
1065                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1066                                    finderArgs, this);
1067    
1068                    if (count == null) {
1069                            Session session = null;
1070    
1071                            try {
1072                                    session = openSession();
1073    
1074                                    Query q = session.createQuery(_SQL_COUNT_SCLICENSE);
1075    
1076                                    count = (Long)q.uniqueResult();
1077                            }
1078                            catch (Exception e) {
1079                                    throw processException(e);
1080                            }
1081                            finally {
1082                                    if (count == null) {
1083                                            count = Long.valueOf(0);
1084                                    }
1085    
1086                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1087                                            count);
1088    
1089                                    closeSession(session);
1090                            }
1091                    }
1092    
1093                    return count.intValue();
1094            }
1095    
1096            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1097                    long pk) throws SystemException {
1098                    return getSCProductEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1099            }
1100    
1101            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1102                    long pk, int start, int end) throws SystemException {
1103                    return getSCProductEntries(pk, start, end, null);
1104            }
1105    
1106            public static final FinderPath FINDER_PATH_GET_SCPRODUCTENTRIES = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1107                            SCLicenseModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1108                            SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
1109                            "getSCProductEntries",
1110                            new String[] {
1111                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1112                                    "com.liferay.portal.kernel.util.OrderByComparator"
1113                            });
1114    
1115            public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1116                    long pk, int start, int end, OrderByComparator orderByComparator)
1117                    throws SystemException {
1118                    Object[] finderArgs = new Object[] {
1119                                    pk, String.valueOf(start), String.valueOf(end),
1120                                    String.valueOf(orderByComparator)
1121                            };
1122    
1123                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> list = (List<com.liferay.portlet.softwarecatalog.model.SCProductEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_SCPRODUCTENTRIES,
1124                                    finderArgs, this);
1125    
1126                    if (list == null) {
1127                            Session session = null;
1128    
1129                            try {
1130                                    session = openSession();
1131    
1132                                    String sql = null;
1133    
1134                                    if (orderByComparator != null) {
1135                                            sql = _SQL_GETSCPRODUCTENTRIES.concat(ORDER_BY_CLAUSE)
1136                                                                                                      .concat(orderByComparator.getOrderBy());
1137                                    }
1138                                    else {
1139                                            sql = _SQL_GETSCPRODUCTENTRIES.concat(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ORDER_BY_SQL);
1140                                    }
1141    
1142                                    SQLQuery q = session.createSQLQuery(sql);
1143    
1144                                    q.addEntity("SCProductEntry",
1145                                            com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryImpl.class);
1146    
1147                                    QueryPos qPos = QueryPos.getInstance(q);
1148    
1149                                    qPos.add(pk);
1150    
1151                                    list = (List<com.liferay.portlet.softwarecatalog.model.SCProductEntry>)QueryUtil.list(q,
1152                                                    getDialect(), start, end);
1153                            }
1154                            catch (Exception e) {
1155                                    throw processException(e);
1156                            }
1157                            finally {
1158                                    if (list == null) {
1159                                            list = new ArrayList<com.liferay.portlet.softwarecatalog.model.SCProductEntry>();
1160                                    }
1161    
1162                                    scProductEntryPersistence.cacheResult(list);
1163    
1164                                    FinderCacheUtil.putResult(FINDER_PATH_GET_SCPRODUCTENTRIES,
1165                                            finderArgs, list);
1166    
1167                                    closeSession(session);
1168                            }
1169                    }
1170    
1171                    return list;
1172            }
1173    
1174            public static final FinderPath FINDER_PATH_GET_SCPRODUCTENTRIES_SIZE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1175                            SCLicenseModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1176                            SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
1177                            "getSCProductEntriesSize", new String[] { Long.class.getName() });
1178    
1179            public int getSCProductEntriesSize(long pk) throws SystemException {
1180                    Object[] finderArgs = new Object[] { pk };
1181    
1182                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SCPRODUCTENTRIES_SIZE,
1183                                    finderArgs, this);
1184    
1185                    if (count == null) {
1186                            Session session = null;
1187    
1188                            try {
1189                                    session = openSession();
1190    
1191                                    SQLQuery q = session.createSQLQuery(_SQL_GETSCPRODUCTENTRIESSIZE);
1192    
1193                                    q.addScalar(COUNT_COLUMN_NAME,
1194                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1195    
1196                                    QueryPos qPos = QueryPos.getInstance(q);
1197    
1198                                    qPos.add(pk);
1199    
1200                                    count = (Long)q.uniqueResult();
1201                            }
1202                            catch (Exception e) {
1203                                    throw processException(e);
1204                            }
1205                            finally {
1206                                    if (count == null) {
1207                                            count = Long.valueOf(0);
1208                                    }
1209    
1210                                    FinderCacheUtil.putResult(FINDER_PATH_GET_SCPRODUCTENTRIES_SIZE,
1211                                            finderArgs, count);
1212    
1213                                    closeSession(session);
1214                            }
1215                    }
1216    
1217                    return count.intValue();
1218            }
1219    
1220            public static final FinderPath FINDER_PATH_CONTAINS_SCPRODUCTENTRY = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1221                            SCLicenseModelImpl.FINDER_CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES,
1222                            SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME,
1223                            "containsSCProductEntry",
1224                            new String[] { Long.class.getName(), Long.class.getName() });
1225    
1226            public boolean containsSCProductEntry(long pk, long scProductEntryPK)
1227                    throws SystemException {
1228                    Object[] finderArgs = new Object[] { pk, scProductEntryPK };
1229    
1230                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SCPRODUCTENTRY,
1231                                    finderArgs, this);
1232    
1233                    if (value == null) {
1234                            try {
1235                                    value = Boolean.valueOf(containsSCProductEntry.contains(pk,
1236                                                            scProductEntryPK));
1237                            }
1238                            catch (Exception e) {
1239                                    throw processException(e);
1240                            }
1241                            finally {
1242                                    if (value == null) {
1243                                            value = Boolean.FALSE;
1244                                    }
1245    
1246                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SCPRODUCTENTRY,
1247                                            finderArgs, value);
1248                            }
1249                    }
1250    
1251                    return value.booleanValue();
1252            }
1253    
1254            public boolean containsSCProductEntries(long pk) throws SystemException {
1255                    if (getSCProductEntriesSize(pk) > 0) {
1256                            return true;
1257                    }
1258                    else {
1259                            return false;
1260                    }
1261            }
1262    
1263            public void addSCProductEntry(long pk, long scProductEntryPK)
1264                    throws SystemException {
1265                    try {
1266                            addSCProductEntry.add(pk, scProductEntryPK);
1267                    }
1268                    catch (Exception e) {
1269                            throw processException(e);
1270                    }
1271                    finally {
1272                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1273                    }
1274            }
1275    
1276            public void addSCProductEntry(long pk,
1277                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry)
1278                    throws SystemException {
1279                    try {
1280                            addSCProductEntry.add(pk, scProductEntry.getPrimaryKey());
1281                    }
1282                    catch (Exception e) {
1283                            throw processException(e);
1284                    }
1285                    finally {
1286                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1287                    }
1288            }
1289    
1290            public void addSCProductEntries(long pk, long[] scProductEntryPKs)
1291                    throws SystemException {
1292                    try {
1293                            for (long scProductEntryPK : scProductEntryPKs) {
1294                                    addSCProductEntry.add(pk, scProductEntryPK);
1295                            }
1296                    }
1297                    catch (Exception e) {
1298                            throw processException(e);
1299                    }
1300                    finally {
1301                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1302                    }
1303            }
1304    
1305            public void addSCProductEntries(long pk,
1306                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1307                    throws SystemException {
1308                    try {
1309                            for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1310                                    addSCProductEntry.add(pk, scProductEntry.getPrimaryKey());
1311                            }
1312                    }
1313                    catch (Exception e) {
1314                            throw processException(e);
1315                    }
1316                    finally {
1317                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1318                    }
1319            }
1320    
1321            public void clearSCProductEntries(long pk) throws SystemException {
1322                    try {
1323                            clearSCProductEntries.clear(pk);
1324                    }
1325                    catch (Exception e) {
1326                            throw processException(e);
1327                    }
1328                    finally {
1329                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1330                    }
1331            }
1332    
1333            public void removeSCProductEntry(long pk, long scProductEntryPK)
1334                    throws SystemException {
1335                    try {
1336                            removeSCProductEntry.remove(pk, scProductEntryPK);
1337                    }
1338                    catch (Exception e) {
1339                            throw processException(e);
1340                    }
1341                    finally {
1342                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1343                    }
1344            }
1345    
1346            public void removeSCProductEntry(long pk,
1347                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry)
1348                    throws SystemException {
1349                    try {
1350                            removeSCProductEntry.remove(pk, scProductEntry.getPrimaryKey());
1351                    }
1352                    catch (Exception e) {
1353                            throw processException(e);
1354                    }
1355                    finally {
1356                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1357                    }
1358            }
1359    
1360            public void removeSCProductEntries(long pk, long[] scProductEntryPKs)
1361                    throws SystemException {
1362                    try {
1363                            for (long scProductEntryPK : scProductEntryPKs) {
1364                                    removeSCProductEntry.remove(pk, scProductEntryPK);
1365                            }
1366                    }
1367                    catch (Exception e) {
1368                            throw processException(e);
1369                    }
1370                    finally {
1371                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1372                    }
1373            }
1374    
1375            public void removeSCProductEntries(long pk,
1376                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1377                    throws SystemException {
1378                    try {
1379                            for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1380                                    removeSCProductEntry.remove(pk, scProductEntry.getPrimaryKey());
1381                            }
1382                    }
1383                    catch (Exception e) {
1384                            throw processException(e);
1385                    }
1386                    finally {
1387                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1388                    }
1389            }
1390    
1391            public void setSCProductEntries(long pk, long[] scProductEntryPKs)
1392                    throws SystemException {
1393                    try {
1394                            Set<Long> scProductEntryPKSet = SetUtil.fromArray(scProductEntryPKs);
1395    
1396                            List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries =
1397                                    getSCProductEntries(pk);
1398    
1399                            for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1400                                    if (!scProductEntryPKSet.contains(
1401                                                            scProductEntry.getPrimaryKey())) {
1402                                            removeSCProductEntry.remove(pk,
1403                                                    scProductEntry.getPrimaryKey());
1404                                    }
1405                                    else {
1406                                            scProductEntryPKSet.remove(scProductEntry.getPrimaryKey());
1407                                    }
1408                            }
1409    
1410                            for (Long scProductEntryPK : scProductEntryPKSet) {
1411                                    addSCProductEntry.add(pk, scProductEntryPK);
1412                            }
1413                    }
1414                    catch (Exception e) {
1415                            throw processException(e);
1416                    }
1417                    finally {
1418                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1419                    }
1420            }
1421    
1422            public void setSCProductEntries(long pk,
1423                    List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1424                    throws SystemException {
1425                    try {
1426                            long[] scProductEntryPKs = new long[scProductEntries.size()];
1427    
1428                            for (int i = 0; i < scProductEntries.size(); i++) {
1429                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry =
1430                                            scProductEntries.get(i);
1431    
1432                                    scProductEntryPKs[i] = scProductEntry.getPrimaryKey();
1433                            }
1434    
1435                            setSCProductEntries(pk, scProductEntryPKs);
1436                    }
1437                    catch (Exception e) {
1438                            throw processException(e);
1439                    }
1440                    finally {
1441                            FinderCacheUtil.clearCache(SCLicenseModelImpl.MAPPING_TABLE_SCLICENSES_SCPRODUCTENTRIES_NAME);
1442                    }
1443            }
1444    
1445            public void afterPropertiesSet() {
1446                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1447                                            com.liferay.portal.util.PropsUtil.get(
1448                                                    "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCLicense")));
1449    
1450                    if (listenerClassNames.length > 0) {
1451                            try {
1452                                    List<ModelListener<SCLicense>> listenersList = new ArrayList<ModelListener<SCLicense>>();
1453    
1454                                    for (String listenerClassName : listenerClassNames) {
1455                                            listenersList.add((ModelListener<SCLicense>)InstanceFactory.newInstance(
1456                                                            listenerClassName));
1457                                    }
1458    
1459                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1460                            }
1461                            catch (Exception e) {
1462                                    _log.error(e);
1463                            }
1464                    }
1465    
1466                    containsSCProductEntry = new ContainsSCProductEntry(this);
1467    
1468                    addSCProductEntry = new AddSCProductEntry(this);
1469                    clearSCProductEntries = new ClearSCProductEntries(this);
1470                    removeSCProductEntry = new RemoveSCProductEntry(this);
1471            }
1472    
1473            @BeanReference(type = SCLicensePersistence.class)
1474            protected SCLicensePersistence scLicensePersistence;
1475            @BeanReference(type = SCFrameworkVersionPersistence.class)
1476            protected SCFrameworkVersionPersistence scFrameworkVersionPersistence;
1477            @BeanReference(type = SCProductEntryPersistence.class)
1478            protected SCProductEntryPersistence scProductEntryPersistence;
1479            @BeanReference(type = SCProductScreenshotPersistence.class)
1480            protected SCProductScreenshotPersistence scProductScreenshotPersistence;
1481            @BeanReference(type = SCProductVersionPersistence.class)
1482            protected SCProductVersionPersistence scProductVersionPersistence;
1483            @BeanReference(type = ResourcePersistence.class)
1484            protected ResourcePersistence resourcePersistence;
1485            @BeanReference(type = UserPersistence.class)
1486            protected UserPersistence userPersistence;
1487            protected ContainsSCProductEntry containsSCProductEntry;
1488            protected AddSCProductEntry addSCProductEntry;
1489            protected ClearSCProductEntries clearSCProductEntries;
1490            protected RemoveSCProductEntry removeSCProductEntry;
1491    
1492            protected class ContainsSCProductEntry {
1493                    protected ContainsSCProductEntry(
1494                            SCLicensePersistenceImpl persistenceImpl) {
1495                            super();
1496    
1497                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1498                                            _SQL_CONTAINSSCPRODUCTENTRY,
1499                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
1500                                            RowMapper.COUNT);
1501                    }
1502    
1503                    protected boolean contains(long licenseId, long productEntryId) {
1504                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1505                                                    new Long(licenseId), new Long(productEntryId)
1506                                            });
1507    
1508                            if (results.size() > 0) {
1509                                    Integer count = results.get(0);
1510    
1511                                    if (count.intValue() > 0) {
1512                                            return true;
1513                                    }
1514                            }
1515    
1516                            return false;
1517                    }
1518    
1519                    private MappingSqlQuery<Integer> _mappingSqlQuery;
1520            }
1521    
1522            protected class AddSCProductEntry {
1523                    protected AddSCProductEntry(SCLicensePersistenceImpl persistenceImpl) {
1524                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1525                                            "INSERT INTO SCLicenses_SCProductEntries (licenseId, productEntryId) VALUES (?, ?)",
1526                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
1527                            _persistenceImpl = persistenceImpl;
1528                    }
1529    
1530                    protected void add(long licenseId, long productEntryId)
1531                            throws SystemException {
1532                            if (!_persistenceImpl.containsSCProductEntry.contains(licenseId,
1533                                                    productEntryId)) {
1534                                    ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry>[] scProductEntryListeners =
1535                                            scProductEntryPersistence.getListeners();
1536    
1537                                    for (ModelListener<SCLicense> listener : listeners) {
1538                                            listener.onBeforeAddAssociation(licenseId,
1539                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1540                                                    productEntryId);
1541                                    }
1542    
1543                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1544                                            listener.onBeforeAddAssociation(productEntryId,
1545                                                    SCLicense.class.getName(), licenseId);
1546                                    }
1547    
1548                                    _sqlUpdate.update(new Object[] {
1549                                                    new Long(licenseId), new Long(productEntryId)
1550                                            });
1551    
1552                                    for (ModelListener<SCLicense> listener : listeners) {
1553                                            listener.onAfterAddAssociation(licenseId,
1554                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1555                                                    productEntryId);
1556                                    }
1557    
1558                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1559                                            listener.onAfterAddAssociation(productEntryId,
1560                                                    SCLicense.class.getName(), licenseId);
1561                                    }
1562                            }
1563                    }
1564    
1565                    private SqlUpdate _sqlUpdate;
1566                    private SCLicensePersistenceImpl _persistenceImpl;
1567            }
1568    
1569            protected class ClearSCProductEntries {
1570                    protected ClearSCProductEntries(
1571                            SCLicensePersistenceImpl persistenceImpl) {
1572                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1573                                            "DELETE FROM SCLicenses_SCProductEntries WHERE licenseId = ?",
1574                                            new int[] { java.sql.Types.BIGINT });
1575                    }
1576    
1577                    protected void clear(long licenseId) throws SystemException {
1578                            ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry>[] scProductEntryListeners =
1579                                    scProductEntryPersistence.getListeners();
1580    
1581                            List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries =
1582                                    null;
1583    
1584                            if ((listeners.length > 0) || (scProductEntryListeners.length > 0)) {
1585                                    scProductEntries = getSCProductEntries(licenseId);
1586    
1587                                    for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1588                                            for (ModelListener<SCLicense> listener : listeners) {
1589                                                    listener.onBeforeRemoveAssociation(licenseId,
1590                                                            com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1591                                                            scProductEntry.getPrimaryKey());
1592                                            }
1593    
1594                                            for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1595                                                    listener.onBeforeRemoveAssociation(scProductEntry.getPrimaryKey(),
1596                                                            SCLicense.class.getName(), licenseId);
1597                                            }
1598                                    }
1599                            }
1600    
1601                            _sqlUpdate.update(new Object[] { new Long(licenseId) });
1602    
1603                            if ((listeners.length > 0) || (scProductEntryListeners.length > 0)) {
1604                                    for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1605                                            for (ModelListener<SCLicense> listener : listeners) {
1606                                                    listener.onAfterRemoveAssociation(licenseId,
1607                                                            com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1608                                                            scProductEntry.getPrimaryKey());
1609                                            }
1610    
1611                                            for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1612                                                    listener.onAfterRemoveAssociation(scProductEntry.getPrimaryKey(),
1613                                                            SCLicense.class.getName(), licenseId);
1614                                            }
1615                                    }
1616                            }
1617                    }
1618    
1619                    private SqlUpdate _sqlUpdate;
1620            }
1621    
1622            protected class RemoveSCProductEntry {
1623                    protected RemoveSCProductEntry(SCLicensePersistenceImpl persistenceImpl) {
1624                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1625                                            "DELETE FROM SCLicenses_SCProductEntries WHERE licenseId = ? AND productEntryId = ?",
1626                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
1627                            _persistenceImpl = persistenceImpl;
1628                    }
1629    
1630                    protected void remove(long licenseId, long productEntryId)
1631                            throws SystemException {
1632                            if (_persistenceImpl.containsSCProductEntry.contains(licenseId,
1633                                                    productEntryId)) {
1634                                    ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry>[] scProductEntryListeners =
1635                                            scProductEntryPersistence.getListeners();
1636    
1637                                    for (ModelListener<SCLicense> listener : listeners) {
1638                                            listener.onBeforeRemoveAssociation(licenseId,
1639                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1640                                                    productEntryId);
1641                                    }
1642    
1643                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1644                                            listener.onBeforeRemoveAssociation(productEntryId,
1645                                                    SCLicense.class.getName(), licenseId);
1646                                    }
1647    
1648                                    _sqlUpdate.update(new Object[] {
1649                                                    new Long(licenseId), new Long(productEntryId)
1650                                            });
1651    
1652                                    for (ModelListener<SCLicense> listener : listeners) {
1653                                            listener.onAfterRemoveAssociation(licenseId,
1654                                                    com.liferay.portlet.softwarecatalog.model.SCProductEntry.class.getName(),
1655                                                    productEntryId);
1656                                    }
1657    
1658                                    for (ModelListener<com.liferay.portlet.softwarecatalog.model.SCProductEntry> listener : scProductEntryListeners) {
1659                                            listener.onAfterRemoveAssociation(productEntryId,
1660                                                    SCLicense.class.getName(), licenseId);
1661                                    }
1662                            }
1663                    }
1664    
1665                    private SqlUpdate _sqlUpdate;
1666                    private SCLicensePersistenceImpl _persistenceImpl;
1667            }
1668    
1669            private static final String _SQL_SELECT_SCLICENSE = "SELECT scLicense FROM SCLicense scLicense";
1670            private static final String _SQL_SELECT_SCLICENSE_WHERE = "SELECT scLicense FROM SCLicense scLicense WHERE ";
1671            private static final String _SQL_COUNT_SCLICENSE = "SELECT COUNT(scLicense) FROM SCLicense scLicense";
1672            private static final String _SQL_COUNT_SCLICENSE_WHERE = "SELECT COUNT(scLicense) FROM SCLicense scLicense WHERE ";
1673            private static final String _SQL_GETSCPRODUCTENTRIES = "SELECT {SCProductEntry.*} FROM SCProductEntry INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.productEntryId = SCProductEntry.productEntryId) WHERE (SCLicenses_SCProductEntries.licenseId = ?)";
1674            private static final String _SQL_GETSCPRODUCTENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE licenseId = ?";
1675            private static final String _SQL_CONTAINSSCPRODUCTENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE licenseId = ? AND productEntryId = ?";
1676            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "scLicense.active = ?";
1677            private static final String _FINDER_COLUMN_A_R_ACTIVE_2 = "scLicense.active = ? AND ";
1678            private static final String _FINDER_COLUMN_A_R_RECOMMENDED_2 = "scLicense.recommended = ?";
1679            private static final String _ORDER_BY_ENTITY_ALIAS = "scLicense.";
1680            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCLicense exists with the primary key ";
1681            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCLicense exists with the key {";
1682            private static Log _log = LogFactoryUtil.getLog(SCLicensePersistenceImpl.class);
1683    }