001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchWorkflowInstanceLinkException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.model.WorkflowInstanceLink;
039 import com.liferay.portal.model.impl.WorkflowInstanceLinkImpl;
040 import com.liferay.portal.model.impl.WorkflowInstanceLinkModelImpl;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.List;
048
049
061 public class WorkflowInstanceLinkPersistenceImpl extends BasePersistenceImpl<WorkflowInstanceLink>
062 implements WorkflowInstanceLinkPersistence {
063
068 public static final String FINDER_CLASS_NAME_ENTITY = WorkflowInstanceLinkImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List1";
071 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List2";
073 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
074 WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
075 WorkflowInstanceLinkImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
078 WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
079 WorkflowInstanceLinkImpl.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
082 WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_C = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
085 WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
086 WorkflowInstanceLinkImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C_C",
088 new String[] {
089 Long.class.getName(), Long.class.getName(), Long.class.getName(),
090 Long.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C =
096 new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
097 WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
098 WorkflowInstanceLinkImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C_C",
100 new String[] {
101 Long.class.getName(), Long.class.getName(), Long.class.getName(),
102 Long.class.getName()
103 },
104 WorkflowInstanceLinkModelImpl.GROUPID_COLUMN_BITMASK |
105 WorkflowInstanceLinkModelImpl.COMPANYID_COLUMN_BITMASK |
106 WorkflowInstanceLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK |
107 WorkflowInstanceLinkModelImpl.CLASSPK_COLUMN_BITMASK |
108 WorkflowInstanceLinkModelImpl.CREATEDATE_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_C = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
110 WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_C",
112 new String[] {
113 Long.class.getName(), Long.class.getName(), Long.class.getName(),
114 Long.class.getName()
115 });
116
117
127 public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
128 long companyId, long classNameId, long classPK)
129 throws SystemException {
130 return findByG_C_C_C(groupId, companyId, classNameId, classPK,
131 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
132 }
133
134
150 public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
151 long companyId, long classNameId, long classPK, int start, int end)
152 throws SystemException {
153 return findByG_C_C_C(groupId, companyId, classNameId, classPK, start,
154 end, null);
155 }
156
157
174 public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
175 long companyId, long classNameId, long classPK, int start, int end,
176 OrderByComparator orderByComparator) throws SystemException {
177 boolean pagination = true;
178 FinderPath finderPath = null;
179 Object[] finderArgs = null;
180
181 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
182 (orderByComparator == null)) {
183 pagination = false;
184 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C;
185 finderArgs = new Object[] { groupId, companyId, classNameId, classPK };
186 }
187 else {
188 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_C;
189 finderArgs = new Object[] {
190 groupId, companyId, classNameId, classPK,
191
192 start, end, orderByComparator
193 };
194 }
195
196 List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(finderPath,
197 finderArgs, this);
198
199 if ((list != null) && !list.isEmpty()) {
200 for (WorkflowInstanceLink workflowInstanceLink : list) {
201 if ((groupId != workflowInstanceLink.getGroupId()) ||
202 (companyId != workflowInstanceLink.getCompanyId()) ||
203 (classNameId != workflowInstanceLink.getClassNameId()) ||
204 (classPK != workflowInstanceLink.getClassPK())) {
205 list = null;
206
207 break;
208 }
209 }
210 }
211
212 if (list == null) {
213 StringBundler query = null;
214
215 if (orderByComparator != null) {
216 query = new StringBundler(6 +
217 (orderByComparator.getOrderByFields().length * 3));
218 }
219 else {
220 query = new StringBundler(6);
221 }
222
223 query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
224
225 query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
226
227 query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
228
229 query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
230
231 query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
232
233 if (orderByComparator != null) {
234 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
235 orderByComparator);
236 }
237 else
238 if (pagination) {
239 query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
240 }
241
242 String sql = query.toString();
243
244 Session session = null;
245
246 try {
247 session = openSession();
248
249 Query q = session.createQuery(sql);
250
251 QueryPos qPos = QueryPos.getInstance(q);
252
253 qPos.add(groupId);
254
255 qPos.add(companyId);
256
257 qPos.add(classNameId);
258
259 qPos.add(classPK);
260
261 if (!pagination) {
262 list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
263 getDialect(), start, end, false);
264
265 Collections.sort(list);
266
267 list = new UnmodifiableList<WorkflowInstanceLink>(list);
268 }
269 else {
270 list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
271 getDialect(), start, end);
272 }
273
274 cacheResult(list);
275
276 FinderCacheUtil.putResult(finderPath, finderArgs, list);
277 }
278 catch (Exception e) {
279 FinderCacheUtil.removeResult(finderPath, finderArgs);
280
281 throw processException(e);
282 }
283 finally {
284 closeSession(session);
285 }
286 }
287
288 return list;
289 }
290
291
303 public WorkflowInstanceLink findByG_C_C_C_First(long groupId,
304 long companyId, long classNameId, long classPK,
305 OrderByComparator orderByComparator)
306 throws NoSuchWorkflowInstanceLinkException, SystemException {
307 WorkflowInstanceLink workflowInstanceLink = fetchByG_C_C_C_First(groupId,
308 companyId, classNameId, classPK, orderByComparator);
309
310 if (workflowInstanceLink != null) {
311 return workflowInstanceLink;
312 }
313
314 StringBundler msg = new StringBundler(10);
315
316 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
317
318 msg.append("groupId=");
319 msg.append(groupId);
320
321 msg.append(", companyId=");
322 msg.append(companyId);
323
324 msg.append(", classNameId=");
325 msg.append(classNameId);
326
327 msg.append(", classPK=");
328 msg.append(classPK);
329
330 msg.append(StringPool.CLOSE_CURLY_BRACE);
331
332 throw new NoSuchWorkflowInstanceLinkException(msg.toString());
333 }
334
335
346 public WorkflowInstanceLink fetchByG_C_C_C_First(long groupId,
347 long companyId, long classNameId, long classPK,
348 OrderByComparator orderByComparator) throws SystemException {
349 List<WorkflowInstanceLink> list = findByG_C_C_C(groupId, companyId,
350 classNameId, classPK, 0, 1, orderByComparator);
351
352 if (!list.isEmpty()) {
353 return list.get(0);
354 }
355
356 return null;
357 }
358
359
371 public WorkflowInstanceLink findByG_C_C_C_Last(long groupId,
372 long companyId, long classNameId, long classPK,
373 OrderByComparator orderByComparator)
374 throws NoSuchWorkflowInstanceLinkException, SystemException {
375 WorkflowInstanceLink workflowInstanceLink = fetchByG_C_C_C_Last(groupId,
376 companyId, classNameId, classPK, orderByComparator);
377
378 if (workflowInstanceLink != null) {
379 return workflowInstanceLink;
380 }
381
382 StringBundler msg = new StringBundler(10);
383
384 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
385
386 msg.append("groupId=");
387 msg.append(groupId);
388
389 msg.append(", companyId=");
390 msg.append(companyId);
391
392 msg.append(", classNameId=");
393 msg.append(classNameId);
394
395 msg.append(", classPK=");
396 msg.append(classPK);
397
398 msg.append(StringPool.CLOSE_CURLY_BRACE);
399
400 throw new NoSuchWorkflowInstanceLinkException(msg.toString());
401 }
402
403
414 public WorkflowInstanceLink fetchByG_C_C_C_Last(long groupId,
415 long companyId, long classNameId, long classPK,
416 OrderByComparator orderByComparator) throws SystemException {
417 int count = countByG_C_C_C(groupId, companyId, classNameId, classPK);
418
419 List<WorkflowInstanceLink> list = findByG_C_C_C(groupId, companyId,
420 classNameId, classPK, count - 1, count, orderByComparator);
421
422 if (!list.isEmpty()) {
423 return list.get(0);
424 }
425
426 return null;
427 }
428
429
442 public WorkflowInstanceLink[] findByG_C_C_C_PrevAndNext(
443 long workflowInstanceLinkId, long groupId, long companyId,
444 long classNameId, long classPK, OrderByComparator orderByComparator)
445 throws NoSuchWorkflowInstanceLinkException, SystemException {
446 WorkflowInstanceLink workflowInstanceLink = findByPrimaryKey(workflowInstanceLinkId);
447
448 Session session = null;
449
450 try {
451 session = openSession();
452
453 WorkflowInstanceLink[] array = new WorkflowInstanceLinkImpl[3];
454
455 array[0] = getByG_C_C_C_PrevAndNext(session, workflowInstanceLink,
456 groupId, companyId, classNameId, classPK,
457 orderByComparator, true);
458
459 array[1] = workflowInstanceLink;
460
461 array[2] = getByG_C_C_C_PrevAndNext(session, workflowInstanceLink,
462 groupId, companyId, classNameId, classPK,
463 orderByComparator, false);
464
465 return array;
466 }
467 catch (Exception e) {
468 throw processException(e);
469 }
470 finally {
471 closeSession(session);
472 }
473 }
474
475 protected WorkflowInstanceLink getByG_C_C_C_PrevAndNext(Session session,
476 WorkflowInstanceLink workflowInstanceLink, long groupId,
477 long companyId, long classNameId, long classPK,
478 OrderByComparator orderByComparator, boolean previous) {
479 StringBundler query = null;
480
481 if (orderByComparator != null) {
482 query = new StringBundler(6 +
483 (orderByComparator.getOrderByFields().length * 6));
484 }
485 else {
486 query = new StringBundler(3);
487 }
488
489 query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
490
491 query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
492
493 query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
494
495 query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
496
497 query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
498
499 if (orderByComparator != null) {
500 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
501
502 if (orderByConditionFields.length > 0) {
503 query.append(WHERE_AND);
504 }
505
506 for (int i = 0; i < orderByConditionFields.length; i++) {
507 query.append(_ORDER_BY_ENTITY_ALIAS);
508 query.append(orderByConditionFields[i]);
509
510 if ((i + 1) < orderByConditionFields.length) {
511 if (orderByComparator.isAscending() ^ previous) {
512 query.append(WHERE_GREATER_THAN_HAS_NEXT);
513 }
514 else {
515 query.append(WHERE_LESSER_THAN_HAS_NEXT);
516 }
517 }
518 else {
519 if (orderByComparator.isAscending() ^ previous) {
520 query.append(WHERE_GREATER_THAN);
521 }
522 else {
523 query.append(WHERE_LESSER_THAN);
524 }
525 }
526 }
527
528 query.append(ORDER_BY_CLAUSE);
529
530 String[] orderByFields = orderByComparator.getOrderByFields();
531
532 for (int i = 0; i < orderByFields.length; i++) {
533 query.append(_ORDER_BY_ENTITY_ALIAS);
534 query.append(orderByFields[i]);
535
536 if ((i + 1) < orderByFields.length) {
537 if (orderByComparator.isAscending() ^ previous) {
538 query.append(ORDER_BY_ASC_HAS_NEXT);
539 }
540 else {
541 query.append(ORDER_BY_DESC_HAS_NEXT);
542 }
543 }
544 else {
545 if (orderByComparator.isAscending() ^ previous) {
546 query.append(ORDER_BY_ASC);
547 }
548 else {
549 query.append(ORDER_BY_DESC);
550 }
551 }
552 }
553 }
554 else {
555 query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
556 }
557
558 String sql = query.toString();
559
560 Query q = session.createQuery(sql);
561
562 q.setFirstResult(0);
563 q.setMaxResults(2);
564
565 QueryPos qPos = QueryPos.getInstance(q);
566
567 qPos.add(groupId);
568
569 qPos.add(companyId);
570
571 qPos.add(classNameId);
572
573 qPos.add(classPK);
574
575 if (orderByComparator != null) {
576 Object[] values = orderByComparator.getOrderByConditionValues(workflowInstanceLink);
577
578 for (Object value : values) {
579 qPos.add(value);
580 }
581 }
582
583 List<WorkflowInstanceLink> list = q.list();
584
585 if (list.size() == 2) {
586 return list.get(1);
587 }
588 else {
589 return null;
590 }
591 }
592
593
602 public void removeByG_C_C_C(long groupId, long companyId, long classNameId,
603 long classPK) throws SystemException {
604 for (WorkflowInstanceLink workflowInstanceLink : findByG_C_C_C(
605 groupId, companyId, classNameId, classPK, QueryUtil.ALL_POS,
606 QueryUtil.ALL_POS, null)) {
607 remove(workflowInstanceLink);
608 }
609 }
610
611
621 public int countByG_C_C_C(long groupId, long companyId, long classNameId,
622 long classPK) throws SystemException {
623 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_C;
624
625 Object[] finderArgs = new Object[] {
626 groupId, companyId, classNameId, classPK
627 };
628
629 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
630 this);
631
632 if (count == null) {
633 StringBundler query = new StringBundler(5);
634
635 query.append(_SQL_COUNT_WORKFLOWINSTANCELINK_WHERE);
636
637 query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
638
639 query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
640
641 query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
642
643 query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
644
645 String sql = query.toString();
646
647 Session session = null;
648
649 try {
650 session = openSession();
651
652 Query q = session.createQuery(sql);
653
654 QueryPos qPos = QueryPos.getInstance(q);
655
656 qPos.add(groupId);
657
658 qPos.add(companyId);
659
660 qPos.add(classNameId);
661
662 qPos.add(classPK);
663
664 count = (Long)q.uniqueResult();
665
666 FinderCacheUtil.putResult(finderPath, finderArgs, count);
667 }
668 catch (Exception e) {
669 FinderCacheUtil.removeResult(finderPath, finderArgs);
670
671 throw processException(e);
672 }
673 finally {
674 closeSession(session);
675 }
676 }
677
678 return count.intValue();
679 }
680
681 private static final String _FINDER_COLUMN_G_C_C_C_GROUPID_2 = "workflowInstanceLink.groupId = ? AND ";
682 private static final String _FINDER_COLUMN_G_C_C_C_COMPANYID_2 = "workflowInstanceLink.companyId = ? AND ";
683 private static final String _FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2 = "workflowInstanceLink.classNameId = ? AND ";
684 private static final String _FINDER_COLUMN_G_C_C_C_CLASSPK_2 = "workflowInstanceLink.classPK = ?";
685
686
691 public void cacheResult(WorkflowInstanceLink workflowInstanceLink) {
692 EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
693 WorkflowInstanceLinkImpl.class,
694 workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
695
696 workflowInstanceLink.resetOriginalValues();
697 }
698
699
704 public void cacheResult(List<WorkflowInstanceLink> workflowInstanceLinks) {
705 for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
706 if (EntityCacheUtil.getResult(
707 WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
708 WorkflowInstanceLinkImpl.class,
709 workflowInstanceLink.getPrimaryKey()) == null) {
710 cacheResult(workflowInstanceLink);
711 }
712 else {
713 workflowInstanceLink.resetOriginalValues();
714 }
715 }
716 }
717
718
725 @Override
726 public void clearCache() {
727 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
728 CacheRegistryUtil.clear(WorkflowInstanceLinkImpl.class.getName());
729 }
730
731 EntityCacheUtil.clearCache(WorkflowInstanceLinkImpl.class.getName());
732
733 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
734 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
735 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
736 }
737
738
745 @Override
746 public void clearCache(WorkflowInstanceLink workflowInstanceLink) {
747 EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
748 WorkflowInstanceLinkImpl.class, workflowInstanceLink.getPrimaryKey());
749
750 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
751 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
752 }
753
754 @Override
755 public void clearCache(List<WorkflowInstanceLink> workflowInstanceLinks) {
756 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
757 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
758
759 for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
760 EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
761 WorkflowInstanceLinkImpl.class,
762 workflowInstanceLink.getPrimaryKey());
763 }
764 }
765
766
772 public WorkflowInstanceLink create(long workflowInstanceLinkId) {
773 WorkflowInstanceLink workflowInstanceLink = new WorkflowInstanceLinkImpl();
774
775 workflowInstanceLink.setNew(true);
776 workflowInstanceLink.setPrimaryKey(workflowInstanceLinkId);
777
778 return workflowInstanceLink;
779 }
780
781
789 public WorkflowInstanceLink remove(long workflowInstanceLinkId)
790 throws NoSuchWorkflowInstanceLinkException, SystemException {
791 return remove((Serializable)workflowInstanceLinkId);
792 }
793
794
802 @Override
803 public WorkflowInstanceLink remove(Serializable primaryKey)
804 throws NoSuchWorkflowInstanceLinkException, SystemException {
805 Session session = null;
806
807 try {
808 session = openSession();
809
810 WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
811 primaryKey);
812
813 if (workflowInstanceLink == null) {
814 if (_log.isWarnEnabled()) {
815 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
816 }
817
818 throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
819 primaryKey);
820 }
821
822 return remove(workflowInstanceLink);
823 }
824 catch (NoSuchWorkflowInstanceLinkException nsee) {
825 throw nsee;
826 }
827 catch (Exception e) {
828 throw processException(e);
829 }
830 finally {
831 closeSession(session);
832 }
833 }
834
835 @Override
836 protected WorkflowInstanceLink removeImpl(
837 WorkflowInstanceLink workflowInstanceLink) throws SystemException {
838 workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
839
840 Session session = null;
841
842 try {
843 session = openSession();
844
845 if (!session.contains(workflowInstanceLink)) {
846 workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
847 workflowInstanceLink.getPrimaryKeyObj());
848 }
849
850 if (workflowInstanceLink != null) {
851 session.delete(workflowInstanceLink);
852 }
853 }
854 catch (Exception e) {
855 throw processException(e);
856 }
857 finally {
858 closeSession(session);
859 }
860
861 if (workflowInstanceLink != null) {
862 clearCache(workflowInstanceLink);
863 }
864
865 return workflowInstanceLink;
866 }
867
868 @Override
869 public WorkflowInstanceLink updateImpl(
870 com.liferay.portal.model.WorkflowInstanceLink workflowInstanceLink)
871 throws SystemException {
872 workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
873
874 boolean isNew = workflowInstanceLink.isNew();
875
876 WorkflowInstanceLinkModelImpl workflowInstanceLinkModelImpl = (WorkflowInstanceLinkModelImpl)workflowInstanceLink;
877
878 Session session = null;
879
880 try {
881 session = openSession();
882
883 if (workflowInstanceLink.isNew()) {
884 session.save(workflowInstanceLink);
885
886 workflowInstanceLink.setNew(false);
887 }
888 else {
889 session.merge(workflowInstanceLink);
890 }
891 }
892 catch (Exception e) {
893 throw processException(e);
894 }
895 finally {
896 closeSession(session);
897 }
898
899 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
900
901 if (isNew || !WorkflowInstanceLinkModelImpl.COLUMN_BITMASK_ENABLED) {
902 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
903 }
904
905 else {
906 if ((workflowInstanceLinkModelImpl.getColumnBitmask() &
907 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C.getColumnBitmask()) != 0) {
908 Object[] args = new Object[] {
909 workflowInstanceLinkModelImpl.getOriginalGroupId(),
910 workflowInstanceLinkModelImpl.getOriginalCompanyId(),
911 workflowInstanceLinkModelImpl.getOriginalClassNameId(),
912 workflowInstanceLinkModelImpl.getOriginalClassPK()
913 };
914
915 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
916 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
917 args);
918
919 args = new Object[] {
920 workflowInstanceLinkModelImpl.getGroupId(),
921 workflowInstanceLinkModelImpl.getCompanyId(),
922 workflowInstanceLinkModelImpl.getClassNameId(),
923 workflowInstanceLinkModelImpl.getClassPK()
924 };
925
926 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
927 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
928 args);
929 }
930 }
931
932 EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
933 WorkflowInstanceLinkImpl.class,
934 workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
935
936 return workflowInstanceLink;
937 }
938
939 protected WorkflowInstanceLink toUnwrappedModel(
940 WorkflowInstanceLink workflowInstanceLink) {
941 if (workflowInstanceLink instanceof WorkflowInstanceLinkImpl) {
942 return workflowInstanceLink;
943 }
944
945 WorkflowInstanceLinkImpl workflowInstanceLinkImpl = new WorkflowInstanceLinkImpl();
946
947 workflowInstanceLinkImpl.setNew(workflowInstanceLink.isNew());
948 workflowInstanceLinkImpl.setPrimaryKey(workflowInstanceLink.getPrimaryKey());
949
950 workflowInstanceLinkImpl.setWorkflowInstanceLinkId(workflowInstanceLink.getWorkflowInstanceLinkId());
951 workflowInstanceLinkImpl.setGroupId(workflowInstanceLink.getGroupId());
952 workflowInstanceLinkImpl.setCompanyId(workflowInstanceLink.getCompanyId());
953 workflowInstanceLinkImpl.setUserId(workflowInstanceLink.getUserId());
954 workflowInstanceLinkImpl.setUserName(workflowInstanceLink.getUserName());
955 workflowInstanceLinkImpl.setCreateDate(workflowInstanceLink.getCreateDate());
956 workflowInstanceLinkImpl.setModifiedDate(workflowInstanceLink.getModifiedDate());
957 workflowInstanceLinkImpl.setClassNameId(workflowInstanceLink.getClassNameId());
958 workflowInstanceLinkImpl.setClassPK(workflowInstanceLink.getClassPK());
959 workflowInstanceLinkImpl.setWorkflowInstanceId(workflowInstanceLink.getWorkflowInstanceId());
960
961 return workflowInstanceLinkImpl;
962 }
963
964
972 @Override
973 public WorkflowInstanceLink findByPrimaryKey(Serializable primaryKey)
974 throws NoSuchWorkflowInstanceLinkException, SystemException {
975 WorkflowInstanceLink workflowInstanceLink = fetchByPrimaryKey(primaryKey);
976
977 if (workflowInstanceLink == null) {
978 if (_log.isWarnEnabled()) {
979 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
980 }
981
982 throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
983 primaryKey);
984 }
985
986 return workflowInstanceLink;
987 }
988
989
997 public WorkflowInstanceLink findByPrimaryKey(long workflowInstanceLinkId)
998 throws NoSuchWorkflowInstanceLinkException, SystemException {
999 return findByPrimaryKey((Serializable)workflowInstanceLinkId);
1000 }
1001
1002
1009 @Override
1010 public WorkflowInstanceLink fetchByPrimaryKey(Serializable primaryKey)
1011 throws SystemException {
1012 WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)EntityCacheUtil.getResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1013 WorkflowInstanceLinkImpl.class, primaryKey);
1014
1015 if (workflowInstanceLink == _nullWorkflowInstanceLink) {
1016 return null;
1017 }
1018
1019 if (workflowInstanceLink == null) {
1020 Session session = null;
1021
1022 try {
1023 session = openSession();
1024
1025 workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
1026 primaryKey);
1027
1028 if (workflowInstanceLink != null) {
1029 cacheResult(workflowInstanceLink);
1030 }
1031 else {
1032 EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1033 WorkflowInstanceLinkImpl.class, primaryKey,
1034 _nullWorkflowInstanceLink);
1035 }
1036 }
1037 catch (Exception e) {
1038 EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1039 WorkflowInstanceLinkImpl.class, primaryKey);
1040
1041 throw processException(e);
1042 }
1043 finally {
1044 closeSession(session);
1045 }
1046 }
1047
1048 return workflowInstanceLink;
1049 }
1050
1051
1058 public WorkflowInstanceLink fetchByPrimaryKey(long workflowInstanceLinkId)
1059 throws SystemException {
1060 return fetchByPrimaryKey((Serializable)workflowInstanceLinkId);
1061 }
1062
1063
1069 public List<WorkflowInstanceLink> findAll() throws SystemException {
1070 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1071 }
1072
1073
1085 public List<WorkflowInstanceLink> findAll(int start, int end)
1086 throws SystemException {
1087 return findAll(start, end, null);
1088 }
1089
1090
1103 public List<WorkflowInstanceLink> findAll(int start, int end,
1104 OrderByComparator orderByComparator) throws SystemException {
1105 boolean pagination = true;
1106 FinderPath finderPath = null;
1107 Object[] finderArgs = null;
1108
1109 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1110 (orderByComparator == null)) {
1111 pagination = false;
1112 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1113 finderArgs = FINDER_ARGS_EMPTY;
1114 }
1115 else {
1116 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1117 finderArgs = new Object[] { start, end, orderByComparator };
1118 }
1119
1120 List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(finderPath,
1121 finderArgs, this);
1122
1123 if (list == null) {
1124 StringBundler query = null;
1125 String sql = null;
1126
1127 if (orderByComparator != null) {
1128 query = new StringBundler(2 +
1129 (orderByComparator.getOrderByFields().length * 3));
1130
1131 query.append(_SQL_SELECT_WORKFLOWINSTANCELINK);
1132
1133 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1134 orderByComparator);
1135
1136 sql = query.toString();
1137 }
1138 else {
1139 sql = _SQL_SELECT_WORKFLOWINSTANCELINK;
1140
1141 if (pagination) {
1142 sql = sql.concat(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
1143 }
1144 }
1145
1146 Session session = null;
1147
1148 try {
1149 session = openSession();
1150
1151 Query q = session.createQuery(sql);
1152
1153 if (!pagination) {
1154 list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1155 getDialect(), start, end, false);
1156
1157 Collections.sort(list);
1158
1159 list = new UnmodifiableList<WorkflowInstanceLink>(list);
1160 }
1161 else {
1162 list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1163 getDialect(), start, end);
1164 }
1165
1166 cacheResult(list);
1167
1168 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1169 }
1170 catch (Exception e) {
1171 FinderCacheUtil.removeResult(finderPath, finderArgs);
1172
1173 throw processException(e);
1174 }
1175 finally {
1176 closeSession(session);
1177 }
1178 }
1179
1180 return list;
1181 }
1182
1183
1188 public void removeAll() throws SystemException {
1189 for (WorkflowInstanceLink workflowInstanceLink : findAll()) {
1190 remove(workflowInstanceLink);
1191 }
1192 }
1193
1194
1200 public int countAll() throws SystemException {
1201 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1202 FINDER_ARGS_EMPTY, this);
1203
1204 if (count == null) {
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 Query q = session.createQuery(_SQL_COUNT_WORKFLOWINSTANCELINK);
1211
1212 count = (Long)q.uniqueResult();
1213
1214 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1215 FINDER_ARGS_EMPTY, count);
1216 }
1217 catch (Exception e) {
1218 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1219 FINDER_ARGS_EMPTY);
1220
1221 throw processException(e);
1222 }
1223 finally {
1224 closeSession(session);
1225 }
1226 }
1227
1228 return count.intValue();
1229 }
1230
1231
1234 public void afterPropertiesSet() {
1235 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1236 com.liferay.portal.util.PropsUtil.get(
1237 "value.object.listener.com.liferay.portal.model.WorkflowInstanceLink")));
1238
1239 if (listenerClassNames.length > 0) {
1240 try {
1241 List<ModelListener<WorkflowInstanceLink>> listenersList = new ArrayList<ModelListener<WorkflowInstanceLink>>();
1242
1243 for (String listenerClassName : listenerClassNames) {
1244 listenersList.add((ModelListener<WorkflowInstanceLink>)InstanceFactory.newInstance(
1245 getClassLoader(), listenerClassName));
1246 }
1247
1248 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1249 }
1250 catch (Exception e) {
1251 _log.error(e);
1252 }
1253 }
1254 }
1255
1256 public void destroy() {
1257 EntityCacheUtil.removeCache(WorkflowInstanceLinkImpl.class.getName());
1258 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1259 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1260 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1261 }
1262
1263 private static final String _SQL_SELECT_WORKFLOWINSTANCELINK = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink";
1264 private static final String _SQL_SELECT_WORKFLOWINSTANCELINK_WHERE = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1265 private static final String _SQL_COUNT_WORKFLOWINSTANCELINK = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink";
1266 private static final String _SQL_COUNT_WORKFLOWINSTANCELINK_WHERE = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1267 private static final String _ORDER_BY_ENTITY_ALIAS = "workflowInstanceLink.";
1268 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowInstanceLink exists with the primary key ";
1269 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowInstanceLink exists with the key {";
1270 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1271 private static Log _log = LogFactoryUtil.getLog(WorkflowInstanceLinkPersistenceImpl.class);
1272 private static WorkflowInstanceLink _nullWorkflowInstanceLink = new WorkflowInstanceLinkImpl() {
1273 @Override
1274 public Object clone() {
1275 return this;
1276 }
1277
1278 @Override
1279 public CacheModel<WorkflowInstanceLink> toCacheModel() {
1280 return _nullWorkflowInstanceLinkCacheModel;
1281 }
1282 };
1283
1284 private static CacheModel<WorkflowInstanceLink> _nullWorkflowInstanceLinkCacheModel =
1285 new CacheModel<WorkflowInstanceLink>() {
1286 public WorkflowInstanceLink toEntityModel() {
1287 return _nullWorkflowInstanceLink;
1288 }
1289 };
1290 }