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