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