1
14
15 package com.liferay.portlet.asset.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.kernel.annotation.BeanReference;
19 import com.liferay.portal.kernel.cache.CacheRegistry;
20 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
21 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
22 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
23 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
24 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
25 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
26 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
27 import com.liferay.portal.kernel.dao.orm.FinderPath;
28 import com.liferay.portal.kernel.dao.orm.Query;
29 import com.liferay.portal.kernel.dao.orm.QueryPos;
30 import com.liferay.portal.kernel.dao.orm.QueryUtil;
31 import com.liferay.portal.kernel.dao.orm.SQLQuery;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.dao.orm.Type;
34 import com.liferay.portal.kernel.exception.SystemException;
35 import com.liferay.portal.kernel.log.Log;
36 import com.liferay.portal.kernel.log.LogFactoryUtil;
37 import com.liferay.portal.kernel.util.GetterUtil;
38 import com.liferay.portal.kernel.util.OrderByComparator;
39 import com.liferay.portal.kernel.util.SetUtil;
40 import com.liferay.portal.kernel.util.StringBundler;
41 import com.liferay.portal.kernel.util.StringPool;
42 import com.liferay.portal.kernel.util.StringUtil;
43 import com.liferay.portal.model.ModelListener;
44 import com.liferay.portal.service.persistence.BatchSessionUtil;
45 import com.liferay.portal.service.persistence.ResourcePersistence;
46 import com.liferay.portal.service.persistence.UserPersistence;
47 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48
49 import com.liferay.portlet.asset.NoSuchTagException;
50 import com.liferay.portlet.asset.model.AssetTag;
51 import com.liferay.portlet.asset.model.impl.AssetTagImpl;
52 import com.liferay.portlet.asset.model.impl.AssetTagModelImpl;
53
54 import java.io.Serializable;
55
56 import java.sql.Types;
57
58 import java.util.ArrayList;
59 import java.util.Collections;
60 import java.util.List;
61 import java.util.Set;
62
63
76 public class AssetTagPersistenceImpl extends BasePersistenceImpl<AssetTag>
77 implements AssetTagPersistence {
78 public static final String FINDER_CLASS_NAME_ENTITY = AssetTagImpl.class.getName();
79 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
80 ".List";
81 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
82 AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
83 "findByGroupId", new String[] { Long.class.getName() });
84 public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
85 AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
86 "findByGroupId",
87 new String[] {
88 Long.class.getName(),
89
90 "java.lang.Integer", "java.lang.Integer",
91 "com.liferay.portal.kernel.util.OrderByComparator"
92 });
93 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
94 AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95 "countByGroupId", new String[] { Long.class.getName() });
96 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
97 AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
98 "findAll", new String[0]);
99 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
100 AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "countAll", new String[0]);
102
103 public void cacheResult(AssetTag assetTag) {
104 EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
105 AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
106 }
107
108 public void cacheResult(List<AssetTag> assetTags) {
109 for (AssetTag assetTag : assetTags) {
110 if (EntityCacheUtil.getResult(
111 AssetTagModelImpl.ENTITY_CACHE_ENABLED,
112 AssetTagImpl.class, assetTag.getPrimaryKey(), this) == null) {
113 cacheResult(assetTag);
114 }
115 }
116 }
117
118 public void clearCache() {
119 CacheRegistry.clear(AssetTagImpl.class.getName());
120 EntityCacheUtil.clearCache(AssetTagImpl.class.getName());
121 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
122 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
123 }
124
125 public AssetTag create(long tagId) {
126 AssetTag assetTag = new AssetTagImpl();
127
128 assetTag.setNew(true);
129 assetTag.setPrimaryKey(tagId);
130
131 return assetTag;
132 }
133
134 public AssetTag remove(Serializable primaryKey)
135 throws NoSuchModelException, SystemException {
136 return remove(((Long)primaryKey).longValue());
137 }
138
139 public AssetTag remove(long tagId)
140 throws NoSuchTagException, SystemException {
141 Session session = null;
142
143 try {
144 session = openSession();
145
146 AssetTag assetTag = (AssetTag)session.get(AssetTagImpl.class,
147 new Long(tagId));
148
149 if (assetTag == null) {
150 if (_log.isWarnEnabled()) {
151 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagId);
152 }
153
154 throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
155 tagId);
156 }
157
158 return remove(assetTag);
159 }
160 catch (NoSuchTagException nsee) {
161 throw nsee;
162 }
163 catch (Exception e) {
164 throw processException(e);
165 }
166 finally {
167 closeSession(session);
168 }
169 }
170
171 public AssetTag remove(AssetTag assetTag) throws SystemException {
172 for (ModelListener<AssetTag> listener : listeners) {
173 listener.onBeforeRemove(assetTag);
174 }
175
176 assetTag = removeImpl(assetTag);
177
178 for (ModelListener<AssetTag> listener : listeners) {
179 listener.onAfterRemove(assetTag);
180 }
181
182 return assetTag;
183 }
184
185 protected AssetTag removeImpl(AssetTag assetTag) throws SystemException {
186 assetTag = toUnwrappedModel(assetTag);
187
188 try {
189 clearAssetEntries.clear(assetTag.getPrimaryKey());
190 }
191 catch (Exception e) {
192 throw processException(e);
193 }
194 finally {
195 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
196 }
197
198 Session session = null;
199
200 try {
201 session = openSession();
202
203 if (assetTag.isCachedModel() || BatchSessionUtil.isEnabled()) {
204 Object staleObject = session.get(AssetTagImpl.class,
205 assetTag.getPrimaryKeyObj());
206
207 if (staleObject != null) {
208 session.evict(staleObject);
209 }
210 }
211
212 session.delete(assetTag);
213
214 session.flush();
215 }
216 catch (Exception e) {
217 throw processException(e);
218 }
219 finally {
220 closeSession(session);
221 }
222
223 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
224
225 EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
226 AssetTagImpl.class, assetTag.getPrimaryKey());
227
228 return assetTag;
229 }
230
231 public AssetTag updateImpl(
232 com.liferay.portlet.asset.model.AssetTag assetTag, boolean merge)
233 throws SystemException {
234 assetTag = toUnwrappedModel(assetTag);
235
236 Session session = null;
237
238 try {
239 session = openSession();
240
241 BatchSessionUtil.update(session, assetTag, merge);
242
243 assetTag.setNew(false);
244 }
245 catch (Exception e) {
246 throw processException(e);
247 }
248 finally {
249 closeSession(session);
250 }
251
252 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
253
254 EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
255 AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
256
257 return assetTag;
258 }
259
260 protected AssetTag toUnwrappedModel(AssetTag assetTag) {
261 if (assetTag instanceof AssetTagImpl) {
262 return assetTag;
263 }
264
265 AssetTagImpl assetTagImpl = new AssetTagImpl();
266
267 assetTagImpl.setNew(assetTag.isNew());
268 assetTagImpl.setPrimaryKey(assetTag.getPrimaryKey());
269
270 assetTagImpl.setTagId(assetTag.getTagId());
271 assetTagImpl.setGroupId(assetTag.getGroupId());
272 assetTagImpl.setCompanyId(assetTag.getCompanyId());
273 assetTagImpl.setUserId(assetTag.getUserId());
274 assetTagImpl.setUserName(assetTag.getUserName());
275 assetTagImpl.setCreateDate(assetTag.getCreateDate());
276 assetTagImpl.setModifiedDate(assetTag.getModifiedDate());
277 assetTagImpl.setName(assetTag.getName());
278 assetTagImpl.setAssetCount(assetTag.getAssetCount());
279
280 return assetTagImpl;
281 }
282
283 public AssetTag findByPrimaryKey(Serializable primaryKey)
284 throws NoSuchModelException, SystemException {
285 return findByPrimaryKey(((Long)primaryKey).longValue());
286 }
287
288 public AssetTag findByPrimaryKey(long tagId)
289 throws NoSuchTagException, SystemException {
290 AssetTag assetTag = fetchByPrimaryKey(tagId);
291
292 if (assetTag == null) {
293 if (_log.isWarnEnabled()) {
294 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagId);
295 }
296
297 throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
298 tagId);
299 }
300
301 return assetTag;
302 }
303
304 public AssetTag fetchByPrimaryKey(Serializable primaryKey)
305 throws SystemException {
306 return fetchByPrimaryKey(((Long)primaryKey).longValue());
307 }
308
309 public AssetTag fetchByPrimaryKey(long tagId) throws SystemException {
310 AssetTag assetTag = (AssetTag)EntityCacheUtil.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
311 AssetTagImpl.class, tagId, this);
312
313 if (assetTag == null) {
314 Session session = null;
315
316 try {
317 session = openSession();
318
319 assetTag = (AssetTag)session.get(AssetTagImpl.class,
320 new Long(tagId));
321 }
322 catch (Exception e) {
323 throw processException(e);
324 }
325 finally {
326 if (assetTag != null) {
327 cacheResult(assetTag);
328 }
329
330 closeSession(session);
331 }
332 }
333
334 return assetTag;
335 }
336
337 public List<AssetTag> findByGroupId(long groupId) throws SystemException {
338 Object[] finderArgs = new Object[] { new Long(groupId) };
339
340 List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
341 finderArgs, this);
342
343 if (list == null) {
344 Session session = null;
345
346 try {
347 session = openSession();
348
349 StringBundler query = new StringBundler(3);
350
351 query.append(_SQL_SELECT_ASSETTAG_WHERE);
352
353 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
354
355 query.append(AssetTagModelImpl.ORDER_BY_JPQL);
356
357 String sql = query.toString();
358
359 Query q = session.createQuery(sql);
360
361 QueryPos qPos = QueryPos.getInstance(q);
362
363 qPos.add(groupId);
364
365 list = q.list();
366 }
367 catch (Exception e) {
368 throw processException(e);
369 }
370 finally {
371 if (list == null) {
372 list = new ArrayList<AssetTag>();
373 }
374
375 cacheResult(list);
376
377 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
378 finderArgs, list);
379
380 closeSession(session);
381 }
382 }
383
384 return list;
385 }
386
387 public List<AssetTag> findByGroupId(long groupId, int start, int end)
388 throws SystemException {
389 return findByGroupId(groupId, start, end, null);
390 }
391
392 public List<AssetTag> findByGroupId(long groupId, int start, int end,
393 OrderByComparator orderByComparator) throws SystemException {
394 Object[] finderArgs = new Object[] {
395 new Long(groupId),
396
397 String.valueOf(start), String.valueOf(end),
398 String.valueOf(orderByComparator)
399 };
400
401 List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
402 finderArgs, this);
403
404 if (list == null) {
405 Session session = null;
406
407 try {
408 session = openSession();
409
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(3 +
414 (orderByComparator.getOrderByFields().length * 3));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_ASSETTAG_WHERE);
421
422 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
423
424 if (orderByComparator != null) {
425 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
426 orderByComparator);
427 }
428
429 else {
430 query.append(AssetTagModelImpl.ORDER_BY_JPQL);
431 }
432
433 String sql = query.toString();
434
435 Query q = session.createQuery(sql);
436
437 QueryPos qPos = QueryPos.getInstance(q);
438
439 qPos.add(groupId);
440
441 list = (List<AssetTag>)QueryUtil.list(q, getDialect(), start,
442 end);
443 }
444 catch (Exception e) {
445 throw processException(e);
446 }
447 finally {
448 if (list == null) {
449 list = new ArrayList<AssetTag>();
450 }
451
452 cacheResult(list);
453
454 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
455 finderArgs, list);
456
457 closeSession(session);
458 }
459 }
460
461 return list;
462 }
463
464 public AssetTag findByGroupId_First(long groupId,
465 OrderByComparator orderByComparator)
466 throws NoSuchTagException, SystemException {
467 List<AssetTag> list = findByGroupId(groupId, 0, 1, orderByComparator);
468
469 if (list.isEmpty()) {
470 StringBundler msg = new StringBundler(4);
471
472 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
473
474 msg.append("groupId=");
475 msg.append(groupId);
476
477 msg.append(StringPool.CLOSE_CURLY_BRACE);
478
479 throw new NoSuchTagException(msg.toString());
480 }
481 else {
482 return list.get(0);
483 }
484 }
485
486 public AssetTag findByGroupId_Last(long groupId,
487 OrderByComparator orderByComparator)
488 throws NoSuchTagException, SystemException {
489 int count = countByGroupId(groupId);
490
491 List<AssetTag> list = findByGroupId(groupId, count - 1, count,
492 orderByComparator);
493
494 if (list.isEmpty()) {
495 StringBundler msg = new StringBundler(4);
496
497 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
498
499 msg.append("groupId=");
500 msg.append(groupId);
501
502 msg.append(StringPool.CLOSE_CURLY_BRACE);
503
504 throw new NoSuchTagException(msg.toString());
505 }
506 else {
507 return list.get(0);
508 }
509 }
510
511 public AssetTag[] findByGroupId_PrevAndNext(long tagId, long groupId,
512 OrderByComparator orderByComparator)
513 throws NoSuchTagException, SystemException {
514 AssetTag assetTag = findByPrimaryKey(tagId);
515
516 int count = countByGroupId(groupId);
517
518 Session session = null;
519
520 try {
521 session = openSession();
522
523 StringBundler query = null;
524
525 if (orderByComparator != null) {
526 query = new StringBundler(3 +
527 (orderByComparator.getOrderByFields().length * 3));
528 }
529 else {
530 query = new StringBundler(3);
531 }
532
533 query.append(_SQL_SELECT_ASSETTAG_WHERE);
534
535 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
536
537 if (orderByComparator != null) {
538 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
539 orderByComparator);
540 }
541
542 else {
543 query.append(AssetTagModelImpl.ORDER_BY_JPQL);
544 }
545
546 String sql = query.toString();
547
548 Query q = session.createQuery(sql);
549
550 QueryPos qPos = QueryPos.getInstance(q);
551
552 qPos.add(groupId);
553
554 Object[] objArray = QueryUtil.getPrevAndNext(q, count,
555 orderByComparator, assetTag);
556
557 AssetTag[] array = new AssetTagImpl[3];
558
559 array[0] = (AssetTag)objArray[0];
560 array[1] = (AssetTag)objArray[1];
561 array[2] = (AssetTag)objArray[2];
562
563 return array;
564 }
565 catch (Exception e) {
566 throw processException(e);
567 }
568 finally {
569 closeSession(session);
570 }
571 }
572
573 public List<AssetTag> findAll() throws SystemException {
574 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
575 }
576
577 public List<AssetTag> findAll(int start, int end) throws SystemException {
578 return findAll(start, end, null);
579 }
580
581 public List<AssetTag> findAll(int start, int end,
582 OrderByComparator orderByComparator) throws SystemException {
583 Object[] finderArgs = new Object[] {
584 String.valueOf(start), String.valueOf(end),
585 String.valueOf(orderByComparator)
586 };
587
588 List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
589 finderArgs, this);
590
591 if (list == null) {
592 Session session = null;
593
594 try {
595 session = openSession();
596
597 StringBundler query = null;
598 String sql = null;
599
600 if (orderByComparator != null) {
601 query = new StringBundler(2 +
602 (orderByComparator.getOrderByFields().length * 3));
603
604 query.append(_SQL_SELECT_ASSETTAG);
605
606 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
607 orderByComparator);
608
609 sql = query.toString();
610 }
611
612 else {
613 sql = _SQL_SELECT_ASSETTAG.concat(AssetTagModelImpl.ORDER_BY_JPQL);
614 }
615
616 Query q = session.createQuery(sql);
617
618 if (orderByComparator == null) {
619 list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
620 start, end, false);
621
622 Collections.sort(list);
623 }
624 else {
625 list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
626 start, end);
627 }
628 }
629 catch (Exception e) {
630 throw processException(e);
631 }
632 finally {
633 if (list == null) {
634 list = new ArrayList<AssetTag>();
635 }
636
637 cacheResult(list);
638
639 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
640
641 closeSession(session);
642 }
643 }
644
645 return list;
646 }
647
648 public void removeByGroupId(long groupId) throws SystemException {
649 for (AssetTag assetTag : findByGroupId(groupId)) {
650 remove(assetTag);
651 }
652 }
653
654 public void removeAll() throws SystemException {
655 for (AssetTag assetTag : findAll()) {
656 remove(assetTag);
657 }
658 }
659
660 public int countByGroupId(long groupId) throws SystemException {
661 Object[] finderArgs = new Object[] { new Long(groupId) };
662
663 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
664 finderArgs, this);
665
666 if (count == null) {
667 Session session = null;
668
669 try {
670 session = openSession();
671
672 StringBundler query = new StringBundler(2);
673
674 query.append(_SQL_COUNT_ASSETTAG_WHERE);
675
676 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
677
678 String sql = query.toString();
679
680 Query q = session.createQuery(sql);
681
682 QueryPos qPos = QueryPos.getInstance(q);
683
684 qPos.add(groupId);
685
686 count = (Long)q.uniqueResult();
687 }
688 catch (Exception e) {
689 throw processException(e);
690 }
691 finally {
692 if (count == null) {
693 count = Long.valueOf(0);
694 }
695
696 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
697 finderArgs, count);
698
699 closeSession(session);
700 }
701 }
702
703 return count.intValue();
704 }
705
706 public int countAll() throws SystemException {
707 Object[] finderArgs = new Object[0];
708
709 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
710 finderArgs, this);
711
712 if (count == null) {
713 Session session = null;
714
715 try {
716 session = openSession();
717
718 Query q = session.createQuery(_SQL_COUNT_ASSETTAG);
719
720 count = (Long)q.uniqueResult();
721 }
722 catch (Exception e) {
723 throw processException(e);
724 }
725 finally {
726 if (count == null) {
727 count = Long.valueOf(0);
728 }
729
730 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
731 count);
732
733 closeSession(session);
734 }
735 }
736
737 return count.intValue();
738 }
739
740 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
741 long pk) throws SystemException {
742 return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
743 }
744
745 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
746 long pk, int start, int end) throws SystemException {
747 return getAssetEntries(pk, start, end, null);
748 }
749
750 public static final FinderPath FINDER_PATH_GET_ASSETENTRIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
751 AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
752 AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
753 "getAssetEntries",
754 new String[] {
755 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
756 "com.liferay.portal.kernel.util.OrderByComparator"
757 });
758
759 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
760 long pk, int start, int end, OrderByComparator orderByComparator)
761 throws SystemException {
762 Object[] finderArgs = new Object[] {
763 new Long(pk), String.valueOf(start), String.valueOf(end),
764 String.valueOf(orderByComparator)
765 };
766
767 List<com.liferay.portlet.asset.model.AssetEntry> list = (List<com.liferay.portlet.asset.model.AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES,
768 finderArgs, this);
769
770 if (list == null) {
771 Session session = null;
772
773 try {
774 session = openSession();
775
776 String sql = null;
777
778 if (orderByComparator != null) {
779 sql = _SQL_GETASSETENTRIES.concat(ORDER_BY_CLAUSE)
780 .concat(orderByComparator.getOrderBy());
781 }
782
783 sql = _SQL_GETASSETENTRIES;
784
785 SQLQuery q = session.createSQLQuery(sql);
786
787 q.addEntity("AssetEntry",
788 com.liferay.portlet.asset.model.impl.AssetEntryImpl.class);
789
790 QueryPos qPos = QueryPos.getInstance(q);
791
792 qPos.add(pk);
793
794 list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
795 getDialect(), start, end);
796 }
797 catch (Exception e) {
798 throw processException(e);
799 }
800 finally {
801 if (list == null) {
802 list = new ArrayList<com.liferay.portlet.asset.model.AssetEntry>();
803 }
804
805 assetEntryPersistence.cacheResult(list);
806
807 FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES,
808 finderArgs, list);
809
810 closeSession(session);
811 }
812 }
813
814 return list;
815 }
816
817 public static final FinderPath FINDER_PATH_GET_ASSETENTRIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
818 AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
819 AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
820 "getAssetEntriesSize", new String[] { Long.class.getName() });
821
822 public int getAssetEntriesSize(long pk) throws SystemException {
823 Object[] finderArgs = new Object[] { new Long(pk) };
824
825 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
826 finderArgs, this);
827
828 if (count == null) {
829 Session session = null;
830
831 try {
832 session = openSession();
833
834 SQLQuery q = session.createSQLQuery(_SQL_GETASSETENTRIESSIZE);
835
836 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
837
838 QueryPos qPos = QueryPos.getInstance(q);
839
840 qPos.add(pk);
841
842 count = (Long)q.uniqueResult();
843 }
844 catch (Exception e) {
845 throw processException(e);
846 }
847 finally {
848 if (count == null) {
849 count = Long.valueOf(0);
850 }
851
852 FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
853 finderArgs, count);
854
855 closeSession(session);
856 }
857 }
858
859 return count.intValue();
860 }
861
862 public static final FinderPath FINDER_PATH_CONTAINS_ASSETENTRY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
863 AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
864 AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
865 "containsAssetEntry",
866 new String[] { Long.class.getName(), Long.class.getName() });
867
868 public boolean containsAssetEntry(long pk, long assetEntryPK)
869 throws SystemException {
870 Object[] finderArgs = new Object[] { new Long(pk), new Long(assetEntryPK) };
871
872 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETENTRY,
873 finderArgs, this);
874
875 if (value == null) {
876 try {
877 value = Boolean.valueOf(containsAssetEntry.contains(pk,
878 assetEntryPK));
879 }
880 catch (Exception e) {
881 throw processException(e);
882 }
883 finally {
884 if (value == null) {
885 value = Boolean.FALSE;
886 }
887
888 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETENTRY,
889 finderArgs, value);
890 }
891 }
892
893 return value.booleanValue();
894 }
895
896 public boolean containsAssetEntries(long pk) throws SystemException {
897 if (getAssetEntriesSize(pk) > 0) {
898 return true;
899 }
900 else {
901 return false;
902 }
903 }
904
905 public void addAssetEntry(long pk, long assetEntryPK)
906 throws SystemException {
907 try {
908 addAssetEntry.add(pk, assetEntryPK);
909 }
910 catch (Exception e) {
911 throw processException(e);
912 }
913 finally {
914 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
915 }
916 }
917
918 public void addAssetEntry(long pk,
919 com.liferay.portlet.asset.model.AssetEntry assetEntry)
920 throws SystemException {
921 try {
922 addAssetEntry.add(pk, assetEntry.getPrimaryKey());
923 }
924 catch (Exception e) {
925 throw processException(e);
926 }
927 finally {
928 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
929 }
930 }
931
932 public void addAssetEntries(long pk, long[] assetEntryPKs)
933 throws SystemException {
934 try {
935 for (long assetEntryPK : assetEntryPKs) {
936 addAssetEntry.add(pk, assetEntryPK);
937 }
938 }
939 catch (Exception e) {
940 throw processException(e);
941 }
942 finally {
943 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
944 }
945 }
946
947 public void addAssetEntries(long pk,
948 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
949 throws SystemException {
950 try {
951 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
952 addAssetEntry.add(pk, assetEntry.getPrimaryKey());
953 }
954 }
955 catch (Exception e) {
956 throw processException(e);
957 }
958 finally {
959 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
960 }
961 }
962
963 public void clearAssetEntries(long pk) throws SystemException {
964 try {
965 clearAssetEntries.clear(pk);
966 }
967 catch (Exception e) {
968 throw processException(e);
969 }
970 finally {
971 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
972 }
973 }
974
975 public void removeAssetEntry(long pk, long assetEntryPK)
976 throws SystemException {
977 try {
978 removeAssetEntry.remove(pk, assetEntryPK);
979 }
980 catch (Exception e) {
981 throw processException(e);
982 }
983 finally {
984 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
985 }
986 }
987
988 public void removeAssetEntry(long pk,
989 com.liferay.portlet.asset.model.AssetEntry assetEntry)
990 throws SystemException {
991 try {
992 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
993 }
994 catch (Exception e) {
995 throw processException(e);
996 }
997 finally {
998 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
999 }
1000 }
1001
1002 public void removeAssetEntries(long pk, long[] assetEntryPKs)
1003 throws SystemException {
1004 try {
1005 for (long assetEntryPK : assetEntryPKs) {
1006 removeAssetEntry.remove(pk, assetEntryPK);
1007 }
1008 }
1009 catch (Exception e) {
1010 throw processException(e);
1011 }
1012 finally {
1013 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1014 }
1015 }
1016
1017 public void removeAssetEntries(long pk,
1018 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1019 throws SystemException {
1020 try {
1021 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1022 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1023 }
1024 }
1025 catch (Exception e) {
1026 throw processException(e);
1027 }
1028 finally {
1029 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1030 }
1031 }
1032
1033 public void setAssetEntries(long pk, long[] assetEntryPKs)
1034 throws SystemException {
1035 try {
1036 Set<Long> assetEntryPKSet = SetUtil.fromArray(assetEntryPKs);
1037
1038 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = getAssetEntries(pk);
1039
1040 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1041 if (!assetEntryPKSet.contains(assetEntry.getPrimaryKey())) {
1042 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1043 }
1044 else {
1045 assetEntryPKSet.remove(assetEntry.getPrimaryKey());
1046 }
1047 }
1048
1049 for (Long assetEntryPK : assetEntryPKSet) {
1050 addAssetEntry.add(pk, assetEntryPK);
1051 }
1052 }
1053 catch (Exception e) {
1054 throw processException(e);
1055 }
1056 finally {
1057 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1058 }
1059 }
1060
1061 public void setAssetEntries(long pk,
1062 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1063 throws SystemException {
1064 try {
1065 long[] assetEntryPKs = new long[assetEntries.size()];
1066
1067 for (int i = 0; i < assetEntries.size(); i++) {
1068 com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
1069
1070 assetEntryPKs[i] = assetEntry.getPrimaryKey();
1071 }
1072
1073 setAssetEntries(pk, assetEntryPKs);
1074 }
1075 catch (Exception e) {
1076 throw processException(e);
1077 }
1078 finally {
1079 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1080 }
1081 }
1082
1083 public void afterPropertiesSet() {
1084 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1085 com.liferay.portal.util.PropsUtil.get(
1086 "value.object.listener.com.liferay.portlet.asset.model.AssetTag")));
1087
1088 if (listenerClassNames.length > 0) {
1089 try {
1090 List<ModelListener<AssetTag>> listenersList = new ArrayList<ModelListener<AssetTag>>();
1091
1092 for (String listenerClassName : listenerClassNames) {
1093 listenersList.add((ModelListener<AssetTag>)Class.forName(
1094 listenerClassName).newInstance());
1095 }
1096
1097 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1098 }
1099 catch (Exception e) {
1100 _log.error(e);
1101 }
1102 }
1103
1104 containsAssetEntry = new ContainsAssetEntry(this);
1105
1106 addAssetEntry = new AddAssetEntry(this);
1107 clearAssetEntries = new ClearAssetEntries(this);
1108 removeAssetEntry = new RemoveAssetEntry(this);
1109 }
1110
1111 @BeanReference(type = AssetCategoryPersistence.class)
1112 protected AssetCategoryPersistence assetCategoryPersistence;
1113 @BeanReference(type = AssetCategoryPropertyPersistence.class)
1114 protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1115 @BeanReference(type = AssetEntryPersistence.class)
1116 protected AssetEntryPersistence assetEntryPersistence;
1117 @BeanReference(type = AssetLinkPersistence.class)
1118 protected AssetLinkPersistence assetLinkPersistence;
1119 @BeanReference(type = AssetTagPersistence.class)
1120 protected AssetTagPersistence assetTagPersistence;
1121 @BeanReference(type = AssetTagPropertyPersistence.class)
1122 protected AssetTagPropertyPersistence assetTagPropertyPersistence;
1123 @BeanReference(type = AssetTagStatsPersistence.class)
1124 protected AssetTagStatsPersistence assetTagStatsPersistence;
1125 @BeanReference(type = AssetVocabularyPersistence.class)
1126 protected AssetVocabularyPersistence assetVocabularyPersistence;
1127 @BeanReference(type = ResourcePersistence.class)
1128 protected ResourcePersistence resourcePersistence;
1129 @BeanReference(type = UserPersistence.class)
1130 protected UserPersistence userPersistence;
1131 protected ContainsAssetEntry containsAssetEntry;
1132 protected AddAssetEntry addAssetEntry;
1133 protected ClearAssetEntries clearAssetEntries;
1134 protected RemoveAssetEntry removeAssetEntry;
1135
1136 protected class ContainsAssetEntry {
1137 protected ContainsAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1138 super();
1139
1140 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1141 _SQL_CONTAINSASSETENTRY,
1142 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1143 }
1144
1145 protected boolean contains(long tagId, long entryId) {
1146 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1147 new Long(tagId), new Long(entryId)
1148 });
1149
1150 if (results.size() > 0) {
1151 Integer count = results.get(0);
1152
1153 if (count.intValue() > 0) {
1154 return true;
1155 }
1156 }
1157
1158 return false;
1159 }
1160
1161 private MappingSqlQuery<Integer> _mappingSqlQuery;
1162 }
1163
1164 protected class AddAssetEntry {
1165 protected AddAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1166 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1167 "INSERT INTO AssetEntries_AssetTags (tagId, entryId) VALUES (?, ?)",
1168 new int[] { Types.BIGINT, Types.BIGINT });
1169 _persistenceImpl = persistenceImpl;
1170 }
1171
1172 protected void add(long tagId, long entryId) throws SystemException {
1173 if (!_persistenceImpl.containsAssetEntry.contains(tagId, entryId)) {
1174 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
1175 assetEntryPersistence.getListeners();
1176
1177 for (ModelListener<AssetTag> listener : listeners) {
1178 listener.onBeforeAddAssociation(tagId,
1179 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1180 entryId);
1181 }
1182
1183 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1184 listener.onBeforeAddAssociation(entryId,
1185 AssetTag.class.getName(), tagId);
1186 }
1187
1188 _sqlUpdate.update(new Object[] {
1189 new Long(tagId), new Long(entryId)
1190 });
1191
1192 for (ModelListener<AssetTag> listener : listeners) {
1193 listener.onAfterAddAssociation(tagId,
1194 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1195 entryId);
1196 }
1197
1198 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1199 listener.onAfterAddAssociation(entryId,
1200 AssetTag.class.getName(), tagId);
1201 }
1202 }
1203 }
1204
1205 private SqlUpdate _sqlUpdate;
1206 private AssetTagPersistenceImpl _persistenceImpl;
1207 }
1208
1209 protected class ClearAssetEntries {
1210 protected ClearAssetEntries(AssetTagPersistenceImpl persistenceImpl) {
1211 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1212 "DELETE FROM AssetEntries_AssetTags WHERE tagId = ?",
1213 new int[] { Types.BIGINT });
1214 }
1215
1216 protected void clear(long tagId) throws SystemException {
1217 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
1218 assetEntryPersistence.getListeners();
1219
1220 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = null;
1221
1222 if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
1223 assetEntries = getAssetEntries(tagId);
1224
1225 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1226 for (ModelListener<AssetTag> listener : listeners) {
1227 listener.onBeforeRemoveAssociation(tagId,
1228 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1229 assetEntry.getPrimaryKey());
1230 }
1231
1232 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1233 listener.onBeforeRemoveAssociation(assetEntry.getPrimaryKey(),
1234 AssetTag.class.getName(), tagId);
1235 }
1236 }
1237 }
1238
1239 _sqlUpdate.update(new Object[] { new Long(tagId) });
1240
1241 if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
1242 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1243 for (ModelListener<AssetTag> listener : listeners) {
1244 listener.onAfterRemoveAssociation(tagId,
1245 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1246 assetEntry.getPrimaryKey());
1247 }
1248
1249 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1250 listener.onAfterRemoveAssociation(assetEntry.getPrimaryKey(),
1251 AssetTag.class.getName(), tagId);
1252 }
1253 }
1254 }
1255 }
1256
1257 private SqlUpdate _sqlUpdate;
1258 }
1259
1260 protected class RemoveAssetEntry {
1261 protected RemoveAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1262 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1263 "DELETE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?",
1264 new int[] { Types.BIGINT, Types.BIGINT });
1265 _persistenceImpl = persistenceImpl;
1266 }
1267
1268 protected void remove(long tagId, long entryId)
1269 throws SystemException {
1270 if (_persistenceImpl.containsAssetEntry.contains(tagId, entryId)) {
1271 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
1272 assetEntryPersistence.getListeners();
1273
1274 for (ModelListener<AssetTag> listener : listeners) {
1275 listener.onBeforeRemoveAssociation(tagId,
1276 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1277 entryId);
1278 }
1279
1280 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1281 listener.onBeforeRemoveAssociation(entryId,
1282 AssetTag.class.getName(), tagId);
1283 }
1284
1285 _sqlUpdate.update(new Object[] {
1286 new Long(tagId), new Long(entryId)
1287 });
1288
1289 for (ModelListener<AssetTag> listener : listeners) {
1290 listener.onAfterRemoveAssociation(tagId,
1291 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1292 entryId);
1293 }
1294
1295 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1296 listener.onAfterRemoveAssociation(entryId,
1297 AssetTag.class.getName(), tagId);
1298 }
1299 }
1300 }
1301
1302 private SqlUpdate _sqlUpdate;
1303 private AssetTagPersistenceImpl _persistenceImpl;
1304 }
1305
1306 private static final String _SQL_SELECT_ASSETTAG = "SELECT assetTag FROM AssetTag assetTag";
1307 private static final String _SQL_SELECT_ASSETTAG_WHERE = "SELECT assetTag FROM AssetTag assetTag WHERE ";
1308 private static final String _SQL_COUNT_ASSETTAG = "SELECT COUNT(assetTag) FROM AssetTag assetTag";
1309 private static final String _SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(assetTag) FROM AssetTag assetTag WHERE ";
1310 private static final String _SQL_GETASSETENTRIES = "SELECT {AssetEntry.*} FROM AssetEntry INNER JOIN AssetEntries_AssetTags ON (AssetEntries_AssetTags.entryId = AssetEntry.entryId) WHERE (AssetEntries_AssetTags.tagId = ?)";
1311 private static final String _SQL_GETASSETENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ?";
1312 private static final String _SQL_CONTAINSASSETENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?";
1313 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetTag.groupId = ?";
1314 private static final String _ORDER_BY_ENTITY_ALIAS = "assetTag.";
1315 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTag exists with the primary key ";
1316 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTag exists with the key {";
1317 private static Log _log = LogFactoryUtil.getLog(AssetTagPersistenceImpl.class);
1318}