1
22
23 package com.liferay.portlet.tags.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.annotation.BeanReference;
27 import com.liferay.portal.kernel.cache.CacheRegistry;
28 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderPath;
32 import com.liferay.portal.kernel.dao.orm.Query;
33 import com.liferay.portal.kernel.dao.orm.QueryPos;
34 import com.liferay.portal.kernel.dao.orm.QueryUtil;
35 import com.liferay.portal.kernel.dao.orm.Session;
36 import com.liferay.portal.kernel.log.Log;
37 import com.liferay.portal.kernel.log.LogFactoryUtil;
38 import com.liferay.portal.kernel.util.GetterUtil;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.StringPool;
41 import com.liferay.portal.kernel.util.StringUtil;
42 import com.liferay.portal.kernel.util.Validator;
43 import com.liferay.portal.model.ModelListener;
44 import com.liferay.portal.service.persistence.BatchSessionUtil;
45 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
46
47 import com.liferay.portlet.tags.NoSuchVocabularyException;
48 import com.liferay.portlet.tags.model.TagsVocabulary;
49 import com.liferay.portlet.tags.model.impl.TagsVocabularyImpl;
50 import com.liferay.portlet.tags.model.impl.TagsVocabularyModelImpl;
51
52 import java.util.ArrayList;
53 import java.util.Collections;
54 import java.util.List;
55
56
62 public class TagsVocabularyPersistenceImpl extends BasePersistenceImpl
63 implements TagsVocabularyPersistence {
64 public static final String FINDER_CLASS_NAME_ENTITY = TagsVocabularyImpl.class.getName();
65 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
66 ".List";
67 public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
68 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
69 FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
70 new String[] { Long.class.getName(), String.class.getName() });
71 public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
72 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
73 FINDER_CLASS_NAME_LIST, "countByG_N",
74 new String[] { Long.class.getName(), String.class.getName() });
75 public static final FinderPath FINDER_PATH_FIND_BY_G_F = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
76 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
77 FINDER_CLASS_NAME_LIST, "findByG_F",
78 new String[] { Long.class.getName(), Boolean.class.getName() });
79 public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_F = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
80 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
81 FINDER_CLASS_NAME_LIST, "findByG_F",
82 new String[] {
83 Long.class.getName(), Boolean.class.getName(),
84
85 "java.lang.Integer", "java.lang.Integer",
86 "com.liferay.portal.kernel.util.OrderByComparator"
87 });
88 public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
89 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
90 FINDER_CLASS_NAME_LIST, "countByG_F",
91 new String[] { Long.class.getName(), Boolean.class.getName() });
92 public static final FinderPath FINDER_PATH_FIND_BY_C_F = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
93 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
94 FINDER_CLASS_NAME_LIST, "findByC_F",
95 new String[] { Long.class.getName(), Boolean.class.getName() });
96 public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_F = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
97 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
98 FINDER_CLASS_NAME_LIST, "findByC_F",
99 new String[] {
100 Long.class.getName(), Boolean.class.getName(),
101
102 "java.lang.Integer", "java.lang.Integer",
103 "com.liferay.portal.kernel.util.OrderByComparator"
104 });
105 public static final FinderPath FINDER_PATH_COUNT_BY_C_F = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
106 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
107 FINDER_CLASS_NAME_LIST, "countByC_F",
108 new String[] { Long.class.getName(), Boolean.class.getName() });
109 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
110 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
111 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
113 TagsVocabularyModelImpl.FINDER_CACHE_ENABLED,
114 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
115
116 public void cacheResult(TagsVocabulary tagsVocabulary) {
117 EntityCacheUtil.putResult(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
118 TagsVocabularyImpl.class, tagsVocabulary.getPrimaryKey(),
119 tagsVocabulary);
120
121 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
122 new Object[] {
123 new Long(tagsVocabulary.getGroupId()),
124
125 tagsVocabulary.getName()
126 }, tagsVocabulary);
127 }
128
129 public void cacheResult(List<TagsVocabulary> tagsVocabularies) {
130 for (TagsVocabulary tagsVocabulary : tagsVocabularies) {
131 if (EntityCacheUtil.getResult(
132 TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
133 TagsVocabularyImpl.class,
134 tagsVocabulary.getPrimaryKey(), this) == null) {
135 cacheResult(tagsVocabulary);
136 }
137 }
138 }
139
140 public void clearCache() {
141 CacheRegistry.clear(TagsVocabularyImpl.class.getName());
142 EntityCacheUtil.clearCache(TagsVocabularyImpl.class.getName());
143 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
144 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
145 }
146
147 public TagsVocabulary create(long vocabularyId) {
148 TagsVocabulary tagsVocabulary = new TagsVocabularyImpl();
149
150 tagsVocabulary.setNew(true);
151 tagsVocabulary.setPrimaryKey(vocabularyId);
152
153 return tagsVocabulary;
154 }
155
156 public TagsVocabulary remove(long vocabularyId)
157 throws NoSuchVocabularyException, SystemException {
158 Session session = null;
159
160 try {
161 session = openSession();
162
163 TagsVocabulary tagsVocabulary = (TagsVocabulary)session.get(TagsVocabularyImpl.class,
164 new Long(vocabularyId));
165
166 if (tagsVocabulary == null) {
167 if (_log.isWarnEnabled()) {
168 _log.warn("No TagsVocabulary exists with the primary key " +
169 vocabularyId);
170 }
171
172 throw new NoSuchVocabularyException(
173 "No TagsVocabulary exists with the primary key " +
174 vocabularyId);
175 }
176
177 return remove(tagsVocabulary);
178 }
179 catch (NoSuchVocabularyException nsee) {
180 throw nsee;
181 }
182 catch (Exception e) {
183 throw processException(e);
184 }
185 finally {
186 closeSession(session);
187 }
188 }
189
190 public TagsVocabulary remove(TagsVocabulary tagsVocabulary)
191 throws SystemException {
192 for (ModelListener<TagsVocabulary> listener : listeners) {
193 listener.onBeforeRemove(tagsVocabulary);
194 }
195
196 tagsVocabulary = removeImpl(tagsVocabulary);
197
198 for (ModelListener<TagsVocabulary> listener : listeners) {
199 listener.onAfterRemove(tagsVocabulary);
200 }
201
202 return tagsVocabulary;
203 }
204
205 protected TagsVocabulary removeImpl(TagsVocabulary tagsVocabulary)
206 throws SystemException {
207 Session session = null;
208
209 try {
210 session = openSession();
211
212 if (tagsVocabulary.isCachedModel() || BatchSessionUtil.isEnabled()) {
213 Object staleObject = session.get(TagsVocabularyImpl.class,
214 tagsVocabulary.getPrimaryKeyObj());
215
216 if (staleObject != null) {
217 session.evict(staleObject);
218 }
219 }
220
221 session.delete(tagsVocabulary);
222
223 session.flush();
224 }
225 catch (Exception e) {
226 throw processException(e);
227 }
228 finally {
229 closeSession(session);
230 }
231
232 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
233
234 TagsVocabularyModelImpl tagsVocabularyModelImpl = (TagsVocabularyModelImpl)tagsVocabulary;
235
236 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
237 new Object[] {
238 new Long(tagsVocabularyModelImpl.getOriginalGroupId()),
239
240 tagsVocabularyModelImpl.getOriginalName()
241 });
242
243 EntityCacheUtil.removeResult(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
244 TagsVocabularyImpl.class, tagsVocabulary.getPrimaryKey());
245
246 return tagsVocabulary;
247 }
248
249
252 public TagsVocabulary update(TagsVocabulary tagsVocabulary)
253 throws SystemException {
254 if (_log.isWarnEnabled()) {
255 _log.warn(
256 "Using the deprecated update(TagsVocabulary tagsVocabulary) method. Use update(TagsVocabulary tagsVocabulary, boolean merge) instead.");
257 }
258
259 return update(tagsVocabulary, false);
260 }
261
262
275 public TagsVocabulary update(TagsVocabulary tagsVocabulary, boolean merge)
276 throws SystemException {
277 boolean isNew = tagsVocabulary.isNew();
278
279 for (ModelListener<TagsVocabulary> listener : listeners) {
280 if (isNew) {
281 listener.onBeforeCreate(tagsVocabulary);
282 }
283 else {
284 listener.onBeforeUpdate(tagsVocabulary);
285 }
286 }
287
288 tagsVocabulary = updateImpl(tagsVocabulary, merge);
289
290 for (ModelListener<TagsVocabulary> listener : listeners) {
291 if (isNew) {
292 listener.onAfterCreate(tagsVocabulary);
293 }
294 else {
295 listener.onAfterUpdate(tagsVocabulary);
296 }
297 }
298
299 return tagsVocabulary;
300 }
301
302 public TagsVocabulary updateImpl(
303 com.liferay.portlet.tags.model.TagsVocabulary tagsVocabulary,
304 boolean merge) throws SystemException {
305 boolean isNew = tagsVocabulary.isNew();
306
307 TagsVocabularyModelImpl tagsVocabularyModelImpl = (TagsVocabularyModelImpl)tagsVocabulary;
308
309 Session session = null;
310
311 try {
312 session = openSession();
313
314 BatchSessionUtil.update(session, tagsVocabulary, merge);
315
316 tagsVocabulary.setNew(false);
317 }
318 catch (Exception e) {
319 throw processException(e);
320 }
321 finally {
322 closeSession(session);
323 }
324
325 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
326
327 EntityCacheUtil.putResult(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
328 TagsVocabularyImpl.class, tagsVocabulary.getPrimaryKey(),
329 tagsVocabulary);
330
331 if (!isNew &&
332 ((tagsVocabulary.getGroupId() != tagsVocabularyModelImpl.getOriginalGroupId()) ||
333 !Validator.equals(tagsVocabulary.getName(),
334 tagsVocabularyModelImpl.getOriginalName()))) {
335 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
336 new Object[] {
337 new Long(tagsVocabularyModelImpl.getOriginalGroupId()),
338
339 tagsVocabularyModelImpl.getOriginalName()
340 });
341 }
342
343 if (isNew ||
344 ((tagsVocabulary.getGroupId() != tagsVocabularyModelImpl.getOriginalGroupId()) ||
345 !Validator.equals(tagsVocabulary.getName(),
346 tagsVocabularyModelImpl.getOriginalName()))) {
347 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
348 new Object[] {
349 new Long(tagsVocabulary.getGroupId()),
350
351 tagsVocabulary.getName()
352 }, tagsVocabulary);
353 }
354
355 return tagsVocabulary;
356 }
357
358 public TagsVocabulary findByPrimaryKey(long vocabularyId)
359 throws NoSuchVocabularyException, SystemException {
360 TagsVocabulary tagsVocabulary = fetchByPrimaryKey(vocabularyId);
361
362 if (tagsVocabulary == null) {
363 if (_log.isWarnEnabled()) {
364 _log.warn("No TagsVocabulary exists with the primary key " +
365 vocabularyId);
366 }
367
368 throw new NoSuchVocabularyException(
369 "No TagsVocabulary exists with the primary key " +
370 vocabularyId);
371 }
372
373 return tagsVocabulary;
374 }
375
376 public TagsVocabulary fetchByPrimaryKey(long vocabularyId)
377 throws SystemException {
378 TagsVocabulary tagsVocabulary = (TagsVocabulary)EntityCacheUtil.getResult(TagsVocabularyModelImpl.ENTITY_CACHE_ENABLED,
379 TagsVocabularyImpl.class, vocabularyId, this);
380
381 if (tagsVocabulary == null) {
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 tagsVocabulary = (TagsVocabulary)session.get(TagsVocabularyImpl.class,
388 new Long(vocabularyId));
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 if (tagsVocabulary != null) {
395 cacheResult(tagsVocabulary);
396 }
397
398 closeSession(session);
399 }
400 }
401
402 return tagsVocabulary;
403 }
404
405 public TagsVocabulary findByG_N(long groupId, String name)
406 throws NoSuchVocabularyException, SystemException {
407 TagsVocabulary tagsVocabulary = fetchByG_N(groupId, name);
408
409 if (tagsVocabulary == null) {
410 StringBuilder msg = new StringBuilder();
411
412 msg.append("No TagsVocabulary exists with the key {");
413
414 msg.append("groupId=" + groupId);
415
416 msg.append(", ");
417 msg.append("name=" + name);
418
419 msg.append(StringPool.CLOSE_CURLY_BRACE);
420
421 if (_log.isWarnEnabled()) {
422 _log.warn(msg.toString());
423 }
424
425 throw new NoSuchVocabularyException(msg.toString());
426 }
427
428 return tagsVocabulary;
429 }
430
431 public TagsVocabulary fetchByG_N(long groupId, String name)
432 throws SystemException {
433 return fetchByG_N(groupId, name, true);
434 }
435
436 public TagsVocabulary fetchByG_N(long groupId, String name,
437 boolean retrieveFromCache) throws SystemException {
438 Object[] finderArgs = new Object[] { new Long(groupId), name };
439
440 Object result = null;
441
442 if (retrieveFromCache) {
443 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
444 finderArgs, this);
445 }
446
447 if (result == null) {
448 Session session = null;
449
450 try {
451 session = openSession();
452
453 StringBuilder query = new StringBuilder();
454
455 query.append(
456 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
457
458 query.append("groupId = ?");
459
460 query.append(" AND ");
461
462 if (name == null) {
463 query.append("name IS NULL");
464 }
465 else {
466 query.append("name = ?");
467 }
468
469 query.append(" ");
470
471 query.append("ORDER BY ");
472
473 query.append("name ASC");
474
475 Query q = session.createQuery(query.toString());
476
477 QueryPos qPos = QueryPos.getInstance(q);
478
479 qPos.add(groupId);
480
481 if (name != null) {
482 qPos.add(name);
483 }
484
485 List<TagsVocabulary> list = q.list();
486
487 result = list;
488
489 TagsVocabulary tagsVocabulary = null;
490
491 if (list.isEmpty()) {
492 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
493 finderArgs, list);
494 }
495 else {
496 tagsVocabulary = list.get(0);
497
498 cacheResult(tagsVocabulary);
499
500 if ((tagsVocabulary.getGroupId() != groupId) ||
501 (tagsVocabulary.getName() == null) ||
502 !tagsVocabulary.getName().equals(name)) {
503 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
504 finderArgs, tagsVocabulary);
505 }
506 }
507
508 return tagsVocabulary;
509 }
510 catch (Exception e) {
511 throw processException(e);
512 }
513 finally {
514 if (result == null) {
515 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
516 finderArgs, new ArrayList<TagsVocabulary>());
517 }
518
519 closeSession(session);
520 }
521 }
522 else {
523 if (result instanceof List) {
524 return null;
525 }
526 else {
527 return (TagsVocabulary)result;
528 }
529 }
530 }
531
532 public List<TagsVocabulary> findByG_F(long groupId, boolean folksonomy)
533 throws SystemException {
534 Object[] finderArgs = new Object[] {
535 new Long(groupId), Boolean.valueOf(folksonomy)
536 };
537
538 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F,
539 finderArgs, this);
540
541 if (list == null) {
542 Session session = null;
543
544 try {
545 session = openSession();
546
547 StringBuilder query = new StringBuilder();
548
549 query.append(
550 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
551
552 query.append("groupId = ?");
553
554 query.append(" AND ");
555
556 query.append("folksonomy = ?");
557
558 query.append(" ");
559
560 query.append("ORDER BY ");
561
562 query.append("name ASC");
563
564 Query q = session.createQuery(query.toString());
565
566 QueryPos qPos = QueryPos.getInstance(q);
567
568 qPos.add(groupId);
569
570 qPos.add(folksonomy);
571
572 list = q.list();
573 }
574 catch (Exception e) {
575 throw processException(e);
576 }
577 finally {
578 if (list == null) {
579 list = new ArrayList<TagsVocabulary>();
580 }
581
582 cacheResult(list);
583
584 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F, finderArgs,
585 list);
586
587 closeSession(session);
588 }
589 }
590
591 return list;
592 }
593
594 public List<TagsVocabulary> findByG_F(long groupId, boolean folksonomy,
595 int start, int end) throws SystemException {
596 return findByG_F(groupId, folksonomy, start, end, null);
597 }
598
599 public List<TagsVocabulary> findByG_F(long groupId, boolean folksonomy,
600 int start, int end, OrderByComparator obc) throws SystemException {
601 Object[] finderArgs = new Object[] {
602 new Long(groupId), Boolean.valueOf(folksonomy),
603
604 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
605 };
606
607 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_F,
608 finderArgs, this);
609
610 if (list == null) {
611 Session session = null;
612
613 try {
614 session = openSession();
615
616 StringBuilder query = new StringBuilder();
617
618 query.append(
619 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
620
621 query.append("groupId = ?");
622
623 query.append(" AND ");
624
625 query.append("folksonomy = ?");
626
627 query.append(" ");
628
629 if (obc != null) {
630 query.append("ORDER BY ");
631 query.append(obc.getOrderBy());
632 }
633
634 else {
635 query.append("ORDER BY ");
636
637 query.append("name ASC");
638 }
639
640 Query q = session.createQuery(query.toString());
641
642 QueryPos qPos = QueryPos.getInstance(q);
643
644 qPos.add(groupId);
645
646 qPos.add(folksonomy);
647
648 list = (List<TagsVocabulary>)QueryUtil.list(q, getDialect(),
649 start, end);
650 }
651 catch (Exception e) {
652 throw processException(e);
653 }
654 finally {
655 if (list == null) {
656 list = new ArrayList<TagsVocabulary>();
657 }
658
659 cacheResult(list);
660
661 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_F,
662 finderArgs, list);
663
664 closeSession(session);
665 }
666 }
667
668 return list;
669 }
670
671 public TagsVocabulary findByG_F_First(long groupId, boolean folksonomy,
672 OrderByComparator obc)
673 throws NoSuchVocabularyException, SystemException {
674 List<TagsVocabulary> list = findByG_F(groupId, folksonomy, 0, 1, obc);
675
676 if (list.isEmpty()) {
677 StringBuilder msg = new StringBuilder();
678
679 msg.append("No TagsVocabulary exists with the key {");
680
681 msg.append("groupId=" + groupId);
682
683 msg.append(", ");
684 msg.append("folksonomy=" + folksonomy);
685
686 msg.append(StringPool.CLOSE_CURLY_BRACE);
687
688 throw new NoSuchVocabularyException(msg.toString());
689 }
690 else {
691 return list.get(0);
692 }
693 }
694
695 public TagsVocabulary findByG_F_Last(long groupId, boolean folksonomy,
696 OrderByComparator obc)
697 throws NoSuchVocabularyException, SystemException {
698 int count = countByG_F(groupId, folksonomy);
699
700 List<TagsVocabulary> list = findByG_F(groupId, folksonomy, count - 1,
701 count, obc);
702
703 if (list.isEmpty()) {
704 StringBuilder msg = new StringBuilder();
705
706 msg.append("No TagsVocabulary exists with the key {");
707
708 msg.append("groupId=" + groupId);
709
710 msg.append(", ");
711 msg.append("folksonomy=" + folksonomy);
712
713 msg.append(StringPool.CLOSE_CURLY_BRACE);
714
715 throw new NoSuchVocabularyException(msg.toString());
716 }
717 else {
718 return list.get(0);
719 }
720 }
721
722 public TagsVocabulary[] findByG_F_PrevAndNext(long vocabularyId,
723 long groupId, boolean folksonomy, OrderByComparator obc)
724 throws NoSuchVocabularyException, SystemException {
725 TagsVocabulary tagsVocabulary = findByPrimaryKey(vocabularyId);
726
727 int count = countByG_F(groupId, folksonomy);
728
729 Session session = null;
730
731 try {
732 session = openSession();
733
734 StringBuilder query = new StringBuilder();
735
736 query.append(
737 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
738
739 query.append("groupId = ?");
740
741 query.append(" AND ");
742
743 query.append("folksonomy = ?");
744
745 query.append(" ");
746
747 if (obc != null) {
748 query.append("ORDER BY ");
749 query.append(obc.getOrderBy());
750 }
751
752 else {
753 query.append("ORDER BY ");
754
755 query.append("name ASC");
756 }
757
758 Query q = session.createQuery(query.toString());
759
760 QueryPos qPos = QueryPos.getInstance(q);
761
762 qPos.add(groupId);
763
764 qPos.add(folksonomy);
765
766 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
767 tagsVocabulary);
768
769 TagsVocabulary[] array = new TagsVocabularyImpl[3];
770
771 array[0] = (TagsVocabulary)objArray[0];
772 array[1] = (TagsVocabulary)objArray[1];
773 array[2] = (TagsVocabulary)objArray[2];
774
775 return array;
776 }
777 catch (Exception e) {
778 throw processException(e);
779 }
780 finally {
781 closeSession(session);
782 }
783 }
784
785 public List<TagsVocabulary> findByC_F(long companyId, boolean folksonomy)
786 throws SystemException {
787 Object[] finderArgs = new Object[] {
788 new Long(companyId), Boolean.valueOf(folksonomy)
789 };
790
791 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_F,
792 finderArgs, this);
793
794 if (list == null) {
795 Session session = null;
796
797 try {
798 session = openSession();
799
800 StringBuilder query = new StringBuilder();
801
802 query.append(
803 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
804
805 query.append("companyId = ?");
806
807 query.append(" AND ");
808
809 query.append("folksonomy = ?");
810
811 query.append(" ");
812
813 query.append("ORDER BY ");
814
815 query.append("name ASC");
816
817 Query q = session.createQuery(query.toString());
818
819 QueryPos qPos = QueryPos.getInstance(q);
820
821 qPos.add(companyId);
822
823 qPos.add(folksonomy);
824
825 list = q.list();
826 }
827 catch (Exception e) {
828 throw processException(e);
829 }
830 finally {
831 if (list == null) {
832 list = new ArrayList<TagsVocabulary>();
833 }
834
835 cacheResult(list);
836
837 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_F, finderArgs,
838 list);
839
840 closeSession(session);
841 }
842 }
843
844 return list;
845 }
846
847 public List<TagsVocabulary> findByC_F(long companyId, boolean folksonomy,
848 int start, int end) throws SystemException {
849 return findByC_F(companyId, folksonomy, start, end, null);
850 }
851
852 public List<TagsVocabulary> findByC_F(long companyId, boolean folksonomy,
853 int start, int end, OrderByComparator obc) throws SystemException {
854 Object[] finderArgs = new Object[] {
855 new Long(companyId), Boolean.valueOf(folksonomy),
856
857 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
858 };
859
860 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_F,
861 finderArgs, this);
862
863 if (list == null) {
864 Session session = null;
865
866 try {
867 session = openSession();
868
869 StringBuilder query = new StringBuilder();
870
871 query.append(
872 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
873
874 query.append("companyId = ?");
875
876 query.append(" AND ");
877
878 query.append("folksonomy = ?");
879
880 query.append(" ");
881
882 if (obc != null) {
883 query.append("ORDER BY ");
884 query.append(obc.getOrderBy());
885 }
886
887 else {
888 query.append("ORDER BY ");
889
890 query.append("name ASC");
891 }
892
893 Query q = session.createQuery(query.toString());
894
895 QueryPos qPos = QueryPos.getInstance(q);
896
897 qPos.add(companyId);
898
899 qPos.add(folksonomy);
900
901 list = (List<TagsVocabulary>)QueryUtil.list(q, getDialect(),
902 start, end);
903 }
904 catch (Exception e) {
905 throw processException(e);
906 }
907 finally {
908 if (list == null) {
909 list = new ArrayList<TagsVocabulary>();
910 }
911
912 cacheResult(list);
913
914 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_F,
915 finderArgs, list);
916
917 closeSession(session);
918 }
919 }
920
921 return list;
922 }
923
924 public TagsVocabulary findByC_F_First(long companyId, boolean folksonomy,
925 OrderByComparator obc)
926 throws NoSuchVocabularyException, SystemException {
927 List<TagsVocabulary> list = findByC_F(companyId, folksonomy, 0, 1, obc);
928
929 if (list.isEmpty()) {
930 StringBuilder msg = new StringBuilder();
931
932 msg.append("No TagsVocabulary exists with the key {");
933
934 msg.append("companyId=" + companyId);
935
936 msg.append(", ");
937 msg.append("folksonomy=" + folksonomy);
938
939 msg.append(StringPool.CLOSE_CURLY_BRACE);
940
941 throw new NoSuchVocabularyException(msg.toString());
942 }
943 else {
944 return list.get(0);
945 }
946 }
947
948 public TagsVocabulary findByC_F_Last(long companyId, boolean folksonomy,
949 OrderByComparator obc)
950 throws NoSuchVocabularyException, SystemException {
951 int count = countByC_F(companyId, folksonomy);
952
953 List<TagsVocabulary> list = findByC_F(companyId, folksonomy, count - 1,
954 count, obc);
955
956 if (list.isEmpty()) {
957 StringBuilder msg = new StringBuilder();
958
959 msg.append("No TagsVocabulary exists with the key {");
960
961 msg.append("companyId=" + companyId);
962
963 msg.append(", ");
964 msg.append("folksonomy=" + folksonomy);
965
966 msg.append(StringPool.CLOSE_CURLY_BRACE);
967
968 throw new NoSuchVocabularyException(msg.toString());
969 }
970 else {
971 return list.get(0);
972 }
973 }
974
975 public TagsVocabulary[] findByC_F_PrevAndNext(long vocabularyId,
976 long companyId, boolean folksonomy, OrderByComparator obc)
977 throws NoSuchVocabularyException, SystemException {
978 TagsVocabulary tagsVocabulary = findByPrimaryKey(vocabularyId);
979
980 int count = countByC_F(companyId, folksonomy);
981
982 Session session = null;
983
984 try {
985 session = openSession();
986
987 StringBuilder query = new StringBuilder();
988
989 query.append(
990 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
991
992 query.append("companyId = ?");
993
994 query.append(" AND ");
995
996 query.append("folksonomy = ?");
997
998 query.append(" ");
999
1000 if (obc != null) {
1001 query.append("ORDER BY ");
1002 query.append(obc.getOrderBy());
1003 }
1004
1005 else {
1006 query.append("ORDER BY ");
1007
1008 query.append("name ASC");
1009 }
1010
1011 Query q = session.createQuery(query.toString());
1012
1013 QueryPos qPos = QueryPos.getInstance(q);
1014
1015 qPos.add(companyId);
1016
1017 qPos.add(folksonomy);
1018
1019 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1020 tagsVocabulary);
1021
1022 TagsVocabulary[] array = new TagsVocabularyImpl[3];
1023
1024 array[0] = (TagsVocabulary)objArray[0];
1025 array[1] = (TagsVocabulary)objArray[1];
1026 array[2] = (TagsVocabulary)objArray[2];
1027
1028 return array;
1029 }
1030 catch (Exception e) {
1031 throw processException(e);
1032 }
1033 finally {
1034 closeSession(session);
1035 }
1036 }
1037
1038 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1039 throws SystemException {
1040 Session session = null;
1041
1042 try {
1043 session = openSession();
1044
1045 dynamicQuery.compile(session);
1046
1047 return dynamicQuery.list();
1048 }
1049 catch (Exception e) {
1050 throw processException(e);
1051 }
1052 finally {
1053 closeSession(session);
1054 }
1055 }
1056
1057 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1058 int start, int end) throws SystemException {
1059 Session session = null;
1060
1061 try {
1062 session = openSession();
1063
1064 dynamicQuery.setLimit(start, end);
1065
1066 dynamicQuery.compile(session);
1067
1068 return dynamicQuery.list();
1069 }
1070 catch (Exception e) {
1071 throw processException(e);
1072 }
1073 finally {
1074 closeSession(session);
1075 }
1076 }
1077
1078 public List<TagsVocabulary> findAll() throws SystemException {
1079 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1080 }
1081
1082 public List<TagsVocabulary> findAll(int start, int end)
1083 throws SystemException {
1084 return findAll(start, end, null);
1085 }
1086
1087 public List<TagsVocabulary> findAll(int start, int end,
1088 OrderByComparator obc) throws SystemException {
1089 Object[] finderArgs = new Object[] {
1090 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1091 };
1092
1093 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1094 finderArgs, this);
1095
1096 if (list == null) {
1097 Session session = null;
1098
1099 try {
1100 session = openSession();
1101
1102 StringBuilder query = new StringBuilder();
1103
1104 query.append(
1105 "FROM com.liferay.portlet.tags.model.TagsVocabulary ");
1106
1107 if (obc != null) {
1108 query.append("ORDER BY ");
1109 query.append(obc.getOrderBy());
1110 }
1111
1112 else {
1113 query.append("ORDER BY ");
1114
1115 query.append("name ASC");
1116 }
1117
1118 Query q = session.createQuery(query.toString());
1119
1120 if (obc == null) {
1121 list = (List<TagsVocabulary>)QueryUtil.list(q,
1122 getDialect(), start, end, false);
1123
1124 Collections.sort(list);
1125 }
1126 else {
1127 list = (List<TagsVocabulary>)QueryUtil.list(q,
1128 getDialect(), start, end);
1129 }
1130 }
1131 catch (Exception e) {
1132 throw processException(e);
1133 }
1134 finally {
1135 if (list == null) {
1136 list = new ArrayList<TagsVocabulary>();
1137 }
1138
1139 cacheResult(list);
1140
1141 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1142
1143 closeSession(session);
1144 }
1145 }
1146
1147 return list;
1148 }
1149
1150 public void removeByG_N(long groupId, String name)
1151 throws NoSuchVocabularyException, SystemException {
1152 TagsVocabulary tagsVocabulary = findByG_N(groupId, name);
1153
1154 remove(tagsVocabulary);
1155 }
1156
1157 public void removeByG_F(long groupId, boolean folksonomy)
1158 throws SystemException {
1159 for (TagsVocabulary tagsVocabulary : findByG_F(groupId, folksonomy)) {
1160 remove(tagsVocabulary);
1161 }
1162 }
1163
1164 public void removeByC_F(long companyId, boolean folksonomy)
1165 throws SystemException {
1166 for (TagsVocabulary tagsVocabulary : findByC_F(companyId, folksonomy)) {
1167 remove(tagsVocabulary);
1168 }
1169 }
1170
1171 public void removeAll() throws SystemException {
1172 for (TagsVocabulary tagsVocabulary : findAll()) {
1173 remove(tagsVocabulary);
1174 }
1175 }
1176
1177 public int countByG_N(long groupId, String name) throws SystemException {
1178 Object[] finderArgs = new Object[] { new Long(groupId), name };
1179
1180 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1181 finderArgs, this);
1182
1183 if (count == null) {
1184 Session session = null;
1185
1186 try {
1187 session = openSession();
1188
1189 StringBuilder query = new StringBuilder();
1190
1191 query.append("SELECT COUNT(*) ");
1192 query.append(
1193 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
1194
1195 query.append("groupId = ?");
1196
1197 query.append(" AND ");
1198
1199 if (name == null) {
1200 query.append("name IS NULL");
1201 }
1202 else {
1203 query.append("name = ?");
1204 }
1205
1206 query.append(" ");
1207
1208 Query q = session.createQuery(query.toString());
1209
1210 QueryPos qPos = QueryPos.getInstance(q);
1211
1212 qPos.add(groupId);
1213
1214 if (name != null) {
1215 qPos.add(name);
1216 }
1217
1218 count = (Long)q.uniqueResult();
1219 }
1220 catch (Exception e) {
1221 throw processException(e);
1222 }
1223 finally {
1224 if (count == null) {
1225 count = Long.valueOf(0);
1226 }
1227
1228 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1229 count);
1230
1231 closeSession(session);
1232 }
1233 }
1234
1235 return count.intValue();
1236 }
1237
1238 public int countByG_F(long groupId, boolean folksonomy)
1239 throws SystemException {
1240 Object[] finderArgs = new Object[] {
1241 new Long(groupId), Boolean.valueOf(folksonomy)
1242 };
1243
1244 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
1245 finderArgs, this);
1246
1247 if (count == null) {
1248 Session session = null;
1249
1250 try {
1251 session = openSession();
1252
1253 StringBuilder query = new StringBuilder();
1254
1255 query.append("SELECT COUNT(*) ");
1256 query.append(
1257 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
1258
1259 query.append("groupId = ?");
1260
1261 query.append(" AND ");
1262
1263 query.append("folksonomy = ?");
1264
1265 query.append(" ");
1266
1267 Query q = session.createQuery(query.toString());
1268
1269 QueryPos qPos = QueryPos.getInstance(q);
1270
1271 qPos.add(groupId);
1272
1273 qPos.add(folksonomy);
1274
1275 count = (Long)q.uniqueResult();
1276 }
1277 catch (Exception e) {
1278 throw processException(e);
1279 }
1280 finally {
1281 if (count == null) {
1282 count = Long.valueOf(0);
1283 }
1284
1285 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
1286 count);
1287
1288 closeSession(session);
1289 }
1290 }
1291
1292 return count.intValue();
1293 }
1294
1295 public int countByC_F(long companyId, boolean folksonomy)
1296 throws SystemException {
1297 Object[] finderArgs = new Object[] {
1298 new Long(companyId), Boolean.valueOf(folksonomy)
1299 };
1300
1301 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_F,
1302 finderArgs, this);
1303
1304 if (count == null) {
1305 Session session = null;
1306
1307 try {
1308 session = openSession();
1309
1310 StringBuilder query = new StringBuilder();
1311
1312 query.append("SELECT COUNT(*) ");
1313 query.append(
1314 "FROM com.liferay.portlet.tags.model.TagsVocabulary WHERE ");
1315
1316 query.append("companyId = ?");
1317
1318 query.append(" AND ");
1319
1320 query.append("folksonomy = ?");
1321
1322 query.append(" ");
1323
1324 Query q = session.createQuery(query.toString());
1325
1326 QueryPos qPos = QueryPos.getInstance(q);
1327
1328 qPos.add(companyId);
1329
1330 qPos.add(folksonomy);
1331
1332 count = (Long)q.uniqueResult();
1333 }
1334 catch (Exception e) {
1335 throw processException(e);
1336 }
1337 finally {
1338 if (count == null) {
1339 count = Long.valueOf(0);
1340 }
1341
1342 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_F, finderArgs,
1343 count);
1344
1345 closeSession(session);
1346 }
1347 }
1348
1349 return count.intValue();
1350 }
1351
1352 public int countAll() throws SystemException {
1353 Object[] finderArgs = new Object[0];
1354
1355 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1356 finderArgs, this);
1357
1358 if (count == null) {
1359 Session session = null;
1360
1361 try {
1362 session = openSession();
1363
1364 Query q = session.createQuery(
1365 "SELECT COUNT(*) FROM com.liferay.portlet.tags.model.TagsVocabulary");
1366
1367 count = (Long)q.uniqueResult();
1368 }
1369 catch (Exception e) {
1370 throw processException(e);
1371 }
1372 finally {
1373 if (count == null) {
1374 count = Long.valueOf(0);
1375 }
1376
1377 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1378 count);
1379
1380 closeSession(session);
1381 }
1382 }
1383
1384 return count.intValue();
1385 }
1386
1387 public void afterPropertiesSet() {
1388 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1389 com.liferay.portal.util.PropsUtil.get(
1390 "value.object.listener.com.liferay.portlet.tags.model.TagsVocabulary")));
1391
1392 if (listenerClassNames.length > 0) {
1393 try {
1394 List<ModelListener<TagsVocabulary>> listenersList = new ArrayList<ModelListener<TagsVocabulary>>();
1395
1396 for (String listenerClassName : listenerClassNames) {
1397 listenersList.add((ModelListener<TagsVocabulary>)Class.forName(
1398 listenerClassName).newInstance());
1399 }
1400
1401 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1402 }
1403 catch (Exception e) {
1404 _log.error(e);
1405 }
1406 }
1407 }
1408
1409 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
1410 protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1411 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
1412 protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
1413 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence.impl")
1414 protected com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence tagsPropertyPersistence;
1415 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsSourcePersistence.impl")
1416 protected com.liferay.portlet.tags.service.persistence.TagsSourcePersistence tagsSourcePersistence;
1417 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence.impl")
1418 protected com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence tagsVocabularyPersistence;
1419 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1420 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1421 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1422 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1423 private static Log _log = LogFactoryUtil.getLog(TagsVocabularyPersistenceImpl.class);
1424}