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