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