001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchLockException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.CalendarUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.Lock;
041 import com.liferay.portal.model.ModelListener;
042 import com.liferay.portal.model.impl.LockImpl;
043 import com.liferay.portal.model.impl.LockModelImpl;
044 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.Date;
051 import java.util.List;
052
053
065 public class LockPersistenceImpl extends BasePersistenceImpl<Lock>
066 implements LockPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = LockImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
078 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
081 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
084 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
087 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
089 new String[] {
090 String.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
096 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
098 new String[] { String.class.getName() },
099 LockModelImpl.UUID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
101 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
103 new String[] { String.class.getName() });
104
105
112 public List<Lock> findByUuid(String uuid) throws SystemException {
113 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
114 }
115
116
129 public List<Lock> findByUuid(String uuid, int start, int end)
130 throws SystemException {
131 return findByUuid(uuid, start, end, null);
132 }
133
134
148 public List<Lock> findByUuid(String uuid, int start, int end,
149 OrderByComparator orderByComparator) throws SystemException {
150 boolean pagination = true;
151 FinderPath finderPath = null;
152 Object[] finderArgs = null;
153
154 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
155 (orderByComparator == null)) {
156 pagination = false;
157 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
158 finderArgs = new Object[] { uuid };
159 }
160 else {
161 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
162 finderArgs = new Object[] { uuid, start, end, orderByComparator };
163 }
164
165 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
166 finderArgs, this);
167
168 if ((list != null) && !list.isEmpty()) {
169 for (Lock lock : list) {
170 if (!Validator.equals(uuid, lock.getUuid())) {
171 list = null;
172
173 break;
174 }
175 }
176 }
177
178 if (list == null) {
179 StringBundler query = null;
180
181 if (orderByComparator != null) {
182 query = new StringBundler(3 +
183 (orderByComparator.getOrderByFields().length * 3));
184 }
185 else {
186 query = new StringBundler(3);
187 }
188
189 query.append(_SQL_SELECT_LOCK_WHERE);
190
191 boolean bindUuid = false;
192
193 if (uuid == null) {
194 query.append(_FINDER_COLUMN_UUID_UUID_1);
195 }
196 else if (uuid.equals(StringPool.BLANK)) {
197 query.append(_FINDER_COLUMN_UUID_UUID_3);
198 }
199 else {
200 bindUuid = true;
201
202 query.append(_FINDER_COLUMN_UUID_UUID_2);
203 }
204
205 if (orderByComparator != null) {
206 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
207 orderByComparator);
208 }
209 else
210 if (pagination) {
211 query.append(LockModelImpl.ORDER_BY_JPQL);
212 }
213
214 String sql = query.toString();
215
216 Session session = null;
217
218 try {
219 session = openSession();
220
221 Query q = session.createQuery(sql);
222
223 QueryPos qPos = QueryPos.getInstance(q);
224
225 if (bindUuid) {
226 qPos.add(uuid);
227 }
228
229 if (!pagination) {
230 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
231 end, false);
232
233 Collections.sort(list);
234
235 list = new UnmodifiableList<Lock>(list);
236 }
237 else {
238 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
239 end);
240 }
241
242 cacheResult(list);
243
244 FinderCacheUtil.putResult(finderPath, finderArgs, list);
245 }
246 catch (Exception e) {
247 FinderCacheUtil.removeResult(finderPath, finderArgs);
248
249 throw processException(e);
250 }
251 finally {
252 closeSession(session);
253 }
254 }
255
256 return list;
257 }
258
259
268 public Lock findByUuid_First(String uuid,
269 OrderByComparator orderByComparator)
270 throws NoSuchLockException, SystemException {
271 Lock lock = fetchByUuid_First(uuid, orderByComparator);
272
273 if (lock != null) {
274 return lock;
275 }
276
277 StringBundler msg = new StringBundler(4);
278
279 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
280
281 msg.append("uuid=");
282 msg.append(uuid);
283
284 msg.append(StringPool.CLOSE_CURLY_BRACE);
285
286 throw new NoSuchLockException(msg.toString());
287 }
288
289
297 public Lock fetchByUuid_First(String uuid,
298 OrderByComparator orderByComparator) throws SystemException {
299 List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
300
301 if (!list.isEmpty()) {
302 return list.get(0);
303 }
304
305 return null;
306 }
307
308
317 public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
318 throws NoSuchLockException, SystemException {
319 Lock lock = fetchByUuid_Last(uuid, orderByComparator);
320
321 if (lock != null) {
322 return lock;
323 }
324
325 StringBundler msg = new StringBundler(4);
326
327 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
328
329 msg.append("uuid=");
330 msg.append(uuid);
331
332 msg.append(StringPool.CLOSE_CURLY_BRACE);
333
334 throw new NoSuchLockException(msg.toString());
335 }
336
337
345 public Lock fetchByUuid_Last(String uuid,
346 OrderByComparator orderByComparator) throws SystemException {
347 int count = countByUuid(uuid);
348
349 List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
350
351 if (!list.isEmpty()) {
352 return list.get(0);
353 }
354
355 return null;
356 }
357
358
368 public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
369 OrderByComparator orderByComparator)
370 throws NoSuchLockException, SystemException {
371 Lock lock = findByPrimaryKey(lockId);
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 Lock[] array = new LockImpl[3];
379
380 array[0] = getByUuid_PrevAndNext(session, lock, uuid,
381 orderByComparator, true);
382
383 array[1] = lock;
384
385 array[2] = getByUuid_PrevAndNext(session, lock, uuid,
386 orderByComparator, false);
387
388 return array;
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396 }
397
398 protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
399 String uuid, OrderByComparator orderByComparator, boolean previous) {
400 StringBundler query = null;
401
402 if (orderByComparator != null) {
403 query = new StringBundler(6 +
404 (orderByComparator.getOrderByFields().length * 6));
405 }
406 else {
407 query = new StringBundler(3);
408 }
409
410 query.append(_SQL_SELECT_LOCK_WHERE);
411
412 boolean bindUuid = false;
413
414 if (uuid == null) {
415 query.append(_FINDER_COLUMN_UUID_UUID_1);
416 }
417 else if (uuid.equals(StringPool.BLANK)) {
418 query.append(_FINDER_COLUMN_UUID_UUID_3);
419 }
420 else {
421 bindUuid = true;
422
423 query.append(_FINDER_COLUMN_UUID_UUID_2);
424 }
425
426 if (orderByComparator != null) {
427 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
428
429 if (orderByConditionFields.length > 0) {
430 query.append(WHERE_AND);
431 }
432
433 for (int i = 0; i < orderByConditionFields.length; i++) {
434 query.append(_ORDER_BY_ENTITY_ALIAS);
435 query.append(orderByConditionFields[i]);
436
437 if ((i + 1) < orderByConditionFields.length) {
438 if (orderByComparator.isAscending() ^ previous) {
439 query.append(WHERE_GREATER_THAN_HAS_NEXT);
440 }
441 else {
442 query.append(WHERE_LESSER_THAN_HAS_NEXT);
443 }
444 }
445 else {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(WHERE_GREATER_THAN);
448 }
449 else {
450 query.append(WHERE_LESSER_THAN);
451 }
452 }
453 }
454
455 query.append(ORDER_BY_CLAUSE);
456
457 String[] orderByFields = orderByComparator.getOrderByFields();
458
459 for (int i = 0; i < orderByFields.length; i++) {
460 query.append(_ORDER_BY_ENTITY_ALIAS);
461 query.append(orderByFields[i]);
462
463 if ((i + 1) < orderByFields.length) {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(ORDER_BY_ASC_HAS_NEXT);
466 }
467 else {
468 query.append(ORDER_BY_DESC_HAS_NEXT);
469 }
470 }
471 else {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(ORDER_BY_ASC);
474 }
475 else {
476 query.append(ORDER_BY_DESC);
477 }
478 }
479 }
480 }
481 else {
482 query.append(LockModelImpl.ORDER_BY_JPQL);
483 }
484
485 String sql = query.toString();
486
487 Query q = session.createQuery(sql);
488
489 q.setFirstResult(0);
490 q.setMaxResults(2);
491
492 QueryPos qPos = QueryPos.getInstance(q);
493
494 if (bindUuid) {
495 qPos.add(uuid);
496 }
497
498 if (orderByComparator != null) {
499 Object[] values = orderByComparator.getOrderByConditionValues(lock);
500
501 for (Object value : values) {
502 qPos.add(value);
503 }
504 }
505
506 List<Lock> list = q.list();
507
508 if (list.size() == 2) {
509 return list.get(1);
510 }
511 else {
512 return null;
513 }
514 }
515
516
522 public void removeByUuid(String uuid) throws SystemException {
523 for (Lock lock : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
524 null)) {
525 remove(lock);
526 }
527 }
528
529
536 public int countByUuid(String uuid) throws SystemException {
537 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
538
539 Object[] finderArgs = new Object[] { uuid };
540
541 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
542 this);
543
544 if (count == null) {
545 StringBundler query = new StringBundler(2);
546
547 query.append(_SQL_COUNT_LOCK_WHERE);
548
549 boolean bindUuid = false;
550
551 if (uuid == null) {
552 query.append(_FINDER_COLUMN_UUID_UUID_1);
553 }
554 else if (uuid.equals(StringPool.BLANK)) {
555 query.append(_FINDER_COLUMN_UUID_UUID_3);
556 }
557 else {
558 bindUuid = true;
559
560 query.append(_FINDER_COLUMN_UUID_UUID_2);
561 }
562
563 String sql = query.toString();
564
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 Query q = session.createQuery(sql);
571
572 QueryPos qPos = QueryPos.getInstance(q);
573
574 if (bindUuid) {
575 qPos.add(uuid);
576 }
577
578 count = (Long)q.uniqueResult();
579
580 FinderCacheUtil.putResult(finderPath, finderArgs, count);
581 }
582 catch (Exception e) {
583 FinderCacheUtil.removeResult(finderPath, finderArgs);
584
585 throw processException(e);
586 }
587 finally {
588 closeSession(session);
589 }
590 }
591
592 return count.intValue();
593 }
594
595 private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
596 private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
597 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = '')";
598 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
599 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
600 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
601 new String[] {
602 String.class.getName(), Long.class.getName(),
603
604 Integer.class.getName(), Integer.class.getName(),
605 OrderByComparator.class.getName()
606 });
607 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
608 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
609 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
610 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
611 new String[] { String.class.getName(), Long.class.getName() },
612 LockModelImpl.UUID_COLUMN_BITMASK |
613 LockModelImpl.COMPANYID_COLUMN_BITMASK);
614 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
615 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
616 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
617 new String[] { String.class.getName(), Long.class.getName() });
618
619
627 public List<Lock> findByUuid_C(String uuid, long companyId)
628 throws SystemException {
629 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
630 QueryUtil.ALL_POS, null);
631 }
632
633
647 public List<Lock> findByUuid_C(String uuid, long companyId, int start,
648 int end) throws SystemException {
649 return findByUuid_C(uuid, companyId, start, end, null);
650 }
651
652
667 public List<Lock> findByUuid_C(String uuid, long companyId, int start,
668 int end, OrderByComparator orderByComparator) throws SystemException {
669 boolean pagination = true;
670 FinderPath finderPath = null;
671 Object[] finderArgs = null;
672
673 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
674 (orderByComparator == null)) {
675 pagination = false;
676 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
677 finderArgs = new Object[] { uuid, companyId };
678 }
679 else {
680 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
681 finderArgs = new Object[] {
682 uuid, companyId,
683
684 start, end, orderByComparator
685 };
686 }
687
688 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
689 finderArgs, this);
690
691 if ((list != null) && !list.isEmpty()) {
692 for (Lock lock : list) {
693 if (!Validator.equals(uuid, lock.getUuid()) ||
694 (companyId != lock.getCompanyId())) {
695 list = null;
696
697 break;
698 }
699 }
700 }
701
702 if (list == null) {
703 StringBundler query = null;
704
705 if (orderByComparator != null) {
706 query = new StringBundler(4 +
707 (orderByComparator.getOrderByFields().length * 3));
708 }
709 else {
710 query = new StringBundler(4);
711 }
712
713 query.append(_SQL_SELECT_LOCK_WHERE);
714
715 boolean bindUuid = false;
716
717 if (uuid == null) {
718 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
719 }
720 else if (uuid.equals(StringPool.BLANK)) {
721 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
722 }
723 else {
724 bindUuid = true;
725
726 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
727 }
728
729 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
730
731 if (orderByComparator != null) {
732 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
733 orderByComparator);
734 }
735 else
736 if (pagination) {
737 query.append(LockModelImpl.ORDER_BY_JPQL);
738 }
739
740 String sql = query.toString();
741
742 Session session = null;
743
744 try {
745 session = openSession();
746
747 Query q = session.createQuery(sql);
748
749 QueryPos qPos = QueryPos.getInstance(q);
750
751 if (bindUuid) {
752 qPos.add(uuid);
753 }
754
755 qPos.add(companyId);
756
757 if (!pagination) {
758 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
759 end, false);
760
761 Collections.sort(list);
762
763 list = new UnmodifiableList<Lock>(list);
764 }
765 else {
766 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
767 end);
768 }
769
770 cacheResult(list);
771
772 FinderCacheUtil.putResult(finderPath, finderArgs, list);
773 }
774 catch (Exception e) {
775 FinderCacheUtil.removeResult(finderPath, finderArgs);
776
777 throw processException(e);
778 }
779 finally {
780 closeSession(session);
781 }
782 }
783
784 return list;
785 }
786
787
797 public Lock findByUuid_C_First(String uuid, long companyId,
798 OrderByComparator orderByComparator)
799 throws NoSuchLockException, SystemException {
800 Lock lock = fetchByUuid_C_First(uuid, companyId, orderByComparator);
801
802 if (lock != null) {
803 return lock;
804 }
805
806 StringBundler msg = new StringBundler(6);
807
808 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
809
810 msg.append("uuid=");
811 msg.append(uuid);
812
813 msg.append(", companyId=");
814 msg.append(companyId);
815
816 msg.append(StringPool.CLOSE_CURLY_BRACE);
817
818 throw new NoSuchLockException(msg.toString());
819 }
820
821
830 public Lock fetchByUuid_C_First(String uuid, long companyId,
831 OrderByComparator orderByComparator) throws SystemException {
832 List<Lock> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
833
834 if (!list.isEmpty()) {
835 return list.get(0);
836 }
837
838 return null;
839 }
840
841
851 public Lock findByUuid_C_Last(String uuid, long companyId,
852 OrderByComparator orderByComparator)
853 throws NoSuchLockException, SystemException {
854 Lock lock = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
855
856 if (lock != null) {
857 return lock;
858 }
859
860 StringBundler msg = new StringBundler(6);
861
862 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
863
864 msg.append("uuid=");
865 msg.append(uuid);
866
867 msg.append(", companyId=");
868 msg.append(companyId);
869
870 msg.append(StringPool.CLOSE_CURLY_BRACE);
871
872 throw new NoSuchLockException(msg.toString());
873 }
874
875
884 public Lock fetchByUuid_C_Last(String uuid, long companyId,
885 OrderByComparator orderByComparator) throws SystemException {
886 int count = countByUuid_C(uuid, companyId);
887
888 List<Lock> list = findByUuid_C(uuid, companyId, count - 1, count,
889 orderByComparator);
890
891 if (!list.isEmpty()) {
892 return list.get(0);
893 }
894
895 return null;
896 }
897
898
909 public Lock[] findByUuid_C_PrevAndNext(long lockId, String uuid,
910 long companyId, OrderByComparator orderByComparator)
911 throws NoSuchLockException, SystemException {
912 Lock lock = findByPrimaryKey(lockId);
913
914 Session session = null;
915
916 try {
917 session = openSession();
918
919 Lock[] array = new LockImpl[3];
920
921 array[0] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
922 orderByComparator, true);
923
924 array[1] = lock;
925
926 array[2] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
927 orderByComparator, false);
928
929 return array;
930 }
931 catch (Exception e) {
932 throw processException(e);
933 }
934 finally {
935 closeSession(session);
936 }
937 }
938
939 protected Lock getByUuid_C_PrevAndNext(Session session, Lock lock,
940 String uuid, long companyId, OrderByComparator orderByComparator,
941 boolean previous) {
942 StringBundler query = null;
943
944 if (orderByComparator != null) {
945 query = new StringBundler(6 +
946 (orderByComparator.getOrderByFields().length * 6));
947 }
948 else {
949 query = new StringBundler(3);
950 }
951
952 query.append(_SQL_SELECT_LOCK_WHERE);
953
954 boolean bindUuid = false;
955
956 if (uuid == null) {
957 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
958 }
959 else if (uuid.equals(StringPool.BLANK)) {
960 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
961 }
962 else {
963 bindUuid = true;
964
965 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
966 }
967
968 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
969
970 if (orderByComparator != null) {
971 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
972
973 if (orderByConditionFields.length > 0) {
974 query.append(WHERE_AND);
975 }
976
977 for (int i = 0; i < orderByConditionFields.length; i++) {
978 query.append(_ORDER_BY_ENTITY_ALIAS);
979 query.append(orderByConditionFields[i]);
980
981 if ((i + 1) < orderByConditionFields.length) {
982 if (orderByComparator.isAscending() ^ previous) {
983 query.append(WHERE_GREATER_THAN_HAS_NEXT);
984 }
985 else {
986 query.append(WHERE_LESSER_THAN_HAS_NEXT);
987 }
988 }
989 else {
990 if (orderByComparator.isAscending() ^ previous) {
991 query.append(WHERE_GREATER_THAN);
992 }
993 else {
994 query.append(WHERE_LESSER_THAN);
995 }
996 }
997 }
998
999 query.append(ORDER_BY_CLAUSE);
1000
1001 String[] orderByFields = orderByComparator.getOrderByFields();
1002
1003 for (int i = 0; i < orderByFields.length; i++) {
1004 query.append(_ORDER_BY_ENTITY_ALIAS);
1005 query.append(orderByFields[i]);
1006
1007 if ((i + 1) < orderByFields.length) {
1008 if (orderByComparator.isAscending() ^ previous) {
1009 query.append(ORDER_BY_ASC_HAS_NEXT);
1010 }
1011 else {
1012 query.append(ORDER_BY_DESC_HAS_NEXT);
1013 }
1014 }
1015 else {
1016 if (orderByComparator.isAscending() ^ previous) {
1017 query.append(ORDER_BY_ASC);
1018 }
1019 else {
1020 query.append(ORDER_BY_DESC);
1021 }
1022 }
1023 }
1024 }
1025 else {
1026 query.append(LockModelImpl.ORDER_BY_JPQL);
1027 }
1028
1029 String sql = query.toString();
1030
1031 Query q = session.createQuery(sql);
1032
1033 q.setFirstResult(0);
1034 q.setMaxResults(2);
1035
1036 QueryPos qPos = QueryPos.getInstance(q);
1037
1038 if (bindUuid) {
1039 qPos.add(uuid);
1040 }
1041
1042 qPos.add(companyId);
1043
1044 if (orderByComparator != null) {
1045 Object[] values = orderByComparator.getOrderByConditionValues(lock);
1046
1047 for (Object value : values) {
1048 qPos.add(value);
1049 }
1050 }
1051
1052 List<Lock> list = q.list();
1053
1054 if (list.size() == 2) {
1055 return list.get(1);
1056 }
1057 else {
1058 return null;
1059 }
1060 }
1061
1062
1069 public void removeByUuid_C(String uuid, long companyId)
1070 throws SystemException {
1071 for (Lock lock : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1072 QueryUtil.ALL_POS, null)) {
1073 remove(lock);
1074 }
1075 }
1076
1077
1085 public int countByUuid_C(String uuid, long companyId)
1086 throws SystemException {
1087 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1088
1089 Object[] finderArgs = new Object[] { uuid, companyId };
1090
1091 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1092 this);
1093
1094 if (count == null) {
1095 StringBundler query = new StringBundler(3);
1096
1097 query.append(_SQL_COUNT_LOCK_WHERE);
1098
1099 boolean bindUuid = false;
1100
1101 if (uuid == null) {
1102 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1103 }
1104 else if (uuid.equals(StringPool.BLANK)) {
1105 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1106 }
1107 else {
1108 bindUuid = true;
1109
1110 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1111 }
1112
1113 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1114
1115 String sql = query.toString();
1116
1117 Session session = null;
1118
1119 try {
1120 session = openSession();
1121
1122 Query q = session.createQuery(sql);
1123
1124 QueryPos qPos = QueryPos.getInstance(q);
1125
1126 if (bindUuid) {
1127 qPos.add(uuid);
1128 }
1129
1130 qPos.add(companyId);
1131
1132 count = (Long)q.uniqueResult();
1133
1134 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1135 }
1136 catch (Exception e) {
1137 FinderCacheUtil.removeResult(finderPath, finderArgs);
1138
1139 throw processException(e);
1140 }
1141 finally {
1142 closeSession(session);
1143 }
1144 }
1145
1146 return count.intValue();
1147 }
1148
1149 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "lock.uuid IS NULL AND ";
1150 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "lock.uuid = ? AND ";
1151 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = '') AND ";
1152 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "lock.companyId = ?";
1153 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE =
1154 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1155 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
1156 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtExpirationDate",
1157 new String[] {
1158 Date.class.getName(),
1159
1160 Integer.class.getName(), Integer.class.getName(),
1161 OrderByComparator.class.getName()
1162 });
1163 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE =
1164 new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1165 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1166 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByLtExpirationDate",
1167 new String[] { Date.class.getName() });
1168
1169
1176 public List<Lock> findByLtExpirationDate(Date expirationDate)
1177 throws SystemException {
1178 return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
1179 QueryUtil.ALL_POS, null);
1180 }
1181
1182
1195 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1196 int end) throws SystemException {
1197 return findByLtExpirationDate(expirationDate, start, end, null);
1198 }
1199
1200
1214 public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1215 int end, OrderByComparator orderByComparator) throws SystemException {
1216 boolean pagination = true;
1217 FinderPath finderPath = null;
1218 Object[] finderArgs = null;
1219
1220 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE;
1221 finderArgs = new Object[] { expirationDate, start, end, orderByComparator };
1222
1223 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1224 finderArgs, this);
1225
1226 if ((list != null) && !list.isEmpty()) {
1227 for (Lock lock : list) {
1228 if (!Validator.equals(expirationDate, lock.getExpirationDate())) {
1229 list = null;
1230
1231 break;
1232 }
1233 }
1234 }
1235
1236 if (list == null) {
1237 StringBundler query = null;
1238
1239 if (orderByComparator != null) {
1240 query = new StringBundler(3 +
1241 (orderByComparator.getOrderByFields().length * 3));
1242 }
1243 else {
1244 query = new StringBundler(3);
1245 }
1246
1247 query.append(_SQL_SELECT_LOCK_WHERE);
1248
1249 boolean bindExpirationDate = false;
1250
1251 if (expirationDate == null) {
1252 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1253 }
1254 else {
1255 bindExpirationDate = true;
1256
1257 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1258 }
1259
1260 if (orderByComparator != null) {
1261 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1262 orderByComparator);
1263 }
1264 else
1265 if (pagination) {
1266 query.append(LockModelImpl.ORDER_BY_JPQL);
1267 }
1268
1269 String sql = query.toString();
1270
1271 Session session = null;
1272
1273 try {
1274 session = openSession();
1275
1276 Query q = session.createQuery(sql);
1277
1278 QueryPos qPos = QueryPos.getInstance(q);
1279
1280 if (bindExpirationDate) {
1281 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1282 }
1283
1284 if (!pagination) {
1285 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1286 end, false);
1287
1288 Collections.sort(list);
1289
1290 list = new UnmodifiableList<Lock>(list);
1291 }
1292 else {
1293 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1294 end);
1295 }
1296
1297 cacheResult(list);
1298
1299 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1300 }
1301 catch (Exception e) {
1302 FinderCacheUtil.removeResult(finderPath, finderArgs);
1303
1304 throw processException(e);
1305 }
1306 finally {
1307 closeSession(session);
1308 }
1309 }
1310
1311 return list;
1312 }
1313
1314
1323 public Lock findByLtExpirationDate_First(Date expirationDate,
1324 OrderByComparator orderByComparator)
1325 throws NoSuchLockException, SystemException {
1326 Lock lock = fetchByLtExpirationDate_First(expirationDate,
1327 orderByComparator);
1328
1329 if (lock != null) {
1330 return lock;
1331 }
1332
1333 StringBundler msg = new StringBundler(4);
1334
1335 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1336
1337 msg.append("expirationDate=");
1338 msg.append(expirationDate);
1339
1340 msg.append(StringPool.CLOSE_CURLY_BRACE);
1341
1342 throw new NoSuchLockException(msg.toString());
1343 }
1344
1345
1353 public Lock fetchByLtExpirationDate_First(Date expirationDate,
1354 OrderByComparator orderByComparator) throws SystemException {
1355 List<Lock> list = findByLtExpirationDate(expirationDate, 0, 1,
1356 orderByComparator);
1357
1358 if (!list.isEmpty()) {
1359 return list.get(0);
1360 }
1361
1362 return null;
1363 }
1364
1365
1374 public Lock findByLtExpirationDate_Last(Date expirationDate,
1375 OrderByComparator orderByComparator)
1376 throws NoSuchLockException, SystemException {
1377 Lock lock = fetchByLtExpirationDate_Last(expirationDate,
1378 orderByComparator);
1379
1380 if (lock != null) {
1381 return lock;
1382 }
1383
1384 StringBundler msg = new StringBundler(4);
1385
1386 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1387
1388 msg.append("expirationDate=");
1389 msg.append(expirationDate);
1390
1391 msg.append(StringPool.CLOSE_CURLY_BRACE);
1392
1393 throw new NoSuchLockException(msg.toString());
1394 }
1395
1396
1404 public Lock fetchByLtExpirationDate_Last(Date expirationDate,
1405 OrderByComparator orderByComparator) throws SystemException {
1406 int count = countByLtExpirationDate(expirationDate);
1407
1408 List<Lock> list = findByLtExpirationDate(expirationDate, count - 1,
1409 count, orderByComparator);
1410
1411 if (!list.isEmpty()) {
1412 return list.get(0);
1413 }
1414
1415 return null;
1416 }
1417
1418
1428 public Lock[] findByLtExpirationDate_PrevAndNext(long lockId,
1429 Date expirationDate, OrderByComparator orderByComparator)
1430 throws NoSuchLockException, SystemException {
1431 Lock lock = findByPrimaryKey(lockId);
1432
1433 Session session = null;
1434
1435 try {
1436 session = openSession();
1437
1438 Lock[] array = new LockImpl[3];
1439
1440 array[0] = getByLtExpirationDate_PrevAndNext(session, lock,
1441 expirationDate, orderByComparator, true);
1442
1443 array[1] = lock;
1444
1445 array[2] = getByLtExpirationDate_PrevAndNext(session, lock,
1446 expirationDate, orderByComparator, false);
1447
1448 return array;
1449 }
1450 catch (Exception e) {
1451 throw processException(e);
1452 }
1453 finally {
1454 closeSession(session);
1455 }
1456 }
1457
1458 protected Lock getByLtExpirationDate_PrevAndNext(Session session,
1459 Lock lock, Date expirationDate, OrderByComparator orderByComparator,
1460 boolean previous) {
1461 StringBundler query = null;
1462
1463 if (orderByComparator != null) {
1464 query = new StringBundler(6 +
1465 (orderByComparator.getOrderByFields().length * 6));
1466 }
1467 else {
1468 query = new StringBundler(3);
1469 }
1470
1471 query.append(_SQL_SELECT_LOCK_WHERE);
1472
1473 boolean bindExpirationDate = false;
1474
1475 if (expirationDate == null) {
1476 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1477 }
1478 else {
1479 bindExpirationDate = true;
1480
1481 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1482 }
1483
1484 if (orderByComparator != null) {
1485 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1486
1487 if (orderByConditionFields.length > 0) {
1488 query.append(WHERE_AND);
1489 }
1490
1491 for (int i = 0; i < orderByConditionFields.length; i++) {
1492 query.append(_ORDER_BY_ENTITY_ALIAS);
1493 query.append(orderByConditionFields[i]);
1494
1495 if ((i + 1) < orderByConditionFields.length) {
1496 if (orderByComparator.isAscending() ^ previous) {
1497 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1498 }
1499 else {
1500 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1501 }
1502 }
1503 else {
1504 if (orderByComparator.isAscending() ^ previous) {
1505 query.append(WHERE_GREATER_THAN);
1506 }
1507 else {
1508 query.append(WHERE_LESSER_THAN);
1509 }
1510 }
1511 }
1512
1513 query.append(ORDER_BY_CLAUSE);
1514
1515 String[] orderByFields = orderByComparator.getOrderByFields();
1516
1517 for (int i = 0; i < orderByFields.length; i++) {
1518 query.append(_ORDER_BY_ENTITY_ALIAS);
1519 query.append(orderByFields[i]);
1520
1521 if ((i + 1) < orderByFields.length) {
1522 if (orderByComparator.isAscending() ^ previous) {
1523 query.append(ORDER_BY_ASC_HAS_NEXT);
1524 }
1525 else {
1526 query.append(ORDER_BY_DESC_HAS_NEXT);
1527 }
1528 }
1529 else {
1530 if (orderByComparator.isAscending() ^ previous) {
1531 query.append(ORDER_BY_ASC);
1532 }
1533 else {
1534 query.append(ORDER_BY_DESC);
1535 }
1536 }
1537 }
1538 }
1539 else {
1540 query.append(LockModelImpl.ORDER_BY_JPQL);
1541 }
1542
1543 String sql = query.toString();
1544
1545 Query q = session.createQuery(sql);
1546
1547 q.setFirstResult(0);
1548 q.setMaxResults(2);
1549
1550 QueryPos qPos = QueryPos.getInstance(q);
1551
1552 if (bindExpirationDate) {
1553 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1554 }
1555
1556 if (orderByComparator != null) {
1557 Object[] values = orderByComparator.getOrderByConditionValues(lock);
1558
1559 for (Object value : values) {
1560 qPos.add(value);
1561 }
1562 }
1563
1564 List<Lock> list = q.list();
1565
1566 if (list.size() == 2) {
1567 return list.get(1);
1568 }
1569 else {
1570 return null;
1571 }
1572 }
1573
1574
1580 public void removeByLtExpirationDate(Date expirationDate)
1581 throws SystemException {
1582 for (Lock lock : findByLtExpirationDate(expirationDate,
1583 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1584 remove(lock);
1585 }
1586 }
1587
1588
1595 public int countByLtExpirationDate(Date expirationDate)
1596 throws SystemException {
1597 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE;
1598
1599 Object[] finderArgs = new Object[] { expirationDate };
1600
1601 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1602 this);
1603
1604 if (count == null) {
1605 StringBundler query = new StringBundler(2);
1606
1607 query.append(_SQL_COUNT_LOCK_WHERE);
1608
1609 boolean bindExpirationDate = false;
1610
1611 if (expirationDate == null) {
1612 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1613 }
1614 else {
1615 bindExpirationDate = true;
1616
1617 query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1618 }
1619
1620 String sql = query.toString();
1621
1622 Session session = null;
1623
1624 try {
1625 session = openSession();
1626
1627 Query q = session.createQuery(sql);
1628
1629 QueryPos qPos = QueryPos.getInstance(q);
1630
1631 if (bindExpirationDate) {
1632 qPos.add(CalendarUtil.getTimestamp(expirationDate));
1633 }
1634
1635 count = (Long)q.uniqueResult();
1636
1637 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1638 }
1639 catch (Exception e) {
1640 FinderCacheUtil.removeResult(finderPath, finderArgs);
1641
1642 throw processException(e);
1643 }
1644 finally {
1645 closeSession(session);
1646 }
1647 }
1648
1649 return count.intValue();
1650 }
1651
1652 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
1653 "lock.expirationDate < NULL";
1654 private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
1655 "lock.expirationDate < ?";
1656 public static final FinderPath FINDER_PATH_FETCH_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1657 LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
1658 FINDER_CLASS_NAME_ENTITY, "fetchByC_K",
1659 new String[] { String.class.getName(), String.class.getName() },
1660 LockModelImpl.CLASSNAME_COLUMN_BITMASK |
1661 LockModelImpl.KEY_COLUMN_BITMASK);
1662 public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1663 LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1664 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
1665 new String[] { String.class.getName(), String.class.getName() });
1666
1667
1676 public Lock findByC_K(String className, String key)
1677 throws NoSuchLockException, SystemException {
1678 Lock lock = fetchByC_K(className, key);
1679
1680 if (lock == null) {
1681 StringBundler msg = new StringBundler(6);
1682
1683 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1684
1685 msg.append("className=");
1686 msg.append(className);
1687
1688 msg.append(", key=");
1689 msg.append(key);
1690
1691 msg.append(StringPool.CLOSE_CURLY_BRACE);
1692
1693 if (_log.isWarnEnabled()) {
1694 _log.warn(msg.toString());
1695 }
1696
1697 throw new NoSuchLockException(msg.toString());
1698 }
1699
1700 return lock;
1701 }
1702
1703
1711 public Lock fetchByC_K(String className, String key)
1712 throws SystemException {
1713 return fetchByC_K(className, key, true);
1714 }
1715
1716
1725 public Lock fetchByC_K(String className, String key,
1726 boolean retrieveFromCache) throws SystemException {
1727 Object[] finderArgs = new Object[] { className, key };
1728
1729 Object result = null;
1730
1731 if (retrieveFromCache) {
1732 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K,
1733 finderArgs, this);
1734 }
1735
1736 if (result instanceof Lock) {
1737 Lock lock = (Lock)result;
1738
1739 if (!Validator.equals(className, lock.getClassName()) ||
1740 !Validator.equals(key, lock.getKey())) {
1741 result = null;
1742 }
1743 }
1744
1745 if (result == null) {
1746 StringBundler query = new StringBundler(4);
1747
1748 query.append(_SQL_SELECT_LOCK_WHERE);
1749
1750 boolean bindClassName = false;
1751
1752 if (className == null) {
1753 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1754 }
1755 else if (className.equals(StringPool.BLANK)) {
1756 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1757 }
1758 else {
1759 bindClassName = true;
1760
1761 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1762 }
1763
1764 boolean bindKey = false;
1765
1766 if (key == null) {
1767 query.append(_FINDER_COLUMN_C_K_KEY_1);
1768 }
1769 else if (key.equals(StringPool.BLANK)) {
1770 query.append(_FINDER_COLUMN_C_K_KEY_3);
1771 }
1772 else {
1773 bindKey = true;
1774
1775 query.append(_FINDER_COLUMN_C_K_KEY_2);
1776 }
1777
1778 String sql = query.toString();
1779
1780 Session session = null;
1781
1782 try {
1783 session = openSession();
1784
1785 Query q = session.createQuery(sql);
1786
1787 QueryPos qPos = QueryPos.getInstance(q);
1788
1789 if (bindClassName) {
1790 qPos.add(className);
1791 }
1792
1793 if (bindKey) {
1794 qPos.add(key);
1795 }
1796
1797 List<Lock> list = q.list();
1798
1799 if (list.isEmpty()) {
1800 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1801 finderArgs, list);
1802 }
1803 else {
1804 Lock lock = list.get(0);
1805
1806 result = lock;
1807
1808 cacheResult(lock);
1809
1810 if ((lock.getClassName() == null) ||
1811 !lock.getClassName().equals(className) ||
1812 (lock.getKey() == null) ||
1813 !lock.getKey().equals(key)) {
1814 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1815 finderArgs, lock);
1816 }
1817 }
1818 }
1819 catch (Exception e) {
1820 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
1821 finderArgs);
1822
1823 throw processException(e);
1824 }
1825 finally {
1826 closeSession(session);
1827 }
1828 }
1829
1830 if (result instanceof List<?>) {
1831 return null;
1832 }
1833 else {
1834 return (Lock)result;
1835 }
1836 }
1837
1838
1846 public Lock removeByC_K(String className, String key)
1847 throws NoSuchLockException, SystemException {
1848 Lock lock = findByC_K(className, key);
1849
1850 return remove(lock);
1851 }
1852
1853
1861 public int countByC_K(String className, String key)
1862 throws SystemException {
1863 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_K;
1864
1865 Object[] finderArgs = new Object[] { className, key };
1866
1867 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1868 this);
1869
1870 if (count == null) {
1871 StringBundler query = new StringBundler(3);
1872
1873 query.append(_SQL_COUNT_LOCK_WHERE);
1874
1875 boolean bindClassName = false;
1876
1877 if (className == null) {
1878 query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1879 }
1880 else if (className.equals(StringPool.BLANK)) {
1881 query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1882 }
1883 else {
1884 bindClassName = true;
1885
1886 query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1887 }
1888
1889 boolean bindKey = false;
1890
1891 if (key == null) {
1892 query.append(_FINDER_COLUMN_C_K_KEY_1);
1893 }
1894 else if (key.equals(StringPool.BLANK)) {
1895 query.append(_FINDER_COLUMN_C_K_KEY_3);
1896 }
1897 else {
1898 bindKey = true;
1899
1900 query.append(_FINDER_COLUMN_C_K_KEY_2);
1901 }
1902
1903 String sql = query.toString();
1904
1905 Session session = null;
1906
1907 try {
1908 session = openSession();
1909
1910 Query q = session.createQuery(sql);
1911
1912 QueryPos qPos = QueryPos.getInstance(q);
1913
1914 if (bindClassName) {
1915 qPos.add(className);
1916 }
1917
1918 if (bindKey) {
1919 qPos.add(key);
1920 }
1921
1922 count = (Long)q.uniqueResult();
1923
1924 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1925 }
1926 catch (Exception e) {
1927 FinderCacheUtil.removeResult(finderPath, finderArgs);
1928
1929 throw processException(e);
1930 }
1931 finally {
1932 closeSession(session);
1933 }
1934 }
1935
1936 return count.intValue();
1937 }
1938
1939 private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
1940 private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
1941 private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = '') AND ";
1942 private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
1943 private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
1944 private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = '')";
1945
1946
1951 public void cacheResult(Lock lock) {
1952 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
1953 LockImpl.class, lock.getPrimaryKey(), lock);
1954
1955 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1956 new Object[] { lock.getClassName(), lock.getKey() }, lock);
1957
1958 lock.resetOriginalValues();
1959 }
1960
1961
1966 public void cacheResult(List<Lock> locks) {
1967 for (Lock lock : locks) {
1968 if (EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
1969 LockImpl.class, lock.getPrimaryKey()) == null) {
1970 cacheResult(lock);
1971 }
1972 else {
1973 lock.resetOriginalValues();
1974 }
1975 }
1976 }
1977
1978
1985 @Override
1986 public void clearCache() {
1987 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1988 CacheRegistryUtil.clear(LockImpl.class.getName());
1989 }
1990
1991 EntityCacheUtil.clearCache(LockImpl.class.getName());
1992
1993 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1994 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1995 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1996 }
1997
1998
2005 @Override
2006 public void clearCache(Lock lock) {
2007 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2008 LockImpl.class, lock.getPrimaryKey());
2009
2010 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2011 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2012
2013 clearUniqueFindersCache(lock);
2014 }
2015
2016 @Override
2017 public void clearCache(List<Lock> locks) {
2018 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2019 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2020
2021 for (Lock lock : locks) {
2022 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2023 LockImpl.class, lock.getPrimaryKey());
2024
2025 clearUniqueFindersCache(lock);
2026 }
2027 }
2028
2029 protected void cacheUniqueFindersCache(Lock lock) {
2030 if (lock.isNew()) {
2031 Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2032
2033 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, args,
2034 Long.valueOf(1));
2035 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K, args, lock);
2036 }
2037 else {
2038 LockModelImpl lockModelImpl = (LockModelImpl)lock;
2039
2040 if ((lockModelImpl.getColumnBitmask() &
2041 FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
2042 Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2043
2044 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, args,
2045 Long.valueOf(1));
2046 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K, args, lock);
2047 }
2048 }
2049 }
2050
2051 protected void clearUniqueFindersCache(Lock lock) {
2052 LockModelImpl lockModelImpl = (LockModelImpl)lock;
2053
2054 Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2055
2056 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2057 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
2058
2059 if ((lockModelImpl.getColumnBitmask() &
2060 FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
2061 args = new Object[] {
2062 lockModelImpl.getOriginalClassName(),
2063 lockModelImpl.getOriginalKey()
2064 };
2065
2066 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2067 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
2068 }
2069 }
2070
2071
2077 public Lock create(long lockId) {
2078 Lock lock = new LockImpl();
2079
2080 lock.setNew(true);
2081 lock.setPrimaryKey(lockId);
2082
2083 String uuid = PortalUUIDUtil.generate();
2084
2085 lock.setUuid(uuid);
2086
2087 return lock;
2088 }
2089
2090
2098 public Lock remove(long lockId) throws NoSuchLockException, SystemException {
2099 return remove((Serializable)lockId);
2100 }
2101
2102
2110 @Override
2111 public Lock remove(Serializable primaryKey)
2112 throws NoSuchLockException, SystemException {
2113 Session session = null;
2114
2115 try {
2116 session = openSession();
2117
2118 Lock lock = (Lock)session.get(LockImpl.class, primaryKey);
2119
2120 if (lock == null) {
2121 if (_log.isWarnEnabled()) {
2122 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2123 }
2124
2125 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2126 primaryKey);
2127 }
2128
2129 return remove(lock);
2130 }
2131 catch (NoSuchLockException nsee) {
2132 throw nsee;
2133 }
2134 catch (Exception e) {
2135 throw processException(e);
2136 }
2137 finally {
2138 closeSession(session);
2139 }
2140 }
2141
2142 @Override
2143 protected Lock removeImpl(Lock lock) throws SystemException {
2144 lock = toUnwrappedModel(lock);
2145
2146 Session session = null;
2147
2148 try {
2149 session = openSession();
2150
2151 if (!session.contains(lock)) {
2152 lock = (Lock)session.get(LockImpl.class, lock.getPrimaryKeyObj());
2153 }
2154
2155 if (lock != null) {
2156 session.delete(lock);
2157 }
2158 }
2159 catch (Exception e) {
2160 throw processException(e);
2161 }
2162 finally {
2163 closeSession(session);
2164 }
2165
2166 if (lock != null) {
2167 clearCache(lock);
2168 }
2169
2170 return lock;
2171 }
2172
2173 @Override
2174 public Lock updateImpl(com.liferay.portal.model.Lock lock)
2175 throws SystemException {
2176 lock = toUnwrappedModel(lock);
2177
2178 boolean isNew = lock.isNew();
2179
2180 LockModelImpl lockModelImpl = (LockModelImpl)lock;
2181
2182 if (Validator.isNull(lock.getUuid())) {
2183 String uuid = PortalUUIDUtil.generate();
2184
2185 lock.setUuid(uuid);
2186 }
2187
2188 Session session = null;
2189
2190 try {
2191 session = openSession();
2192
2193 if (lock.isNew()) {
2194 session.save(lock);
2195
2196 lock.setNew(false);
2197 }
2198 else {
2199 session.merge(lock);
2200 }
2201 }
2202 catch (Exception e) {
2203 throw processException(e);
2204 }
2205 finally {
2206 closeSession(session);
2207 }
2208
2209 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2210
2211 if (isNew || !LockModelImpl.COLUMN_BITMASK_ENABLED) {
2212 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2213 }
2214
2215 else {
2216 if ((lockModelImpl.getColumnBitmask() &
2217 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2218 Object[] args = new Object[] { lockModelImpl.getOriginalUuid() };
2219
2220 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2221 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2222 args);
2223
2224 args = new Object[] { lockModelImpl.getUuid() };
2225
2226 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2227 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2228 args);
2229 }
2230
2231 if ((lockModelImpl.getColumnBitmask() &
2232 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2233 Object[] args = new Object[] {
2234 lockModelImpl.getOriginalUuid(),
2235 lockModelImpl.getOriginalCompanyId()
2236 };
2237
2238 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2239 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2240 args);
2241
2242 args = new Object[] {
2243 lockModelImpl.getUuid(), lockModelImpl.getCompanyId()
2244 };
2245
2246 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2247 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2248 args);
2249 }
2250 }
2251
2252 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2253 LockImpl.class, lock.getPrimaryKey(), lock);
2254
2255 clearUniqueFindersCache(lock);
2256 cacheUniqueFindersCache(lock);
2257
2258 return lock;
2259 }
2260
2261 protected Lock toUnwrappedModel(Lock lock) {
2262 if (lock instanceof LockImpl) {
2263 return lock;
2264 }
2265
2266 LockImpl lockImpl = new LockImpl();
2267
2268 lockImpl.setNew(lock.isNew());
2269 lockImpl.setPrimaryKey(lock.getPrimaryKey());
2270
2271 lockImpl.setUuid(lock.getUuid());
2272 lockImpl.setLockId(lock.getLockId());
2273 lockImpl.setCompanyId(lock.getCompanyId());
2274 lockImpl.setUserId(lock.getUserId());
2275 lockImpl.setUserName(lock.getUserName());
2276 lockImpl.setCreateDate(lock.getCreateDate());
2277 lockImpl.setClassName(lock.getClassName());
2278 lockImpl.setKey(lock.getKey());
2279 lockImpl.setOwner(lock.getOwner());
2280 lockImpl.setInheritable(lock.isInheritable());
2281 lockImpl.setExpirationDate(lock.getExpirationDate());
2282
2283 return lockImpl;
2284 }
2285
2286
2294 @Override
2295 public Lock findByPrimaryKey(Serializable primaryKey)
2296 throws NoSuchLockException, SystemException {
2297 Lock lock = fetchByPrimaryKey(primaryKey);
2298
2299 if (lock == null) {
2300 if (_log.isWarnEnabled()) {
2301 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2302 }
2303
2304 throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2305 primaryKey);
2306 }
2307
2308 return lock;
2309 }
2310
2311
2319 public Lock findByPrimaryKey(long lockId)
2320 throws NoSuchLockException, SystemException {
2321 return findByPrimaryKey((Serializable)lockId);
2322 }
2323
2324
2331 @Override
2332 public Lock fetchByPrimaryKey(Serializable primaryKey)
2333 throws SystemException {
2334 Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2335 LockImpl.class, primaryKey);
2336
2337 if (lock == _nullLock) {
2338 return null;
2339 }
2340
2341 if (lock == null) {
2342 Session session = null;
2343
2344 try {
2345 session = openSession();
2346
2347 lock = (Lock)session.get(LockImpl.class, primaryKey);
2348
2349 if (lock != null) {
2350 cacheResult(lock);
2351 }
2352 else {
2353 EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2354 LockImpl.class, primaryKey, _nullLock);
2355 }
2356 }
2357 catch (Exception e) {
2358 EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2359 LockImpl.class, primaryKey);
2360
2361 throw processException(e);
2362 }
2363 finally {
2364 closeSession(session);
2365 }
2366 }
2367
2368 return lock;
2369 }
2370
2371
2378 public Lock fetchByPrimaryKey(long lockId) throws SystemException {
2379 return fetchByPrimaryKey((Serializable)lockId);
2380 }
2381
2382
2388 public List<Lock> findAll() throws SystemException {
2389 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2390 }
2391
2392
2404 public List<Lock> findAll(int start, int end) throws SystemException {
2405 return findAll(start, end, null);
2406 }
2407
2408
2421 public List<Lock> findAll(int start, int end,
2422 OrderByComparator orderByComparator) throws SystemException {
2423 boolean pagination = true;
2424 FinderPath finderPath = null;
2425 Object[] finderArgs = null;
2426
2427 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2428 (orderByComparator == null)) {
2429 pagination = false;
2430 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2431 finderArgs = FINDER_ARGS_EMPTY;
2432 }
2433 else {
2434 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2435 finderArgs = new Object[] { start, end, orderByComparator };
2436 }
2437
2438 List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
2439 finderArgs, this);
2440
2441 if (list == null) {
2442 StringBundler query = null;
2443 String sql = null;
2444
2445 if (orderByComparator != null) {
2446 query = new StringBundler(2 +
2447 (orderByComparator.getOrderByFields().length * 3));
2448
2449 query.append(_SQL_SELECT_LOCK);
2450
2451 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2452 orderByComparator);
2453
2454 sql = query.toString();
2455 }
2456 else {
2457 sql = _SQL_SELECT_LOCK;
2458
2459 if (pagination) {
2460 sql = sql.concat(LockModelImpl.ORDER_BY_JPQL);
2461 }
2462 }
2463
2464 Session session = null;
2465
2466 try {
2467 session = openSession();
2468
2469 Query q = session.createQuery(sql);
2470
2471 if (!pagination) {
2472 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2473 end, false);
2474
2475 Collections.sort(list);
2476
2477 list = new UnmodifiableList<Lock>(list);
2478 }
2479 else {
2480 list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2481 end);
2482 }
2483
2484 cacheResult(list);
2485
2486 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2487 }
2488 catch (Exception e) {
2489 FinderCacheUtil.removeResult(finderPath, finderArgs);
2490
2491 throw processException(e);
2492 }
2493 finally {
2494 closeSession(session);
2495 }
2496 }
2497
2498 return list;
2499 }
2500
2501
2506 public void removeAll() throws SystemException {
2507 for (Lock lock : findAll()) {
2508 remove(lock);
2509 }
2510 }
2511
2512
2518 public int countAll() throws SystemException {
2519 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2520 FINDER_ARGS_EMPTY, this);
2521
2522 if (count == null) {
2523 Session session = null;
2524
2525 try {
2526 session = openSession();
2527
2528 Query q = session.createQuery(_SQL_COUNT_LOCK);
2529
2530 count = (Long)q.uniqueResult();
2531
2532 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2533 FINDER_ARGS_EMPTY, count);
2534 }
2535 catch (Exception e) {
2536 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2537 FINDER_ARGS_EMPTY);
2538
2539 throw processException(e);
2540 }
2541 finally {
2542 closeSession(session);
2543 }
2544 }
2545
2546 return count.intValue();
2547 }
2548
2549
2552 public void afterPropertiesSet() {
2553 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2554 com.liferay.portal.util.PropsUtil.get(
2555 "value.object.listener.com.liferay.portal.model.Lock")));
2556
2557 if (listenerClassNames.length > 0) {
2558 try {
2559 List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
2560
2561 for (String listenerClassName : listenerClassNames) {
2562 listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
2563 listenerClassName));
2564 }
2565
2566 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2567 }
2568 catch (Exception e) {
2569 _log.error(e);
2570 }
2571 }
2572 }
2573
2574 public void destroy() {
2575 EntityCacheUtil.removeCache(LockImpl.class.getName());
2576 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2577 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2578 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2579 }
2580
2581 private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
2582 private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
2583 private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
2584 private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
2585 private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
2586 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
2587 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
2588 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2589 private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
2590 private static Lock _nullLock = new LockImpl() {
2591 @Override
2592 public Object clone() {
2593 return this;
2594 }
2595
2596 @Override
2597 public CacheModel<Lock> toCacheModel() {
2598 return _nullLockCacheModel;
2599 }
2600 };
2601
2602 private static CacheModel<Lock> _nullLockCacheModel = new CacheModel<Lock>() {
2603 public Lock toEntityModel() {
2604 return _nullLock;
2605 }
2606 };
2607 }