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_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
097 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
099 new String[] {
100 String.class.getName(), Long.class.getName(),
101
102 "java.lang.Integer", "java.lang.Integer",
103 "com.liferay.portal.kernel.util.OrderByComparator"
104 });
105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
106 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
107 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
109 new String[] { String.class.getName(), Long.class.getName() },
110 LockModelImpl.UUID_COLUMN_BITMASK |
111 LockModelImpl.COMPANYID_COLUMN_BITMASK);
112 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
113 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
115 new String[] { String.class.getName(), Long.class.getName() });
116 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE =
117 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
118 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
119 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtExpirationDate",
120 new String[] {
121 Date.class.getName(),
122
123 "java.lang.Integer", "java.lang.Integer",
124 "com.liferay.portal.kernel.util.OrderByComparator"
125 });
126 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE =
127 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
128 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
129 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByLtExpirationDate",
130 new String[] { Date.class.getName() });
131 public static final FinderPath FINDER_PATH_FETCH_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
132 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
133 FINDER_CLASS_NAME_ENTITY, "fetchByC_K",
134 new String[] { String.class.getName(), String.class.getName() },
135 LockModelImpl.CLASSNAME_COLUMN_BITMASK |
136 LockModelImpl.KEY_COLUMN_BITMASK);
137 public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
138 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
139 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
140 new String[] { String.class.getName(), String.class.getName() });
141 public static final FinderPath FINDER_PATH_FETCH_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
142 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
143 FINDER_CLASS_NAME_ENTITY, "fetchByC_K_O",
144 new String[] {
145 String.class.getName(), String.class.getName(),
146 String.class.getName()
147 },
148 LockModelImpl.CLASSNAME_COLUMN_BITMASK |
149 LockModelImpl.KEY_COLUMN_BITMASK |
150 LockModelImpl.OWNER_COLUMN_BITMASK);
151 public static final FinderPath FINDER_PATH_COUNT_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
152 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
153 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K_O",
154 new String[] {
155 String.class.getName(), String.class.getName(),
156 String.class.getName()
157 });
158 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
159 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
160 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
161 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
162 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
163 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
164 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
165 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
166 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
167
168
173 public void cacheResult(Lock lock) {
174 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
175 LockImpl.class, lock.getPrimaryKey(), lock);
176
177 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
178 new Object[] { lock.getClassName(), lock.getKey() }, lock);
179
180 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
181 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() },
182 lock);
183
184 lock.resetOriginalValues();
185 }
186
187
192 public void cacheResult(List<Lock> locks) {
193 for (Lock lock : locks) {
194 if (EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
195 LockImpl.class, lock.getPrimaryKey()) == null) {
196 cacheResult(lock);
197 }
198 else {
199 lock.resetOriginalValues();
200 }
201 }
202 }
203
204
211 @Override
212 public void clearCache() {
213 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
214 CacheRegistryUtil.clear(LockImpl.class.getName());
215 }
216
217 EntityCacheUtil.clearCache(LockImpl.class.getName());
218
219 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
220 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
221 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
222 }
223
224
231 @Override
232 public void clearCache(Lock lock) {
233 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
234 LockImpl.class, lock.getPrimaryKey());
235
236 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
237 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
238
239 clearUniqueFindersCache(lock);
240 }
241
242 @Override
243 public void clearCache(List<Lock> locks) {
244 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
245 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
246
247 for (Lock lock : locks) {
248 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
249 LockImpl.class, lock.getPrimaryKey());
250
251 clearUniqueFindersCache(lock);
252 }
253 }
254
255 protected void clearUniqueFindersCache(Lock lock) {
256 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
257 new Object[] { lock.getClassName(), lock.getKey() });
258
259 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O,
260 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() });
261 }
262
263
269 public Lock create(long lockId) {
270 Lock lock = new LockImpl();
271
272 lock.setNew(true);
273 lock.setPrimaryKey(lockId);
274
275 String uuid = PortalUUIDUtil.generate();
276
277 lock.setUuid(uuid);
278
279 return lock;
280 }
281
282
290 public Lock remove(long lockId) throws NoSuchLockException, SystemException {
291 return remove(Long.valueOf(lockId));
292 }
293
294
302 @Override
303 public Lock remove(Serializable primaryKey)
304 throws NoSuchLockException, SystemException {
305 Session session = null;
306
307 try {
308 session = openSession();
309
310 Lock lock = (Lock)session.get(LockImpl.class, primaryKey);
311
312 if (lock == null) {
313 if (_log.isWarnEnabled()) {
314 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
315 }
316
317 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
318 primaryKey);
319 }
320
321 return remove(lock);
322 }
323 catch (NoSuchLockException nsee) {
324 throw nsee;
325 }
326 catch (Exception e) {
327 throw processException(e);
328 }
329 finally {
330 closeSession(session);
331 }
332 }
333
334 @Override
335 protected Lock removeImpl(Lock lock) throws SystemException {
336 lock = toUnwrappedModel(lock);
337
338 Session session = null;
339
340 try {
341 session = openSession();
342
343 if (lock.isCachedModel()) {
344 lock = (Lock)session.get(LockImpl.class, lock.getPrimaryKeyObj());
345 }
346
347 session.delete(lock);
348 }
349 catch (Exception e) {
350 throw processException(e);
351 }
352 finally {
353 closeSession(session);
354 }
355
356 clearCache(lock);
357
358 return lock;
359 }
360
361 @Override
362 public Lock updateImpl(com.liferay.portal.model.Lock lock)
363 throws SystemException {
364 lock = toUnwrappedModel(lock);
365
366 boolean isNew = lock.isNew();
367
368 LockModelImpl lockModelImpl = (LockModelImpl)lock;
369
370 if (Validator.isNull(lock.getUuid())) {
371 String uuid = PortalUUIDUtil.generate();
372
373 lock.setUuid(uuid);
374 }
375
376 Session session = null;
377
378 try {
379 session = openSession();
380
381 if (lock.isNew()) {
382 session.save(lock);
383
384 lock.setNew(false);
385 }
386 else {
387 session.merge(lock);
388 }
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396
397 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
398
399 if (isNew || !LockModelImpl.COLUMN_BITMASK_ENABLED) {
400 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
401 }
402
403 else {
404 if ((lockModelImpl.getColumnBitmask() &
405 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
406 Object[] args = new Object[] { lockModelImpl.getOriginalUuid() };
407
408 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
409 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
410 args);
411
412 args = new Object[] { lockModelImpl.getUuid() };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
415 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
416 args);
417 }
418
419 if ((lockModelImpl.getColumnBitmask() &
420 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
421 Object[] args = new Object[] {
422 lockModelImpl.getOriginalUuid(),
423 Long.valueOf(lockModelImpl.getOriginalCompanyId())
424 };
425
426 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
427 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
428 args);
429
430 args = new Object[] {
431 lockModelImpl.getUuid(),
432 Long.valueOf(lockModelImpl.getCompanyId())
433 };
434
435 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
436 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
437 args);
438 }
439 }
440
441 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
442 LockImpl.class, lock.getPrimaryKey(), lock);
443
444 if (isNew) {
445 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
446 new Object[] { lock.getClassName(), lock.getKey() }, lock);
447
448 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
449 new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() },
450 lock);
451 }
452 else {
453 if ((lockModelImpl.getColumnBitmask() &
454 FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
455 Object[] args = new Object[] {
456 lockModelImpl.getOriginalClassName(),
457
458 lockModelImpl.getOriginalKey()
459 };
460
461 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
462
463 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
464
465 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
466 new Object[] { lock.getClassName(), lock.getKey() }, lock);
467 }
468
469 if ((lockModelImpl.getColumnBitmask() &
470 FINDER_PATH_FETCH_BY_C_K_O.getColumnBitmask()) != 0) {
471 Object[] args = new Object[] {
472 lockModelImpl.getOriginalClassName(),
473
474 lockModelImpl.getOriginalKey(),
475
476 lockModelImpl.getOriginalOwner()
477 };
478
479 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K_O, args);
480
481 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O, args);
482
483 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
484 new Object[] {
485 lock.getClassName(),
486
487 lock.getKey(),
488
489 lock.getOwner()
490 }, lock);
491 }
492 }
493
494 return lock;
495 }
496
497 protected Lock toUnwrappedModel(Lock lock) {
498 if (lock instanceof LockImpl) {
499 return lock;
500 }
501
502 LockImpl lockImpl = new LockImpl();
503
504 lockImpl.setNew(lock.isNew());
505 lockImpl.setPrimaryKey(lock.getPrimaryKey());
506
507 lockImpl.setUuid(lock.getUuid());
508 lockImpl.setLockId(lock.getLockId());
509 lockImpl.setCompanyId(lock.getCompanyId());
510 lockImpl.setUserId(lock.getUserId());
511 lockImpl.setUserName(lock.getUserName());
512 lockImpl.setCreateDate(lock.getCreateDate());
513 lockImpl.setClassName(lock.getClassName());
514 lockImpl.setKey(lock.getKey());
515 lockImpl.setOwner(lock.getOwner());
516 lockImpl.setInheritable(lock.isInheritable());
517 lockImpl.setExpirationDate(lock.getExpirationDate());
518
519 return lockImpl;
520 }
521
522
530 @Override
531 public Lock findByPrimaryKey(Serializable primaryKey)
532 throws NoSuchModelException, SystemException {
533 return findByPrimaryKey(((Long)primaryKey).longValue());
534 }
535
536
544 public Lock findByPrimaryKey(long lockId)
545 throws NoSuchLockException, SystemException {
546 Lock lock = fetchByPrimaryKey(lockId);
547
548 if (lock == null) {
549 if (_log.isWarnEnabled()) {
550 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + lockId);
551 }
552
553 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
554 lockId);
555 }
556
557 return lock;
558 }
559
560
567 @Override
568 public Lock fetchByPrimaryKey(Serializable primaryKey)
569 throws SystemException {
570 return fetchByPrimaryKey(((Long)primaryKey).longValue());
571 }
572
573
580 public Lock fetchByPrimaryKey(long lockId) throws SystemException {
581 Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
582 LockImpl.class, lockId);
583
584 if (lock == _nullLock) {
585 return null;
586 }
587
588 if (lock == null) {
589 Session session = null;
590
591 boolean hasException = false;
592
593 try {
594 session = openSession();
595
596 lock = (Lock)session.get(LockImpl.class, Long.valueOf(lockId));
597 }
598 catch (Exception e) {
599 hasException = true;
600
601 throw processException(e);
602 }
603 finally {
604 if (lock != null) {
605 cacheResult(lock);
606 }
607 else if (!hasException) {
608 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
609 LockImpl.class, lockId, _nullLock);
610 }
611
612 closeSession(session);
613 }
614 }
615
616 return lock;
617 }
618
619
626 public List<Lock> findByUuid(String uuid) throws SystemException {
627 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
628 }
629
630
643 public List<Lock> findByUuid(String uuid, int start, int end)
644 throws SystemException {
645 return findByUuid(uuid, start, end, null);
646 }
647
648
662 public List<Lock> findByUuid(String uuid, int start, int end,
663 OrderByComparator orderByComparator) throws SystemException {
664 FinderPath finderPath = null;
665 Object[] finderArgs = null;
666
667 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
668 (orderByComparator == null)) {
669 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
670 finderArgs = new Object[] { uuid };
671 }
672 else {
673 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
674 finderArgs = new Object[] { uuid, start, end, orderByComparator };
675 }
676
677 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
678 finderArgs, this);
679
680 if ((list != null) && !list.isEmpty()) {
681 for (Lock lock : list) {
682 if (!Validator.equals(uuid, lock.getUuid())) {
683 list = null;
684
685 break;
686 }
687 }
688 }
689
690 if (list == null) {
691 StringBundler query = null;
692
693 if (orderByComparator != null) {
694 query = new StringBundler(3 +
695 (orderByComparator.getOrderByFields().length * 3));
696 }
697 else {
698 query = new StringBundler(2);
699 }
700
701 query.append(_SQL_SELECT_LOCK_WHERE);
702
703 if (uuid == null) {
704 query.append(_FINDER_COLUMN_UUID_UUID_1);
705 }
706 else {
707 if (uuid.equals(StringPool.BLANK)) {
708 query.append(_FINDER_COLUMN_UUID_UUID_3);
709 }
710 else {
711 query.append(_FINDER_COLUMN_UUID_UUID_2);
712 }
713 }
714
715 if (orderByComparator != null) {
716 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
717 orderByComparator);
718 }
719
720 String sql = query.toString();
721
722 Session session = null;
723
724 try {
725 session = openSession();
726
727 Query q = session.createQuery(sql);
728
729 QueryPos qPos = QueryPos.getInstance(q);
730
731 if (uuid != null) {
732 qPos.add(uuid);
733 }
734
735 list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
736 }
737 catch (Exception e) {
738 throw processException(e);
739 }
740 finally {
741 if (list == null) {
742 FinderCacheUtil.removeResult(finderPath, finderArgs);
743 }
744 else {
745 cacheResult(list);
746
747 FinderCacheUtil.putResult(finderPath, finderArgs, list);
748 }
749
750 closeSession(session);
751 }
752 }
753
754 return list;
755 }
756
757
766 public Lock findByUuid_First(String uuid,
767 OrderByComparator orderByComparator)
768 throws NoSuchLockException, SystemException {
769 Lock lock = fetchByUuid_First(uuid, orderByComparator);
770
771 if (lock != null) {
772 return lock;
773 }
774
775 StringBundler msg = new StringBundler(4);
776
777 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
778
779 msg.append("uuid=");
780 msg.append(uuid);
781
782 msg.append(StringPool.CLOSE_CURLY_BRACE);
783
784 throw new NoSuchLockException(msg.toString());
785 }
786
787
795 public Lock fetchByUuid_First(String uuid,
796 OrderByComparator orderByComparator) throws SystemException {
797 List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
798
799 if (!list.isEmpty()) {
800 return list.get(0);
801 }
802
803 return null;
804 }
805
806
815 public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
816 throws NoSuchLockException, SystemException {
817 Lock lock = fetchByUuid_Last(uuid, orderByComparator);
818
819 if (lock != null) {
820 return lock;
821 }
822
823 StringBundler msg = new StringBundler(4);
824
825 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
826
827 msg.append("uuid=");
828 msg.append(uuid);
829
830 msg.append(StringPool.CLOSE_CURLY_BRACE);
831
832 throw new NoSuchLockException(msg.toString());
833 }
834
835
843 public Lock fetchByUuid_Last(String uuid,
844 OrderByComparator orderByComparator) throws SystemException {
845 int count = countByUuid(uuid);
846
847 List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
848
849 if (!list.isEmpty()) {
850 return list.get(0);
851 }
852
853 return null;
854 }
855
856
866 public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
867 OrderByComparator orderByComparator)
868 throws NoSuchLockException, SystemException {
869 Lock lock = findByPrimaryKey(lockId);
870
871 Session session = null;
872
873 try {
874 session = openSession();
875
876 Lock[] array = new LockImpl[3];
877
878 array[0] = getByUuid_PrevAndNext(session, lock, uuid,
879 orderByComparator, true);
880
881 array[1] = lock;
882
883 array[2] = getByUuid_PrevAndNext(session, lock, uuid,
884 orderByComparator, false);
885
886 return array;
887 }
888 catch (Exception e) {
889 throw processException(e);
890 }
891 finally {
892 closeSession(session);
893 }
894 }
895
896 protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
897 String uuid, OrderByComparator orderByComparator, boolean previous) {
898 StringBundler query = null;
899
900 if (orderByComparator != null) {
901 query = new StringBundler(6 +
902 (orderByComparator.getOrderByFields().length * 6));
903 }
904 else {
905 query = new StringBundler(3);
906 }
907
908 query.append(_SQL_SELECT_LOCK_WHERE);
909
910 if (uuid == null) {
911 query.append(_FINDER_COLUMN_UUID_UUID_1);
912 }
913 else {
914 if (uuid.equals(StringPool.BLANK)) {
915 query.append(_FINDER_COLUMN_UUID_UUID_3);
916 }
917 else {
918 query.append(_FINDER_COLUMN_UUID_UUID_2);
919 }
920 }
921
922 if (orderByComparator != null) {
923 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
924
925 if (orderByConditionFields.length > 0) {
926 query.append(WHERE_AND);
927 }
928
929 for (int i = 0; i < orderByConditionFields.length; i++) {
930 query.append(_ORDER_BY_ENTITY_ALIAS);
931 query.append(orderByConditionFields[i]);
932
933 if ((i + 1) < orderByConditionFields.length) {
934 if (orderByComparator.isAscending() ^ previous) {
935 query.append(WHERE_GREATER_THAN_HAS_NEXT);
936 }
937 else {
938 query.append(WHERE_LESSER_THAN_HAS_NEXT);
939 }
940 }
941 else {
942 if (orderByComparator.isAscending() ^ previous) {
943 query.append(WHERE_GREATER_THAN);
944 }
945 else {
946 query.append(WHERE_LESSER_THAN);
947 }
948 }
949 }
950
951 query.append(ORDER_BY_CLAUSE);
952
953 String[] orderByFields = orderByComparator.getOrderByFields();
954
955 for (int i = 0; i < orderByFields.length; i++) {
956 query.append(_ORDER_BY_ENTITY_ALIAS);
957 query.append(orderByFields[i]);
958
959 if ((i + 1) < orderByFields.length) {
960 if (orderByComparator.isAscending() ^ previous) {
961 query.append(ORDER_BY_ASC_HAS_NEXT);
962 }
963 else {
964 query.append(ORDER_BY_DESC_HAS_NEXT);
965 }
966 }
967 else {
968 if (orderByComparator.isAscending() ^ previous) {
969 query.append(ORDER_BY_ASC);
970 }
971 else {
972 query.append(ORDER_BY_DESC);
973 }
974 }
975 }
976 }
977
978 String sql = query.toString();
979
980 Query q = session.createQuery(sql);
981
982 q.setFirstResult(0);
983 q.setMaxResults(2);
984
985 QueryPos qPos = QueryPos.getInstance(q);
986
987 if (uuid != null) {
988 qPos.add(uuid);
989 }
990
991 if (orderByComparator != null) {
992 Object[] values = orderByComparator.getOrderByConditionValues(lock);
993
994 for (Object value : values) {
995 qPos.add(value);
996 }
997 }
998
999 List<Lock> list = q.list();
1000
1001 if (list.size() == 2) {
1002 return list.get(1);
1003 }
1004 else {
1005 return null;
1006 }
1007 }
1008
1009
1017 public List<Lock> findByUuid_C(String uuid, long companyId)
1018 throws SystemException {
1019 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1020 QueryUtil.ALL_POS, null);
1021 }
1022
1023
1037 public List<Lock> findByUuid_C(String uuid, long companyId, int start,
1038 int end) throws SystemException {
1039 return findByUuid_C(uuid, companyId, start, end, null);
1040 }
1041
1042
1057 public List<Lock> findByUuid_C(String uuid, long companyId, int start,
1058 int end, OrderByComparator orderByComparator) throws SystemException {
1059 FinderPath finderPath = null;
1060 Object[] finderArgs = null;
1061
1062 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1063 (orderByComparator == null)) {
1064 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1065 finderArgs = new Object[] { uuid, companyId };
1066 }
1067 else {
1068 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1069 finderArgs = new Object[] {
1070 uuid, companyId,
1071
1072 start, end, orderByComparator
1073 };
1074 }
1075
1076 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1077 finderArgs, this);
1078
1079 if ((list != null) && !list.isEmpty()) {
1080 for (Lock lock : list) {
1081 if (!Validator.equals(uuid, lock.getUuid()) ||
1082 (companyId != lock.getCompanyId())) {
1083 list = null;
1084
1085 break;
1086 }
1087 }
1088 }
1089
1090 if (list == null) {
1091 StringBundler query = null;
1092
1093 if (orderByComparator != null) {
1094 query = new StringBundler(4 +
1095 (orderByComparator.getOrderByFields().length * 3));
1096 }
1097 else {
1098 query = new StringBundler(3);
1099 }
1100
1101 query.append(_SQL_SELECT_LOCK_WHERE);
1102
1103 if (uuid == null) {
1104 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1105 }
1106 else {
1107 if (uuid.equals(StringPool.BLANK)) {
1108 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1109 }
1110 else {
1111 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1112 }
1113 }
1114
1115 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1116
1117 if (orderByComparator != null) {
1118 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1119 orderByComparator);
1120 }
1121
1122 String sql = query.toString();
1123
1124 Session session = null;
1125
1126 try {
1127 session = openSession();
1128
1129 Query q = session.createQuery(sql);
1130
1131 QueryPos qPos = QueryPos.getInstance(q);
1132
1133 if (uuid != null) {
1134 qPos.add(uuid);
1135 }
1136
1137 qPos.add(companyId);
1138
1139 list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
1140 }
1141 catch (Exception e) {
1142 throw processException(e);
1143 }
1144 finally {
1145 if (list == null) {
1146 FinderCacheUtil.removeResult(finderPath, finderArgs);
1147 }
1148 else {
1149 cacheResult(list);
1150
1151 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1152 }
1153
1154 closeSession(session);
1155 }
1156 }
1157
1158 return list;
1159 }
1160
1161
1171 public Lock findByUuid_C_First(String uuid, long companyId,
1172 OrderByComparator orderByComparator)
1173 throws NoSuchLockException, SystemException {
1174 Lock lock = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1175
1176 if (lock != null) {
1177 return lock;
1178 }
1179
1180 StringBundler msg = new StringBundler(6);
1181
1182 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1183
1184 msg.append("uuid=");
1185 msg.append(uuid);
1186
1187 msg.append(", companyId=");
1188 msg.append(companyId);
1189
1190 msg.append(StringPool.CLOSE_CURLY_BRACE);
1191
1192 throw new NoSuchLockException(msg.toString());
1193 }
1194
1195
1204 public Lock fetchByUuid_C_First(String uuid, long companyId,
1205 OrderByComparator orderByComparator) throws SystemException {
1206 List<Lock> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1207
1208 if (!list.isEmpty()) {
1209 return list.get(0);
1210 }
1211
1212 return null;
1213 }
1214
1215
1225 public Lock findByUuid_C_Last(String uuid, long companyId,
1226 OrderByComparator orderByComparator)
1227 throws NoSuchLockException, SystemException {
1228 Lock lock = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1229
1230 if (lock != null) {
1231 return lock;
1232 }
1233
1234 StringBundler msg = new StringBundler(6);
1235
1236 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1237
1238 msg.append("uuid=");
1239 msg.append(uuid);
1240
1241 msg.append(", companyId=");
1242 msg.append(companyId);
1243
1244 msg.append(StringPool.CLOSE_CURLY_BRACE);
1245
1246 throw new NoSuchLockException(msg.toString());
1247 }
1248
1249
1258 public Lock fetchByUuid_C_Last(String uuid, long companyId,
1259 OrderByComparator orderByComparator) throws SystemException {
1260 int count = countByUuid_C(uuid, companyId);
1261
1262 List<Lock> list = findByUuid_C(uuid, companyId, count - 1, count,
1263 orderByComparator);
1264
1265 if (!list.isEmpty()) {
1266 return list.get(0);
1267 }
1268
1269 return null;
1270 }
1271
1272
1283 public Lock[] findByUuid_C_PrevAndNext(long lockId, String uuid,
1284 long companyId, OrderByComparator orderByComparator)
1285 throws NoSuchLockException, SystemException {
1286 Lock lock = findByPrimaryKey(lockId);
1287
1288 Session session = null;
1289
1290 try {
1291 session = openSession();
1292
1293 Lock[] array = new LockImpl[3];
1294
1295 array[0] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
1296 orderByComparator, true);
1297
1298 array[1] = lock;
1299
1300 array[2] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
1301 orderByComparator, false);
1302
1303 return array;
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 closeSession(session);
1310 }
1311 }
1312
1313 protected Lock getByUuid_C_PrevAndNext(Session session, Lock lock,
1314 String uuid, long companyId, OrderByComparator orderByComparator,
1315 boolean previous) {
1316 StringBundler query = null;
1317
1318 if (orderByComparator != null) {
1319 query = new StringBundler(6 +
1320 (orderByComparator.getOrderByFields().length * 6));
1321 }
1322 else {
1323 query = new StringBundler(3);
1324 }
1325
1326 query.append(_SQL_SELECT_LOCK_WHERE);
1327
1328 if (uuid == null) {
1329 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1330 }
1331 else {
1332 if (uuid.equals(StringPool.BLANK)) {
1333 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1334 }
1335 else {
1336 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1337 }
1338 }
1339
1340 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1341
1342 if (orderByComparator != null) {
1343 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1344
1345 if (orderByConditionFields.length > 0) {
1346 query.append(WHERE_AND);
1347 }
1348
1349 for (int i = 0; i < orderByConditionFields.length; i++) {
1350 query.append(_ORDER_BY_ENTITY_ALIAS);
1351 query.append(orderByConditionFields[i]);
1352
1353 if ((i + 1) < orderByConditionFields.length) {
1354 if (orderByComparator.isAscending() ^ previous) {
1355 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1356 }
1357 else {
1358 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1359 }
1360 }
1361 else {
1362 if (orderByComparator.isAscending() ^ previous) {
1363 query.append(WHERE_GREATER_THAN);
1364 }
1365 else {
1366 query.append(WHERE_LESSER_THAN);
1367 }
1368 }
1369 }
1370
1371 query.append(ORDER_BY_CLAUSE);
1372
1373 String[] orderByFields = orderByComparator.getOrderByFields();
1374
1375 for (int i = 0; i < orderByFields.length; i++) {
1376 query.append(_ORDER_BY_ENTITY_ALIAS);
1377 query.append(orderByFields[i]);
1378
1379 if ((i + 1) < orderByFields.length) {
1380 if (orderByComparator.isAscending() ^ previous) {
1381 query.append(ORDER_BY_ASC_HAS_NEXT);
1382 }
1383 else {
1384 query.append(ORDER_BY_DESC_HAS_NEXT);
1385 }
1386 }
1387 else {
1388 if (orderByComparator.isAscending() ^ previous) {
1389 query.append(ORDER_BY_ASC);
1390 }
1391 else {
1392 query.append(ORDER_BY_DESC);
1393 }
1394 }
1395 }
1396 }
1397
1398 String sql = query.toString();
1399
1400 Query q = session.createQuery(sql);
1401
1402 q.setFirstResult(0);
1403 q.setMaxResults(2);
1404
1405 QueryPos qPos = QueryPos.getInstance(q);
1406
1407 if (uuid != null) {
1408 qPos.add(uuid);
1409 }
1410
1411 qPos.add(companyId);
1412
1413 if (orderByComparator != null) {
1414 Object[] values = orderByComparator.getOrderByConditionValues(lock);
1415
1416 for (Object value : values) {
1417 qPos.add(value);
1418 }
1419 }
1420
1421 List<Lock> list = q.list();
1422
1423 if (list.size() == 2) {
1424 return list.get(1);
1425 }
1426 else {
1427 return null;
1428 }
1429 }
1430
1431
1438 public List<Lock> findByLtExpirationDate(Date expirationDate)
1439 throws SystemException {
1440 return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
1441 QueryUtil.ALL_POS, null);
1442 }
1443
1444
1457 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1458 int end) throws SystemException {
1459 return findByLtExpirationDate(expirationDate, start, end, null);
1460 }
1461
1462
1476 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1477 int end, OrderByComparator orderByComparator) throws SystemException {
1478 FinderPath finderPath = null;
1479 Object[] finderArgs = null;
1480
1481 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE;
1482 finderArgs = new Object[] { expirationDate, start, end, orderByComparator };
1483
1484 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1485 finderArgs, this);
1486
1487 if ((list != null) && !list.isEmpty()) {
1488 for (Lock lock : list) {
1489 if (!Validator.equals(expirationDate, lock.getExpirationDate())) {
1490 list = null;
1491
1492 break;
1493 }
1494 }
1495 }
1496
1497 if (list == null) {
1498 StringBundler query = null;
1499
1500 if (orderByComparator != null) {
1501 query = new StringBundler(3 +
1502 (orderByComparator.getOrderByFields().length * 3));
1503 }
1504 else {
1505 query = new StringBundler(2);
1506 }
1507
1508 query.append(_SQL_SELECT_LOCK_WHERE);
1509
1510 if (expirationDate == null) {
1511 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1512 }
1513 else {
1514 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1515 }
1516
1517 if (orderByComparator != null) {
1518 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1519 orderByComparator);
1520 }
1521
1522 String sql = query.toString();
1523
1524 Session session = null;
1525
1526 try {
1527 session = openSession();
1528
1529 Query q = session.createQuery(sql);
1530
1531 QueryPos qPos = QueryPos.getInstance(q);
1532
1533 if (expirationDate != null) {
1534 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1535 }
1536
1537 list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
1538 }
1539 catch (Exception e) {
1540 throw processException(e);
1541 }
1542 finally {
1543 if (list == null) {
1544 FinderCacheUtil.removeResult(finderPath, finderArgs);
1545 }
1546 else {
1547 cacheResult(list);
1548
1549 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1550 }
1551
1552 closeSession(session);
1553 }
1554 }
1555
1556 return list;
1557 }
1558
1559
1568 public Lock findByLtExpirationDate_First(Date expirationDate,
1569 OrderByComparator orderByComparator)
1570 throws NoSuchLockException, SystemException {
1571 Lock lock = fetchByLtExpirationDate_First(expirationDate,
1572 orderByComparator);
1573
1574 if (lock != null) {
1575 return lock;
1576 }
1577
1578 StringBundler msg = new StringBundler(4);
1579
1580 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1581
1582 msg.append("expirationDate=");
1583 msg.append(expirationDate);
1584
1585 msg.append(StringPool.CLOSE_CURLY_BRACE);
1586
1587 throw new NoSuchLockException(msg.toString());
1588 }
1589
1590
1598 public Lock fetchByLtExpirationDate_First(Date expirationDate,
1599 OrderByComparator orderByComparator) throws SystemException {
1600 List<Lock> list = findByLtExpirationDate(expirationDate, 0, 1,
1601 orderByComparator);
1602
1603 if (!list.isEmpty()) {
1604 return list.get(0);
1605 }
1606
1607 return null;
1608 }
1609
1610
1619 public Lock findByLtExpirationDate_Last(Date expirationDate,
1620 OrderByComparator orderByComparator)
1621 throws NoSuchLockException, SystemException {
1622 Lock lock = fetchByLtExpirationDate_Last(expirationDate,
1623 orderByComparator);
1624
1625 if (lock != null) {
1626 return lock;
1627 }
1628
1629 StringBundler msg = new StringBundler(4);
1630
1631 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1632
1633 msg.append("expirationDate=");
1634 msg.append(expirationDate);
1635
1636 msg.append(StringPool.CLOSE_CURLY_BRACE);
1637
1638 throw new NoSuchLockException(msg.toString());
1639 }
1640
1641
1649 public Lock fetchByLtExpirationDate_Last(Date expirationDate,
1650 OrderByComparator orderByComparator) throws SystemException {
1651 int count = countByLtExpirationDate(expirationDate);
1652
1653 List<Lock> list = findByLtExpirationDate(expirationDate, count - 1,
1654 count, orderByComparator);
1655
1656 if (!list.isEmpty()) {
1657 return list.get(0);
1658 }
1659
1660 return null;
1661 }
1662
1663
1673 public Lock[] findByLtExpirationDate_PrevAndNext(long lockId,
1674 Date expirationDate, OrderByComparator orderByComparator)
1675 throws NoSuchLockException, SystemException {
1676 Lock lock = findByPrimaryKey(lockId);
1677
1678 Session session = null;
1679
1680 try {
1681 session = openSession();
1682
1683 Lock[] array = new LockImpl[3];
1684
1685 array[0] = getByLtExpirationDate_PrevAndNext(session, lock,
1686 expirationDate, orderByComparator, true);
1687
1688 array[1] = lock;
1689
1690 array[2] = getByLtExpirationDate_PrevAndNext(session, lock,
1691 expirationDate, orderByComparator, false);
1692
1693 return array;
1694 }
1695 catch (Exception e) {
1696 throw processException(e);
1697 }
1698 finally {
1699 closeSession(session);
1700 }
1701 }
1702
1703 protected Lock getByLtExpirationDate_PrevAndNext(Session session,
1704 Lock lock, Date expirationDate, OrderByComparator orderByComparator,
1705 boolean previous) {
1706 StringBundler query = null;
1707
1708 if (orderByComparator != null) {
1709 query = new StringBundler(6 +
1710 (orderByComparator.getOrderByFields().length * 6));
1711 }
1712 else {
1713 query = new StringBundler(3);
1714 }
1715
1716 query.append(_SQL_SELECT_LOCK_WHERE);
1717
1718 if (expirationDate == null) {
1719 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1720 }
1721 else {
1722 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1723 }
1724
1725 if (orderByComparator != null) {
1726 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1727
1728 if (orderByConditionFields.length > 0) {
1729 query.append(WHERE_AND);
1730 }
1731
1732 for (int i = 0; i < orderByConditionFields.length; i++) {
1733 query.append(_ORDER_BY_ENTITY_ALIAS);
1734 query.append(orderByConditionFields[i]);
1735
1736 if ((i + 1) < orderByConditionFields.length) {
1737 if (orderByComparator.isAscending() ^ previous) {
1738 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1739 }
1740 else {
1741 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1742 }
1743 }
1744 else {
1745 if (orderByComparator.isAscending() ^ previous) {
1746 query.append(WHERE_GREATER_THAN);
1747 }
1748 else {
1749 query.append(WHERE_LESSER_THAN);
1750 }
1751 }
1752 }
1753
1754 query.append(ORDER_BY_CLAUSE);
1755
1756 String[] orderByFields = orderByComparator.getOrderByFields();
1757
1758 for (int i = 0; i < orderByFields.length; i++) {
1759 query.append(_ORDER_BY_ENTITY_ALIAS);
1760 query.append(orderByFields[i]);
1761
1762 if ((i + 1) < orderByFields.length) {
1763 if (orderByComparator.isAscending() ^ previous) {
1764 query.append(ORDER_BY_ASC_HAS_NEXT);
1765 }
1766 else {
1767 query.append(ORDER_BY_DESC_HAS_NEXT);
1768 }
1769 }
1770 else {
1771 if (orderByComparator.isAscending() ^ previous) {
1772 query.append(ORDER_BY_ASC);
1773 }
1774 else {
1775 query.append(ORDER_BY_DESC);
1776 }
1777 }
1778 }
1779 }
1780
1781 String sql = query.toString();
1782
1783 Query q = session.createQuery(sql);
1784
1785 q.setFirstResult(0);
1786 q.setMaxResults(2);
1787
1788 QueryPos qPos = QueryPos.getInstance(q);
1789
1790 if (expirationDate != null) {
1791 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1792 }
1793
1794 if (orderByComparator != null) {
1795 Object[] values = orderByComparator.getOrderByConditionValues(lock);
1796
1797 for (Object value : values) {
1798 qPos.add(value);
1799 }
1800 }
1801
1802 List<Lock> list = q.list();
1803
1804 if (list.size() == 2) {
1805 return list.get(1);
1806 }
1807 else {
1808 return null;
1809 }
1810 }
1811
1812
1821 public Lock findByC_K(String className, String key)
1822 throws NoSuchLockException, SystemException {
1823 Lock lock = fetchByC_K(className, key);
1824
1825 if (lock == null) {
1826 StringBundler msg = new StringBundler(6);
1827
1828 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1829
1830 msg.append("className=");
1831 msg.append(className);
1832
1833 msg.append(", key=");
1834 msg.append(key);
1835
1836 msg.append(StringPool.CLOSE_CURLY_BRACE);
1837
1838 if (_log.isWarnEnabled()) {
1839 _log.warn(msg.toString());
1840 }
1841
1842 throw new NoSuchLockException(msg.toString());
1843 }
1844
1845 return lock;
1846 }
1847
1848
1856 public Lock fetchByC_K(String className, String key)
1857 throws SystemException {
1858 return fetchByC_K(className, key, true);
1859 }
1860
1861
1870 public Lock fetchByC_K(String className, String key,
1871 boolean retrieveFromCache) throws SystemException {
1872 Object[] finderArgs = new Object[] { className, key };
1873
1874 Object result = null;
1875
1876 if (retrieveFromCache) {
1877 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K,
1878 finderArgs, this);
1879 }
1880
1881 if (result instanceof Lock) {
1882 Lock lock = (Lock)result;
1883
1884 if (!Validator.equals(className, lock.getClassName()) ||
1885 !Validator.equals(key, lock.getKey())) {
1886 result = null;
1887 }
1888 }
1889
1890 if (result == null) {
1891 StringBundler query = new StringBundler(3);
1892
1893 query.append(_SQL_SELECT_LOCK_WHERE);
1894
1895 if (className == null) {
1896 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1897 }
1898 else {
1899 if (className.equals(StringPool.BLANK)) {
1900 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1901 }
1902 else {
1903 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1904 }
1905 }
1906
1907 if (key == null) {
1908 query.append(_FINDER_COLUMN_C_K_KEY_1);
1909 }
1910 else {
1911 if (key.equals(StringPool.BLANK)) {
1912 query.append(_FINDER_COLUMN_C_K_KEY_3);
1913 }
1914 else {
1915 query.append(_FINDER_COLUMN_C_K_KEY_2);
1916 }
1917 }
1918
1919 String sql = query.toString();
1920
1921 Session session = null;
1922
1923 try {
1924 session = openSession();
1925
1926 Query q = session.createQuery(sql);
1927
1928 QueryPos qPos = QueryPos.getInstance(q);
1929
1930 if (className != null) {
1931 qPos.add(className);
1932 }
1933
1934 if (key != null) {
1935 qPos.add(key);
1936 }
1937
1938 List<Lock> list = q.list();
1939
1940 result = list;
1941
1942 Lock lock = null;
1943
1944 if (list.isEmpty()) {
1945 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1946 finderArgs, list);
1947 }
1948 else {
1949 lock = list.get(0);
1950
1951 cacheResult(lock);
1952
1953 if ((lock.getClassName() == null) ||
1954 !lock.getClassName().equals(className) ||
1955 (lock.getKey() == null) ||
1956 !lock.getKey().equals(key)) {
1957 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1958 finderArgs, lock);
1959 }
1960 }
1961
1962 return lock;
1963 }
1964 catch (Exception e) {
1965 throw processException(e);
1966 }
1967 finally {
1968 if (result == null) {
1969 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
1970 finderArgs);
1971 }
1972
1973 closeSession(session);
1974 }
1975 }
1976 else {
1977 if (result instanceof List<?>) {
1978 return null;
1979 }
1980 else {
1981 return (Lock)result;
1982 }
1983 }
1984 }
1985
1986
1996 public Lock findByC_K_O(String className, String key, String owner)
1997 throws NoSuchLockException, SystemException {
1998 Lock lock = fetchByC_K_O(className, key, owner);
1999
2000 if (lock == null) {
2001 StringBundler msg = new StringBundler(8);
2002
2003 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2004
2005 msg.append("className=");
2006 msg.append(className);
2007
2008 msg.append(", key=");
2009 msg.append(key);
2010
2011 msg.append(", owner=");
2012 msg.append(owner);
2013
2014 msg.append(StringPool.CLOSE_CURLY_BRACE);
2015
2016 if (_log.isWarnEnabled()) {
2017 _log.warn(msg.toString());
2018 }
2019
2020 throw new NoSuchLockException(msg.toString());
2021 }
2022
2023 return lock;
2024 }
2025
2026
2035 public Lock fetchByC_K_O(String className, String key, String owner)
2036 throws SystemException {
2037 return fetchByC_K_O(className, key, owner, true);
2038 }
2039
2040
2050 public Lock fetchByC_K_O(String className, String key, String owner,
2051 boolean retrieveFromCache) throws SystemException {
2052 Object[] finderArgs = new Object[] { className, key, owner };
2053
2054 Object result = null;
2055
2056 if (retrieveFromCache) {
2057 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K_O,
2058 finderArgs, this);
2059 }
2060
2061 if (result instanceof Lock) {
2062 Lock lock = (Lock)result;
2063
2064 if (!Validator.equals(className, lock.getClassName()) ||
2065 !Validator.equals(key, lock.getKey()) ||
2066 !Validator.equals(owner, lock.getOwner())) {
2067 result = null;
2068 }
2069 }
2070
2071 if (result == null) {
2072 StringBundler query = new StringBundler(4);
2073
2074 query.append(_SQL_SELECT_LOCK_WHERE);
2075
2076 if (className == null) {
2077 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
2078 }
2079 else {
2080 if (className.equals(StringPool.BLANK)) {
2081 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
2082 }
2083 else {
2084 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
2085 }
2086 }
2087
2088 if (key == null) {
2089 query.append(_FINDER_COLUMN_C_K_O_KEY_1);
2090 }
2091 else {
2092 if (key.equals(StringPool.BLANK)) {
2093 query.append(_FINDER_COLUMN_C_K_O_KEY_3);
2094 }
2095 else {
2096 query.append(_FINDER_COLUMN_C_K_O_KEY_2);
2097 }
2098 }
2099
2100 if (owner == null) {
2101 query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
2102 }
2103 else {
2104 if (owner.equals(StringPool.BLANK)) {
2105 query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
2106 }
2107 else {
2108 query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
2109 }
2110 }
2111
2112 String sql = query.toString();
2113
2114 Session session = null;
2115
2116 try {
2117 session = openSession();
2118
2119 Query q = session.createQuery(sql);
2120
2121 QueryPos qPos = QueryPos.getInstance(q);
2122
2123 if (className != null) {
2124 qPos.add(className);
2125 }
2126
2127 if (key != null) {
2128 qPos.add(key);
2129 }
2130
2131 if (owner != null) {
2132 qPos.add(owner);
2133 }
2134
2135 List<Lock> list = q.list();
2136
2137 result = list;
2138
2139 Lock lock = null;
2140
2141 if (list.isEmpty()) {
2142 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
2143 finderArgs, list);
2144 }
2145 else {
2146 lock = list.get(0);
2147
2148 cacheResult(lock);
2149
2150 if ((lock.getClassName() == null) ||
2151 !lock.getClassName().equals(className) ||
2152 (lock.getKey() == null) ||
2153 !lock.getKey().equals(key) ||
2154 (lock.getOwner() == null) ||
2155 !lock.getOwner().equals(owner)) {
2156 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
2157 finderArgs, lock);
2158 }
2159 }
2160
2161 return lock;
2162 }
2163 catch (Exception e) {
2164 throw processException(e);
2165 }
2166 finally {
2167 if (result == null) {
2168 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O,
2169 finderArgs);
2170 }
2171
2172 closeSession(session);
2173 }
2174 }
2175 else {
2176 if (result instanceof List<?>) {
2177 return null;
2178 }
2179 else {
2180 return (Lock)result;
2181 }
2182 }
2183 }
2184
2185
2191 public List<Lock> findAll() throws SystemException {
2192 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2193 }
2194
2195
2207 public List<Lock> findAll(int start, int end) throws SystemException {
2208 return findAll(start, end, null);
2209 }
2210
2211
2224 public List<Lock> findAll(int start, int end,
2225 OrderByComparator orderByComparator) throws SystemException {
2226 FinderPath finderPath = null;
2227 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2228
2229 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2230 (orderByComparator == null)) {
2231 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2232 finderArgs = FINDER_ARGS_EMPTY;
2233 }
2234 else {
2235 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2236 finderArgs = new Object[] { start, end, orderByComparator };
2237 }
2238
2239 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
2240 finderArgs, this);
2241
2242 if (list == null) {
2243 StringBundler query = null;
2244 String sql = null;
2245
2246 if (orderByComparator != null) {
2247 query = new StringBundler(2 +
2248 (orderByComparator.getOrderByFields().length * 3));
2249
2250 query.append(_SQL_SELECT_LOCK);
2251
2252 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2253 orderByComparator);
2254
2255 sql = query.toString();
2256 }
2257 else {
2258 sql = _SQL_SELECT_LOCK;
2259 }
2260
2261 Session session = null;
2262
2263 try {
2264 session = openSession();
2265
2266 Query q = session.createQuery(sql);
2267
2268 if (orderByComparator == null) {
2269 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2270 end, false);
2271
2272 Collections.sort(list);
2273 }
2274 else {
2275 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2276 end);
2277 }
2278 }
2279 catch (Exception e) {
2280 throw processException(e);
2281 }
2282 finally {
2283 if (list == null) {
2284 FinderCacheUtil.removeResult(finderPath, finderArgs);
2285 }
2286 else {
2287 cacheResult(list);
2288
2289 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2290 }
2291
2292 closeSession(session);
2293 }
2294 }
2295
2296 return list;
2297 }
2298
2299
2305 public void removeByUuid(String uuid) throws SystemException {
2306 for (Lock lock : findByUuid(uuid)) {
2307 remove(lock);
2308 }
2309 }
2310
2311
2318 public void removeByUuid_C(String uuid, long companyId)
2319 throws SystemException {
2320 for (Lock lock : findByUuid_C(uuid, companyId)) {
2321 remove(lock);
2322 }
2323 }
2324
2325
2331 public void removeByLtExpirationDate(Date expirationDate)
2332 throws SystemException {
2333 for (Lock lock : findByLtExpirationDate(expirationDate)) {
2334 remove(lock);
2335 }
2336 }
2337
2338
2346 public Lock removeByC_K(String className, String key)
2347 throws NoSuchLockException, SystemException {
2348 Lock lock = findByC_K(className, key);
2349
2350 return remove(lock);
2351 }
2352
2353
2362 public Lock removeByC_K_O(String className, String key, String owner)
2363 throws NoSuchLockException, SystemException {
2364 Lock lock = findByC_K_O(className, key, owner);
2365
2366 return remove(lock);
2367 }
2368
2369
2374 public void removeAll() throws SystemException {
2375 for (Lock lock : findAll()) {
2376 remove(lock);
2377 }
2378 }
2379
2380
2387 public int countByUuid(String uuid) throws SystemException {
2388 Object[] finderArgs = new Object[] { uuid };
2389
2390 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2391 finderArgs, this);
2392
2393 if (count == null) {
2394 StringBundler query = new StringBundler(2);
2395
2396 query.append(_SQL_COUNT_LOCK_WHERE);
2397
2398 if (uuid == null) {
2399 query.append(_FINDER_COLUMN_UUID_UUID_1);
2400 }
2401 else {
2402 if (uuid.equals(StringPool.BLANK)) {
2403 query.append(_FINDER_COLUMN_UUID_UUID_3);
2404 }
2405 else {
2406 query.append(_FINDER_COLUMN_UUID_UUID_2);
2407 }
2408 }
2409
2410 String sql = query.toString();
2411
2412 Session session = null;
2413
2414 try {
2415 session = openSession();
2416
2417 Query q = session.createQuery(sql);
2418
2419 QueryPos qPos = QueryPos.getInstance(q);
2420
2421 if (uuid != null) {
2422 qPos.add(uuid);
2423 }
2424
2425 count = (Long)q.uniqueResult();
2426 }
2427 catch (Exception e) {
2428 throw processException(e);
2429 }
2430 finally {
2431 if (count == null) {
2432 count = Long.valueOf(0);
2433 }
2434
2435 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2436 finderArgs, count);
2437
2438 closeSession(session);
2439 }
2440 }
2441
2442 return count.intValue();
2443 }
2444
2445
2453 public int countByUuid_C(String uuid, long companyId)
2454 throws SystemException {
2455 Object[] finderArgs = new Object[] { uuid, companyId };
2456
2457 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
2458 finderArgs, this);
2459
2460 if (count == null) {
2461 StringBundler query = new StringBundler(3);
2462
2463 query.append(_SQL_COUNT_LOCK_WHERE);
2464
2465 if (uuid == null) {
2466 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
2467 }
2468 else {
2469 if (uuid.equals(StringPool.BLANK)) {
2470 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
2471 }
2472 else {
2473 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
2474 }
2475 }
2476
2477 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2478
2479 String sql = query.toString();
2480
2481 Session session = null;
2482
2483 try {
2484 session = openSession();
2485
2486 Query q = session.createQuery(sql);
2487
2488 QueryPos qPos = QueryPos.getInstance(q);
2489
2490 if (uuid != null) {
2491 qPos.add(uuid);
2492 }
2493
2494 qPos.add(companyId);
2495
2496 count = (Long)q.uniqueResult();
2497 }
2498 catch (Exception e) {
2499 throw processException(e);
2500 }
2501 finally {
2502 if (count == null) {
2503 count = Long.valueOf(0);
2504 }
2505
2506 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
2507 finderArgs, count);
2508
2509 closeSession(session);
2510 }
2511 }
2512
2513 return count.intValue();
2514 }
2515
2516
2523 public int countByLtExpirationDate(Date expirationDate)
2524 throws SystemException {
2525 Object[] finderArgs = new Object[] { expirationDate };
2526
2527 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE,
2528 finderArgs, this);
2529
2530 if (count == null) {
2531 StringBundler query = new StringBundler(2);
2532
2533 query.append(_SQL_COUNT_LOCK_WHERE);
2534
2535 if (expirationDate == null) {
2536 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
2537 }
2538 else {
2539 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
2540 }
2541
2542 String sql = query.toString();
2543
2544 Session session = null;
2545
2546 try {
2547 session = openSession();
2548
2549 Query q = session.createQuery(sql);
2550
2551 QueryPos qPos = QueryPos.getInstance(q);
2552
2553 if (expirationDate != null) {
2554 qPos.add(CalendarUtil.getTimestamp(expirationDate));
2555 }
2556
2557 count = (Long)q.uniqueResult();
2558 }
2559 catch (Exception e) {
2560 throw processException(e);
2561 }
2562 finally {
2563 if (count == null) {
2564 count = Long.valueOf(0);
2565 }
2566
2567 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE,
2568 finderArgs, count);
2569
2570 closeSession(session);
2571 }
2572 }
2573
2574 return count.intValue();
2575 }
2576
2577
2585 public int countByC_K(String className, String key)
2586 throws SystemException {
2587 Object[] finderArgs = new Object[] { className, key };
2588
2589 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
2590 finderArgs, this);
2591
2592 if (count == null) {
2593 StringBundler query = new StringBundler(3);
2594
2595 query.append(_SQL_COUNT_LOCK_WHERE);
2596
2597 if (className == null) {
2598 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
2599 }
2600 else {
2601 if (className.equals(StringPool.BLANK)) {
2602 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
2603 }
2604 else {
2605 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
2606 }
2607 }
2608
2609 if (key == null) {
2610 query.append(_FINDER_COLUMN_C_K_KEY_1);
2611 }
2612 else {
2613 if (key.equals(StringPool.BLANK)) {
2614 query.append(_FINDER_COLUMN_C_K_KEY_3);
2615 }
2616 else {
2617 query.append(_FINDER_COLUMN_C_K_KEY_2);
2618 }
2619 }
2620
2621 String sql = query.toString();
2622
2623 Session session = null;
2624
2625 try {
2626 session = openSession();
2627
2628 Query q = session.createQuery(sql);
2629
2630 QueryPos qPos = QueryPos.getInstance(q);
2631
2632 if (className != null) {
2633 qPos.add(className);
2634 }
2635
2636 if (key != null) {
2637 qPos.add(key);
2638 }
2639
2640 count = (Long)q.uniqueResult();
2641 }
2642 catch (Exception e) {
2643 throw processException(e);
2644 }
2645 finally {
2646 if (count == null) {
2647 count = Long.valueOf(0);
2648 }
2649
2650 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
2651 count);
2652
2653 closeSession(session);
2654 }
2655 }
2656
2657 return count.intValue();
2658 }
2659
2660
2669 public int countByC_K_O(String className, String key, String owner)
2670 throws SystemException {
2671 Object[] finderArgs = new Object[] { className, key, owner };
2672
2673 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K_O,
2674 finderArgs, this);
2675
2676 if (count == null) {
2677 StringBundler query = new StringBundler(4);
2678
2679 query.append(_SQL_COUNT_LOCK_WHERE);
2680
2681 if (className == null) {
2682 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
2683 }
2684 else {
2685 if (className.equals(StringPool.BLANK)) {
2686 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
2687 }
2688 else {
2689 query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
2690 }
2691 }
2692
2693 if (key == null) {
2694 query.append(_FINDER_COLUMN_C_K_O_KEY_1);
2695 }
2696 else {
2697 if (key.equals(StringPool.BLANK)) {
2698 query.append(_FINDER_COLUMN_C_K_O_KEY_3);
2699 }
2700 else {
2701 query.append(_FINDER_COLUMN_C_K_O_KEY_2);
2702 }
2703 }
2704
2705 if (owner == null) {
2706 query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
2707 }
2708 else {
2709 if (owner.equals(StringPool.BLANK)) {
2710 query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
2711 }
2712 else {
2713 query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
2714 }
2715 }
2716
2717 String sql = query.toString();
2718
2719 Session session = null;
2720
2721 try {
2722 session = openSession();
2723
2724 Query q = session.createQuery(sql);
2725
2726 QueryPos qPos = QueryPos.getInstance(q);
2727
2728 if (className != null) {
2729 qPos.add(className);
2730 }
2731
2732 if (key != null) {
2733 qPos.add(key);
2734 }
2735
2736 if (owner != null) {
2737 qPos.add(owner);
2738 }
2739
2740 count = (Long)q.uniqueResult();
2741 }
2742 catch (Exception e) {
2743 throw processException(e);
2744 }
2745 finally {
2746 if (count == null) {
2747 count = Long.valueOf(0);
2748 }
2749
2750 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K_O,
2751 finderArgs, count);
2752
2753 closeSession(session);
2754 }
2755 }
2756
2757 return count.intValue();
2758 }
2759
2760
2766 public int countAll() throws SystemException {
2767 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2768 FINDER_ARGS_EMPTY, this);
2769
2770 if (count == null) {
2771 Session session = null;
2772
2773 try {
2774 session = openSession();
2775
2776 Query q = session.createQuery(_SQL_COUNT_LOCK);
2777
2778 count = (Long)q.uniqueResult();
2779 }
2780 catch (Exception e) {
2781 throw processException(e);
2782 }
2783 finally {
2784 if (count == null) {
2785 count = Long.valueOf(0);
2786 }
2787
2788 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2789 FINDER_ARGS_EMPTY, count);
2790
2791 closeSession(session);
2792 }
2793 }
2794
2795 return count.intValue();
2796 }
2797
2798
2801 public void afterPropertiesSet() {
2802 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2803 com.liferay.portal.util.PropsUtil.get(
2804 "value.object.listener.com.liferay.portal.model.Lock")));
2805
2806 if (listenerClassNames.length > 0) {
2807 try {
2808 List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
2809
2810 for (String listenerClassName : listenerClassNames) {
2811 listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
2812 listenerClassName));
2813 }
2814
2815 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2816 }
2817 catch (Exception e) {
2818 _log.error(e);
2819 }
2820 }
2821 }
2822
2823 public void destroy() {
2824 EntityCacheUtil.removeCache(LockImpl.class.getName());
2825 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2826 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2827 }
2828
2829 @BeanReference(type = AccountPersistence.class)
2830 protected AccountPersistence accountPersistence;
2831 @BeanReference(type = AddressPersistence.class)
2832 protected AddressPersistence addressPersistence;
2833 @BeanReference(type = BrowserTrackerPersistence.class)
2834 protected BrowserTrackerPersistence browserTrackerPersistence;
2835 @BeanReference(type = ClassNamePersistence.class)
2836 protected ClassNamePersistence classNamePersistence;
2837 @BeanReference(type = ClusterGroupPersistence.class)
2838 protected ClusterGroupPersistence clusterGroupPersistence;
2839 @BeanReference(type = CompanyPersistence.class)
2840 protected CompanyPersistence companyPersistence;
2841 @BeanReference(type = ContactPersistence.class)
2842 protected ContactPersistence contactPersistence;
2843 @BeanReference(type = CountryPersistence.class)
2844 protected CountryPersistence countryPersistence;
2845 @BeanReference(type = EmailAddressPersistence.class)
2846 protected EmailAddressPersistence emailAddressPersistence;
2847 @BeanReference(type = GroupPersistence.class)
2848 protected GroupPersistence groupPersistence;
2849 @BeanReference(type = ImagePersistence.class)
2850 protected ImagePersistence imagePersistence;
2851 @BeanReference(type = LayoutPersistence.class)
2852 protected LayoutPersistence layoutPersistence;
2853 @BeanReference(type = LayoutBranchPersistence.class)
2854 protected LayoutBranchPersistence layoutBranchPersistence;
2855 @BeanReference(type = LayoutPrototypePersistence.class)
2856 protected LayoutPrototypePersistence layoutPrototypePersistence;
2857 @BeanReference(type = LayoutRevisionPersistence.class)
2858 protected LayoutRevisionPersistence layoutRevisionPersistence;
2859 @BeanReference(type = LayoutSetPersistence.class)
2860 protected LayoutSetPersistence layoutSetPersistence;
2861 @BeanReference(type = LayoutSetBranchPersistence.class)
2862 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2863 @BeanReference(type = LayoutSetPrototypePersistence.class)
2864 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2865 @BeanReference(type = ListTypePersistence.class)
2866 protected ListTypePersistence listTypePersistence;
2867 @BeanReference(type = LockPersistence.class)
2868 protected LockPersistence lockPersistence;
2869 @BeanReference(type = MembershipRequestPersistence.class)
2870 protected MembershipRequestPersistence membershipRequestPersistence;
2871 @BeanReference(type = OrganizationPersistence.class)
2872 protected OrganizationPersistence organizationPersistence;
2873 @BeanReference(type = OrgGroupRolePersistence.class)
2874 protected OrgGroupRolePersistence orgGroupRolePersistence;
2875 @BeanReference(type = OrgLaborPersistence.class)
2876 protected OrgLaborPersistence orgLaborPersistence;
2877 @BeanReference(type = PasswordPolicyPersistence.class)
2878 protected PasswordPolicyPersistence passwordPolicyPersistence;
2879 @BeanReference(type = PasswordPolicyRelPersistence.class)
2880 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2881 @BeanReference(type = PasswordTrackerPersistence.class)
2882 protected PasswordTrackerPersistence passwordTrackerPersistence;
2883 @BeanReference(type = PhonePersistence.class)
2884 protected PhonePersistence phonePersistence;
2885 @BeanReference(type = PluginSettingPersistence.class)
2886 protected PluginSettingPersistence pluginSettingPersistence;
2887 @BeanReference(type = PortalPreferencesPersistence.class)
2888 protected PortalPreferencesPersistence portalPreferencesPersistence;
2889 @BeanReference(type = PortletPersistence.class)
2890 protected PortletPersistence portletPersistence;
2891 @BeanReference(type = PortletItemPersistence.class)
2892 protected PortletItemPersistence portletItemPersistence;
2893 @BeanReference(type = PortletPreferencesPersistence.class)
2894 protected PortletPreferencesPersistence portletPreferencesPersistence;
2895 @BeanReference(type = RegionPersistence.class)
2896 protected RegionPersistence regionPersistence;
2897 @BeanReference(type = ReleasePersistence.class)
2898 protected ReleasePersistence releasePersistence;
2899 @BeanReference(type = RepositoryPersistence.class)
2900 protected RepositoryPersistence repositoryPersistence;
2901 @BeanReference(type = RepositoryEntryPersistence.class)
2902 protected RepositoryEntryPersistence repositoryEntryPersistence;
2903 @BeanReference(type = ResourceActionPersistence.class)
2904 protected ResourceActionPersistence resourceActionPersistence;
2905 @BeanReference(type = ResourceBlockPersistence.class)
2906 protected ResourceBlockPersistence resourceBlockPersistence;
2907 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2908 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2909 @BeanReference(type = ResourcePermissionPersistence.class)
2910 protected ResourcePermissionPersistence resourcePermissionPersistence;
2911 @BeanReference(type = ResourceTypePermissionPersistence.class)
2912 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2913 @BeanReference(type = RolePersistence.class)
2914 protected RolePersistence rolePersistence;
2915 @BeanReference(type = ServiceComponentPersistence.class)
2916 protected ServiceComponentPersistence serviceComponentPersistence;
2917 @BeanReference(type = ShardPersistence.class)
2918 protected ShardPersistence shardPersistence;
2919 @BeanReference(type = SubscriptionPersistence.class)
2920 protected SubscriptionPersistence subscriptionPersistence;
2921 @BeanReference(type = TeamPersistence.class)
2922 protected TeamPersistence teamPersistence;
2923 @BeanReference(type = TicketPersistence.class)
2924 protected TicketPersistence ticketPersistence;
2925 @BeanReference(type = UserPersistence.class)
2926 protected UserPersistence userPersistence;
2927 @BeanReference(type = UserGroupPersistence.class)
2928 protected UserGroupPersistence userGroupPersistence;
2929 @BeanReference(type = UserGroupGroupRolePersistence.class)
2930 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2931 @BeanReference(type = UserGroupRolePersistence.class)
2932 protected UserGroupRolePersistence userGroupRolePersistence;
2933 @BeanReference(type = UserIdMapperPersistence.class)
2934 protected UserIdMapperPersistence userIdMapperPersistence;
2935 @BeanReference(type = UserNotificationEventPersistence.class)
2936 protected UserNotificationEventPersistence userNotificationEventPersistence;
2937 @BeanReference(type = UserTrackerPersistence.class)
2938 protected UserTrackerPersistence userTrackerPersistence;
2939 @BeanReference(type = UserTrackerPathPersistence.class)
2940 protected UserTrackerPathPersistence userTrackerPathPersistence;
2941 @BeanReference(type = VirtualHostPersistence.class)
2942 protected VirtualHostPersistence virtualHostPersistence;
2943 @BeanReference(type = WebDAVPropsPersistence.class)
2944 protected WebDAVPropsPersistence webDAVPropsPersistence;
2945 @BeanReference(type = WebsitePersistence.class)
2946 protected WebsitePersistence websitePersistence;
2947 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2948 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2949 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2950 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2951 private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
2952 private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
2953 private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
2954 private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
2955 private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
2956 private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
2957 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?)";
2958 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "lock.uuid IS NULL AND ";
2959 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "lock.uuid = ? AND ";
2960 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?) AND ";
2961 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "lock.companyId = ?";
2962 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
2963 "lock.expirationDate < NULL";
2964 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
2965 "lock.expirationDate < ?";
2966 private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
2967 private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
2968 private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
2969 private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
2970 private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
2971 private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = ?)";
2972 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_1 = "lock.className IS NULL AND ";
2973 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_2 = "lock.className = ? AND ";
2974 private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
2975 private static final String _FINDER_COLUMN_C_K_O_KEY_1 = "lock.key IS NULL AND ";
2976 private static final String _FINDER_COLUMN_C_K_O_KEY_2 = "lock.key = ? AND ";
2977 private static final String _FINDER_COLUMN_C_K_O_KEY_3 = "(lock.key IS NULL OR lock.key = ?) AND ";
2978 private static final String _FINDER_COLUMN_C_K_O_OWNER_1 = "lock.owner IS NULL";
2979 private static final String _FINDER_COLUMN_C_K_O_OWNER_2 = "lock.owner = ?";
2980 private static final String _FINDER_COLUMN_C_K_O_OWNER_3 = "(lock.owner IS NULL OR lock.owner = ?)";
2981 private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
2982 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
2983 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
2984 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2985 private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
2986 private static Lock _nullLock = new LockImpl() {
2987 @Override
2988 public Object clone() {
2989 return this;
2990 }
2991
2992 @Override
2993 public CacheModel<Lock> toCacheModel() {
2994 return _nullLockCacheModel;
2995 }
2996 };
2997
2998 private static CacheModel<Lock> _nullLockCacheModel = new CacheModel<Lock>() {
2999 public Lock toEntityModel() {
3000 return _nullLock;
3001 }
3002 };
3003 }