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