001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchLockException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.CalendarUtil;
032 import com.liferay.portal.kernel.util.GetterUtil;
033 import com.liferay.portal.kernel.util.InstanceFactory;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.StringBundler;
036 import com.liferay.portal.kernel.util.StringPool;
037 import com.liferay.portal.kernel.util.StringUtil;
038 import com.liferay.portal.kernel.util.Validator;
039 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040 import com.liferay.portal.model.CacheModel;
041 import com.liferay.portal.model.Lock;
042 import com.liferay.portal.model.ModelListener;
043 import com.liferay.portal.model.impl.LockImpl;
044 import com.liferay.portal.model.impl.LockModelImpl;
045 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.Date;
052 import java.util.List;
053
054
066 public class LockPersistenceImpl extends BasePersistenceImpl<Lock>
067 implements LockPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = LockImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
079 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
081 new String[] {
082 String.class.getName(),
083
084 "java.lang.Integer", "java.lang.Integer",
085 "com.liferay.portal.kernel.util.OrderByComparator"
086 });
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
088 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
090 new String[] { String.class.getName() },
091 LockModelImpl.UUID_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
093 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
095 new String[] { String.class.getName() });
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE =
097 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
098 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
099 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtExpirationDate",
100 new String[] {
101 Date.class.getName(),
102
103 "java.lang.Integer", "java.lang.Integer",
104 "com.liferay.portal.kernel.util.OrderByComparator"
105 });
106 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE =
107 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
108 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByLtExpirationDate",
110 new String[] { Date.class.getName() });
111 public static final FinderPath FINDER_PATH_FETCH_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
112 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
113 FINDER_CLASS_NAME_ENTITY, "fetchByC_K",
114 new String[] { String.class.getName(), String.class.getName() },
115 LockModelImpl.CLASSNAME_COLUMN_BITMASK |
116 LockModelImpl.KEY_COLUMN_BITMASK);
117 public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
118 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
119 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
120 new String[] { String.class.getName(), String.class.getName() });
121 public static final FinderPath FINDER_PATH_FETCH_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
122 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
123 FINDER_CLASS_NAME_ENTITY, "fetchByC_K_O",
124 new String[] {
125 String.class.getName(), String.class.getName(),
126 String.class.getName()
127 },
128 LockModelImpl.CLASSNAME_COLUMN_BITMASK |
129 LockModelImpl.KEY_COLUMN_BITMASK |
130 LockModelImpl.OWNER_COLUMN_BITMASK);
131 public static final FinderPath FINDER_PATH_COUNT_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
132 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
133 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K_O",
134 new String[] {
135 String.class.getName(), String.class.getName(),
136 String.class.getName()
137 });
138 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
139 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
140 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
141 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
142 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
143 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
144 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
145 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
146 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
147
148
153 public void cacheResult(Lock lock) {
154 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
155 LockImpl.class, lock.getPrimaryKey(), lock);
156
157 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
158 new Object[] { lock.getClassName(), lock.getKey() }, lock);
159
160 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
161 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() },
162 lock);
163
164 lock.resetOriginalValues();
165 }
166
167
172 public void cacheResult(List<Lock> locks) {
173 for (Lock lock : locks) {
174 if (EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
175 LockImpl.class, lock.getPrimaryKey()) == null) {
176 cacheResult(lock);
177 }
178 else {
179 lock.resetOriginalValues();
180 }
181 }
182 }
183
184
191 @Override
192 public void clearCache() {
193 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
194 CacheRegistryUtil.clear(LockImpl.class.getName());
195 }
196
197 EntityCacheUtil.clearCache(LockImpl.class.getName());
198
199 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
200 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
201 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
202 }
203
204
211 @Override
212 public void clearCache(Lock lock) {
213 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
214 LockImpl.class, lock.getPrimaryKey());
215
216 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
217 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
218
219 clearUniqueFindersCache(lock);
220 }
221
222 @Override
223 public void clearCache(List<Lock> locks) {
224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
226
227 for (Lock lock : locks) {
228 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
229 LockImpl.class, lock.getPrimaryKey());
230
231 clearUniqueFindersCache(lock);
232 }
233 }
234
235 protected void clearUniqueFindersCache(Lock lock) {
236 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
237 new Object[] { lock.getClassName(), lock.getKey() });
238
239 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O,
240 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() });
241 }
242
243
249 public Lock create(long lockId) {
250 Lock lock = new LockImpl();
251
252 lock.setNew(true);
253 lock.setPrimaryKey(lockId);
254
255 String uuid = PortalUUIDUtil.generate();
256
257 lock.setUuid(uuid);
258
259 return lock;
260 }
261
262
270 public Lock remove(long lockId) throws NoSuchLockException, SystemException {
271 return remove(Long.valueOf(lockId));
272 }
273
274
282 @Override
283 public Lock remove(Serializable primaryKey)
284 throws NoSuchLockException, SystemException {
285 Session session = null;
286
287 try {
288 session = openSession();
289
290 Lock lock = (Lock)session.get(LockImpl.class, primaryKey);
291
292 if (lock == null) {
293 if (_log.isWarnEnabled()) {
294 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
295 }
296
297 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
298 primaryKey);
299 }
300
301 return remove(lock);
302 }
303 catch (NoSuchLockException nsee) {
304 throw nsee;
305 }
306 catch (Exception e) {
307 throw processException(e);
308 }
309 finally {
310 closeSession(session);
311 }
312 }
313
314 @Override
315 protected Lock removeImpl(Lock lock) throws SystemException {
316 lock = toUnwrappedModel(lock);
317
318 Session session = null;
319
320 try {
321 session = openSession();
322
323 BatchSessionUtil.delete(session, lock);
324 }
325 catch (Exception e) {
326 throw processException(e);
327 }
328 finally {
329 closeSession(session);
330 }
331
332 clearCache(lock);
333
334 return lock;
335 }
336
337 @Override
338 public Lock updateImpl(com.liferay.portal.model.Lock lock, boolean merge)
339 throws SystemException {
340 lock = toUnwrappedModel(lock);
341
342 boolean isNew = lock.isNew();
343
344 LockModelImpl lockModelImpl = (LockModelImpl)lock;
345
346 if (Validator.isNull(lock.getUuid())) {
347 String uuid = PortalUUIDUtil.generate();
348
349 lock.setUuid(uuid);
350 }
351
352 Session session = null;
353
354 try {
355 session = openSession();
356
357 BatchSessionUtil.update(session, lock, merge);
358
359 lock.setNew(false);
360 }
361 catch (Exception e) {
362 throw processException(e);
363 }
364 finally {
365 closeSession(session);
366 }
367
368 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
369
370 if (isNew || !LockModelImpl.COLUMN_BITMASK_ENABLED) {
371 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
372 }
373
374 else {
375 if ((lockModelImpl.getColumnBitmask() &
376 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
377 Object[] args = new Object[] { lockModelImpl.getOriginalUuid() };
378
379 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
380 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
381 args);
382
383 args = new Object[] { lockModelImpl.getUuid() };
384
385 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
386 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
387 args);
388 }
389 }
390
391 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
392 LockImpl.class, lock.getPrimaryKey(), lock);
393
394 if (isNew) {
395 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
396 new Object[] { lock.getClassName(), lock.getKey() }, lock);
397
398 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
399 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() },
400 lock);
401 }
402 else {
403 if ((lockModelImpl.getColumnBitmask() &
404 FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
405 Object[] args = new Object[] {
406 lockModelImpl.getOriginalClassName(),
407
408 lockModelImpl.getOriginalKey()
409 };
410
411 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
412
413 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
414
415 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
416 new Object[] { lock.getClassName(), lock.getKey() }, lock);
417 }
418
419 if ((lockModelImpl.getColumnBitmask() &
420 FINDER_PATH_FETCH_BY_C_K_O.getColumnBitmask()) != 0) {
421 Object[] args = new Object[] {
422 lockModelImpl.getOriginalClassName(),
423
424 lockModelImpl.getOriginalKey(),
425
426 lockModelImpl.getOriginalOwner()
427 };
428
429 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K_O, args);
430
431 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O, args);
432
433 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
434 new Object[] {
435 lock.getClassName(),
436
437 lock.getKey(),
438
439 lock.getOwner()
440 }, lock);
441 }
442 }
443
444 return lock;
445 }
446
447 protected Lock toUnwrappedModel(Lock lock) {
448 if (lock instanceof LockImpl) {
449 return lock;
450 }
451
452 LockImpl lockImpl = new LockImpl();
453
454 lockImpl.setNew(lock.isNew());
455 lockImpl.setPrimaryKey(lock.getPrimaryKey());
456
457 lockImpl.setUuid(lock.getUuid());
458 lockImpl.setLockId(lock.getLockId());
459 lockImpl.setCompanyId(lock.getCompanyId());
460 lockImpl.setUserId(lock.getUserId());
461 lockImpl.setUserName(lock.getUserName());
462 lockImpl.setCreateDate(lock.getCreateDate());
463 lockImpl.setClassName(lock.getClassName());
464 lockImpl.setKey(lock.getKey());
465 lockImpl.setOwner(lock.getOwner());
466 lockImpl.setInheritable(lock.isInheritable());
467 lockImpl.setExpirationDate(lock.getExpirationDate());
468
469 return lockImpl;
470 }
471
472
480 @Override
481 public Lock findByPrimaryKey(Serializable primaryKey)
482 throws NoSuchModelException, SystemException {
483 return findByPrimaryKey(((Long)primaryKey).longValue());
484 }
485
486
494 public Lock findByPrimaryKey(long lockId)
495 throws NoSuchLockException, SystemException {
496 Lock lock = fetchByPrimaryKey(lockId);
497
498 if (lock == null) {
499 if (_log.isWarnEnabled()) {
500 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + lockId);
501 }
502
503 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
504 lockId);
505 }
506
507 return lock;
508 }
509
510
517 @Override
518 public Lock fetchByPrimaryKey(Serializable primaryKey)
519 throws SystemException {
520 return fetchByPrimaryKey(((Long)primaryKey).longValue());
521 }
522
523
530 public Lock fetchByPrimaryKey(long lockId) throws SystemException {
531 Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
532 LockImpl.class, lockId);
533
534 if (lock == _nullLock) {
535 return null;
536 }
537
538 if (lock == null) {
539 Session session = null;
540
541 boolean hasException = false;
542
543 try {
544 session = openSession();
545
546 lock = (Lock)session.get(LockImpl.class, Long.valueOf(lockId));
547 }
548 catch (Exception e) {
549 hasException = true;
550
551 throw processException(e);
552 }
553 finally {
554 if (lock != null) {
555 cacheResult(lock);
556 }
557 else if (!hasException) {
558 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
559 LockImpl.class, lockId, _nullLock);
560 }
561
562 closeSession(session);
563 }
564 }
565
566 return lock;
567 }
568
569
576 public List<Lock> findByUuid(String uuid) throws SystemException {
577 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
578 }
579
580
593 public List<Lock> findByUuid(String uuid, int start, int end)
594 throws SystemException {
595 return findByUuid(uuid, start, end, null);
596 }
597
598
612 public List<Lock> findByUuid(String uuid, int start, int end,
613 OrderByComparator orderByComparator) throws SystemException {
614 FinderPath finderPath = null;
615 Object[] finderArgs = null;
616
617 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
618 (orderByComparator == null)) {
619 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
620 finderArgs = new Object[] { uuid };
621 }
622 else {
623 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
624 finderArgs = new Object[] { uuid, start, end, orderByComparator };
625 }
626
627 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
628 finderArgs, this);
629
630 if ((list != null) && !list.isEmpty()) {
631 for (Lock lock : list) {
632 if (!Validator.equals(uuid, lock.getUuid())) {
633 list = null;
634
635 break;
636 }
637 }
638 }
639
640 if (list == null) {
641 StringBundler query = null;
642
643 if (orderByComparator != null) {
644 query = new StringBundler(3 +
645 (orderByComparator.getOrderByFields().length * 3));
646 }
647 else {
648 query = new StringBundler(2);
649 }
650
651 query.append(_SQL_SELECT_LOCK_WHERE);
652
653 if (uuid == null) {
654 query.append(_FINDER_COLUMN_UUID_UUID_1);
655 }
656 else {
657 if (uuid.equals(StringPool.BLANK)) {
658 query.append(_FINDER_COLUMN_UUID_UUID_3);
659 }
660 else {
661 query.append(_FINDER_COLUMN_UUID_UUID_2);
662 }
663 }
664
665 if (orderByComparator != null) {
666 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
667 orderByComparator);
668 }
669
670 String sql = query.toString();
671
672 Session session = null;
673
674 try {
675 session = openSession();
676
677 Query q = session.createQuery(sql);
678
679 QueryPos qPos = QueryPos.getInstance(q);
680
681 if (uuid != null) {
682 qPos.add(uuid);
683 }
684
685 list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
686 }
687 catch (Exception e) {
688 throw processException(e);
689 }
690 finally {
691 if (list == null) {
692 FinderCacheUtil.removeResult(finderPath, finderArgs);
693 }
694 else {
695 cacheResult(list);
696
697 FinderCacheUtil.putResult(finderPath, finderArgs, list);
698 }
699
700 closeSession(session);
701 }
702 }
703
704 return list;
705 }
706
707
716 public Lock findByUuid_First(String uuid,
717 OrderByComparator orderByComparator)
718 throws NoSuchLockException, SystemException {
719 Lock lock = fetchByUuid_First(uuid, orderByComparator);
720
721 if (lock != null) {
722 return lock;
723 }
724
725 StringBundler msg = new StringBundler(4);
726
727 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
728
729 msg.append("uuid=");
730 msg.append(uuid);
731
732 msg.append(StringPool.CLOSE_CURLY_BRACE);
733
734 throw new NoSuchLockException(msg.toString());
735 }
736
737
745 public Lock fetchByUuid_First(String uuid,
746 OrderByComparator orderByComparator) throws SystemException {
747 List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
748
749 if (!list.isEmpty()) {
750 return list.get(0);
751 }
752
753 return null;
754 }
755
756
765 public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
766 throws NoSuchLockException, SystemException {
767 Lock lock = fetchByUuid_Last(uuid, orderByComparator);
768
769 if (lock != null) {
770 return lock;
771 }
772
773 StringBundler msg = new StringBundler(4);
774
775 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
776
777 msg.append("uuid=");
778 msg.append(uuid);
779
780 msg.append(StringPool.CLOSE_CURLY_BRACE);
781
782 throw new NoSuchLockException(msg.toString());
783 }
784
785
793 public Lock fetchByUuid_Last(String uuid,
794 OrderByComparator orderByComparator) throws SystemException {
795 int count = countByUuid(uuid);
796
797 List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
798
799 if (!list.isEmpty()) {
800 return list.get(0);
801 }
802
803 return null;
804 }
805
806
816 public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
817 OrderByComparator orderByComparator)
818 throws NoSuchLockException, SystemException {
819 Lock lock = findByPrimaryKey(lockId);
820
821 Session session = null;
822
823 try {
824 session = openSession();
825
826 Lock[] array = new LockImpl[3];
827
828 array[0] = getByUuid_PrevAndNext(session, lock, uuid,
829 orderByComparator, true);
830
831 array[1] = lock;
832
833 array[2] = getByUuid_PrevAndNext(session, lock, uuid,
834 orderByComparator, false);
835
836 return array;
837 }
838 catch (Exception e) {
839 throw processException(e);
840 }
841 finally {
842 closeSession(session);
843 }
844 }
845
846 protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
847 String uuid, OrderByComparator orderByComparator, boolean previous) {
848 StringBundler query = null;
849
850 if (orderByComparator != null) {
851 query = new StringBundler(6 +
852 (orderByComparator.getOrderByFields().length * 6));
853 }
854 else {
855 query = new StringBundler(3);
856 }
857
858 query.append(_SQL_SELECT_LOCK_WHERE);
859
860 if (uuid == null) {
861 query.append(_FINDER_COLUMN_UUID_UUID_1);
862 }
863 else {
864 if (uuid.equals(StringPool.BLANK)) {
865 query.append(_FINDER_COLUMN_UUID_UUID_3);
866 }
867 else {
868 query.append(_FINDER_COLUMN_UUID_UUID_2);
869 }
870 }
871
872 if (orderByComparator != null) {
873 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
874
875 if (orderByConditionFields.length > 0) {
876 query.append(WHERE_AND);
877 }
878
879 for (int i = 0; i < orderByConditionFields.length; i++) {
880 query.append(_ORDER_BY_ENTITY_ALIAS);
881 query.append(orderByConditionFields[i]);
882
883 if ((i + 1) < orderByConditionFields.length) {
884 if (orderByComparator.isAscending() ^ previous) {
885 query.append(WHERE_GREATER_THAN_HAS_NEXT);
886 }
887 else {
888 query.append(WHERE_LESSER_THAN_HAS_NEXT);
889 }
890 }
891 else {
892 if (orderByComparator.isAscending() ^ previous) {
893 query.append(WHERE_GREATER_THAN);
894 }
895 else {
896 query.append(WHERE_LESSER_THAN);
897 }
898 }
899 }
900
901 query.append(ORDER_BY_CLAUSE);
902
903 String[] orderByFields = orderByComparator.getOrderByFields();
904
905 for (int i = 0; i < orderByFields.length; i++) {
906 query.append(_ORDER_BY_ENTITY_ALIAS);
907 query.append(orderByFields[i]);
908
909 if ((i + 1) < orderByFields.length) {
910 if (orderByComparator.isAscending() ^ previous) {
911 query.append(ORDER_BY_ASC_HAS_NEXT);
912 }
913 else {
914 query.append(ORDER_BY_DESC_HAS_NEXT);
915 }
916 }
917 else {
918 if (orderByComparator.isAscending() ^ previous) {
919 query.append(ORDER_BY_ASC);
920 }
921 else {
922 query.append(ORDER_BY_DESC);
923 }
924 }
925 }
926 }
927
928 String sql = query.toString();
929
930 Query q = session.createQuery(sql);
931
932 q.setFirstResult(0);
933 q.setMaxResults(2);
934
935 QueryPos qPos = QueryPos.getInstance(q);
936
937 if (uuid != null) {
938 qPos.add(uuid);
939 }
940
941 if (orderByComparator != null) {
942 Object[] values = orderByComparator.getOrderByConditionValues(lock);
943
944 for (Object value : values) {
945 qPos.add(value);
946 }
947 }
948
949 List<Lock> list = q.list();
950
951 if (list.size() == 2) {
952 return list.get(1);
953 }
954 else {
955 return null;
956 }
957 }
958
959
966 public List<Lock> findByLtExpirationDate(Date expirationDate)
967 throws SystemException {
968 return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
969 QueryUtil.ALL_POS, null);
970 }
971
972
985 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
986 int end) throws SystemException {
987 return findByLtExpirationDate(expirationDate, start, end, null);
988 }
989
990
1004 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1005 int end, OrderByComparator orderByComparator) throws SystemException {
1006 FinderPath finderPath = null;
1007 Object[] finderArgs = null;
1008
1009 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE;
1010 finderArgs = new Object[] { expirationDate, start, end, orderByComparator };
1011
1012 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1013 finderArgs, this);
1014
1015 if ((list != null) && !list.isEmpty()) {
1016 for (Lock lock : list) {
1017 if (!Validator.equals(expirationDate, lock.getExpirationDate())) {
1018 list = null;
1019
1020 break;
1021 }
1022 }
1023 }
1024
1025 if (list == null) {
1026 StringBundler query = null;
1027
1028 if (orderByComparator != null) {
1029 query = new StringBundler(3 +
1030 (orderByComparator.getOrderByFields().length * 3));
1031 }
1032 else {
1033 query = new StringBundler(2);
1034 }
1035
1036 query.append(_SQL_SELECT_LOCK_WHERE);
1037
1038 if (expirationDate == null) {
1039 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1040 }
1041 else {
1042 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1043 }
1044
1045 if (orderByComparator != null) {
1046 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1047 orderByComparator);
1048 }
1049
1050 String sql = query.toString();
1051
1052 Session session = null;
1053
1054 try {
1055 session = openSession();
1056
1057 Query q = session.createQuery(sql);
1058
1059 QueryPos qPos = QueryPos.getInstance(q);
1060
1061 if (expirationDate != null) {
1062 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1063 }
1064
1065 list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
1066 }
1067 catch (Exception e) {
1068 throw processException(e);
1069 }
1070 finally {
1071 if (list == null) {
1072 FinderCacheUtil.removeResult(finderPath, finderArgs);
1073 }
1074 else {
1075 cacheResult(list);
1076
1077 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1078 }
1079
1080 closeSession(session);
1081 }
1082 }
1083
1084 return list;
1085 }
1086
1087
1096 public Lock findByLtExpirationDate_First(Date expirationDate,
1097 OrderByComparator orderByComparator)
1098 throws NoSuchLockException, SystemException {
1099 Lock lock = fetchByLtExpirationDate_First(expirationDate,
1100 orderByComparator);
1101
1102 if (lock != null) {
1103 return lock;
1104 }
1105
1106 StringBundler msg = new StringBundler(4);
1107
1108 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1109
1110 msg.append("expirationDate=");
1111 msg.append(expirationDate);
1112
1113 msg.append(StringPool.CLOSE_CURLY_BRACE);
1114
1115 throw new NoSuchLockException(msg.toString());
1116 }
1117
1118
1126 public Lock fetchByLtExpirationDate_First(Date expirationDate,
1127 OrderByComparator orderByComparator) throws SystemException {
1128 List<Lock> list = findByLtExpirationDate(expirationDate, 0, 1,
1129 orderByComparator);
1130
1131 if (!list.isEmpty()) {
1132 return list.get(0);
1133 }
1134
1135 return null;
1136 }
1137
1138
1147 public Lock findByLtExpirationDate_Last(Date expirationDate,
1148 OrderByComparator orderByComparator)
1149 throws NoSuchLockException, SystemException {
1150 Lock lock = fetchByLtExpirationDate_Last(expirationDate,
1151 orderByComparator);
1152
1153 if (lock != null) {
1154 return lock;
1155 }
1156
1157 StringBundler msg = new StringBundler(4);
1158
1159 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1160
1161 msg.append("expirationDate=");
1162 msg.append(expirationDate);
1163
1164 msg.append(StringPool.CLOSE_CURLY_BRACE);
1165
1166 throw new NoSuchLockException(msg.toString());
1167 }
1168
1169
1177 public Lock fetchByLtExpirationDate_Last(Date expirationDate,
1178 OrderByComparator orderByComparator) throws SystemException {
1179 int count = countByLtExpirationDate(expirationDate);
1180
1181 List<Lock> list = findByLtExpirationDate(expirationDate, count - 1,
1182 count, orderByComparator);
1183
1184 if (!list.isEmpty()) {
1185 return list.get(0);
1186 }
1187
1188 return null;
1189 }
1190
1191
1201 public Lock[] findByLtExpirationDate_PrevAndNext(long lockId,
1202 Date expirationDate, OrderByComparator orderByComparator)
1203 throws NoSuchLockException, SystemException {
1204 Lock lock = findByPrimaryKey(lockId);
1205
1206 Session session = null;
1207
1208 try {
1209 session = openSession();
1210
1211 Lock[] array = new LockImpl[3];
1212
1213 array[0] = getByLtExpirationDate_PrevAndNext(session, lock,
1214 expirationDate, orderByComparator, true);
1215
1216 array[1] = lock;
1217
1218 array[2] = getByLtExpirationDate_PrevAndNext(session, lock,
1219 expirationDate, orderByComparator, false);
1220
1221 return array;
1222 }
1223 catch (Exception e) {
1224 throw processException(e);
1225 }
1226 finally {
1227 closeSession(session);
1228 }
1229 }
1230
1231 protected Lock getByLtExpirationDate_PrevAndNext(Session session,
1232 Lock lock, Date expirationDate, OrderByComparator orderByComparator,
1233 boolean previous) {
1234 StringBundler query = null;
1235
1236 if (orderByComparator != null) {
1237 query = new StringBundler(6 +
1238 (orderByComparator.getOrderByFields().length * 6));
1239 }
1240 else {
1241 query = new StringBundler(3);
1242 }
1243
1244 query.append(_SQL_SELECT_LOCK_WHERE);
1245
1246 if (expirationDate == null) {
1247 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1248 }
1249 else {
1250 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1251 }
1252
1253 if (orderByComparator != null) {
1254 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1255
1256 if (orderByConditionFields.length > 0) {
1257 query.append(WHERE_AND);
1258 }
1259
1260 for (int i = 0; i < orderByConditionFields.length; i++) {
1261 query.append(_ORDER_BY_ENTITY_ALIAS);
1262 query.append(orderByConditionFields[i]);
1263
1264 if ((i + 1) < orderByConditionFields.length) {
1265 if (orderByComparator.isAscending() ^ previous) {
1266 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1267 }
1268 else {
1269 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1270 }
1271 }
1272 else {
1273 if (orderByComparator.isAscending() ^ previous) {
1274 query.append(WHERE_GREATER_THAN);
1275 }
1276 else {
1277 query.append(WHERE_LESSER_THAN);
1278 }
1279 }
1280 }
1281
1282 query.append(ORDER_BY_CLAUSE);
1283
1284 String[] orderByFields = orderByComparator.getOrderByFields();
1285
1286 for (int i = 0; i < orderByFields.length; i++) {
1287 query.append(_ORDER_BY_ENTITY_ALIAS);
1288 query.append(orderByFields[i]);
1289
1290 if ((i + 1) < orderByFields.length) {
1291 if (orderByComparator.isAscending() ^ previous) {
1292 query.append(ORDER_BY_ASC_HAS_NEXT);
1293 }
1294 else {
1295 query.append(ORDER_BY_DESC_HAS_NEXT);
1296 }
1297 }
1298 else {
1299 if (orderByComparator.isAscending() ^ previous) {
1300 query.append(ORDER_BY_ASC);
1301 }
1302 else {
1303 query.append(ORDER_BY_DESC);
1304 }
1305 }
1306 }
1307 }
1308
1309 String sql = query.toString();
1310
1311 Query q = session.createQuery(sql);
1312
1313 q.setFirstResult(0);
1314 q.setMaxResults(2);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 if (expirationDate != null) {
1319 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1320 }
1321
1322 if (orderByComparator != null) {
1323 Object[] values = orderByComparator.getOrderByConditionValues(lock);
1324
1325 for (Object value : values) {
1326 qPos.add(value);
1327 }
1328 }
1329
1330 List<Lock> list = q.list();
1331
1332 if (list.size() == 2) {
1333 return list.get(1);
1334 }
1335 else {
1336 return null;
1337 }
1338 }
1339
1340
1349 public Lock findByC_K(String className, String key)
1350 throws NoSuchLockException, SystemException {
1351 Lock lock = fetchByC_K(className, key);
1352
1353 if (lock == null) {
1354 StringBundler msg = new StringBundler(6);
1355
1356 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1357
1358 msg.append("className=");
1359 msg.append(className);
1360
1361 msg.append(", key=");
1362 msg.append(key);
1363
1364 msg.append(StringPool.CLOSE_CURLY_BRACE);
1365
1366 if (_log.isWarnEnabled()) {
1367 _log.warn(msg.toString());
1368 }
1369
1370 throw new NoSuchLockException(msg.toString());
1371 }
1372
1373 return lock;
1374 }
1375
1376
1384 public Lock fetchByC_K(String className, String key)
1385 throws SystemException {
1386 return fetchByC_K(className, key, true);
1387 }
1388
1389
1398 public Lock fetchByC_K(String className, String key,
1399 boolean retrieveFromCache) throws SystemException {
1400 Object[] finderArgs = new Object[] { className, key };
1401
1402 Object result = null;
1403
1404 if (retrieveFromCache) {
1405 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K,
1406 finderArgs, this);
1407 }
1408
1409 if (result instanceof Lock) {
1410 Lock lock = (Lock)result;
1411
1412 if (!Validator.equals(className, lock.getClassName()) ||
1413 !Validator.equals(key, lock.getKey())) {
1414 result = null;
1415 }
1416 }
1417
1418 if (result == null) {
1419 StringBundler query = new StringBundler(3);
1420
1421 query.append(_SQL_SELECT_LOCK_WHERE);
1422
1423 if (className == null) {
1424 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1425 }
1426 else {
1427 if (className.equals(StringPool.BLANK)) {
1428 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1429 }
1430 else {
1431 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1432 }
1433 }
1434
1435 if (key == null) {
1436 query.append(_FINDER_COLUMN_C_K_KEY_1);
1437 }
1438 else {
1439 if (key.equals(StringPool.BLANK)) {
1440 query.append(_FINDER_COLUMN_C_K_KEY_3);
1441 }
1442 else {
1443 query.append(_FINDER_COLUMN_C_K_KEY_2);
1444 }
1445 }
1446
1447 String sql = query.toString();
1448
1449 Session session = null;
1450
1451 try {
1452 session = openSession();
1453
1454 Query q = session.createQuery(sql);
1455
1456 QueryPos qPos = QueryPos.getInstance(q);
1457
1458 if (className != null) {
1459 qPos.add(className);
1460 }
1461
1462 if (key != null) {
1463 qPos.add(key);
1464 }
1465
1466 List<Lock> list = q.list();
1467
1468 result = list;
1469
1470 Lock lock = null;
1471
1472 if (list.isEmpty()) {
1473 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1474 finderArgs, list);
1475 }
1476 else {
1477 lock = list.get(0);
1478
1479 cacheResult(lock);
1480
1481 if ((lock.getClassName() == null) ||
1482 !lock.getClassName().equals(className) ||
1483 (lock.getKey() == null) ||
1484 !lock.getKey().equals(key)) {
1485 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1486 finderArgs, lock);
1487 }
1488 }
1489
1490 return lock;
1491 }
1492 catch (Exception e) {
1493 throw processException(e);
1494 }
1495 finally {
1496 if (result == null) {
1497 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
1498 finderArgs);
1499 }
1500
1501 closeSession(session);
1502 }
1503 }
1504 else {
1505 if (result instanceof List<?>) {
1506 return null;
1507 }
1508 else {
1509 return (Lock)result;
1510 }
1511 }
1512 }
1513
1514
1524 public Lock findByC_K_O(String className, String key, String owner)
1525 throws NoSuchLockException, SystemException {
1526 Lock lock = fetchByC_K_O(className, key, owner);
1527
1528 if (lock == null) {
1529 StringBundler msg = new StringBundler(8);
1530
1531 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1532
1533 msg.append("className=");
1534 msg.append(className);
1535
1536 msg.append(", key=");
1537 msg.append(key);
1538
1539 msg.append(", owner=");
1540 msg.append(owner);
1541
1542 msg.append(StringPool.CLOSE_CURLY_BRACE);
1543
1544 if (_log.isWarnEnabled()) {
1545 _log.warn(msg.toString());
1546 }
1547
1548 throw new NoSuchLockException(msg.toString());
1549 }
1550
1551 return lock;
1552 }
1553
1554
1563 public Lock fetchByC_K_O(String className, String key, String owner)
1564 throws SystemException {
1565 return fetchByC_K_O(className, key, owner, true);
1566 }
1567
1568
1578 public Lock fetchByC_K_O(String className, String key, String owner,
1579 boolean retrieveFromCache) throws SystemException {
1580 Object[] finderArgs = new Object[] { className, key, owner };
1581
1582 Object result = null;
1583
1584 if (retrieveFromCache) {
1585 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K_O,
1586 finderArgs, this);
1587 }
1588
1589 if (result instanceof Lock) {
1590 Lock lock = (Lock)result;
1591
1592 if (!Validator.equals(className, lock.getClassName()) ||
1593 !Validator.equals(key, lock.getKey()) ||
1594 !Validator.equals(owner, lock.getOwner())) {
1595 result = null;
1596 }
1597 }
1598
1599 if (result == null) {
1600 StringBundler query = new StringBundler(4);
1601
1602 query.append(_SQL_SELECT_LOCK_WHERE);
1603
1604 if (className == null) {
1605 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
1606 }
1607 else {
1608 if (className.equals(StringPool.BLANK)) {
1609 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
1610 }
1611 else {
1612 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
1613 }
1614 }
1615
1616 if (key == null) {
1617 query.append(_FINDER_COLUMN_C_K_O_KEY_1);
1618 }
1619 else {
1620 if (key.equals(StringPool.BLANK)) {
1621 query.append(_FINDER_COLUMN_C_K_O_KEY_3);
1622 }
1623 else {
1624 query.append(_FINDER_COLUMN_C_K_O_KEY_2);
1625 }
1626 }
1627
1628 if (owner == null) {
1629 query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
1630 }
1631 else {
1632 if (owner.equals(StringPool.BLANK)) {
1633 query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
1634 }
1635 else {
1636 query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
1637 }
1638 }
1639
1640 String sql = query.toString();
1641
1642 Session session = null;
1643
1644 try {
1645 session = openSession();
1646
1647 Query q = session.createQuery(sql);
1648
1649 QueryPos qPos = QueryPos.getInstance(q);
1650
1651 if (className != null) {
1652 qPos.add(className);
1653 }
1654
1655 if (key != null) {
1656 qPos.add(key);
1657 }
1658
1659 if (owner != null) {
1660 qPos.add(owner);
1661 }
1662
1663 List<Lock> list = q.list();
1664
1665 result = list;
1666
1667 Lock lock = null;
1668
1669 if (list.isEmpty()) {
1670 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
1671 finderArgs, list);
1672 }
1673 else {
1674 lock = list.get(0);
1675
1676 cacheResult(lock);
1677
1678 if ((lock.getClassName() == null) ||
1679 !lock.getClassName().equals(className) ||
1680 (lock.getKey() == null) ||
1681 !lock.getKey().equals(key) ||
1682 (lock.getOwner() == null) ||
1683 !lock.getOwner().equals(owner)) {
1684 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
1685 finderArgs, lock);
1686 }
1687 }
1688
1689 return lock;
1690 }
1691 catch (Exception e) {
1692 throw processException(e);
1693 }
1694 finally {
1695 if (result == null) {
1696 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O,
1697 finderArgs);
1698 }
1699
1700 closeSession(session);
1701 }
1702 }
1703 else {
1704 if (result instanceof List<?>) {
1705 return null;
1706 }
1707 else {
1708 return (Lock)result;
1709 }
1710 }
1711 }
1712
1713
1719 public List<Lock> findAll() throws SystemException {
1720 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1721 }
1722
1723
1735 public List<Lock> findAll(int start, int end) throws SystemException {
1736 return findAll(start, end, null);
1737 }
1738
1739
1752 public List<Lock> findAll(int start, int end,
1753 OrderByComparator orderByComparator) throws SystemException {
1754 FinderPath finderPath = null;
1755 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1756
1757 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1758 (orderByComparator == null)) {
1759 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1760 finderArgs = FINDER_ARGS_EMPTY;
1761 }
1762 else {
1763 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1764 finderArgs = new Object[] { start, end, orderByComparator };
1765 }
1766
1767 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1768 finderArgs, this);
1769
1770 if (list == null) {
1771 StringBundler query = null;
1772 String sql = null;
1773
1774 if (orderByComparator != null) {
1775 query = new StringBundler(2 +
1776 (orderByComparator.getOrderByFields().length * 3));
1777
1778 query.append(_SQL_SELECT_LOCK);
1779
1780 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1781 orderByComparator);
1782
1783 sql = query.toString();
1784 }
1785 else {
1786 sql = _SQL_SELECT_LOCK;
1787 }
1788
1789 Session session = null;
1790
1791 try {
1792 session = openSession();
1793
1794 Query q = session.createQuery(sql);
1795
1796 if (orderByComparator == null) {
1797 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1798 end, false);
1799
1800 Collections.sort(list);
1801 }
1802 else {
1803 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1804 end);
1805 }
1806 }
1807 catch (Exception e) {
1808 throw processException(e);
1809 }
1810 finally {
1811 if (list == null) {
1812 FinderCacheUtil.removeResult(finderPath, finderArgs);
1813 }
1814 else {
1815 cacheResult(list);
1816
1817 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1818 }
1819
1820 closeSession(session);
1821 }
1822 }
1823
1824 return list;
1825 }
1826
1827
1833 public void removeByUuid(String uuid) throws SystemException {
1834 for (Lock lock : findByUuid(uuid)) {
1835 remove(lock);
1836 }
1837 }
1838
1839
1845 public void removeByLtExpirationDate(Date expirationDate)
1846 throws SystemException {
1847 for (Lock lock : findByLtExpirationDate(expirationDate)) {
1848 remove(lock);
1849 }
1850 }
1851
1852
1860 public Lock removeByC_K(String className, String key)
1861 throws NoSuchLockException, SystemException {
1862 Lock lock = findByC_K(className, key);
1863
1864 return remove(lock);
1865 }
1866
1867
1876 public Lock removeByC_K_O(String className, String key, String owner)
1877 throws NoSuchLockException, SystemException {
1878 Lock lock = findByC_K_O(className, key, owner);
1879
1880 return remove(lock);
1881 }
1882
1883
1888 public void removeAll() throws SystemException {
1889 for (Lock lock : findAll()) {
1890 remove(lock);
1891 }
1892 }
1893
1894
1901 public int countByUuid(String uuid) throws SystemException {
1902 Object[] finderArgs = new Object[] { uuid };
1903
1904 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1905 finderArgs, this);
1906
1907 if (count == null) {
1908 StringBundler query = new StringBundler(2);
1909
1910 query.append(_SQL_COUNT_LOCK_WHERE);
1911
1912 if (uuid == null) {
1913 query.append(_FINDER_COLUMN_UUID_UUID_1);
1914 }
1915 else {
1916 if (uuid.equals(StringPool.BLANK)) {
1917 query.append(_FINDER_COLUMN_UUID_UUID_3);
1918 }
1919 else {
1920 query.append(_FINDER_COLUMN_UUID_UUID_2);
1921 }
1922 }
1923
1924 String sql = query.toString();
1925
1926 Session session = null;
1927
1928 try {
1929 session = openSession();
1930
1931 Query q = session.createQuery(sql);
1932
1933 QueryPos qPos = QueryPos.getInstance(q);
1934
1935 if (uuid != null) {
1936 qPos.add(uuid);
1937 }
1938
1939 count = (Long)q.uniqueResult();
1940 }
1941 catch (Exception e) {
1942 throw processException(e);
1943 }
1944 finally {
1945 if (count == null) {
1946 count = Long.valueOf(0);
1947 }
1948
1949 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1950 finderArgs, count);
1951
1952 closeSession(session);
1953 }
1954 }
1955
1956 return count.intValue();
1957 }
1958
1959
1966 public int countByLtExpirationDate(Date expirationDate)
1967 throws SystemException {
1968 Object[] finderArgs = new Object[] { expirationDate };
1969
1970 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE,
1971 finderArgs, this);
1972
1973 if (count == null) {
1974 StringBundler query = new StringBundler(2);
1975
1976 query.append(_SQL_COUNT_LOCK_WHERE);
1977
1978 if (expirationDate == null) {
1979 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1980 }
1981 else {
1982 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1983 }
1984
1985 String sql = query.toString();
1986
1987 Session session = null;
1988
1989 try {
1990 session = openSession();
1991
1992 Query q = session.createQuery(sql);
1993
1994 QueryPos qPos = QueryPos.getInstance(q);
1995
1996 if (expirationDate != null) {
1997 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1998 }
1999
2000 count = (Long)q.uniqueResult();
2001 }
2002 catch (Exception e) {
2003 throw processException(e);
2004 }
2005 finally {
2006 if (count == null) {
2007 count = Long.valueOf(0);
2008 }
2009
2010 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE,
2011 finderArgs, count);
2012
2013 closeSession(session);
2014 }
2015 }
2016
2017 return count.intValue();
2018 }
2019
2020
2028 public int countByC_K(String className, String key)
2029 throws SystemException {
2030 Object[] finderArgs = new Object[] { className, key };
2031
2032 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
2033 finderArgs, this);
2034
2035 if (count == null) {
2036 StringBundler query = new StringBundler(3);
2037
2038 query.append(_SQL_COUNT_LOCK_WHERE);
2039
2040 if (className == null) {
2041 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
2042 }
2043 else {
2044 if (className.equals(StringPool.BLANK)) {
2045 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
2046 }
2047 else {
2048 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
2049 }
2050 }
2051
2052 if (key == null) {
2053 query.append(_FINDER_COLUMN_C_K_KEY_1);
2054 }
2055 else {
2056 if (key.equals(StringPool.BLANK)) {
2057 query.append(_FINDER_COLUMN_C_K_KEY_3);
2058 }
2059 else {
2060 query.append(_FINDER_COLUMN_C_K_KEY_2);
2061 }
2062 }
2063
2064 String sql = query.toString();
2065
2066 Session session = null;
2067
2068 try {
2069 session = openSession();
2070
2071 Query q = session.createQuery(sql);
2072
2073 QueryPos qPos = QueryPos.getInstance(q);
2074
2075 if (className != null) {
2076 qPos.add(className);
2077 }
2078
2079 if (key != null) {
2080 qPos.add(key);
2081 }
2082
2083 count = (Long)q.uniqueResult();
2084 }
2085 catch (Exception e) {
2086 throw processException(e);
2087 }
2088 finally {
2089 if (count == null) {
2090 count = Long.valueOf(0);
2091 }
2092
2093 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
2094 count);
2095
2096 closeSession(session);
2097 }
2098 }
2099
2100 return count.intValue();
2101 }
2102
2103
2112 public int countByC_K_O(String className, String key, String owner)
2113 throws SystemException {
2114 Object[] finderArgs = new Object[] { className, key, owner };
2115
2116 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K_O,
2117 finderArgs, this);
2118
2119 if (count == null) {
2120 StringBundler query = new StringBundler(4);
2121
2122 query.append(_SQL_COUNT_LOCK_WHERE);
2123
2124 if (className == null) {
2125 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
2126 }
2127 else {
2128 if (className.equals(StringPool.BLANK)) {
2129 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
2130 }
2131 else {
2132 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
2133 }
2134 }
2135
2136 if (key == null) {
2137 query.append(_FINDER_COLUMN_C_K_O_KEY_1);
2138 }
2139 else {
2140 if (key.equals(StringPool.BLANK)) {
2141 query.append(_FINDER_COLUMN_C_K_O_KEY_3);
2142 }
2143 else {
2144 query.append(_FINDER_COLUMN_C_K_O_KEY_2);
2145 }
2146 }
2147
2148 if (owner == null) {
2149 query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
2150 }
2151 else {
2152 if (owner.equals(StringPool.BLANK)) {
2153 query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
2154 }
2155 else {
2156 query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
2157 }
2158 }
2159
2160 String sql = query.toString();
2161
2162 Session session = null;
2163
2164 try {
2165 session = openSession();
2166
2167 Query q = session.createQuery(sql);
2168
2169 QueryPos qPos = QueryPos.getInstance(q);
2170
2171 if (className != null) {
2172 qPos.add(className);
2173 }
2174
2175 if (key != null) {
2176 qPos.add(key);
2177 }
2178
2179 if (owner != null) {
2180 qPos.add(owner);
2181 }
2182
2183 count = (Long)q.uniqueResult();
2184 }
2185 catch (Exception e) {
2186 throw processException(e);
2187 }
2188 finally {
2189 if (count == null) {
2190 count = Long.valueOf(0);
2191 }
2192
2193 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K_O,
2194 finderArgs, count);
2195
2196 closeSession(session);
2197 }
2198 }
2199
2200 return count.intValue();
2201 }
2202
2203
2209 public int countAll() throws SystemException {
2210 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2211 FINDER_ARGS_EMPTY, this);
2212
2213 if (count == null) {
2214 Session session = null;
2215
2216 try {
2217 session = openSession();
2218
2219 Query q = session.createQuery(_SQL_COUNT_LOCK);
2220
2221 count = (Long)q.uniqueResult();
2222 }
2223 catch (Exception e) {
2224 throw processException(e);
2225 }
2226 finally {
2227 if (count == null) {
2228 count = Long.valueOf(0);
2229 }
2230
2231 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2232 FINDER_ARGS_EMPTY, count);
2233
2234 closeSession(session);
2235 }
2236 }
2237
2238 return count.intValue();
2239 }
2240
2241
2244 public void afterPropertiesSet() {
2245 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2246 com.liferay.portal.util.PropsUtil.get(
2247 "value.object.listener.com.liferay.portal.model.Lock")));
2248
2249 if (listenerClassNames.length > 0) {
2250 try {
2251 List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
2252
2253 for (String listenerClassName : listenerClassNames) {
2254 listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
2255 listenerClassName));
2256 }
2257
2258 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2259 }
2260 catch (Exception e) {
2261 _log.error(e);
2262 }
2263 }
2264 }
2265
2266 public void destroy() {
2267 EntityCacheUtil.removeCache(LockImpl.class.getName());
2268 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2269 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2270 }
2271
2272 @BeanReference(type = AccountPersistence.class)
2273 protected AccountPersistence accountPersistence;
2274 @BeanReference(type = AddressPersistence.class)
2275 protected AddressPersistence addressPersistence;
2276 @BeanReference(type = BrowserTrackerPersistence.class)
2277 protected BrowserTrackerPersistence browserTrackerPersistence;
2278 @BeanReference(type = ClassNamePersistence.class)
2279 protected ClassNamePersistence classNamePersistence;
2280 @BeanReference(type = ClusterGroupPersistence.class)
2281 protected ClusterGroupPersistence clusterGroupPersistence;
2282 @BeanReference(type = CompanyPersistence.class)
2283 protected CompanyPersistence companyPersistence;
2284 @BeanReference(type = ContactPersistence.class)
2285 protected ContactPersistence contactPersistence;
2286 @BeanReference(type = CountryPersistence.class)
2287 protected CountryPersistence countryPersistence;
2288 @BeanReference(type = EmailAddressPersistence.class)
2289 protected EmailAddressPersistence emailAddressPersistence;
2290 @BeanReference(type = GroupPersistence.class)
2291 protected GroupPersistence groupPersistence;
2292 @BeanReference(type = ImagePersistence.class)
2293 protected ImagePersistence imagePersistence;
2294 @BeanReference(type = LayoutPersistence.class)
2295 protected LayoutPersistence layoutPersistence;
2296 @BeanReference(type = LayoutBranchPersistence.class)
2297 protected LayoutBranchPersistence layoutBranchPersistence;
2298 @BeanReference(type = LayoutPrototypePersistence.class)
2299 protected LayoutPrototypePersistence layoutPrototypePersistence;
2300 @BeanReference(type = LayoutRevisionPersistence.class)
2301 protected LayoutRevisionPersistence layoutRevisionPersistence;
2302 @BeanReference(type = LayoutSetPersistence.class)
2303 protected LayoutSetPersistence layoutSetPersistence;
2304 @BeanReference(type = LayoutSetBranchPersistence.class)
2305 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2306 @BeanReference(type = LayoutSetPrototypePersistence.class)
2307 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2308 @BeanReference(type = ListTypePersistence.class)
2309 protected ListTypePersistence listTypePersistence;
2310 @BeanReference(type = LockPersistence.class)
2311 protected LockPersistence lockPersistence;
2312 @BeanReference(type = MembershipRequestPersistence.class)
2313 protected MembershipRequestPersistence membershipRequestPersistence;
2314 @BeanReference(type = OrganizationPersistence.class)
2315 protected OrganizationPersistence organizationPersistence;
2316 @BeanReference(type = OrgGroupPermissionPersistence.class)
2317 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2318 @BeanReference(type = OrgGroupRolePersistence.class)
2319 protected OrgGroupRolePersistence orgGroupRolePersistence;
2320 @BeanReference(type = OrgLaborPersistence.class)
2321 protected OrgLaborPersistence orgLaborPersistence;
2322 @BeanReference(type = PasswordPolicyPersistence.class)
2323 protected PasswordPolicyPersistence passwordPolicyPersistence;
2324 @BeanReference(type = PasswordPolicyRelPersistence.class)
2325 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2326 @BeanReference(type = PasswordTrackerPersistence.class)
2327 protected PasswordTrackerPersistence passwordTrackerPersistence;
2328 @BeanReference(type = PermissionPersistence.class)
2329 protected PermissionPersistence permissionPersistence;
2330 @BeanReference(type = PhonePersistence.class)
2331 protected PhonePersistence phonePersistence;
2332 @BeanReference(type = PluginSettingPersistence.class)
2333 protected PluginSettingPersistence pluginSettingPersistence;
2334 @BeanReference(type = PortalPreferencesPersistence.class)
2335 protected PortalPreferencesPersistence portalPreferencesPersistence;
2336 @BeanReference(type = PortletPersistence.class)
2337 protected PortletPersistence portletPersistence;
2338 @BeanReference(type = PortletItemPersistence.class)
2339 protected PortletItemPersistence portletItemPersistence;
2340 @BeanReference(type = PortletPreferencesPersistence.class)
2341 protected PortletPreferencesPersistence portletPreferencesPersistence;
2342 @BeanReference(type = RegionPersistence.class)
2343 protected RegionPersistence regionPersistence;
2344 @BeanReference(type = ReleasePersistence.class)
2345 protected ReleasePersistence releasePersistence;
2346 @BeanReference(type = RepositoryPersistence.class)
2347 protected RepositoryPersistence repositoryPersistence;
2348 @BeanReference(type = RepositoryEntryPersistence.class)
2349 protected RepositoryEntryPersistence repositoryEntryPersistence;
2350 @BeanReference(type = ResourcePersistence.class)
2351 protected ResourcePersistence resourcePersistence;
2352 @BeanReference(type = ResourceActionPersistence.class)
2353 protected ResourceActionPersistence resourceActionPersistence;
2354 @BeanReference(type = ResourceBlockPersistence.class)
2355 protected ResourceBlockPersistence resourceBlockPersistence;
2356 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2357 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2358 @BeanReference(type = ResourceCodePersistence.class)
2359 protected ResourceCodePersistence resourceCodePersistence;
2360 @BeanReference(type = ResourcePermissionPersistence.class)
2361 protected ResourcePermissionPersistence resourcePermissionPersistence;
2362 @BeanReference(type = ResourceTypePermissionPersistence.class)
2363 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2364 @BeanReference(type = RolePersistence.class)
2365 protected RolePersistence rolePersistence;
2366 @BeanReference(type = ServiceComponentPersistence.class)
2367 protected ServiceComponentPersistence serviceComponentPersistence;
2368 @BeanReference(type = ShardPersistence.class)
2369 protected ShardPersistence shardPersistence;
2370 @BeanReference(type = SubscriptionPersistence.class)
2371 protected SubscriptionPersistence subscriptionPersistence;
2372 @BeanReference(type = TeamPersistence.class)
2373 protected TeamPersistence teamPersistence;
2374 @BeanReference(type = TicketPersistence.class)
2375 protected TicketPersistence ticketPersistence;
2376 @BeanReference(type = UserPersistence.class)
2377 protected UserPersistence userPersistence;
2378 @BeanReference(type = UserGroupPersistence.class)
2379 protected UserGroupPersistence userGroupPersistence;
2380 @BeanReference(type = UserGroupGroupRolePersistence.class)
2381 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2382 @BeanReference(type = UserGroupRolePersistence.class)
2383 protected UserGroupRolePersistence userGroupRolePersistence;
2384 @BeanReference(type = UserIdMapperPersistence.class)
2385 protected UserIdMapperPersistence userIdMapperPersistence;
2386 @BeanReference(type = UserNotificationEventPersistence.class)
2387 protected UserNotificationEventPersistence userNotificationEventPersistence;
2388 @BeanReference(type = UserTrackerPersistence.class)
2389 protected UserTrackerPersistence userTrackerPersistence;
2390 @BeanReference(type = UserTrackerPathPersistence.class)
2391 protected UserTrackerPathPersistence userTrackerPathPersistence;
2392 @BeanReference(type = VirtualHostPersistence.class)
2393 protected VirtualHostPersistence virtualHostPersistence;
2394 @BeanReference(type = WebDAVPropsPersistence.class)
2395 protected WebDAVPropsPersistence webDAVPropsPersistence;
2396 @BeanReference(type = WebsitePersistence.class)
2397 protected WebsitePersistence websitePersistence;
2398 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2399 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2400 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2401 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2402 private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
2403 private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
2404 private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
2405 private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
2406 private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
2407 private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
2408 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?)";
2409 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
2410 "lock.expirationDate < NULL";
2411 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
2412 "lock.expirationDate < ?";
2413 private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
2414 private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
2415 private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
2416 private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
2417 private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
2418 private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = ?)";
2419 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_1 = "lock.className IS NULL AND ";
2420 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_2 = "lock.className = ? AND ";
2421 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
2422 private static final String _FINDER_COLUMN_C_K_O_KEY_1 = "lock.key IS NULL AND ";
2423 private static final String _FINDER_COLUMN_C_K_O_KEY_2 = "lock.key = ? AND ";
2424 private static final String _FINDER_COLUMN_C_K_O_KEY_3 = "(lock.key IS NULL OR lock.key = ?) AND ";
2425 private static final String _FINDER_COLUMN_C_K_O_OWNER_1 = "lock.owner IS NULL";
2426 private static final String _FINDER_COLUMN_C_K_O_OWNER_2 = "lock.owner = ?";
2427 private static final String _FINDER_COLUMN_C_K_O_OWNER_3 = "(lock.owner IS NULL OR lock.owner = ?)";
2428 private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
2429 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
2430 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
2431 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2432 private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
2433 private static Lock _nullLock = new LockImpl() {
2434 @Override
2435 public Object clone() {
2436 return this;
2437 }
2438
2439 @Override
2440 public CacheModel<Lock> toCacheModel() {
2441 return _nullLockCacheModel;
2442 }
2443 };
2444
2445 private static CacheModel<Lock> _nullLockCacheModel = new CacheModel<Lock>() {
2446 public Lock toEntityModel() {
2447 return _nullLock;
2448 }
2449 };
2450 }