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