1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.softwarecatalog.service.persistence;
21  
22  import com.liferay.portal.SystemException;
23  import com.liferay.portal.kernel.annotation.BeanReference;
24  import com.liferay.portal.kernel.cache.CacheRegistry;
25  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
26  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
27  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
28  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
29  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
30  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
31  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
33  import com.liferay.portal.kernel.dao.orm.FinderPath;
34  import com.liferay.portal.kernel.dao.orm.Query;
35  import com.liferay.portal.kernel.dao.orm.QueryPos;
36  import com.liferay.portal.kernel.dao.orm.QueryUtil;
37  import com.liferay.portal.kernel.dao.orm.SQLQuery;
38  import com.liferay.portal.kernel.dao.orm.Session;
39  import com.liferay.portal.kernel.dao.orm.Type;
40  import com.liferay.portal.kernel.log.Log;
41  import com.liferay.portal.kernel.log.LogFactoryUtil;
42  import com.liferay.portal.kernel.util.GetterUtil;
43  import com.liferay.portal.kernel.util.OrderByComparator;
44  import com.liferay.portal.kernel.util.StringPool;
45  import com.liferay.portal.kernel.util.StringUtil;
46  import com.liferay.portal.model.ModelListener;
47  import com.liferay.portal.service.persistence.BatchSessionUtil;
48  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49  
50  import com.liferay.portlet.softwarecatalog.NoSuchProductVersionException;
51  import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
52  import com.liferay.portlet.softwarecatalog.model.impl.SCProductVersionImpl;
53  import com.liferay.portlet.softwarecatalog.model.impl.SCProductVersionModelImpl;
54  
55  import java.sql.Types;
56  
57  import java.util.ArrayList;
58  import java.util.Collections;
59  import java.util.List;
60  
61  /**
62   * <a href="SCProductVersionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
63   *
64   * @author Brian Wing Shun Chan
65   *
66   */
67  public class SCProductVersionPersistenceImpl extends BasePersistenceImpl
68      implements SCProductVersionPersistence {
69      public static final String FINDER_CLASS_NAME_ENTITY = SCProductVersionImpl.class.getName();
70      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
71          ".List";
72      public static final FinderPath FINDER_PATH_FIND_BY_PRODUCTENTRYID = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
73              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
74              FINDER_CLASS_NAME_LIST, "findByProductEntryId",
75              new String[] { Long.class.getName() });
76      public static final FinderPath FINDER_PATH_FIND_BY_OBC_PRODUCTENTRYID = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
77              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
78              FINDER_CLASS_NAME_LIST, "findByProductEntryId",
79              new String[] {
80                  Long.class.getName(),
81                  
82              "java.lang.Integer", "java.lang.Integer",
83                  "com.liferay.portal.kernel.util.OrderByComparator"
84              });
85      public static final FinderPath FINDER_PATH_COUNT_BY_PRODUCTENTRYID = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
86              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
87              FINDER_CLASS_NAME_LIST, "countByProductEntryId",
88              new String[] { Long.class.getName() });
89      public static final FinderPath FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
90              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
91              FINDER_CLASS_NAME_ENTITY, "fetchByDirectDownloadURL",
92              new String[] { String.class.getName() });
93      public static final FinderPath FINDER_PATH_COUNT_BY_DIRECTDOWNLOADURL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
94              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
95              FINDER_CLASS_NAME_LIST, "countByDirectDownloadURL",
96              new String[] { String.class.getName() });
97      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
98              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
99              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
100     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
101             SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
103 
104     public void cacheResult(SCProductVersion scProductVersion) {
105         EntityCacheUtil.putResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
106             SCProductVersionImpl.class, scProductVersion.getPrimaryKey(),
107             scProductVersion);
108 
109         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
110             new Object[] { scProductVersion.getDirectDownloadURL() },
111             scProductVersion);
112     }
113 
114     public void cacheResult(List<SCProductVersion> scProductVersions) {
115         for (SCProductVersion scProductVersion : scProductVersions) {
116             if (EntityCacheUtil.getResult(
117                         SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
118                         SCProductVersionImpl.class,
119                         scProductVersion.getPrimaryKey(), this) == null) {
120                 cacheResult(scProductVersion);
121             }
122         }
123     }
124 
125     public void clearCache() {
126         CacheRegistry.clear(SCProductVersionImpl.class.getName());
127         EntityCacheUtil.clearCache(SCProductVersionImpl.class.getName());
128         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
129         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
130     }
131 
132     public SCProductVersion create(long productVersionId) {
133         SCProductVersion scProductVersion = new SCProductVersionImpl();
134 
135         scProductVersion.setNew(true);
136         scProductVersion.setPrimaryKey(productVersionId);
137 
138         return scProductVersion;
139     }
140 
141     public SCProductVersion remove(long productVersionId)
142         throws NoSuchProductVersionException, SystemException {
143         Session session = null;
144 
145         try {
146             session = openSession();
147 
148             SCProductVersion scProductVersion = (SCProductVersion)session.get(SCProductVersionImpl.class,
149                     new Long(productVersionId));
150 
151             if (scProductVersion == null) {
152                 if (_log.isWarnEnabled()) {
153                     _log.warn(
154                         "No SCProductVersion exists with the primary key " +
155                         productVersionId);
156                 }
157 
158                 throw new NoSuchProductVersionException(
159                     "No SCProductVersion exists with the primary key " +
160                     productVersionId);
161             }
162 
163             return remove(scProductVersion);
164         }
165         catch (NoSuchProductVersionException nsee) {
166             throw nsee;
167         }
168         catch (Exception e) {
169             throw processException(e);
170         }
171         finally {
172             closeSession(session);
173         }
174     }
175 
176     public SCProductVersion remove(SCProductVersion scProductVersion)
177         throws SystemException {
178         for (ModelListener<SCProductVersion> listener : listeners) {
179             listener.onBeforeRemove(scProductVersion);
180         }
181 
182         scProductVersion = removeImpl(scProductVersion);
183 
184         for (ModelListener<SCProductVersion> listener : listeners) {
185             listener.onAfterRemove(scProductVersion);
186         }
187 
188         return scProductVersion;
189     }
190 
191     protected SCProductVersion removeImpl(SCProductVersion scProductVersion)
192         throws SystemException {
193         try {
194             clearSCFrameworkVersions.clear(scProductVersion.getPrimaryKey());
195         }
196         catch (Exception e) {
197             throw processException(e);
198         }
199         finally {
200             FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
201         }
202 
203         Session session = null;
204 
205         try {
206             session = openSession();
207 
208             if (scProductVersion.isCachedModel() ||
209                     BatchSessionUtil.isEnabled()) {
210                 Object staleObject = session.get(SCProductVersionImpl.class,
211                         scProductVersion.getPrimaryKeyObj());
212 
213                 if (staleObject != null) {
214                     session.evict(staleObject);
215                 }
216             }
217 
218             session.delete(scProductVersion);
219 
220             session.flush();
221         }
222         catch (Exception e) {
223             throw processException(e);
224         }
225         finally {
226             closeSession(session);
227         }
228 
229         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
230 
231         SCProductVersionModelImpl scProductVersionModelImpl = (SCProductVersionModelImpl)scProductVersion;
232 
233         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
234             new Object[] {
235                 scProductVersionModelImpl.getOriginalDirectDownloadURL()
236             });
237 
238         EntityCacheUtil.removeResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
239             SCProductVersionImpl.class, scProductVersion.getPrimaryKey());
240 
241         return scProductVersion;
242     }
243 
244     /**
245      * @deprecated Use <code>update(SCProductVersion scProductVersion, boolean merge)</code>.
246      */
247     public SCProductVersion update(SCProductVersion scProductVersion)
248         throws SystemException {
249         if (_log.isWarnEnabled()) {
250             _log.warn(
251                 "Using the deprecated update(SCProductVersion scProductVersion) method. Use update(SCProductVersion scProductVersion, boolean merge) instead.");
252         }
253 
254         return update(scProductVersion, false);
255     }
256 
257     /**
258      * Add, update, or merge, the entity. This method also calls the model
259      * listeners to trigger the proper events associated with adding, deleting,
260      * or updating an entity.
261      *
262      * @param        scProductVersion the entity to add, update, or merge
263      * @param        merge boolean value for whether to merge the entity. The
264      *                default value is false. Setting merge to true is more
265      *                expensive and should only be true when scProductVersion is
266      *                transient. See LEP-5473 for a detailed discussion of this
267      *                method.
268      * @return        true if the portlet can be displayed via Ajax
269      */
270     public SCProductVersion update(SCProductVersion scProductVersion,
271         boolean merge) throws SystemException {
272         boolean isNew = scProductVersion.isNew();
273 
274         for (ModelListener<SCProductVersion> listener : listeners) {
275             if (isNew) {
276                 listener.onBeforeCreate(scProductVersion);
277             }
278             else {
279                 listener.onBeforeUpdate(scProductVersion);
280             }
281         }
282 
283         scProductVersion = updateImpl(scProductVersion, merge);
284 
285         for (ModelListener<SCProductVersion> listener : listeners) {
286             if (isNew) {
287                 listener.onAfterCreate(scProductVersion);
288             }
289             else {
290                 listener.onAfterUpdate(scProductVersion);
291             }
292         }
293 
294         return scProductVersion;
295     }
296 
297     public SCProductVersion updateImpl(
298         com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion,
299         boolean merge) throws SystemException {
300         boolean isNew = scProductVersion.isNew();
301 
302         SCProductVersionModelImpl scProductVersionModelImpl = (SCProductVersionModelImpl)scProductVersion;
303 
304         Session session = null;
305 
306         try {
307             session = openSession();
308 
309             BatchSessionUtil.update(session, scProductVersion, merge);
310 
311             scProductVersion.setNew(false);
312         }
313         catch (Exception e) {
314             throw processException(e);
315         }
316         finally {
317             closeSession(session);
318         }
319 
320         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
321 
322         EntityCacheUtil.putResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
323             SCProductVersionImpl.class, scProductVersion.getPrimaryKey(),
324             scProductVersion);
325 
326         if (!isNew &&
327                 (!scProductVersion.getDirectDownloadURL()
328                                       .equals(scProductVersionModelImpl.getOriginalDirectDownloadURL()))) {
329             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
330                 new Object[] {
331                     scProductVersionModelImpl.getOriginalDirectDownloadURL()
332                 });
333         }
334 
335         if (isNew ||
336                 (!scProductVersion.getDirectDownloadURL()
337                                       .equals(scProductVersionModelImpl.getOriginalDirectDownloadURL()))) {
338             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
339                 new Object[] { scProductVersion.getDirectDownloadURL() },
340                 scProductVersion);
341         }
342 
343         return scProductVersion;
344     }
345 
346     public SCProductVersion findByPrimaryKey(long productVersionId)
347         throws NoSuchProductVersionException, SystemException {
348         SCProductVersion scProductVersion = fetchByPrimaryKey(productVersionId);
349 
350         if (scProductVersion == null) {
351             if (_log.isWarnEnabled()) {
352                 _log.warn("No SCProductVersion exists with the primary key " +
353                     productVersionId);
354             }
355 
356             throw new NoSuchProductVersionException(
357                 "No SCProductVersion exists with the primary key " +
358                 productVersionId);
359         }
360 
361         return scProductVersion;
362     }
363 
364     public SCProductVersion fetchByPrimaryKey(long productVersionId)
365         throws SystemException {
366         SCProductVersion scProductVersion = (SCProductVersion)EntityCacheUtil.getResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
367                 SCProductVersionImpl.class, productVersionId, this);
368 
369         if (scProductVersion == null) {
370             Session session = null;
371 
372             try {
373                 session = openSession();
374 
375                 scProductVersion = (SCProductVersion)session.get(SCProductVersionImpl.class,
376                         new Long(productVersionId));
377             }
378             catch (Exception e) {
379                 throw processException(e);
380             }
381             finally {
382                 if (scProductVersion != null) {
383                     cacheResult(scProductVersion);
384                 }
385 
386                 closeSession(session);
387             }
388         }
389 
390         return scProductVersion;
391     }
392 
393     public List<SCProductVersion> findByProductEntryId(long productEntryId)
394         throws SystemException {
395         Object[] finderArgs = new Object[] { new Long(productEntryId) };
396 
397         List<SCProductVersion> list = (List<SCProductVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
398                 finderArgs, this);
399 
400         if (list == null) {
401             Session session = null;
402 
403             try {
404                 session = openSession();
405 
406                 StringBuilder query = new StringBuilder();
407 
408                 query.append(
409                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
410 
411                 query.append("productEntryId = ?");
412 
413                 query.append(" ");
414 
415                 query.append("ORDER BY ");
416 
417                 query.append("createDate DESC");
418 
419                 Query q = session.createQuery(query.toString());
420 
421                 QueryPos qPos = QueryPos.getInstance(q);
422 
423                 qPos.add(productEntryId);
424 
425                 list = q.list();
426             }
427             catch (Exception e) {
428                 throw processException(e);
429             }
430             finally {
431                 if (list == null) {
432                     list = new ArrayList<SCProductVersion>();
433                 }
434 
435                 cacheResult(list);
436 
437                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
438                     finderArgs, list);
439 
440                 closeSession(session);
441             }
442         }
443 
444         return list;
445     }
446 
447     public List<SCProductVersion> findByProductEntryId(long productEntryId,
448         int start, int end) throws SystemException {
449         return findByProductEntryId(productEntryId, start, end, null);
450     }
451 
452     public List<SCProductVersion> findByProductEntryId(long productEntryId,
453         int start, int end, OrderByComparator obc) throws SystemException {
454         Object[] finderArgs = new Object[] {
455                 new Long(productEntryId),
456                 
457                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
458             };
459 
460         List<SCProductVersion> list = (List<SCProductVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_PRODUCTENTRYID,
461                 finderArgs, this);
462 
463         if (list == null) {
464             Session session = null;
465 
466             try {
467                 session = openSession();
468 
469                 StringBuilder query = new StringBuilder();
470 
471                 query.append(
472                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
473 
474                 query.append("productEntryId = ?");
475 
476                 query.append(" ");
477 
478                 if (obc != null) {
479                     query.append("ORDER BY ");
480                     query.append(obc.getOrderBy());
481                 }
482 
483                 else {
484                     query.append("ORDER BY ");
485 
486                     query.append("createDate DESC");
487                 }
488 
489                 Query q = session.createQuery(query.toString());
490 
491                 QueryPos qPos = QueryPos.getInstance(q);
492 
493                 qPos.add(productEntryId);
494 
495                 list = (List<SCProductVersion>)QueryUtil.list(q, getDialect(),
496                         start, end);
497             }
498             catch (Exception e) {
499                 throw processException(e);
500             }
501             finally {
502                 if (list == null) {
503                     list = new ArrayList<SCProductVersion>();
504                 }
505 
506                 cacheResult(list);
507 
508                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_PRODUCTENTRYID,
509                     finderArgs, list);
510 
511                 closeSession(session);
512             }
513         }
514 
515         return list;
516     }
517 
518     public SCProductVersion findByProductEntryId_First(long productEntryId,
519         OrderByComparator obc)
520         throws NoSuchProductVersionException, SystemException {
521         List<SCProductVersion> list = findByProductEntryId(productEntryId, 0,
522                 1, obc);
523 
524         if (list.isEmpty()) {
525             StringBuilder msg = new StringBuilder();
526 
527             msg.append("No SCProductVersion exists with the key {");
528 
529             msg.append("productEntryId=" + productEntryId);
530 
531             msg.append(StringPool.CLOSE_CURLY_BRACE);
532 
533             throw new NoSuchProductVersionException(msg.toString());
534         }
535         else {
536             return list.get(0);
537         }
538     }
539 
540     public SCProductVersion findByProductEntryId_Last(long productEntryId,
541         OrderByComparator obc)
542         throws NoSuchProductVersionException, SystemException {
543         int count = countByProductEntryId(productEntryId);
544 
545         List<SCProductVersion> list = findByProductEntryId(productEntryId,
546                 count - 1, count, obc);
547 
548         if (list.isEmpty()) {
549             StringBuilder msg = new StringBuilder();
550 
551             msg.append("No SCProductVersion exists with the key {");
552 
553             msg.append("productEntryId=" + productEntryId);
554 
555             msg.append(StringPool.CLOSE_CURLY_BRACE);
556 
557             throw new NoSuchProductVersionException(msg.toString());
558         }
559         else {
560             return list.get(0);
561         }
562     }
563 
564     public SCProductVersion[] findByProductEntryId_PrevAndNext(
565         long productVersionId, long productEntryId, OrderByComparator obc)
566         throws NoSuchProductVersionException, SystemException {
567         SCProductVersion scProductVersion = findByPrimaryKey(productVersionId);
568 
569         int count = countByProductEntryId(productEntryId);
570 
571         Session session = null;
572 
573         try {
574             session = openSession();
575 
576             StringBuilder query = new StringBuilder();
577 
578             query.append(
579                 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
580 
581             query.append("productEntryId = ?");
582 
583             query.append(" ");
584 
585             if (obc != null) {
586                 query.append("ORDER BY ");
587                 query.append(obc.getOrderBy());
588             }
589 
590             else {
591                 query.append("ORDER BY ");
592 
593                 query.append("createDate DESC");
594             }
595 
596             Query q = session.createQuery(query.toString());
597 
598             QueryPos qPos = QueryPos.getInstance(q);
599 
600             qPos.add(productEntryId);
601 
602             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
603                     scProductVersion);
604 
605             SCProductVersion[] array = new SCProductVersionImpl[3];
606 
607             array[0] = (SCProductVersion)objArray[0];
608             array[1] = (SCProductVersion)objArray[1];
609             array[2] = (SCProductVersion)objArray[2];
610 
611             return array;
612         }
613         catch (Exception e) {
614             throw processException(e);
615         }
616         finally {
617             closeSession(session);
618         }
619     }
620 
621     public SCProductVersion findByDirectDownloadURL(String directDownloadURL)
622         throws NoSuchProductVersionException, SystemException {
623         SCProductVersion scProductVersion = fetchByDirectDownloadURL(directDownloadURL);
624 
625         if (scProductVersion == null) {
626             StringBuilder msg = new StringBuilder();
627 
628             msg.append("No SCProductVersion exists with the key {");
629 
630             msg.append("directDownloadURL=" + directDownloadURL);
631 
632             msg.append(StringPool.CLOSE_CURLY_BRACE);
633 
634             if (_log.isWarnEnabled()) {
635                 _log.warn(msg.toString());
636             }
637 
638             throw new NoSuchProductVersionException(msg.toString());
639         }
640 
641         return scProductVersion;
642     }
643 
644     public SCProductVersion fetchByDirectDownloadURL(String directDownloadURL)
645         throws SystemException {
646         return fetchByDirectDownloadURL(directDownloadURL, true);
647     }
648 
649     public SCProductVersion fetchByDirectDownloadURL(String directDownloadURL,
650         boolean retrieveFromCache) throws SystemException {
651         Object[] finderArgs = new Object[] { directDownloadURL };
652 
653         Object result = null;
654 
655         if (retrieveFromCache) {
656             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
657                     finderArgs, this);
658         }
659 
660         if (result == null) {
661             Session session = null;
662 
663             try {
664                 session = openSession();
665 
666                 StringBuilder query = new StringBuilder();
667 
668                 query.append(
669                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
670 
671                 if (directDownloadURL == null) {
672                     query.append("directDownloadURL IS NULL");
673                 }
674                 else {
675                     query.append("lower(directDownloadURL) = ?");
676                 }
677 
678                 query.append(" ");
679 
680                 query.append("ORDER BY ");
681 
682                 query.append("createDate DESC");
683 
684                 Query q = session.createQuery(query.toString());
685 
686                 QueryPos qPos = QueryPos.getInstance(q);
687 
688                 if (directDownloadURL != null) {
689                     qPos.add(directDownloadURL);
690                 }
691 
692                 List<SCProductVersion> list = q.list();
693 
694                 result = list;
695 
696                 SCProductVersion scProductVersion = null;
697 
698                 if (list.isEmpty()) {
699                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
700                         finderArgs, list);
701                 }
702                 else {
703                     scProductVersion = list.get(0);
704 
705                     cacheResult(scProductVersion);
706 
707                     if ((scProductVersion.getDirectDownloadURL() == null) ||
708                             !scProductVersion.getDirectDownloadURL()
709                                                  .equals(directDownloadURL)) {
710                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
711                             finderArgs, list);
712                     }
713                 }
714 
715                 return scProductVersion;
716             }
717             catch (Exception e) {
718                 throw processException(e);
719             }
720             finally {
721                 if (result == null) {
722                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
723                         finderArgs, new ArrayList<SCProductVersion>());
724                 }
725 
726                 closeSession(session);
727             }
728         }
729         else {
730             if (result instanceof List) {
731                 return null;
732             }
733             else {
734                 return (SCProductVersion)result;
735             }
736         }
737     }
738 
739     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
740         throws SystemException {
741         Session session = null;
742 
743         try {
744             session = openSession();
745 
746             dynamicQuery.compile(session);
747 
748             return dynamicQuery.list();
749         }
750         catch (Exception e) {
751             throw processException(e);
752         }
753         finally {
754             closeSession(session);
755         }
756     }
757 
758     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
759         int start, int end) throws SystemException {
760         Session session = null;
761 
762         try {
763             session = openSession();
764 
765             dynamicQuery.setLimit(start, end);
766 
767             dynamicQuery.compile(session);
768 
769             return dynamicQuery.list();
770         }
771         catch (Exception e) {
772             throw processException(e);
773         }
774         finally {
775             closeSession(session);
776         }
777     }
778 
779     public List<SCProductVersion> findAll() throws SystemException {
780         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
781     }
782 
783     public List<SCProductVersion> findAll(int start, int end)
784         throws SystemException {
785         return findAll(start, end, null);
786     }
787 
788     public List<SCProductVersion> findAll(int start, int end,
789         OrderByComparator obc) throws SystemException {
790         Object[] finderArgs = new Object[] {
791                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
792             };
793 
794         List<SCProductVersion> list = (List<SCProductVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
795                 finderArgs, this);
796 
797         if (list == null) {
798             Session session = null;
799 
800             try {
801                 session = openSession();
802 
803                 StringBuilder query = new StringBuilder();
804 
805                 query.append(
806                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion ");
807 
808                 if (obc != null) {
809                     query.append("ORDER BY ");
810                     query.append(obc.getOrderBy());
811                 }
812 
813                 else {
814                     query.append("ORDER BY ");
815 
816                     query.append("createDate DESC");
817                 }
818 
819                 Query q = session.createQuery(query.toString());
820 
821                 if (obc == null) {
822                     list = (List<SCProductVersion>)QueryUtil.list(q,
823                             getDialect(), start, end, false);
824 
825                     Collections.sort(list);
826                 }
827                 else {
828                     list = (List<SCProductVersion>)QueryUtil.list(q,
829                             getDialect(), start, end);
830                 }
831             }
832             catch (Exception e) {
833                 throw processException(e);
834             }
835             finally {
836                 if (list == null) {
837                     list = new ArrayList<SCProductVersion>();
838                 }
839 
840                 cacheResult(list);
841 
842                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
843 
844                 closeSession(session);
845             }
846         }
847 
848         return list;
849     }
850 
851     public void removeByProductEntryId(long productEntryId)
852         throws SystemException {
853         for (SCProductVersion scProductVersion : findByProductEntryId(
854                 productEntryId)) {
855             remove(scProductVersion);
856         }
857     }
858 
859     public void removeByDirectDownloadURL(String directDownloadURL)
860         throws NoSuchProductVersionException, SystemException {
861         SCProductVersion scProductVersion = findByDirectDownloadURL(directDownloadURL);
862 
863         remove(scProductVersion);
864     }
865 
866     public void removeAll() throws SystemException {
867         for (SCProductVersion scProductVersion : findAll()) {
868             remove(scProductVersion);
869         }
870     }
871 
872     public int countByProductEntryId(long productEntryId)
873         throws SystemException {
874         Object[] finderArgs = new Object[] { new Long(productEntryId) };
875 
876         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
877                 finderArgs, this);
878 
879         if (count == null) {
880             Session session = null;
881 
882             try {
883                 session = openSession();
884 
885                 StringBuilder query = new StringBuilder();
886 
887                 query.append("SELECT COUNT(*) ");
888                 query.append(
889                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
890 
891                 query.append("productEntryId = ?");
892 
893                 query.append(" ");
894 
895                 Query q = session.createQuery(query.toString());
896 
897                 QueryPos qPos = QueryPos.getInstance(q);
898 
899                 qPos.add(productEntryId);
900 
901                 count = (Long)q.uniqueResult();
902             }
903             catch (Exception e) {
904                 throw processException(e);
905             }
906             finally {
907                 if (count == null) {
908                     count = Long.valueOf(0);
909                 }
910 
911                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
912                     finderArgs, count);
913 
914                 closeSession(session);
915             }
916         }
917 
918         return count.intValue();
919     }
920 
921     public int countByDirectDownloadURL(String directDownloadURL)
922         throws SystemException {
923         Object[] finderArgs = new Object[] { directDownloadURL };
924 
925         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_DIRECTDOWNLOADURL,
926                 finderArgs, this);
927 
928         if (count == null) {
929             Session session = null;
930 
931             try {
932                 session = openSession();
933 
934                 StringBuilder query = new StringBuilder();
935 
936                 query.append("SELECT COUNT(*) ");
937                 query.append(
938                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
939 
940                 if (directDownloadURL == null) {
941                     query.append("directDownloadURL IS NULL");
942                 }
943                 else {
944                     query.append("lower(directDownloadURL) = ?");
945                 }
946 
947                 query.append(" ");
948 
949                 Query q = session.createQuery(query.toString());
950 
951                 QueryPos qPos = QueryPos.getInstance(q);
952 
953                 if (directDownloadURL != null) {
954                     qPos.add(directDownloadURL);
955                 }
956 
957                 count = (Long)q.uniqueResult();
958             }
959             catch (Exception e) {
960                 throw processException(e);
961             }
962             finally {
963                 if (count == null) {
964                     count = Long.valueOf(0);
965                 }
966 
967                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_DIRECTDOWNLOADURL,
968                     finderArgs, count);
969 
970                 closeSession(session);
971             }
972         }
973 
974         return count.intValue();
975     }
976 
977     public int countAll() throws SystemException {
978         Object[] finderArgs = new Object[0];
979 
980         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
981                 finderArgs, this);
982 
983         if (count == null) {
984             Session session = null;
985 
986             try {
987                 session = openSession();
988 
989                 Query q = session.createQuery(
990                         "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion");
991 
992                 count = (Long)q.uniqueResult();
993             }
994             catch (Exception e) {
995                 throw processException(e);
996             }
997             finally {
998                 if (count == null) {
999                     count = Long.valueOf(0);
1000                }
1001
1002                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1003                    count);
1004
1005                closeSession(session);
1006            }
1007        }
1008
1009        return count.intValue();
1010    }
1011
1012    public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
1013        long pk) throws SystemException {
1014        return getSCFrameworkVersions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1015    }
1016
1017    public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
1018        long pk, int start, int end) throws SystemException {
1019        return getSCFrameworkVersions(pk, start, end, null);
1020    }
1021
1022    public static final FinderPath FINDER_PATH_GET_SCFRAMEWORKVERSIONS = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionModelImpl.ENTITY_CACHE_ENABLED,
1023            SCProductVersionModelImpl.FINDER_CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS,
1024            "SCFrameworkVersi_SCProductVers", "getSCFrameworkVersions",
1025            new String[] {
1026                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1027                "com.liferay.portal.kernel.util.OrderByComparator"
1028            });
1029
1030    public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
1031        long pk, int start, int end, OrderByComparator obc)
1032        throws SystemException {
1033        Object[] finderArgs = new Object[] {
1034                new Long(pk), String.valueOf(start), String.valueOf(end),
1035                String.valueOf(obc)
1036            };
1037
1038        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> list = (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)FinderCacheUtil.getResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS,
1039                finderArgs, this);
1040
1041        if (list == null) {
1042            Session session = null;
1043
1044            try {
1045                session = openSession();
1046
1047                StringBuilder sb = new StringBuilder();
1048
1049                sb.append(_SQL_GETSCFRAMEWORKVERSIONS);
1050
1051                if (obc != null) {
1052                    sb.append("ORDER BY ");
1053                    sb.append(obc.getOrderBy());
1054                }
1055
1056                else {
1057                    sb.append("ORDER BY ");
1058
1059                    sb.append("SCFrameworkVersion.name DESC");
1060                }
1061
1062                String sql = sb.toString();
1063
1064                SQLQuery q = session.createSQLQuery(sql);
1065
1066                q.addEntity("SCFrameworkVersion",
1067                    com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionImpl.class);
1068
1069                QueryPos qPos = QueryPos.getInstance(q);
1070
1071                qPos.add(pk);
1072
1073                list = (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)QueryUtil.list(q,
1074                        getDialect(), start, end);
1075            }
1076            catch (Exception e) {
1077                throw processException(e);
1078            }
1079            finally {
1080                if (list == null) {
1081                    list = new ArrayList<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>();
1082                }
1083
1084                scFrameworkVersionPersistence.cacheResult(list);
1085
1086                FinderCacheUtil.putResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS,
1087                    finderArgs, list);
1088
1089                closeSession(session);
1090            }
1091        }
1092
1093        return list;
1094    }
1095
1096    public static final FinderPath FINDER_PATH_GET_SCFRAMEWORKVERSIONS_SIZE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionModelImpl.ENTITY_CACHE_ENABLED,
1097            SCProductVersionModelImpl.FINDER_CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS,
1098            "SCFrameworkVersi_SCProductVers", "getSCFrameworkVersionsSize",
1099            new String[] { Long.class.getName() });
1100
1101    public int getSCFrameworkVersionsSize(long pk) throws SystemException {
1102        Object[] finderArgs = new Object[] { new Long(pk) };
1103
1104        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS_SIZE,
1105                finderArgs, this);
1106
1107        if (count == null) {
1108            Session session = null;
1109
1110            try {
1111                session = openSession();
1112
1113                SQLQuery q = session.createSQLQuery(_SQL_GETSCFRAMEWORKVERSIONSSIZE);
1114
1115                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1116
1117                QueryPos qPos = QueryPos.getInstance(q);
1118
1119                qPos.add(pk);
1120
1121                count = (Long)q.uniqueResult();
1122            }
1123            catch (Exception e) {
1124                throw processException(e);
1125            }
1126            finally {
1127                if (count == null) {
1128                    count = Long.valueOf(0);
1129                }
1130
1131                FinderCacheUtil.putResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS_SIZE,
1132                    finderArgs, count);
1133
1134                closeSession(session);
1135            }
1136        }
1137
1138        return count.intValue();
1139    }
1140
1141    public static final FinderPath FINDER_PATH_CONTAINS_SCFRAMEWORKVERSION = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionModelImpl.ENTITY_CACHE_ENABLED,
1142            SCProductVersionModelImpl.FINDER_CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS,
1143            "SCFrameworkVersi_SCProductVers", "containsSCFrameworkVersion",
1144            new String[] { Long.class.getName(), Long.class.getName() });
1145
1146    public boolean containsSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1147        throws SystemException {
1148        Object[] finderArgs = new Object[] {
1149                new Long(pk),
1150                
1151                new Long(scFrameworkVersionPK)
1152            };
1153
1154        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SCFRAMEWORKVERSION,
1155                finderArgs, this);
1156
1157        if (value == null) {
1158            try {
1159                value = Boolean.valueOf(containsSCFrameworkVersion.contains(
1160                            pk, scFrameworkVersionPK));
1161            }
1162            catch (Exception e) {
1163                throw processException(e);
1164            }
1165            finally {
1166                if (value == null) {
1167                    value = Boolean.FALSE;
1168                }
1169
1170                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SCFRAMEWORKVERSION,
1171                    finderArgs, value);
1172            }
1173        }
1174
1175        return value.booleanValue();
1176    }
1177
1178    public boolean containsSCFrameworkVersions(long pk)
1179        throws SystemException {
1180        if (getSCFrameworkVersionsSize(pk) > 0) {
1181            return true;
1182        }
1183        else {
1184            return false;
1185        }
1186    }
1187
1188    public void addSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1189        throws SystemException {
1190        try {
1191            addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1192        }
1193        catch (Exception e) {
1194            throw processException(e);
1195        }
1196        finally {
1197            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1198        }
1199    }
1200
1201    public void addSCFrameworkVersion(long pk,
1202        com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1203        throws SystemException {
1204        try {
1205            addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1206        }
1207        catch (Exception e) {
1208            throw processException(e);
1209        }
1210        finally {
1211            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1212        }
1213    }
1214
1215    public void addSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1216        throws SystemException {
1217        try {
1218            for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1219                addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1220            }
1221        }
1222        catch (Exception e) {
1223            throw processException(e);
1224        }
1225        finally {
1226            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1227        }
1228    }
1229
1230    public void addSCFrameworkVersions(long pk,
1231        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1232        throws SystemException {
1233        try {
1234            for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1235                addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1236            }
1237        }
1238        catch (Exception e) {
1239            throw processException(e);
1240        }
1241        finally {
1242            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1243        }
1244    }
1245
1246    public void clearSCFrameworkVersions(long pk) throws SystemException {
1247        try {
1248            clearSCFrameworkVersions.clear(pk);
1249        }
1250        catch (Exception e) {
1251            throw processException(e);
1252        }
1253        finally {
1254            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1255        }
1256    }
1257
1258    public void removeSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1259        throws SystemException {
1260        try {
1261            removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1262        }
1263        catch (Exception e) {
1264            throw processException(e);
1265        }
1266        finally {
1267            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1268        }
1269    }
1270
1271    public void removeSCFrameworkVersion(long pk,
1272        com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1273        throws SystemException {
1274        try {
1275            removeSCFrameworkVersion.remove(pk,
1276                scFrameworkVersion.getPrimaryKey());
1277        }
1278        catch (Exception e) {
1279            throw processException(e);
1280        }
1281        finally {
1282            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1283        }
1284    }
1285
1286    public void removeSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1287        throws SystemException {
1288        try {
1289            for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1290                removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1291            }
1292        }
1293        catch (Exception e) {
1294            throw processException(e);
1295        }
1296        finally {
1297            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1298        }
1299    }
1300
1301    public void removeSCFrameworkVersions(long pk,
1302        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1303        throws SystemException {
1304        try {
1305            for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1306                removeSCFrameworkVersion.remove(pk,
1307                    scFrameworkVersion.getPrimaryKey());
1308            }
1309        }
1310        catch (Exception e) {
1311            throw processException(e);
1312        }
1313        finally {
1314            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1315        }
1316    }
1317
1318    public void setSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1319        throws SystemException {
1320        try {
1321            clearSCFrameworkVersions.clear(pk);
1322
1323            for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1324                addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1325            }
1326        }
1327        catch (Exception e) {
1328            throw processException(e);
1329        }
1330        finally {
1331            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1332        }
1333    }
1334
1335    public void setSCFrameworkVersions(long pk,
1336        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1337        throws SystemException {
1338        try {
1339            clearSCFrameworkVersions.clear(pk);
1340
1341            for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1342                addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1343            }
1344        }
1345        catch (Exception e) {
1346            throw processException(e);
1347        }
1348        finally {
1349            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1350        }
1351    }
1352
1353    public void afterPropertiesSet() {
1354        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1355                    com.liferay.portal.util.PropsUtil.get(
1356                        "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductVersion")));
1357
1358        if (listenerClassNames.length > 0) {
1359            try {
1360                List<ModelListener<SCProductVersion>> listenersList = new ArrayList<ModelListener<SCProductVersion>>();
1361
1362                for (String listenerClassName : listenerClassNames) {
1363                    listenersList.add((ModelListener<SCProductVersion>)Class.forName(
1364                            listenerClassName).newInstance());
1365                }
1366
1367                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1368            }
1369            catch (Exception e) {
1370                _log.error(e);
1371            }
1372        }
1373
1374        containsSCFrameworkVersion = new ContainsSCFrameworkVersion(this);
1375
1376        addSCFrameworkVersion = new AddSCFrameworkVersion(this);
1377        clearSCFrameworkVersions = new ClearSCFrameworkVersions(this);
1378        removeSCFrameworkVersion = new RemoveSCFrameworkVersion(this);
1379    }
1380
1381    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence.impl")
1382    protected com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence scLicensePersistence;
1383    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence.impl")
1384    protected com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence scFrameworkVersionPersistence;
1385    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence.impl")
1386    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence scProductEntryPersistence;
1387    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductScreenshotPersistence.impl")
1388    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductScreenshotPersistence scProductScreenshotPersistence;
1389    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductVersionPersistence.impl")
1390    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductVersionPersistence scProductVersionPersistence;
1391    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1392    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1393    protected ContainsSCFrameworkVersion containsSCFrameworkVersion;
1394    protected AddSCFrameworkVersion addSCFrameworkVersion;
1395    protected ClearSCFrameworkVersions clearSCFrameworkVersions;
1396    protected RemoveSCFrameworkVersion removeSCFrameworkVersion;
1397
1398    protected class ContainsSCFrameworkVersion {
1399        protected ContainsSCFrameworkVersion(
1400            SCProductVersionPersistenceImpl persistenceImpl) {
1401            super();
1402
1403            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1404                    _SQL_CONTAINSSCFRAMEWORKVERSION,
1405                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1406        }
1407
1408        protected boolean contains(long productVersionId,
1409            long frameworkVersionId) {
1410            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1411                        new Long(productVersionId), new Long(frameworkVersionId)
1412                    });
1413
1414            if (results.size() > 0) {
1415                Integer count = results.get(0);
1416
1417                if (count.intValue() > 0) {
1418                    return true;
1419                }
1420            }
1421
1422            return false;
1423        }
1424
1425        private MappingSqlQuery _mappingSqlQuery;
1426    }
1427
1428    protected class AddSCFrameworkVersion {
1429        protected AddSCFrameworkVersion(
1430            SCProductVersionPersistenceImpl persistenceImpl) {
1431            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1432                    "INSERT INTO SCFrameworkVersi_SCProductVers (productVersionId, frameworkVersionId) VALUES (?, ?)",
1433                    new int[] { Types.BIGINT, Types.BIGINT });
1434            _persistenceImpl = persistenceImpl;
1435        }
1436
1437        protected void add(long productVersionId, long frameworkVersionId) {
1438            if (!_persistenceImpl.containsSCFrameworkVersion.contains(
1439                        productVersionId, frameworkVersionId)) {
1440                _sqlUpdate.update(new Object[] {
1441                        new Long(productVersionId), new Long(frameworkVersionId)
1442                    });
1443            }
1444        }
1445
1446        private SqlUpdate _sqlUpdate;
1447        private SCProductVersionPersistenceImpl _persistenceImpl;
1448    }
1449
1450    protected class ClearSCFrameworkVersions {
1451        protected ClearSCFrameworkVersions(
1452            SCProductVersionPersistenceImpl persistenceImpl) {
1453            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1454                    "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?",
1455                    new int[] { Types.BIGINT });
1456        }
1457
1458        protected void clear(long productVersionId) {
1459            _sqlUpdate.update(new Object[] { new Long(productVersionId) });
1460        }
1461
1462        private SqlUpdate _sqlUpdate;
1463    }
1464
1465    protected class RemoveSCFrameworkVersion {
1466        protected RemoveSCFrameworkVersion(
1467            SCProductVersionPersistenceImpl persistenceImpl) {
1468            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1469                    "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?",
1470                    new int[] { Types.BIGINT, Types.BIGINT });
1471        }
1472
1473        protected void remove(long productVersionId, long frameworkVersionId) {
1474            _sqlUpdate.update(new Object[] {
1475                    new Long(productVersionId), new Long(frameworkVersionId)
1476                });
1477        }
1478
1479        private SqlUpdate _sqlUpdate;
1480    }
1481
1482    private static final String _SQL_GETSCFRAMEWORKVERSIONS = "SELECT {SCFrameworkVersion.*} FROM SCFrameworkVersion INNER JOIN SCFrameworkVersi_SCProductVers ON (SCFrameworkVersi_SCProductVers.frameworkVersionId = SCFrameworkVersion.frameworkVersionId) WHERE (SCFrameworkVersi_SCProductVers.productVersionId = ?)";
1483    private static final String _SQL_GETSCFRAMEWORKVERSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?";
1484    private static final String _SQL_CONTAINSSCFRAMEWORKVERSION = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?";
1485    private static Log _log = LogFactoryUtil.getLog(SCProductVersionPersistenceImpl.class);
1486}