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