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