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 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary WHERE ");
457
458 query.append("tagsVocabulary.groupId = ?");
459
460 query.append(" AND ");
461
462 if (name == null) {
463 query.append("tagsVocabulary.name IS NULL");
464 }
465 else {
466 query.append("tagsVocabulary.name = ?");
467 }
468
469 query.append(" ");
470
471 query.append("ORDER BY ");
472
473 query.append("tagsVocabulary.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 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary WHERE ");
551
552 query.append("tagsVocabulary.groupId = ?");
553
554 query.append(" AND ");
555
556 query.append("tagsVocabulary.folksonomy = ?");
557
558 query.append(" ");
559
560 query.append("ORDER BY ");
561
562 query.append("tagsVocabulary.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 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary WHERE ");
620
621 query.append("tagsVocabulary.groupId = ?");
622
623 query.append(" AND ");
624
625 query.append("tagsVocabulary.folksonomy = ?");
626
627 query.append(" ");
628
629 if (obc != null) {
630 query.append("ORDER BY ");
631
632 String[] orderByFields = obc.getOrderByFields();
633
634 for (int i = 0; i < orderByFields.length; i++) {
635 query.append("tagsVocabulary.");
636 query.append(orderByFields[i]);
637
638 if (obc.isAscending()) {
639 query.append(" ASC");
640 }
641 else {
642 query.append(" DESC");
643 }
644
645 if ((i + 1) < orderByFields.length) {
646 query.append(", ");
647 }
648 }
649 }
650
651 else {
652 query.append("ORDER BY ");
653
654 query.append("tagsVocabulary.name ASC");
655 }
656
657 Query q = session.createQuery(query.toString());
658
659 QueryPos qPos = QueryPos.getInstance(q);
660
661 qPos.add(groupId);
662
663 qPos.add(folksonomy);
664
665 list = (List<TagsVocabulary>)QueryUtil.list(q, getDialect(),
666 start, end);
667 }
668 catch (Exception e) {
669 throw processException(e);
670 }
671 finally {
672 if (list == null) {
673 list = new ArrayList<TagsVocabulary>();
674 }
675
676 cacheResult(list);
677
678 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_F,
679 finderArgs, list);
680
681 closeSession(session);
682 }
683 }
684
685 return list;
686 }
687
688 public TagsVocabulary findByG_F_First(long groupId, boolean folksonomy,
689 OrderByComparator obc)
690 throws NoSuchVocabularyException, SystemException {
691 List<TagsVocabulary> list = findByG_F(groupId, folksonomy, 0, 1, obc);
692
693 if (list.isEmpty()) {
694 StringBuilder msg = new StringBuilder();
695
696 msg.append("No TagsVocabulary exists with the key {");
697
698 msg.append("groupId=" + groupId);
699
700 msg.append(", ");
701 msg.append("folksonomy=" + folksonomy);
702
703 msg.append(StringPool.CLOSE_CURLY_BRACE);
704
705 throw new NoSuchVocabularyException(msg.toString());
706 }
707 else {
708 return list.get(0);
709 }
710 }
711
712 public TagsVocabulary findByG_F_Last(long groupId, boolean folksonomy,
713 OrderByComparator obc)
714 throws NoSuchVocabularyException, SystemException {
715 int count = countByG_F(groupId, folksonomy);
716
717 List<TagsVocabulary> list = findByG_F(groupId, folksonomy, count - 1,
718 count, obc);
719
720 if (list.isEmpty()) {
721 StringBuilder msg = new StringBuilder();
722
723 msg.append("No TagsVocabulary exists with the key {");
724
725 msg.append("groupId=" + groupId);
726
727 msg.append(", ");
728 msg.append("folksonomy=" + folksonomy);
729
730 msg.append(StringPool.CLOSE_CURLY_BRACE);
731
732 throw new NoSuchVocabularyException(msg.toString());
733 }
734 else {
735 return list.get(0);
736 }
737 }
738
739 public TagsVocabulary[] findByG_F_PrevAndNext(long vocabularyId,
740 long groupId, boolean folksonomy, OrderByComparator obc)
741 throws NoSuchVocabularyException, SystemException {
742 TagsVocabulary tagsVocabulary = findByPrimaryKey(vocabularyId);
743
744 int count = countByG_F(groupId, folksonomy);
745
746 Session session = null;
747
748 try {
749 session = openSession();
750
751 StringBuilder query = new StringBuilder();
752
753 query.append(
754 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary WHERE ");
755
756 query.append("tagsVocabulary.groupId = ?");
757
758 query.append(" AND ");
759
760 query.append("tagsVocabulary.folksonomy = ?");
761
762 query.append(" ");
763
764 if (obc != null) {
765 query.append("ORDER BY ");
766
767 String[] orderByFields = obc.getOrderByFields();
768
769 for (int i = 0; i < orderByFields.length; i++) {
770 query.append("tagsVocabulary.");
771 query.append(orderByFields[i]);
772
773 if (obc.isAscending()) {
774 query.append(" ASC");
775 }
776 else {
777 query.append(" DESC");
778 }
779
780 if ((i + 1) < orderByFields.length) {
781 query.append(", ");
782 }
783 }
784 }
785
786 else {
787 query.append("ORDER BY ");
788
789 query.append("tagsVocabulary.name ASC");
790 }
791
792 Query q = session.createQuery(query.toString());
793
794 QueryPos qPos = QueryPos.getInstance(q);
795
796 qPos.add(groupId);
797
798 qPos.add(folksonomy);
799
800 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
801 tagsVocabulary);
802
803 TagsVocabulary[] array = new TagsVocabularyImpl[3];
804
805 array[0] = (TagsVocabulary)objArray[0];
806 array[1] = (TagsVocabulary)objArray[1];
807 array[2] = (TagsVocabulary)objArray[2];
808
809 return array;
810 }
811 catch (Exception e) {
812 throw processException(e);
813 }
814 finally {
815 closeSession(session);
816 }
817 }
818
819 public List<TagsVocabulary> findByC_F(long companyId, boolean folksonomy)
820 throws SystemException {
821 Object[] finderArgs = new Object[] {
822 new Long(companyId), Boolean.valueOf(folksonomy)
823 };
824
825 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_F,
826 finderArgs, this);
827
828 if (list == null) {
829 Session session = null;
830
831 try {
832 session = openSession();
833
834 StringBuilder query = new StringBuilder();
835
836 query.append(
837 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary WHERE ");
838
839 query.append("tagsVocabulary.companyId = ?");
840
841 query.append(" AND ");
842
843 query.append("tagsVocabulary.folksonomy = ?");
844
845 query.append(" ");
846
847 query.append("ORDER BY ");
848
849 query.append("tagsVocabulary.name ASC");
850
851 Query q = session.createQuery(query.toString());
852
853 QueryPos qPos = QueryPos.getInstance(q);
854
855 qPos.add(companyId);
856
857 qPos.add(folksonomy);
858
859 list = q.list();
860 }
861 catch (Exception e) {
862 throw processException(e);
863 }
864 finally {
865 if (list == null) {
866 list = new ArrayList<TagsVocabulary>();
867 }
868
869 cacheResult(list);
870
871 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_F, finderArgs,
872 list);
873
874 closeSession(session);
875 }
876 }
877
878 return list;
879 }
880
881 public List<TagsVocabulary> findByC_F(long companyId, boolean folksonomy,
882 int start, int end) throws SystemException {
883 return findByC_F(companyId, folksonomy, start, end, null);
884 }
885
886 public List<TagsVocabulary> findByC_F(long companyId, boolean folksonomy,
887 int start, int end, OrderByComparator obc) throws SystemException {
888 Object[] finderArgs = new Object[] {
889 new Long(companyId), Boolean.valueOf(folksonomy),
890
891 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
892 };
893
894 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_F,
895 finderArgs, this);
896
897 if (list == null) {
898 Session session = null;
899
900 try {
901 session = openSession();
902
903 StringBuilder query = new StringBuilder();
904
905 query.append(
906 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary WHERE ");
907
908 query.append("tagsVocabulary.companyId = ?");
909
910 query.append(" AND ");
911
912 query.append("tagsVocabulary.folksonomy = ?");
913
914 query.append(" ");
915
916 if (obc != null) {
917 query.append("ORDER BY ");
918
919 String[] orderByFields = obc.getOrderByFields();
920
921 for (int i = 0; i < orderByFields.length; i++) {
922 query.append("tagsVocabulary.");
923 query.append(orderByFields[i]);
924
925 if (obc.isAscending()) {
926 query.append(" ASC");
927 }
928 else {
929 query.append(" DESC");
930 }
931
932 if ((i + 1) < orderByFields.length) {
933 query.append(", ");
934 }
935 }
936 }
937
938 else {
939 query.append("ORDER BY ");
940
941 query.append("tagsVocabulary.name ASC");
942 }
943
944 Query q = session.createQuery(query.toString());
945
946 QueryPos qPos = QueryPos.getInstance(q);
947
948 qPos.add(companyId);
949
950 qPos.add(folksonomy);
951
952 list = (List<TagsVocabulary>)QueryUtil.list(q, getDialect(),
953 start, end);
954 }
955 catch (Exception e) {
956 throw processException(e);
957 }
958 finally {
959 if (list == null) {
960 list = new ArrayList<TagsVocabulary>();
961 }
962
963 cacheResult(list);
964
965 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_F,
966 finderArgs, list);
967
968 closeSession(session);
969 }
970 }
971
972 return list;
973 }
974
975 public TagsVocabulary findByC_F_First(long companyId, boolean folksonomy,
976 OrderByComparator obc)
977 throws NoSuchVocabularyException, SystemException {
978 List<TagsVocabulary> list = findByC_F(companyId, folksonomy, 0, 1, obc);
979
980 if (list.isEmpty()) {
981 StringBuilder msg = new StringBuilder();
982
983 msg.append("No TagsVocabulary exists with the key {");
984
985 msg.append("companyId=" + companyId);
986
987 msg.append(", ");
988 msg.append("folksonomy=" + folksonomy);
989
990 msg.append(StringPool.CLOSE_CURLY_BRACE);
991
992 throw new NoSuchVocabularyException(msg.toString());
993 }
994 else {
995 return list.get(0);
996 }
997 }
998
999 public TagsVocabulary findByC_F_Last(long companyId, boolean folksonomy,
1000 OrderByComparator obc)
1001 throws NoSuchVocabularyException, SystemException {
1002 int count = countByC_F(companyId, folksonomy);
1003
1004 List<TagsVocabulary> list = findByC_F(companyId, folksonomy, count - 1,
1005 count, obc);
1006
1007 if (list.isEmpty()) {
1008 StringBuilder msg = new StringBuilder();
1009
1010 msg.append("No TagsVocabulary exists with the key {");
1011
1012 msg.append("companyId=" + companyId);
1013
1014 msg.append(", ");
1015 msg.append("folksonomy=" + folksonomy);
1016
1017 msg.append(StringPool.CLOSE_CURLY_BRACE);
1018
1019 throw new NoSuchVocabularyException(msg.toString());
1020 }
1021 else {
1022 return list.get(0);
1023 }
1024 }
1025
1026 public TagsVocabulary[] findByC_F_PrevAndNext(long vocabularyId,
1027 long companyId, boolean folksonomy, OrderByComparator obc)
1028 throws NoSuchVocabularyException, SystemException {
1029 TagsVocabulary tagsVocabulary = findByPrimaryKey(vocabularyId);
1030
1031 int count = countByC_F(companyId, folksonomy);
1032
1033 Session session = null;
1034
1035 try {
1036 session = openSession();
1037
1038 StringBuilder query = new StringBuilder();
1039
1040 query.append(
1041 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary WHERE ");
1042
1043 query.append("tagsVocabulary.companyId = ?");
1044
1045 query.append(" AND ");
1046
1047 query.append("tagsVocabulary.folksonomy = ?");
1048
1049 query.append(" ");
1050
1051 if (obc != null) {
1052 query.append("ORDER BY ");
1053
1054 String[] orderByFields = obc.getOrderByFields();
1055
1056 for (int i = 0; i < orderByFields.length; i++) {
1057 query.append("tagsVocabulary.");
1058 query.append(orderByFields[i]);
1059
1060 if (obc.isAscending()) {
1061 query.append(" ASC");
1062 }
1063 else {
1064 query.append(" DESC");
1065 }
1066
1067 if ((i + 1) < orderByFields.length) {
1068 query.append(", ");
1069 }
1070 }
1071 }
1072
1073 else {
1074 query.append("ORDER BY ");
1075
1076 query.append("tagsVocabulary.name ASC");
1077 }
1078
1079 Query q = session.createQuery(query.toString());
1080
1081 QueryPos qPos = QueryPos.getInstance(q);
1082
1083 qPos.add(companyId);
1084
1085 qPos.add(folksonomy);
1086
1087 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1088 tagsVocabulary);
1089
1090 TagsVocabulary[] array = new TagsVocabularyImpl[3];
1091
1092 array[0] = (TagsVocabulary)objArray[0];
1093 array[1] = (TagsVocabulary)objArray[1];
1094 array[2] = (TagsVocabulary)objArray[2];
1095
1096 return array;
1097 }
1098 catch (Exception e) {
1099 throw processException(e);
1100 }
1101 finally {
1102 closeSession(session);
1103 }
1104 }
1105
1106 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1107 throws SystemException {
1108 Session session = null;
1109
1110 try {
1111 session = openSession();
1112
1113 dynamicQuery.compile(session);
1114
1115 return dynamicQuery.list();
1116 }
1117 catch (Exception e) {
1118 throw processException(e);
1119 }
1120 finally {
1121 closeSession(session);
1122 }
1123 }
1124
1125 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1126 int start, int end) throws SystemException {
1127 Session session = null;
1128
1129 try {
1130 session = openSession();
1131
1132 dynamicQuery.setLimit(start, end);
1133
1134 dynamicQuery.compile(session);
1135
1136 return dynamicQuery.list();
1137 }
1138 catch (Exception e) {
1139 throw processException(e);
1140 }
1141 finally {
1142 closeSession(session);
1143 }
1144 }
1145
1146 public List<TagsVocabulary> findAll() throws SystemException {
1147 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1148 }
1149
1150 public List<TagsVocabulary> findAll(int start, int end)
1151 throws SystemException {
1152 return findAll(start, end, null);
1153 }
1154
1155 public List<TagsVocabulary> findAll(int start, int end,
1156 OrderByComparator obc) throws SystemException {
1157 Object[] finderArgs = new Object[] {
1158 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1159 };
1160
1161 List<TagsVocabulary> list = (List<TagsVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1162 finderArgs, this);
1163
1164 if (list == null) {
1165 Session session = null;
1166
1167 try {
1168 session = openSession();
1169
1170 StringBuilder query = new StringBuilder();
1171
1172 query.append(
1173 "SELECT tagsVocabulary FROM TagsVocabulary tagsVocabulary ");
1174
1175 if (obc != null) {
1176 query.append("ORDER BY ");
1177
1178 String[] orderByFields = obc.getOrderByFields();
1179
1180 for (int i = 0; i < orderByFields.length; i++) {
1181 query.append("tagsVocabulary.");
1182 query.append(orderByFields[i]);
1183
1184 if (obc.isAscending()) {
1185 query.append(" ASC");
1186 }
1187 else {
1188 query.append(" DESC");
1189 }
1190
1191 if ((i + 1) < orderByFields.length) {
1192 query.append(", ");
1193 }
1194 }
1195 }
1196
1197 else {
1198 query.append("ORDER BY ");
1199
1200 query.append("tagsVocabulary.name ASC");
1201 }
1202
1203 Query q = session.createQuery(query.toString());
1204
1205 if (obc == null) {
1206 list = (List<TagsVocabulary>)QueryUtil.list(q,
1207 getDialect(), start, end, false);
1208
1209 Collections.sort(list);
1210 }
1211 else {
1212 list = (List<TagsVocabulary>)QueryUtil.list(q,
1213 getDialect(), start, end);
1214 }
1215 }
1216 catch (Exception e) {
1217 throw processException(e);
1218 }
1219 finally {
1220 if (list == null) {
1221 list = new ArrayList<TagsVocabulary>();
1222 }
1223
1224 cacheResult(list);
1225
1226 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1227
1228 closeSession(session);
1229 }
1230 }
1231
1232 return list;
1233 }
1234
1235 public void removeByG_N(long groupId, String name)
1236 throws NoSuchVocabularyException, SystemException {
1237 TagsVocabulary tagsVocabulary = findByG_N(groupId, name);
1238
1239 remove(tagsVocabulary);
1240 }
1241
1242 public void removeByG_F(long groupId, boolean folksonomy)
1243 throws SystemException {
1244 for (TagsVocabulary tagsVocabulary : findByG_F(groupId, folksonomy)) {
1245 remove(tagsVocabulary);
1246 }
1247 }
1248
1249 public void removeByC_F(long companyId, boolean folksonomy)
1250 throws SystemException {
1251 for (TagsVocabulary tagsVocabulary : findByC_F(companyId, folksonomy)) {
1252 remove(tagsVocabulary);
1253 }
1254 }
1255
1256 public void removeAll() throws SystemException {
1257 for (TagsVocabulary tagsVocabulary : findAll()) {
1258 remove(tagsVocabulary);
1259 }
1260 }
1261
1262 public int countByG_N(long groupId, String name) throws SystemException {
1263 Object[] finderArgs = new Object[] { new Long(groupId), name };
1264
1265 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1266 finderArgs, this);
1267
1268 if (count == null) {
1269 Session session = null;
1270
1271 try {
1272 session = openSession();
1273
1274 StringBuilder query = new StringBuilder();
1275
1276 query.append("SELECT COUNT(tagsVocabulary) ");
1277 query.append("FROM TagsVocabulary tagsVocabulary WHERE ");
1278
1279 query.append("tagsVocabulary.groupId = ?");
1280
1281 query.append(" AND ");
1282
1283 if (name == null) {
1284 query.append("tagsVocabulary.name IS NULL");
1285 }
1286 else {
1287 query.append("tagsVocabulary.name = ?");
1288 }
1289
1290 query.append(" ");
1291
1292 Query q = session.createQuery(query.toString());
1293
1294 QueryPos qPos = QueryPos.getInstance(q);
1295
1296 qPos.add(groupId);
1297
1298 if (name != null) {
1299 qPos.add(name);
1300 }
1301
1302 count = (Long)q.uniqueResult();
1303 }
1304 catch (Exception e) {
1305 throw processException(e);
1306 }
1307 finally {
1308 if (count == null) {
1309 count = Long.valueOf(0);
1310 }
1311
1312 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1313 count);
1314
1315 closeSession(session);
1316 }
1317 }
1318
1319 return count.intValue();
1320 }
1321
1322 public int countByG_F(long groupId, boolean folksonomy)
1323 throws SystemException {
1324 Object[] finderArgs = new Object[] {
1325 new Long(groupId), Boolean.valueOf(folksonomy)
1326 };
1327
1328 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
1329 finderArgs, this);
1330
1331 if (count == null) {
1332 Session session = null;
1333
1334 try {
1335 session = openSession();
1336
1337 StringBuilder query = new StringBuilder();
1338
1339 query.append("SELECT COUNT(tagsVocabulary) ");
1340 query.append("FROM TagsVocabulary tagsVocabulary WHERE ");
1341
1342 query.append("tagsVocabulary.groupId = ?");
1343
1344 query.append(" AND ");
1345
1346 query.append("tagsVocabulary.folksonomy = ?");
1347
1348 query.append(" ");
1349
1350 Query q = session.createQuery(query.toString());
1351
1352 QueryPos qPos = QueryPos.getInstance(q);
1353
1354 qPos.add(groupId);
1355
1356 qPos.add(folksonomy);
1357
1358 count = (Long)q.uniqueResult();
1359 }
1360 catch (Exception e) {
1361 throw processException(e);
1362 }
1363 finally {
1364 if (count == null) {
1365 count = Long.valueOf(0);
1366 }
1367
1368 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
1369 count);
1370
1371 closeSession(session);
1372 }
1373 }
1374
1375 return count.intValue();
1376 }
1377
1378 public int countByC_F(long companyId, boolean folksonomy)
1379 throws SystemException {
1380 Object[] finderArgs = new Object[] {
1381 new Long(companyId), Boolean.valueOf(folksonomy)
1382 };
1383
1384 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_F,
1385 finderArgs, this);
1386
1387 if (count == null) {
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 StringBuilder query = new StringBuilder();
1394
1395 query.append("SELECT COUNT(tagsVocabulary) ");
1396 query.append("FROM TagsVocabulary tagsVocabulary WHERE ");
1397
1398 query.append("tagsVocabulary.companyId = ?");
1399
1400 query.append(" AND ");
1401
1402 query.append("tagsVocabulary.folksonomy = ?");
1403
1404 query.append(" ");
1405
1406 Query q = session.createQuery(query.toString());
1407
1408 QueryPos qPos = QueryPos.getInstance(q);
1409
1410 qPos.add(companyId);
1411
1412 qPos.add(folksonomy);
1413
1414 count = (Long)q.uniqueResult();
1415 }
1416 catch (Exception e) {
1417 throw processException(e);
1418 }
1419 finally {
1420 if (count == null) {
1421 count = Long.valueOf(0);
1422 }
1423
1424 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_F, finderArgs,
1425 count);
1426
1427 closeSession(session);
1428 }
1429 }
1430
1431 return count.intValue();
1432 }
1433
1434 public int countAll() throws SystemException {
1435 Object[] finderArgs = new Object[0];
1436
1437 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1438 finderArgs, this);
1439
1440 if (count == null) {
1441 Session session = null;
1442
1443 try {
1444 session = openSession();
1445
1446 Query q = session.createQuery(
1447 "SELECT COUNT(tagsVocabulary) FROM TagsVocabulary tagsVocabulary");
1448
1449 count = (Long)q.uniqueResult();
1450 }
1451 catch (Exception e) {
1452 throw processException(e);
1453 }
1454 finally {
1455 if (count == null) {
1456 count = Long.valueOf(0);
1457 }
1458
1459 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1460 count);
1461
1462 closeSession(session);
1463 }
1464 }
1465
1466 return count.intValue();
1467 }
1468
1469 public void afterPropertiesSet() {
1470 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1471 com.liferay.portal.util.PropsUtil.get(
1472 "value.object.listener.com.liferay.portlet.tags.model.TagsVocabulary")));
1473
1474 if (listenerClassNames.length > 0) {
1475 try {
1476 List<ModelListener<TagsVocabulary>> listenersList = new ArrayList<ModelListener<TagsVocabulary>>();
1477
1478 for (String listenerClassName : listenerClassNames) {
1479 listenersList.add((ModelListener<TagsVocabulary>)Class.forName(
1480 listenerClassName).newInstance());
1481 }
1482
1483 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1484 }
1485 catch (Exception e) {
1486 _log.error(e);
1487 }
1488 }
1489 }
1490
1491 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
1492 protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1493 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
1494 protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
1495 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence.impl")
1496 protected com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence tagsPropertyPersistence;
1497 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsSourcePersistence.impl")
1498 protected com.liferay.portlet.tags.service.persistence.TagsSourcePersistence tagsSourcePersistence;
1499 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence.impl")
1500 protected com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence tagsVocabularyPersistence;
1501 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1502 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1503 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1504 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1505 private static Log _log = LogFactoryUtil.getLog(TagsVocabularyPersistenceImpl.class);
1506}