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