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_WITHOUT_PAGINATION_FIND_BY_LTEXPIRATIONDATE =
107 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
108 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
110 "findByLtExpirationDate", new String[] { Date.class.getName() },
111 LockModelImpl.EXPIRATIONDATE_COLUMN_BITMASK);
112 public static final FinderPath FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
113 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
115 "countByLtExpirationDate", new String[] { Date.class.getName() });
116 public static final FinderPath FINDER_PATH_FETCH_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
117 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
118 FINDER_CLASS_NAME_ENTITY, "fetchByC_K",
119 new String[] { String.class.getName(), String.class.getName() },
120 LockModelImpl.CLASSNAME_COLUMN_BITMASK |
121 LockModelImpl.KEY_COLUMN_BITMASK);
122 public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
123 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
124 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
125 new String[] { String.class.getName(), String.class.getName() });
126 public static final FinderPath FINDER_PATH_FETCH_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
127 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
128 FINDER_CLASS_NAME_ENTITY, "fetchByC_K_O",
129 new String[] {
130 String.class.getName(), String.class.getName(),
131 String.class.getName()
132 },
133 LockModelImpl.CLASSNAME_COLUMN_BITMASK |
134 LockModelImpl.KEY_COLUMN_BITMASK |
135 LockModelImpl.OWNER_COLUMN_BITMASK);
136 public static final FinderPath FINDER_PATH_COUNT_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
137 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
138 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K_O",
139 new String[] {
140 String.class.getName(), String.class.getName(),
141 String.class.getName()
142 });
143 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
144 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
145 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
146 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
147 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
148 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
149 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
150 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
151 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
152
153
158 public void cacheResult(Lock lock) {
159 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
160 LockImpl.class, lock.getPrimaryKey(), lock);
161
162 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
163 new Object[] { lock.getClassName(), lock.getKey() }, lock);
164
165 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
166 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() },
167 lock);
168
169 lock.resetOriginalValues();
170 }
171
172
177 public void cacheResult(List<Lock> locks) {
178 for (Lock lock : locks) {
179 if (EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
180 LockImpl.class, lock.getPrimaryKey()) == null) {
181 cacheResult(lock);
182 }
183 else {
184 lock.resetOriginalValues();
185 }
186 }
187 }
188
189
196 @Override
197 public void clearCache() {
198 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
199 CacheRegistryUtil.clear(LockImpl.class.getName());
200 }
201
202 EntityCacheUtil.clearCache(LockImpl.class.getName());
203
204 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
207 }
208
209
216 @Override
217 public void clearCache(Lock lock) {
218 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
219 LockImpl.class, lock.getPrimaryKey());
220
221 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
223
224 clearUniqueFindersCache(lock);
225 }
226
227 @Override
228 public void clearCache(List<Lock> locks) {
229 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
231
232 for (Lock lock : locks) {
233 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
234 LockImpl.class, lock.getPrimaryKey());
235
236 clearUniqueFindersCache(lock);
237 }
238 }
239
240 protected void clearUniqueFindersCache(Lock lock) {
241 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
242 new Object[] { lock.getClassName(), lock.getKey() });
243
244 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O,
245 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() });
246 }
247
248
254 public Lock create(long lockId) {
255 Lock lock = new LockImpl();
256
257 lock.setNew(true);
258 lock.setPrimaryKey(lockId);
259
260 String uuid = PortalUUIDUtil.generate();
261
262 lock.setUuid(uuid);
263
264 return lock;
265 }
266
267
275 public Lock remove(long lockId) throws NoSuchLockException, SystemException {
276 return remove(Long.valueOf(lockId));
277 }
278
279
287 @Override
288 public Lock remove(Serializable primaryKey)
289 throws NoSuchLockException, SystemException {
290 Session session = null;
291
292 try {
293 session = openSession();
294
295 Lock lock = (Lock)session.get(LockImpl.class, primaryKey);
296
297 if (lock == null) {
298 if (_log.isWarnEnabled()) {
299 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
300 }
301
302 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
303 primaryKey);
304 }
305
306 return remove(lock);
307 }
308 catch (NoSuchLockException nsee) {
309 throw nsee;
310 }
311 catch (Exception e) {
312 throw processException(e);
313 }
314 finally {
315 closeSession(session);
316 }
317 }
318
319 @Override
320 protected Lock removeImpl(Lock lock) throws SystemException {
321 lock = toUnwrappedModel(lock);
322
323 Session session = null;
324
325 try {
326 session = openSession();
327
328 BatchSessionUtil.delete(session, lock);
329 }
330 catch (Exception e) {
331 throw processException(e);
332 }
333 finally {
334 closeSession(session);
335 }
336
337 clearCache(lock);
338
339 return lock;
340 }
341
342 @Override
343 public Lock updateImpl(com.liferay.portal.model.Lock lock, boolean merge)
344 throws SystemException {
345 lock = toUnwrappedModel(lock);
346
347 boolean isNew = lock.isNew();
348
349 LockModelImpl lockModelImpl = (LockModelImpl)lock;
350
351 if (Validator.isNull(lock.getUuid())) {
352 String uuid = PortalUUIDUtil.generate();
353
354 lock.setUuid(uuid);
355 }
356
357 Session session = null;
358
359 try {
360 session = openSession();
361
362 BatchSessionUtil.update(session, lock, merge);
363
364 lock.setNew(false);
365 }
366 catch (Exception e) {
367 throw processException(e);
368 }
369 finally {
370 closeSession(session);
371 }
372
373 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
374
375 if (isNew || !LockModelImpl.COLUMN_BITMASK_ENABLED) {
376 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
377 }
378 else {
379 if ((lockModelImpl.getColumnBitmask() &
380 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
381 Object[] args = new Object[] { lockModelImpl.getOriginalUuid() };
382
383 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
384 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
385 args);
386
387 args = new Object[] { lockModelImpl.getUuid() };
388
389 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
390 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
391 args);
392 }
393
394 if ((lockModelImpl.getColumnBitmask() &
395 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTEXPIRATIONDATE.getColumnBitmask()) != 0) {
396 Object[] args = new Object[] {
397 lockModelImpl.getOriginalExpirationDate()
398 };
399
400 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
401 args);
402 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTEXPIRATIONDATE,
403 args);
404
405 args = new Object[] { lockModelImpl.getExpirationDate() };
406
407 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
408 args);
409 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTEXPIRATIONDATE,
410 args);
411 }
412 }
413
414 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
415 LockImpl.class, lock.getPrimaryKey(), lock);
416
417 if (isNew) {
418 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
419 new Object[] { lock.getClassName(), lock.getKey() }, lock);
420
421 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
422 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() },
423 lock);
424 }
425 else {
426 if ((lockModelImpl.getColumnBitmask() &
427 FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
428 Object[] args = new Object[] {
429 lockModelImpl.getOriginalClassName(),
430
431 lockModelImpl.getOriginalKey()
432 };
433
434 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
435 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
436
437 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
438 new Object[] { lock.getClassName(), lock.getKey() }, lock);
439 }
440
441 if ((lockModelImpl.getColumnBitmask() &
442 FINDER_PATH_FETCH_BY_C_K_O.getColumnBitmask()) != 0) {
443 Object[] args = new Object[] {
444 lockModelImpl.getOriginalClassName(),
445
446 lockModelImpl.getOriginalKey(),
447
448 lockModelImpl.getOriginalOwner()
449 };
450
451 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K_O, args);
452 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O, args);
453
454 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
455 new Object[] {
456 lock.getClassName(),
457
458 lock.getKey(),
459
460 lock.getOwner()
461 }, lock);
462 }
463 }
464
465 return lock;
466 }
467
468 protected Lock toUnwrappedModel(Lock lock) {
469 if (lock instanceof LockImpl) {
470 return lock;
471 }
472
473 LockImpl lockImpl = new LockImpl();
474
475 lockImpl.setNew(lock.isNew());
476 lockImpl.setPrimaryKey(lock.getPrimaryKey());
477
478 lockImpl.setUuid(lock.getUuid());
479 lockImpl.setLockId(lock.getLockId());
480 lockImpl.setCompanyId(lock.getCompanyId());
481 lockImpl.setUserId(lock.getUserId());
482 lockImpl.setUserName(lock.getUserName());
483 lockImpl.setCreateDate(lock.getCreateDate());
484 lockImpl.setClassName(lock.getClassName());
485 lockImpl.setKey(lock.getKey());
486 lockImpl.setOwner(lock.getOwner());
487 lockImpl.setInheritable(lock.isInheritable());
488 lockImpl.setExpirationDate(lock.getExpirationDate());
489
490 return lockImpl;
491 }
492
493
501 @Override
502 public Lock findByPrimaryKey(Serializable primaryKey)
503 throws NoSuchModelException, SystemException {
504 return findByPrimaryKey(((Long)primaryKey).longValue());
505 }
506
507
515 public Lock findByPrimaryKey(long lockId)
516 throws NoSuchLockException, SystemException {
517 Lock lock = fetchByPrimaryKey(lockId);
518
519 if (lock == null) {
520 if (_log.isWarnEnabled()) {
521 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + lockId);
522 }
523
524 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
525 lockId);
526 }
527
528 return lock;
529 }
530
531
538 @Override
539 public Lock fetchByPrimaryKey(Serializable primaryKey)
540 throws SystemException {
541 return fetchByPrimaryKey(((Long)primaryKey).longValue());
542 }
543
544
551 public Lock fetchByPrimaryKey(long lockId) throws SystemException {
552 Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
553 LockImpl.class, lockId);
554
555 if (lock == _nullLock) {
556 return null;
557 }
558
559 if (lock == null) {
560 Session session = null;
561
562 boolean hasException = false;
563
564 try {
565 session = openSession();
566
567 lock = (Lock)session.get(LockImpl.class, Long.valueOf(lockId));
568 }
569 catch (Exception e) {
570 hasException = true;
571
572 throw processException(e);
573 }
574 finally {
575 if (lock != null) {
576 cacheResult(lock);
577 }
578 else if (!hasException) {
579 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
580 LockImpl.class, lockId, _nullLock);
581 }
582
583 closeSession(session);
584 }
585 }
586
587 return lock;
588 }
589
590
597 public List<Lock> findByUuid(String uuid) throws SystemException {
598 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
599 }
600
601
614 public List<Lock> findByUuid(String uuid, int start, int end)
615 throws SystemException {
616 return findByUuid(uuid, start, end, null);
617 }
618
619
633 public List<Lock> findByUuid(String uuid, int start, int end,
634 OrderByComparator orderByComparator) throws SystemException {
635 FinderPath finderPath = null;
636 Object[] finderArgs = null;
637
638 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
639 (orderByComparator == null)) {
640 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
641 finderArgs = new Object[] { uuid };
642 }
643 else {
644 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
645 finderArgs = new Object[] { uuid, start, end, orderByComparator };
646 }
647
648 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
649 finderArgs, this);
650
651 if ((list != null) && !list.isEmpty()) {
652 for (Lock lock : list) {
653 if (!Validator.equals(uuid, lock.getUuid())) {
654 list = null;
655
656 break;
657 }
658 }
659 }
660
661 if (list == null) {
662 StringBundler query = null;
663
664 if (orderByComparator != null) {
665 query = new StringBundler(3 +
666 (orderByComparator.getOrderByFields().length * 3));
667 }
668 else {
669 query = new StringBundler(2);
670 }
671
672 query.append(_SQL_SELECT_LOCK_WHERE);
673
674 if (uuid == null) {
675 query.append(_FINDER_COLUMN_UUID_UUID_1);
676 }
677 else {
678 if (uuid.equals(StringPool.BLANK)) {
679 query.append(_FINDER_COLUMN_UUID_UUID_3);
680 }
681 else {
682 query.append(_FINDER_COLUMN_UUID_UUID_2);
683 }
684 }
685
686 if (orderByComparator != null) {
687 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
688 orderByComparator);
689 }
690
691 String sql = query.toString();
692
693 Session session = null;
694
695 try {
696 session = openSession();
697
698 Query q = session.createQuery(sql);
699
700 QueryPos qPos = QueryPos.getInstance(q);
701
702 if (uuid != null) {
703 qPos.add(uuid);
704 }
705
706 list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
707 }
708 catch (Exception e) {
709 throw processException(e);
710 }
711 finally {
712 if (list == null) {
713 FinderCacheUtil.removeResult(finderPath, finderArgs);
714 }
715 else {
716 cacheResult(list);
717
718 FinderCacheUtil.putResult(finderPath, finderArgs, list);
719 }
720
721 closeSession(session);
722 }
723 }
724
725 return list;
726 }
727
728
741 public Lock findByUuid_First(String uuid,
742 OrderByComparator orderByComparator)
743 throws NoSuchLockException, SystemException {
744 List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
745
746 if (list.isEmpty()) {
747 StringBundler msg = new StringBundler(4);
748
749 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
750
751 msg.append("uuid=");
752 msg.append(uuid);
753
754 msg.append(StringPool.CLOSE_CURLY_BRACE);
755
756 throw new NoSuchLockException(msg.toString());
757 }
758 else {
759 return list.get(0);
760 }
761 }
762
763
776 public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
777 throws NoSuchLockException, SystemException {
778 int count = countByUuid(uuid);
779
780 List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
781
782 if (list.isEmpty()) {
783 StringBundler msg = new StringBundler(4);
784
785 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
786
787 msg.append("uuid=");
788 msg.append(uuid);
789
790 msg.append(StringPool.CLOSE_CURLY_BRACE);
791
792 throw new NoSuchLockException(msg.toString());
793 }
794 else {
795 return list.get(0);
796 }
797 }
798
799
813 public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
814 OrderByComparator orderByComparator)
815 throws NoSuchLockException, SystemException {
816 Lock lock = findByPrimaryKey(lockId);
817
818 Session session = null;
819
820 try {
821 session = openSession();
822
823 Lock[] array = new LockImpl[3];
824
825 array[0] = getByUuid_PrevAndNext(session, lock, uuid,
826 orderByComparator, true);
827
828 array[1] = lock;
829
830 array[2] = getByUuid_PrevAndNext(session, lock, uuid,
831 orderByComparator, false);
832
833 return array;
834 }
835 catch (Exception e) {
836 throw processException(e);
837 }
838 finally {
839 closeSession(session);
840 }
841 }
842
843 protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
844 String uuid, OrderByComparator orderByComparator, boolean previous) {
845 StringBundler query = null;
846
847 if (orderByComparator != null) {
848 query = new StringBundler(6 +
849 (orderByComparator.getOrderByFields().length * 6));
850 }
851 else {
852 query = new StringBundler(3);
853 }
854
855 query.append(_SQL_SELECT_LOCK_WHERE);
856
857 if (uuid == null) {
858 query.append(_FINDER_COLUMN_UUID_UUID_1);
859 }
860 else {
861 if (uuid.equals(StringPool.BLANK)) {
862 query.append(_FINDER_COLUMN_UUID_UUID_3);
863 }
864 else {
865 query.append(_FINDER_COLUMN_UUID_UUID_2);
866 }
867 }
868
869 if (orderByComparator != null) {
870 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
871
872 if (orderByConditionFields.length > 0) {
873 query.append(WHERE_AND);
874 }
875
876 for (int i = 0; i < orderByConditionFields.length; i++) {
877 query.append(_ORDER_BY_ENTITY_ALIAS);
878 query.append(orderByConditionFields[i]);
879
880 if ((i + 1) < orderByConditionFields.length) {
881 if (orderByComparator.isAscending() ^ previous) {
882 query.append(WHERE_GREATER_THAN_HAS_NEXT);
883 }
884 else {
885 query.append(WHERE_LESSER_THAN_HAS_NEXT);
886 }
887 }
888 else {
889 if (orderByComparator.isAscending() ^ previous) {
890 query.append(WHERE_GREATER_THAN);
891 }
892 else {
893 query.append(WHERE_LESSER_THAN);
894 }
895 }
896 }
897
898 query.append(ORDER_BY_CLAUSE);
899
900 String[] orderByFields = orderByComparator.getOrderByFields();
901
902 for (int i = 0; i < orderByFields.length; i++) {
903 query.append(_ORDER_BY_ENTITY_ALIAS);
904 query.append(orderByFields[i]);
905
906 if ((i + 1) < orderByFields.length) {
907 if (orderByComparator.isAscending() ^ previous) {
908 query.append(ORDER_BY_ASC_HAS_NEXT);
909 }
910 else {
911 query.append(ORDER_BY_DESC_HAS_NEXT);
912 }
913 }
914 else {
915 if (orderByComparator.isAscending() ^ previous) {
916 query.append(ORDER_BY_ASC);
917 }
918 else {
919 query.append(ORDER_BY_DESC);
920 }
921 }
922 }
923 }
924
925 String sql = query.toString();
926
927 Query q = session.createQuery(sql);
928
929 q.setFirstResult(0);
930 q.setMaxResults(2);
931
932 QueryPos qPos = QueryPos.getInstance(q);
933
934 if (uuid != null) {
935 qPos.add(uuid);
936 }
937
938 if (orderByComparator != null) {
939 Object[] values = orderByComparator.getOrderByConditionValues(lock);
940
941 for (Object value : values) {
942 qPos.add(value);
943 }
944 }
945
946 List<Lock> list = q.list();
947
948 if (list.size() == 2) {
949 return list.get(1);
950 }
951 else {
952 return null;
953 }
954 }
955
956
963 public List<Lock> findByLtExpirationDate(Date expirationDate)
964 throws SystemException {
965 return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
966 QueryUtil.ALL_POS, null);
967 }
968
969
982 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
983 int end) throws SystemException {
984 return findByLtExpirationDate(expirationDate, start, end, null);
985 }
986
987
1001 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1002 int end, OrderByComparator orderByComparator) throws SystemException {
1003 FinderPath finderPath = null;
1004 Object[] finderArgs = null;
1005
1006 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1007 (orderByComparator == null)) {
1008 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTEXPIRATIONDATE;
1009 finderArgs = new Object[] { expirationDate };
1010 }
1011 else {
1012 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE;
1013 finderArgs = new Object[] {
1014 expirationDate,
1015
1016 start, end, orderByComparator
1017 };
1018 }
1019
1020 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1021 finderArgs, this);
1022
1023 if ((list != null) && !list.isEmpty()) {
1024 for (Lock lock : list) {
1025 if (!Validator.equals(expirationDate, lock.getExpirationDate())) {
1026 list = null;
1027
1028 break;
1029 }
1030 }
1031 }
1032
1033 if (list == null) {
1034 StringBundler query = null;
1035
1036 if (orderByComparator != null) {
1037 query = new StringBundler(3 +
1038 (orderByComparator.getOrderByFields().length * 3));
1039 }
1040 else {
1041 query = new StringBundler(2);
1042 }
1043
1044 query.append(_SQL_SELECT_LOCK_WHERE);
1045
1046 if (expirationDate == null) {
1047 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1048 }
1049 else {
1050 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1051 }
1052
1053 if (orderByComparator != null) {
1054 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1055 orderByComparator);
1056 }
1057
1058 String sql = query.toString();
1059
1060 Session session = null;
1061
1062 try {
1063 session = openSession();
1064
1065 Query q = session.createQuery(sql);
1066
1067 QueryPos qPos = QueryPos.getInstance(q);
1068
1069 if (expirationDate != null) {
1070 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1071 }
1072
1073 list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
1074 }
1075 catch (Exception e) {
1076 throw processException(e);
1077 }
1078 finally {
1079 if (list == null) {
1080 FinderCacheUtil.removeResult(finderPath, finderArgs);
1081 }
1082 else {
1083 cacheResult(list);
1084
1085 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1086 }
1087
1088 closeSession(session);
1089 }
1090 }
1091
1092 return list;
1093 }
1094
1095
1108 public Lock findByLtExpirationDate_First(Date expirationDate,
1109 OrderByComparator orderByComparator)
1110 throws NoSuchLockException, SystemException {
1111 List<Lock> list = findByLtExpirationDate(expirationDate, 0, 1,
1112 orderByComparator);
1113
1114 if (list.isEmpty()) {
1115 StringBundler msg = new StringBundler(4);
1116
1117 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1118
1119 msg.append("expirationDate=");
1120 msg.append(expirationDate);
1121
1122 msg.append(StringPool.CLOSE_CURLY_BRACE);
1123
1124 throw new NoSuchLockException(msg.toString());
1125 }
1126 else {
1127 return list.get(0);
1128 }
1129 }
1130
1131
1144 public Lock findByLtExpirationDate_Last(Date expirationDate,
1145 OrderByComparator orderByComparator)
1146 throws NoSuchLockException, SystemException {
1147 int count = countByLtExpirationDate(expirationDate);
1148
1149 List<Lock> list = findByLtExpirationDate(expirationDate, count - 1,
1150 count, orderByComparator);
1151
1152 if (list.isEmpty()) {
1153 StringBundler msg = new StringBundler(4);
1154
1155 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1156
1157 msg.append("expirationDate=");
1158 msg.append(expirationDate);
1159
1160 msg.append(StringPool.CLOSE_CURLY_BRACE);
1161
1162 throw new NoSuchLockException(msg.toString());
1163 }
1164 else {
1165 return list.get(0);
1166 }
1167 }
1168
1169
1183 public Lock[] findByLtExpirationDate_PrevAndNext(long lockId,
1184 Date expirationDate, OrderByComparator orderByComparator)
1185 throws NoSuchLockException, SystemException {
1186 Lock lock = findByPrimaryKey(lockId);
1187
1188 Session session = null;
1189
1190 try {
1191 session = openSession();
1192
1193 Lock[] array = new LockImpl[3];
1194
1195 array[0] = getByLtExpirationDate_PrevAndNext(session, lock,
1196 expirationDate, orderByComparator, true);
1197
1198 array[1] = lock;
1199
1200 array[2] = getByLtExpirationDate_PrevAndNext(session, lock,
1201 expirationDate, orderByComparator, false);
1202
1203 return array;
1204 }
1205 catch (Exception e) {
1206 throw processException(e);
1207 }
1208 finally {
1209 closeSession(session);
1210 }
1211 }
1212
1213 protected Lock getByLtExpirationDate_PrevAndNext(Session session,
1214 Lock lock, Date expirationDate, OrderByComparator orderByComparator,
1215 boolean previous) {
1216 StringBundler query = null;
1217
1218 if (orderByComparator != null) {
1219 query = new StringBundler(6 +
1220 (orderByComparator.getOrderByFields().length * 6));
1221 }
1222 else {
1223 query = new StringBundler(3);
1224 }
1225
1226 query.append(_SQL_SELECT_LOCK_WHERE);
1227
1228 if (expirationDate == null) {
1229 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1230 }
1231 else {
1232 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1233 }
1234
1235 if (orderByComparator != null) {
1236 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1237
1238 if (orderByConditionFields.length > 0) {
1239 query.append(WHERE_AND);
1240 }
1241
1242 for (int i = 0; i < orderByConditionFields.length; i++) {
1243 query.append(_ORDER_BY_ENTITY_ALIAS);
1244 query.append(orderByConditionFields[i]);
1245
1246 if ((i + 1) < orderByConditionFields.length) {
1247 if (orderByComparator.isAscending() ^ previous) {
1248 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1249 }
1250 else {
1251 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1252 }
1253 }
1254 else {
1255 if (orderByComparator.isAscending() ^ previous) {
1256 query.append(WHERE_GREATER_THAN);
1257 }
1258 else {
1259 query.append(WHERE_LESSER_THAN);
1260 }
1261 }
1262 }
1263
1264 query.append(ORDER_BY_CLAUSE);
1265
1266 String[] orderByFields = orderByComparator.getOrderByFields();
1267
1268 for (int i = 0; i < orderByFields.length; i++) {
1269 query.append(_ORDER_BY_ENTITY_ALIAS);
1270 query.append(orderByFields[i]);
1271
1272 if ((i + 1) < orderByFields.length) {
1273 if (orderByComparator.isAscending() ^ previous) {
1274 query.append(ORDER_BY_ASC_HAS_NEXT);
1275 }
1276 else {
1277 query.append(ORDER_BY_DESC_HAS_NEXT);
1278 }
1279 }
1280 else {
1281 if (orderByComparator.isAscending() ^ previous) {
1282 query.append(ORDER_BY_ASC);
1283 }
1284 else {
1285 query.append(ORDER_BY_DESC);
1286 }
1287 }
1288 }
1289 }
1290
1291 String sql = query.toString();
1292
1293 Query q = session.createQuery(sql);
1294
1295 q.setFirstResult(0);
1296 q.setMaxResults(2);
1297
1298 QueryPos qPos = QueryPos.getInstance(q);
1299
1300 if (expirationDate != null) {
1301 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1302 }
1303
1304 if (orderByComparator != null) {
1305 Object[] values = orderByComparator.getOrderByConditionValues(lock);
1306
1307 for (Object value : values) {
1308 qPos.add(value);
1309 }
1310 }
1311
1312 List<Lock> list = q.list();
1313
1314 if (list.size() == 2) {
1315 return list.get(1);
1316 }
1317 else {
1318 return null;
1319 }
1320 }
1321
1322
1331 public Lock findByC_K(String className, String key)
1332 throws NoSuchLockException, SystemException {
1333 Lock lock = fetchByC_K(className, key);
1334
1335 if (lock == null) {
1336 StringBundler msg = new StringBundler(6);
1337
1338 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1339
1340 msg.append("className=");
1341 msg.append(className);
1342
1343 msg.append(", key=");
1344 msg.append(key);
1345
1346 msg.append(StringPool.CLOSE_CURLY_BRACE);
1347
1348 if (_log.isWarnEnabled()) {
1349 _log.warn(msg.toString());
1350 }
1351
1352 throw new NoSuchLockException(msg.toString());
1353 }
1354
1355 return lock;
1356 }
1357
1358
1366 public Lock fetchByC_K(String className, String key)
1367 throws SystemException {
1368 return fetchByC_K(className, key, true);
1369 }
1370
1371
1380 public Lock fetchByC_K(String className, String key,
1381 boolean retrieveFromCache) throws SystemException {
1382 Object[] finderArgs = new Object[] { className, key };
1383
1384 Object result = null;
1385
1386 if (retrieveFromCache) {
1387 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K,
1388 finderArgs, this);
1389 }
1390
1391 if (result instanceof Lock) {
1392 Lock lock = (Lock)result;
1393
1394 if (!Validator.equals(className, lock.getClassName()) ||
1395 !Validator.equals(key, lock.getKey())) {
1396 result = null;
1397 }
1398 }
1399
1400 if (result == null) {
1401 StringBundler query = new StringBundler(3);
1402
1403 query.append(_SQL_SELECT_LOCK_WHERE);
1404
1405 if (className == null) {
1406 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1407 }
1408 else {
1409 if (className.equals(StringPool.BLANK)) {
1410 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1411 }
1412 else {
1413 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1414 }
1415 }
1416
1417 if (key == null) {
1418 query.append(_FINDER_COLUMN_C_K_KEY_1);
1419 }
1420 else {
1421 if (key.equals(StringPool.BLANK)) {
1422 query.append(_FINDER_COLUMN_C_K_KEY_3);
1423 }
1424 else {
1425 query.append(_FINDER_COLUMN_C_K_KEY_2);
1426 }
1427 }
1428
1429 String sql = query.toString();
1430
1431 Session session = null;
1432
1433 try {
1434 session = openSession();
1435
1436 Query q = session.createQuery(sql);
1437
1438 QueryPos qPos = QueryPos.getInstance(q);
1439
1440 if (className != null) {
1441 qPos.add(className);
1442 }
1443
1444 if (key != null) {
1445 qPos.add(key);
1446 }
1447
1448 List<Lock> list = q.list();
1449
1450 result = list;
1451
1452 Lock lock = null;
1453
1454 if (list.isEmpty()) {
1455 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1456 finderArgs, list);
1457 }
1458 else {
1459 lock = list.get(0);
1460
1461 cacheResult(lock);
1462
1463 if ((lock.getClassName() == null) ||
1464 !lock.getClassName().equals(className) ||
1465 (lock.getKey() == null) ||
1466 !lock.getKey().equals(key)) {
1467 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1468 finderArgs, lock);
1469 }
1470 }
1471
1472 return lock;
1473 }
1474 catch (Exception e) {
1475 throw processException(e);
1476 }
1477 finally {
1478 if (result == null) {
1479 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
1480 finderArgs);
1481 }
1482
1483 closeSession(session);
1484 }
1485 }
1486 else {
1487 if (result instanceof List<?>) {
1488 return null;
1489 }
1490 else {
1491 return (Lock)result;
1492 }
1493 }
1494 }
1495
1496
1506 public Lock findByC_K_O(String className, String key, String owner)
1507 throws NoSuchLockException, SystemException {
1508 Lock lock = fetchByC_K_O(className, key, owner);
1509
1510 if (lock == null) {
1511 StringBundler msg = new StringBundler(8);
1512
1513 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1514
1515 msg.append("className=");
1516 msg.append(className);
1517
1518 msg.append(", key=");
1519 msg.append(key);
1520
1521 msg.append(", owner=");
1522 msg.append(owner);
1523
1524 msg.append(StringPool.CLOSE_CURLY_BRACE);
1525
1526 if (_log.isWarnEnabled()) {
1527 _log.warn(msg.toString());
1528 }
1529
1530 throw new NoSuchLockException(msg.toString());
1531 }
1532
1533 return lock;
1534 }
1535
1536
1545 public Lock fetchByC_K_O(String className, String key, String owner)
1546 throws SystemException {
1547 return fetchByC_K_O(className, key, owner, true);
1548 }
1549
1550
1560 public Lock fetchByC_K_O(String className, String key, String owner,
1561 boolean retrieveFromCache) throws SystemException {
1562 Object[] finderArgs = new Object[] { className, key, owner };
1563
1564 Object result = null;
1565
1566 if (retrieveFromCache) {
1567 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K_O,
1568 finderArgs, this);
1569 }
1570
1571 if (result instanceof Lock) {
1572 Lock lock = (Lock)result;
1573
1574 if (!Validator.equals(className, lock.getClassName()) ||
1575 !Validator.equals(key, lock.getKey()) ||
1576 !Validator.equals(owner, lock.getOwner())) {
1577 result = null;
1578 }
1579 }
1580
1581 if (result == null) {
1582 StringBundler query = new StringBundler(4);
1583
1584 query.append(_SQL_SELECT_LOCK_WHERE);
1585
1586 if (className == null) {
1587 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
1588 }
1589 else {
1590 if (className.equals(StringPool.BLANK)) {
1591 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
1592 }
1593 else {
1594 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
1595 }
1596 }
1597
1598 if (key == null) {
1599 query.append(_FINDER_COLUMN_C_K_O_KEY_1);
1600 }
1601 else {
1602 if (key.equals(StringPool.BLANK)) {
1603 query.append(_FINDER_COLUMN_C_K_O_KEY_3);
1604 }
1605 else {
1606 query.append(_FINDER_COLUMN_C_K_O_KEY_2);
1607 }
1608 }
1609
1610 if (owner == null) {
1611 query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
1612 }
1613 else {
1614 if (owner.equals(StringPool.BLANK)) {
1615 query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
1616 }
1617 else {
1618 query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
1619 }
1620 }
1621
1622 String sql = query.toString();
1623
1624 Session session = null;
1625
1626 try {
1627 session = openSession();
1628
1629 Query q = session.createQuery(sql);
1630
1631 QueryPos qPos = QueryPos.getInstance(q);
1632
1633 if (className != null) {
1634 qPos.add(className);
1635 }
1636
1637 if (key != null) {
1638 qPos.add(key);
1639 }
1640
1641 if (owner != null) {
1642 qPos.add(owner);
1643 }
1644
1645 List<Lock> list = q.list();
1646
1647 result = list;
1648
1649 Lock lock = null;
1650
1651 if (list.isEmpty()) {
1652 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
1653 finderArgs, list);
1654 }
1655 else {
1656 lock = list.get(0);
1657
1658 cacheResult(lock);
1659
1660 if ((lock.getClassName() == null) ||
1661 !lock.getClassName().equals(className) ||
1662 (lock.getKey() == null) ||
1663 !lock.getKey().equals(key) ||
1664 (lock.getOwner() == null) ||
1665 !lock.getOwner().equals(owner)) {
1666 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
1667 finderArgs, lock);
1668 }
1669 }
1670
1671 return lock;
1672 }
1673 catch (Exception e) {
1674 throw processException(e);
1675 }
1676 finally {
1677 if (result == null) {
1678 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O,
1679 finderArgs);
1680 }
1681
1682 closeSession(session);
1683 }
1684 }
1685 else {
1686 if (result instanceof List<?>) {
1687 return null;
1688 }
1689 else {
1690 return (Lock)result;
1691 }
1692 }
1693 }
1694
1695
1701 public List<Lock> findAll() throws SystemException {
1702 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1703 }
1704
1705
1717 public List<Lock> findAll(int start, int end) throws SystemException {
1718 return findAll(start, end, null);
1719 }
1720
1721
1734 public List<Lock> findAll(int start, int end,
1735 OrderByComparator orderByComparator) throws SystemException {
1736 FinderPath finderPath = null;
1737 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1738
1739 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1740 (orderByComparator == null)) {
1741 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1742 finderArgs = FINDER_ARGS_EMPTY;
1743 }
1744 else {
1745 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1746 finderArgs = new Object[] { start, end, orderByComparator };
1747 }
1748
1749 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1750 finderArgs, this);
1751
1752 if (list == null) {
1753 StringBundler query = null;
1754 String sql = null;
1755
1756 if (orderByComparator != null) {
1757 query = new StringBundler(2 +
1758 (orderByComparator.getOrderByFields().length * 3));
1759
1760 query.append(_SQL_SELECT_LOCK);
1761
1762 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1763 orderByComparator);
1764
1765 sql = query.toString();
1766 }
1767 else {
1768 sql = _SQL_SELECT_LOCK;
1769 }
1770
1771 Session session = null;
1772
1773 try {
1774 session = openSession();
1775
1776 Query q = session.createQuery(sql);
1777
1778 if (orderByComparator == null) {
1779 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1780 end, false);
1781
1782 Collections.sort(list);
1783 }
1784 else {
1785 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1786 end);
1787 }
1788 }
1789 catch (Exception e) {
1790 throw processException(e);
1791 }
1792 finally {
1793 if (list == null) {
1794 FinderCacheUtil.removeResult(finderPath, finderArgs);
1795 }
1796 else {
1797 cacheResult(list);
1798
1799 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1800 }
1801
1802 closeSession(session);
1803 }
1804 }
1805
1806 return list;
1807 }
1808
1809
1815 public void removeByUuid(String uuid) throws SystemException {
1816 for (Lock lock : findByUuid(uuid)) {
1817 remove(lock);
1818 }
1819 }
1820
1821
1827 public void removeByLtExpirationDate(Date expirationDate)
1828 throws SystemException {
1829 for (Lock lock : findByLtExpirationDate(expirationDate)) {
1830 remove(lock);
1831 }
1832 }
1833
1834
1841 public void removeByC_K(String className, String key)
1842 throws NoSuchLockException, SystemException {
1843 Lock lock = findByC_K(className, key);
1844
1845 remove(lock);
1846 }
1847
1848
1856 public void removeByC_K_O(String className, String key, String owner)
1857 throws NoSuchLockException, SystemException {
1858 Lock lock = findByC_K_O(className, key, owner);
1859
1860 remove(lock);
1861 }
1862
1863
1868 public void removeAll() throws SystemException {
1869 for (Lock lock : findAll()) {
1870 remove(lock);
1871 }
1872 }
1873
1874
1881 public int countByUuid(String uuid) throws SystemException {
1882 Object[] finderArgs = new Object[] { uuid };
1883
1884 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1885 finderArgs, this);
1886
1887 if (count == null) {
1888 StringBundler query = new StringBundler(2);
1889
1890 query.append(_SQL_COUNT_LOCK_WHERE);
1891
1892 if (uuid == null) {
1893 query.append(_FINDER_COLUMN_UUID_UUID_1);
1894 }
1895 else {
1896 if (uuid.equals(StringPool.BLANK)) {
1897 query.append(_FINDER_COLUMN_UUID_UUID_3);
1898 }
1899 else {
1900 query.append(_FINDER_COLUMN_UUID_UUID_2);
1901 }
1902 }
1903
1904 String sql = query.toString();
1905
1906 Session session = null;
1907
1908 try {
1909 session = openSession();
1910
1911 Query q = session.createQuery(sql);
1912
1913 QueryPos qPos = QueryPos.getInstance(q);
1914
1915 if (uuid != null) {
1916 qPos.add(uuid);
1917 }
1918
1919 count = (Long)q.uniqueResult();
1920 }
1921 catch (Exception e) {
1922 throw processException(e);
1923 }
1924 finally {
1925 if (count == null) {
1926 count = Long.valueOf(0);
1927 }
1928
1929 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1930 finderArgs, count);
1931
1932 closeSession(session);
1933 }
1934 }
1935
1936 return count.intValue();
1937 }
1938
1939
1946 public int countByLtExpirationDate(Date expirationDate)
1947 throws SystemException {
1948 Object[] finderArgs = new Object[] { expirationDate };
1949
1950 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
1951 finderArgs, this);
1952
1953 if (count == null) {
1954 StringBundler query = new StringBundler(2);
1955
1956 query.append(_SQL_COUNT_LOCK_WHERE);
1957
1958 if (expirationDate == null) {
1959 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1960 }
1961 else {
1962 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1963 }
1964
1965 String sql = query.toString();
1966
1967 Session session = null;
1968
1969 try {
1970 session = openSession();
1971
1972 Query q = session.createQuery(sql);
1973
1974 QueryPos qPos = QueryPos.getInstance(q);
1975
1976 if (expirationDate != null) {
1977 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1978 }
1979
1980 count = (Long)q.uniqueResult();
1981 }
1982 catch (Exception e) {
1983 throw processException(e);
1984 }
1985 finally {
1986 if (count == null) {
1987 count = Long.valueOf(0);
1988 }
1989
1990 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
1991 finderArgs, count);
1992
1993 closeSession(session);
1994 }
1995 }
1996
1997 return count.intValue();
1998 }
1999
2000
2008 public int countByC_K(String className, String key)
2009 throws SystemException {
2010 Object[] finderArgs = new Object[] { className, key };
2011
2012 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
2013 finderArgs, this);
2014
2015 if (count == null) {
2016 StringBundler query = new StringBundler(3);
2017
2018 query.append(_SQL_COUNT_LOCK_WHERE);
2019
2020 if (className == null) {
2021 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
2022 }
2023 else {
2024 if (className.equals(StringPool.BLANK)) {
2025 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
2026 }
2027 else {
2028 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
2029 }
2030 }
2031
2032 if (key == null) {
2033 query.append(_FINDER_COLUMN_C_K_KEY_1);
2034 }
2035 else {
2036 if (key.equals(StringPool.BLANK)) {
2037 query.append(_FINDER_COLUMN_C_K_KEY_3);
2038 }
2039 else {
2040 query.append(_FINDER_COLUMN_C_K_KEY_2);
2041 }
2042 }
2043
2044 String sql = query.toString();
2045
2046 Session session = null;
2047
2048 try {
2049 session = openSession();
2050
2051 Query q = session.createQuery(sql);
2052
2053 QueryPos qPos = QueryPos.getInstance(q);
2054
2055 if (className != null) {
2056 qPos.add(className);
2057 }
2058
2059 if (key != null) {
2060 qPos.add(key);
2061 }
2062
2063 count = (Long)q.uniqueResult();
2064 }
2065 catch (Exception e) {
2066 throw processException(e);
2067 }
2068 finally {
2069 if (count == null) {
2070 count = Long.valueOf(0);
2071 }
2072
2073 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
2074 count);
2075
2076 closeSession(session);
2077 }
2078 }
2079
2080 return count.intValue();
2081 }
2082
2083
2092 public int countByC_K_O(String className, String key, String owner)
2093 throws SystemException {
2094 Object[] finderArgs = new Object[] { className, key, owner };
2095
2096 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K_O,
2097 finderArgs, this);
2098
2099 if (count == null) {
2100 StringBundler query = new StringBundler(4);
2101
2102 query.append(_SQL_COUNT_LOCK_WHERE);
2103
2104 if (className == null) {
2105 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
2106 }
2107 else {
2108 if (className.equals(StringPool.BLANK)) {
2109 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
2110 }
2111 else {
2112 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
2113 }
2114 }
2115
2116 if (key == null) {
2117 query.append(_FINDER_COLUMN_C_K_O_KEY_1);
2118 }
2119 else {
2120 if (key.equals(StringPool.BLANK)) {
2121 query.append(_FINDER_COLUMN_C_K_O_KEY_3);
2122 }
2123 else {
2124 query.append(_FINDER_COLUMN_C_K_O_KEY_2);
2125 }
2126 }
2127
2128 if (owner == null) {
2129 query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
2130 }
2131 else {
2132 if (owner.equals(StringPool.BLANK)) {
2133 query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
2134 }
2135 else {
2136 query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
2137 }
2138 }
2139
2140 String sql = query.toString();
2141
2142 Session session = null;
2143
2144 try {
2145 session = openSession();
2146
2147 Query q = session.createQuery(sql);
2148
2149 QueryPos qPos = QueryPos.getInstance(q);
2150
2151 if (className != null) {
2152 qPos.add(className);
2153 }
2154
2155 if (key != null) {
2156 qPos.add(key);
2157 }
2158
2159 if (owner != null) {
2160 qPos.add(owner);
2161 }
2162
2163 count = (Long)q.uniqueResult();
2164 }
2165 catch (Exception e) {
2166 throw processException(e);
2167 }
2168 finally {
2169 if (count == null) {
2170 count = Long.valueOf(0);
2171 }
2172
2173 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K_O,
2174 finderArgs, count);
2175
2176 closeSession(session);
2177 }
2178 }
2179
2180 return count.intValue();
2181 }
2182
2183
2189 public int countAll() throws SystemException {
2190 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2191 FINDER_ARGS_EMPTY, this);
2192
2193 if (count == null) {
2194 Session session = null;
2195
2196 try {
2197 session = openSession();
2198
2199 Query q = session.createQuery(_SQL_COUNT_LOCK);
2200
2201 count = (Long)q.uniqueResult();
2202 }
2203 catch (Exception e) {
2204 throw processException(e);
2205 }
2206 finally {
2207 if (count == null) {
2208 count = Long.valueOf(0);
2209 }
2210
2211 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2212 FINDER_ARGS_EMPTY, count);
2213
2214 closeSession(session);
2215 }
2216 }
2217
2218 return count.intValue();
2219 }
2220
2221
2224 public void afterPropertiesSet() {
2225 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2226 com.liferay.portal.util.PropsUtil.get(
2227 "value.object.listener.com.liferay.portal.model.Lock")));
2228
2229 if (listenerClassNames.length > 0) {
2230 try {
2231 List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
2232
2233 for (String listenerClassName : listenerClassNames) {
2234 listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
2235 listenerClassName));
2236 }
2237
2238 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2239 }
2240 catch (Exception e) {
2241 _log.error(e);
2242 }
2243 }
2244 }
2245
2246 public void destroy() {
2247 EntityCacheUtil.removeCache(LockImpl.class.getName());
2248 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2249 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2250 }
2251
2252 @BeanReference(type = AccountPersistence.class)
2253 protected AccountPersistence accountPersistence;
2254 @BeanReference(type = AddressPersistence.class)
2255 protected AddressPersistence addressPersistence;
2256 @BeanReference(type = BrowserTrackerPersistence.class)
2257 protected BrowserTrackerPersistence browserTrackerPersistence;
2258 @BeanReference(type = ClassNamePersistence.class)
2259 protected ClassNamePersistence classNamePersistence;
2260 @BeanReference(type = ClusterGroupPersistence.class)
2261 protected ClusterGroupPersistence clusterGroupPersistence;
2262 @BeanReference(type = CompanyPersistence.class)
2263 protected CompanyPersistence companyPersistence;
2264 @BeanReference(type = ContactPersistence.class)
2265 protected ContactPersistence contactPersistence;
2266 @BeanReference(type = CountryPersistence.class)
2267 protected CountryPersistence countryPersistence;
2268 @BeanReference(type = EmailAddressPersistence.class)
2269 protected EmailAddressPersistence emailAddressPersistence;
2270 @BeanReference(type = GroupPersistence.class)
2271 protected GroupPersistence groupPersistence;
2272 @BeanReference(type = ImagePersistence.class)
2273 protected ImagePersistence imagePersistence;
2274 @BeanReference(type = LayoutPersistence.class)
2275 protected LayoutPersistence layoutPersistence;
2276 @BeanReference(type = LayoutBranchPersistence.class)
2277 protected LayoutBranchPersistence layoutBranchPersistence;
2278 @BeanReference(type = LayoutPrototypePersistence.class)
2279 protected LayoutPrototypePersistence layoutPrototypePersistence;
2280 @BeanReference(type = LayoutRevisionPersistence.class)
2281 protected LayoutRevisionPersistence layoutRevisionPersistence;
2282 @BeanReference(type = LayoutSetPersistence.class)
2283 protected LayoutSetPersistence layoutSetPersistence;
2284 @BeanReference(type = LayoutSetBranchPersistence.class)
2285 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2286 @BeanReference(type = LayoutSetPrototypePersistence.class)
2287 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2288 @BeanReference(type = ListTypePersistence.class)
2289 protected ListTypePersistence listTypePersistence;
2290 @BeanReference(type = LockPersistence.class)
2291 protected LockPersistence lockPersistence;
2292 @BeanReference(type = MembershipRequestPersistence.class)
2293 protected MembershipRequestPersistence membershipRequestPersistence;
2294 @BeanReference(type = OrganizationPersistence.class)
2295 protected OrganizationPersistence organizationPersistence;
2296 @BeanReference(type = OrgGroupPermissionPersistence.class)
2297 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2298 @BeanReference(type = OrgGroupRolePersistence.class)
2299 protected OrgGroupRolePersistence orgGroupRolePersistence;
2300 @BeanReference(type = OrgLaborPersistence.class)
2301 protected OrgLaborPersistence orgLaborPersistence;
2302 @BeanReference(type = PasswordPolicyPersistence.class)
2303 protected PasswordPolicyPersistence passwordPolicyPersistence;
2304 @BeanReference(type = PasswordPolicyRelPersistence.class)
2305 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2306 @BeanReference(type = PasswordTrackerPersistence.class)
2307 protected PasswordTrackerPersistence passwordTrackerPersistence;
2308 @BeanReference(type = PermissionPersistence.class)
2309 protected PermissionPersistence permissionPersistence;
2310 @BeanReference(type = PhonePersistence.class)
2311 protected PhonePersistence phonePersistence;
2312 @BeanReference(type = PluginSettingPersistence.class)
2313 protected PluginSettingPersistence pluginSettingPersistence;
2314 @BeanReference(type = PortalPreferencesPersistence.class)
2315 protected PortalPreferencesPersistence portalPreferencesPersistence;
2316 @BeanReference(type = PortletPersistence.class)
2317 protected PortletPersistence portletPersistence;
2318 @BeanReference(type = PortletItemPersistence.class)
2319 protected PortletItemPersistence portletItemPersistence;
2320 @BeanReference(type = PortletPreferencesPersistence.class)
2321 protected PortletPreferencesPersistence portletPreferencesPersistence;
2322 @BeanReference(type = RegionPersistence.class)
2323 protected RegionPersistence regionPersistence;
2324 @BeanReference(type = ReleasePersistence.class)
2325 protected ReleasePersistence releasePersistence;
2326 @BeanReference(type = RepositoryPersistence.class)
2327 protected RepositoryPersistence repositoryPersistence;
2328 @BeanReference(type = RepositoryEntryPersistence.class)
2329 protected RepositoryEntryPersistence repositoryEntryPersistence;
2330 @BeanReference(type = ResourcePersistence.class)
2331 protected ResourcePersistence resourcePersistence;
2332 @BeanReference(type = ResourceActionPersistence.class)
2333 protected ResourceActionPersistence resourceActionPersistence;
2334 @BeanReference(type = ResourceBlockPersistence.class)
2335 protected ResourceBlockPersistence resourceBlockPersistence;
2336 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2337 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2338 @BeanReference(type = ResourceCodePersistence.class)
2339 protected ResourceCodePersistence resourceCodePersistence;
2340 @BeanReference(type = ResourcePermissionPersistence.class)
2341 protected ResourcePermissionPersistence resourcePermissionPersistence;
2342 @BeanReference(type = ResourceTypePermissionPersistence.class)
2343 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2344 @BeanReference(type = RolePersistence.class)
2345 protected RolePersistence rolePersistence;
2346 @BeanReference(type = ServiceComponentPersistence.class)
2347 protected ServiceComponentPersistence serviceComponentPersistence;
2348 @BeanReference(type = ShardPersistence.class)
2349 protected ShardPersistence shardPersistence;
2350 @BeanReference(type = SubscriptionPersistence.class)
2351 protected SubscriptionPersistence subscriptionPersistence;
2352 @BeanReference(type = TeamPersistence.class)
2353 protected TeamPersistence teamPersistence;
2354 @BeanReference(type = TicketPersistence.class)
2355 protected TicketPersistence ticketPersistence;
2356 @BeanReference(type = UserPersistence.class)
2357 protected UserPersistence userPersistence;
2358 @BeanReference(type = UserGroupPersistence.class)
2359 protected UserGroupPersistence userGroupPersistence;
2360 @BeanReference(type = UserGroupGroupRolePersistence.class)
2361 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2362 @BeanReference(type = UserGroupRolePersistence.class)
2363 protected UserGroupRolePersistence userGroupRolePersistence;
2364 @BeanReference(type = UserIdMapperPersistence.class)
2365 protected UserIdMapperPersistence userIdMapperPersistence;
2366 @BeanReference(type = UserNotificationEventPersistence.class)
2367 protected UserNotificationEventPersistence userNotificationEventPersistence;
2368 @BeanReference(type = UserTrackerPersistence.class)
2369 protected UserTrackerPersistence userTrackerPersistence;
2370 @BeanReference(type = UserTrackerPathPersistence.class)
2371 protected UserTrackerPathPersistence userTrackerPathPersistence;
2372 @BeanReference(type = VirtualHostPersistence.class)
2373 protected VirtualHostPersistence virtualHostPersistence;
2374 @BeanReference(type = WebDAVPropsPersistence.class)
2375 protected WebDAVPropsPersistence webDAVPropsPersistence;
2376 @BeanReference(type = WebsitePersistence.class)
2377 protected WebsitePersistence websitePersistence;
2378 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2379 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2380 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2381 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2382 private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
2383 private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
2384 private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
2385 private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
2386 private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
2387 private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
2388 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?)";
2389 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
2390 "lock.expirationDate < NULL";
2391 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
2392 "lock.expirationDate < ?";
2393 private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
2394 private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
2395 private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
2396 private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
2397 private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
2398 private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = ?)";
2399 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_1 = "lock.className IS NULL AND ";
2400 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_2 = "lock.className = ? AND ";
2401 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
2402 private static final String _FINDER_COLUMN_C_K_O_KEY_1 = "lock.key IS NULL AND ";
2403 private static final String _FINDER_COLUMN_C_K_O_KEY_2 = "lock.key = ? AND ";
2404 private static final String _FINDER_COLUMN_C_K_O_KEY_3 = "(lock.key IS NULL OR lock.key = ?) AND ";
2405 private static final String _FINDER_COLUMN_C_K_O_OWNER_1 = "lock.owner IS NULL";
2406 private static final String _FINDER_COLUMN_C_K_O_OWNER_2 = "lock.owner = ?";
2407 private static final String _FINDER_COLUMN_C_K_O_OWNER_3 = "(lock.owner IS NULL OR lock.owner = ?)";
2408 private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
2409 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
2410 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
2411 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2412 private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
2413 private static Lock _nullLock = new LockImpl() {
2414 @Override
2415 public Object clone() {
2416 return this;
2417 }
2418
2419 @Override
2420 public CacheModel<Lock> toCacheModel() {
2421 return _nullLockCacheModel;
2422 }
2423 };
2424
2425 private static CacheModel<Lock> _nullLockCacheModel = new CacheModel<Lock>() {
2426 public Lock toEntityModel() {
2427 return _nullLock;
2428 }
2429 };
2430 }