001
014
015 package com.liferay.portlet.dynamicdatalists.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.Validator;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035
036 import com.liferay.portlet.dynamicdatalists.NoSuchRecordVersionException;
037 import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
038 import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordVersionImpl;
039 import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordVersionModelImpl;
040 import com.liferay.portlet.dynamicdatalists.service.persistence.DDLRecordVersionPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class DDLRecordVersionPersistenceImpl extends BasePersistenceImpl<DDLRecordVersion>
066 implements DDLRecordVersionPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = DDLRecordVersionImpl.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(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
078 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
079 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
080 "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
082 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
083 DDLRecordVersionImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
086 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECORDID = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
089 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
090 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091 "findByRecordId",
092 new String[] {
093 Long.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID =
099 new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
100 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
101 DDLRecordVersionImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRecordId",
103 new String[] { Long.class.getName() },
104 DDLRecordVersionModelImpl.RECORDID_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_RECORDID = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
106 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRecordId",
108 new String[] { Long.class.getName() });
109
110
116 @Override
117 public List<DDLRecordVersion> findByRecordId(long recordId) {
118 return findByRecordId(recordId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
119 null);
120 }
121
122
134 @Override
135 public List<DDLRecordVersion> findByRecordId(long recordId, int start,
136 int end) {
137 return findByRecordId(recordId, start, end, null);
138 }
139
140
153 @Override
154 public List<DDLRecordVersion> findByRecordId(long recordId, int start,
155 int end, OrderByComparator<DDLRecordVersion> orderByComparator) {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID;
164 finderArgs = new Object[] { recordId };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RECORDID;
168 finderArgs = new Object[] { recordId, start, end, orderByComparator };
169 }
170
171 List<DDLRecordVersion> list = (List<DDLRecordVersion>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (DDLRecordVersion ddlRecordVersion : list) {
176 if ((recordId != ddlRecordVersion.getRecordId())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
196
197 query.append(_FINDER_COLUMN_RECORDID_RECORDID_2);
198
199 if (orderByComparator != null) {
200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
201 orderByComparator);
202 }
203 else
204 if (pagination) {
205 query.append(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
206 }
207
208 String sql = query.toString();
209
210 Session session = null;
211
212 try {
213 session = openSession();
214
215 Query q = session.createQuery(sql);
216
217 QueryPos qPos = QueryPos.getInstance(q);
218
219 qPos.add(recordId);
220
221 if (!pagination) {
222 list = (List<DDLRecordVersion>)QueryUtil.list(q,
223 getDialect(), start, end, false);
224
225 Collections.sort(list);
226
227 list = Collections.unmodifiableList(list);
228 }
229 else {
230 list = (List<DDLRecordVersion>)QueryUtil.list(q,
231 getDialect(), start, end);
232 }
233
234 cacheResult(list);
235
236 FinderCacheUtil.putResult(finderPath, finderArgs, list);
237 }
238 catch (Exception e) {
239 FinderCacheUtil.removeResult(finderPath, finderArgs);
240
241 throw processException(e);
242 }
243 finally {
244 closeSession(session);
245 }
246 }
247
248 return list;
249 }
250
251
259 @Override
260 public DDLRecordVersion findByRecordId_First(long recordId,
261 OrderByComparator<DDLRecordVersion> orderByComparator)
262 throws NoSuchRecordVersionException {
263 DDLRecordVersion ddlRecordVersion = fetchByRecordId_First(recordId,
264 orderByComparator);
265
266 if (ddlRecordVersion != null) {
267 return ddlRecordVersion;
268 }
269
270 StringBundler msg = new StringBundler(4);
271
272 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
273
274 msg.append("recordId=");
275 msg.append(recordId);
276
277 msg.append(StringPool.CLOSE_CURLY_BRACE);
278
279 throw new NoSuchRecordVersionException(msg.toString());
280 }
281
282
289 @Override
290 public DDLRecordVersion fetchByRecordId_First(long recordId,
291 OrderByComparator<DDLRecordVersion> orderByComparator) {
292 List<DDLRecordVersion> list = findByRecordId(recordId, 0, 1,
293 orderByComparator);
294
295 if (!list.isEmpty()) {
296 return list.get(0);
297 }
298
299 return null;
300 }
301
302
310 @Override
311 public DDLRecordVersion findByRecordId_Last(long recordId,
312 OrderByComparator<DDLRecordVersion> orderByComparator)
313 throws NoSuchRecordVersionException {
314 DDLRecordVersion ddlRecordVersion = fetchByRecordId_Last(recordId,
315 orderByComparator);
316
317 if (ddlRecordVersion != null) {
318 return ddlRecordVersion;
319 }
320
321 StringBundler msg = new StringBundler(4);
322
323 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
324
325 msg.append("recordId=");
326 msg.append(recordId);
327
328 msg.append(StringPool.CLOSE_CURLY_BRACE);
329
330 throw new NoSuchRecordVersionException(msg.toString());
331 }
332
333
340 @Override
341 public DDLRecordVersion fetchByRecordId_Last(long recordId,
342 OrderByComparator<DDLRecordVersion> orderByComparator) {
343 int count = countByRecordId(recordId);
344
345 if (count == 0) {
346 return null;
347 }
348
349 List<DDLRecordVersion> list = findByRecordId(recordId, count - 1,
350 count, orderByComparator);
351
352 if (!list.isEmpty()) {
353 return list.get(0);
354 }
355
356 return null;
357 }
358
359
368 @Override
369 public DDLRecordVersion[] findByRecordId_PrevAndNext(long recordVersionId,
370 long recordId, OrderByComparator<DDLRecordVersion> orderByComparator)
371 throws NoSuchRecordVersionException {
372 DDLRecordVersion ddlRecordVersion = findByPrimaryKey(recordVersionId);
373
374 Session session = null;
375
376 try {
377 session = openSession();
378
379 DDLRecordVersion[] array = new DDLRecordVersionImpl[3];
380
381 array[0] = getByRecordId_PrevAndNext(session, ddlRecordVersion,
382 recordId, orderByComparator, true);
383
384 array[1] = ddlRecordVersion;
385
386 array[2] = getByRecordId_PrevAndNext(session, ddlRecordVersion,
387 recordId, orderByComparator, false);
388
389 return array;
390 }
391 catch (Exception e) {
392 throw processException(e);
393 }
394 finally {
395 closeSession(session);
396 }
397 }
398
399 protected DDLRecordVersion getByRecordId_PrevAndNext(Session session,
400 DDLRecordVersion ddlRecordVersion, long recordId,
401 OrderByComparator<DDLRecordVersion> orderByComparator, boolean previous) {
402 StringBundler query = null;
403
404 if (orderByComparator != null) {
405 query = new StringBundler(6 +
406 (orderByComparator.getOrderByFields().length * 6));
407 }
408 else {
409 query = new StringBundler(3);
410 }
411
412 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
413
414 query.append(_FINDER_COLUMN_RECORDID_RECORDID_2);
415
416 if (orderByComparator != null) {
417 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
418
419 if (orderByConditionFields.length > 0) {
420 query.append(WHERE_AND);
421 }
422
423 for (int i = 0; i < orderByConditionFields.length; i++) {
424 query.append(_ORDER_BY_ENTITY_ALIAS);
425 query.append(orderByConditionFields[i]);
426
427 if ((i + 1) < orderByConditionFields.length) {
428 if (orderByComparator.isAscending() ^ previous) {
429 query.append(WHERE_GREATER_THAN_HAS_NEXT);
430 }
431 else {
432 query.append(WHERE_LESSER_THAN_HAS_NEXT);
433 }
434 }
435 else {
436 if (orderByComparator.isAscending() ^ previous) {
437 query.append(WHERE_GREATER_THAN);
438 }
439 else {
440 query.append(WHERE_LESSER_THAN);
441 }
442 }
443 }
444
445 query.append(ORDER_BY_CLAUSE);
446
447 String[] orderByFields = orderByComparator.getOrderByFields();
448
449 for (int i = 0; i < orderByFields.length; i++) {
450 query.append(_ORDER_BY_ENTITY_ALIAS);
451 query.append(orderByFields[i]);
452
453 if ((i + 1) < orderByFields.length) {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(ORDER_BY_ASC_HAS_NEXT);
456 }
457 else {
458 query.append(ORDER_BY_DESC_HAS_NEXT);
459 }
460 }
461 else {
462 if (orderByComparator.isAscending() ^ previous) {
463 query.append(ORDER_BY_ASC);
464 }
465 else {
466 query.append(ORDER_BY_DESC);
467 }
468 }
469 }
470 }
471 else {
472 query.append(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
473 }
474
475 String sql = query.toString();
476
477 Query q = session.createQuery(sql);
478
479 q.setFirstResult(0);
480 q.setMaxResults(2);
481
482 QueryPos qPos = QueryPos.getInstance(q);
483
484 qPos.add(recordId);
485
486 if (orderByComparator != null) {
487 Object[] values = orderByComparator.getOrderByConditionValues(ddlRecordVersion);
488
489 for (Object value : values) {
490 qPos.add(value);
491 }
492 }
493
494 List<DDLRecordVersion> list = q.list();
495
496 if (list.size() == 2) {
497 return list.get(1);
498 }
499 else {
500 return null;
501 }
502 }
503
504
509 @Override
510 public void removeByRecordId(long recordId) {
511 for (DDLRecordVersion ddlRecordVersion : findByRecordId(recordId,
512 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
513 remove(ddlRecordVersion);
514 }
515 }
516
517
523 @Override
524 public int countByRecordId(long recordId) {
525 FinderPath finderPath = FINDER_PATH_COUNT_BY_RECORDID;
526
527 Object[] finderArgs = new Object[] { recordId };
528
529 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
530 this);
531
532 if (count == null) {
533 StringBundler query = new StringBundler(2);
534
535 query.append(_SQL_COUNT_DDLRECORDVERSION_WHERE);
536
537 query.append(_FINDER_COLUMN_RECORDID_RECORDID_2);
538
539 String sql = query.toString();
540
541 Session session = null;
542
543 try {
544 session = openSession();
545
546 Query q = session.createQuery(sql);
547
548 QueryPos qPos = QueryPos.getInstance(q);
549
550 qPos.add(recordId);
551
552 count = (Long)q.uniqueResult();
553
554 FinderCacheUtil.putResult(finderPath, finderArgs, count);
555 }
556 catch (Exception e) {
557 FinderCacheUtil.removeResult(finderPath, finderArgs);
558
559 throw processException(e);
560 }
561 finally {
562 closeSession(session);
563 }
564 }
565
566 return count.intValue();
567 }
568
569 private static final String _FINDER_COLUMN_RECORDID_RECORDID_2 = "ddlRecordVersion.recordId = ?";
570 public static final FinderPath FINDER_PATH_FETCH_BY_R_V = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
571 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
572 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByR_V",
573 new String[] { Long.class.getName(), String.class.getName() },
574 DDLRecordVersionModelImpl.RECORDID_COLUMN_BITMASK |
575 DDLRecordVersionModelImpl.VERSION_COLUMN_BITMASK);
576 public static final FinderPath FINDER_PATH_COUNT_BY_R_V = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
577 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
578 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_V",
579 new String[] { Long.class.getName(), String.class.getName() });
580
581
589 @Override
590 public DDLRecordVersion findByR_V(long recordId, String version)
591 throws NoSuchRecordVersionException {
592 DDLRecordVersion ddlRecordVersion = fetchByR_V(recordId, version);
593
594 if (ddlRecordVersion == null) {
595 StringBundler msg = new StringBundler(6);
596
597 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
598
599 msg.append("recordId=");
600 msg.append(recordId);
601
602 msg.append(", version=");
603 msg.append(version);
604
605 msg.append(StringPool.CLOSE_CURLY_BRACE);
606
607 if (_log.isWarnEnabled()) {
608 _log.warn(msg.toString());
609 }
610
611 throw new NoSuchRecordVersionException(msg.toString());
612 }
613
614 return ddlRecordVersion;
615 }
616
617
624 @Override
625 public DDLRecordVersion fetchByR_V(long recordId, String version) {
626 return fetchByR_V(recordId, version, true);
627 }
628
629
637 @Override
638 public DDLRecordVersion fetchByR_V(long recordId, String version,
639 boolean retrieveFromCache) {
640 Object[] finderArgs = new Object[] { recordId, version };
641
642 Object result = null;
643
644 if (retrieveFromCache) {
645 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_V,
646 finderArgs, this);
647 }
648
649 if (result instanceof DDLRecordVersion) {
650 DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)result;
651
652 if ((recordId != ddlRecordVersion.getRecordId()) ||
653 !Validator.equals(version, ddlRecordVersion.getVersion())) {
654 result = null;
655 }
656 }
657
658 if (result == null) {
659 StringBundler query = new StringBundler(4);
660
661 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
662
663 query.append(_FINDER_COLUMN_R_V_RECORDID_2);
664
665 boolean bindVersion = false;
666
667 if (version == null) {
668 query.append(_FINDER_COLUMN_R_V_VERSION_1);
669 }
670 else if (version.equals(StringPool.BLANK)) {
671 query.append(_FINDER_COLUMN_R_V_VERSION_3);
672 }
673 else {
674 bindVersion = true;
675
676 query.append(_FINDER_COLUMN_R_V_VERSION_2);
677 }
678
679 String sql = query.toString();
680
681 Session session = null;
682
683 try {
684 session = openSession();
685
686 Query q = session.createQuery(sql);
687
688 QueryPos qPos = QueryPos.getInstance(q);
689
690 qPos.add(recordId);
691
692 if (bindVersion) {
693 qPos.add(version);
694 }
695
696 List<DDLRecordVersion> list = q.list();
697
698 if (list.isEmpty()) {
699 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V,
700 finderArgs, list);
701 }
702 else {
703 DDLRecordVersion ddlRecordVersion = list.get(0);
704
705 result = ddlRecordVersion;
706
707 cacheResult(ddlRecordVersion);
708
709 if ((ddlRecordVersion.getRecordId() != recordId) ||
710 (ddlRecordVersion.getVersion() == null) ||
711 !ddlRecordVersion.getVersion().equals(version)) {
712 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V,
713 finderArgs, ddlRecordVersion);
714 }
715 }
716 }
717 catch (Exception e) {
718 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V,
719 finderArgs);
720
721 throw processException(e);
722 }
723 finally {
724 closeSession(session);
725 }
726 }
727
728 if (result instanceof List<?>) {
729 return null;
730 }
731 else {
732 return (DDLRecordVersion)result;
733 }
734 }
735
736
743 @Override
744 public DDLRecordVersion removeByR_V(long recordId, String version)
745 throws NoSuchRecordVersionException {
746 DDLRecordVersion ddlRecordVersion = findByR_V(recordId, version);
747
748 return remove(ddlRecordVersion);
749 }
750
751
758 @Override
759 public int countByR_V(long recordId, String version) {
760 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_V;
761
762 Object[] finderArgs = new Object[] { recordId, version };
763
764 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
765 this);
766
767 if (count == null) {
768 StringBundler query = new StringBundler(3);
769
770 query.append(_SQL_COUNT_DDLRECORDVERSION_WHERE);
771
772 query.append(_FINDER_COLUMN_R_V_RECORDID_2);
773
774 boolean bindVersion = false;
775
776 if (version == null) {
777 query.append(_FINDER_COLUMN_R_V_VERSION_1);
778 }
779 else if (version.equals(StringPool.BLANK)) {
780 query.append(_FINDER_COLUMN_R_V_VERSION_3);
781 }
782 else {
783 bindVersion = true;
784
785 query.append(_FINDER_COLUMN_R_V_VERSION_2);
786 }
787
788 String sql = query.toString();
789
790 Session session = null;
791
792 try {
793 session = openSession();
794
795 Query q = session.createQuery(sql);
796
797 QueryPos qPos = QueryPos.getInstance(q);
798
799 qPos.add(recordId);
800
801 if (bindVersion) {
802 qPos.add(version);
803 }
804
805 count = (Long)q.uniqueResult();
806
807 FinderCacheUtil.putResult(finderPath, finderArgs, count);
808 }
809 catch (Exception e) {
810 FinderCacheUtil.removeResult(finderPath, finderArgs);
811
812 throw processException(e);
813 }
814 finally {
815 closeSession(session);
816 }
817 }
818
819 return count.intValue();
820 }
821
822 private static final String _FINDER_COLUMN_R_V_RECORDID_2 = "ddlRecordVersion.recordId = ? AND ";
823 private static final String _FINDER_COLUMN_R_V_VERSION_1 = "ddlRecordVersion.version IS NULL";
824 private static final String _FINDER_COLUMN_R_V_VERSION_2 = "ddlRecordVersion.version = ?";
825 private static final String _FINDER_COLUMN_R_V_VERSION_3 = "(ddlRecordVersion.version IS NULL OR ddlRecordVersion.version = '')";
826 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
827 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
828 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
829 "findByR_S",
830 new String[] {
831 Long.class.getName(), Integer.class.getName(),
832
833 Integer.class.getName(), Integer.class.getName(),
834 OrderByComparator.class.getName()
835 });
836 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
837 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
838 DDLRecordVersionImpl.class,
839 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_S",
840 new String[] { Long.class.getName(), Integer.class.getName() },
841 DDLRecordVersionModelImpl.RECORDID_COLUMN_BITMASK |
842 DDLRecordVersionModelImpl.STATUS_COLUMN_BITMASK);
843 public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
844 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
845 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_S",
846 new String[] { Long.class.getName(), Integer.class.getName() });
847
848
855 @Override
856 public List<DDLRecordVersion> findByR_S(long recordId, int status) {
857 return findByR_S(recordId, status, QueryUtil.ALL_POS,
858 QueryUtil.ALL_POS, null);
859 }
860
861
874 @Override
875 public List<DDLRecordVersion> findByR_S(long recordId, int status,
876 int start, int end) {
877 return findByR_S(recordId, status, start, end, null);
878 }
879
880
894 @Override
895 public List<DDLRecordVersion> findByR_S(long recordId, int status,
896 int start, int end,
897 OrderByComparator<DDLRecordVersion> orderByComparator) {
898 boolean pagination = true;
899 FinderPath finderPath = null;
900 Object[] finderArgs = null;
901
902 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
903 (orderByComparator == null)) {
904 pagination = false;
905 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S;
906 finderArgs = new Object[] { recordId, status };
907 }
908 else {
909 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S;
910 finderArgs = new Object[] {
911 recordId, status,
912
913 start, end, orderByComparator
914 };
915 }
916
917 List<DDLRecordVersion> list = (List<DDLRecordVersion>)FinderCacheUtil.getResult(finderPath,
918 finderArgs, this);
919
920 if ((list != null) && !list.isEmpty()) {
921 for (DDLRecordVersion ddlRecordVersion : list) {
922 if ((recordId != ddlRecordVersion.getRecordId()) ||
923 (status != ddlRecordVersion.getStatus())) {
924 list = null;
925
926 break;
927 }
928 }
929 }
930
931 if (list == null) {
932 StringBundler query = null;
933
934 if (orderByComparator != null) {
935 query = new StringBundler(4 +
936 (orderByComparator.getOrderByFields().length * 3));
937 }
938 else {
939 query = new StringBundler(4);
940 }
941
942 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
943
944 query.append(_FINDER_COLUMN_R_S_RECORDID_2);
945
946 query.append(_FINDER_COLUMN_R_S_STATUS_2);
947
948 if (orderByComparator != null) {
949 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
950 orderByComparator);
951 }
952 else
953 if (pagination) {
954 query.append(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
955 }
956
957 String sql = query.toString();
958
959 Session session = null;
960
961 try {
962 session = openSession();
963
964 Query q = session.createQuery(sql);
965
966 QueryPos qPos = QueryPos.getInstance(q);
967
968 qPos.add(recordId);
969
970 qPos.add(status);
971
972 if (!pagination) {
973 list = (List<DDLRecordVersion>)QueryUtil.list(q,
974 getDialect(), start, end, false);
975
976 Collections.sort(list);
977
978 list = Collections.unmodifiableList(list);
979 }
980 else {
981 list = (List<DDLRecordVersion>)QueryUtil.list(q,
982 getDialect(), start, end);
983 }
984
985 cacheResult(list);
986
987 FinderCacheUtil.putResult(finderPath, finderArgs, list);
988 }
989 catch (Exception e) {
990 FinderCacheUtil.removeResult(finderPath, finderArgs);
991
992 throw processException(e);
993 }
994 finally {
995 closeSession(session);
996 }
997 }
998
999 return list;
1000 }
1001
1002
1011 @Override
1012 public DDLRecordVersion findByR_S_First(long recordId, int status,
1013 OrderByComparator<DDLRecordVersion> orderByComparator)
1014 throws NoSuchRecordVersionException {
1015 DDLRecordVersion ddlRecordVersion = fetchByR_S_First(recordId, status,
1016 orderByComparator);
1017
1018 if (ddlRecordVersion != null) {
1019 return ddlRecordVersion;
1020 }
1021
1022 StringBundler msg = new StringBundler(6);
1023
1024 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1025
1026 msg.append("recordId=");
1027 msg.append(recordId);
1028
1029 msg.append(", status=");
1030 msg.append(status);
1031
1032 msg.append(StringPool.CLOSE_CURLY_BRACE);
1033
1034 throw new NoSuchRecordVersionException(msg.toString());
1035 }
1036
1037
1045 @Override
1046 public DDLRecordVersion fetchByR_S_First(long recordId, int status,
1047 OrderByComparator<DDLRecordVersion> orderByComparator) {
1048 List<DDLRecordVersion> list = findByR_S(recordId, status, 0, 1,
1049 orderByComparator);
1050
1051 if (!list.isEmpty()) {
1052 return list.get(0);
1053 }
1054
1055 return null;
1056 }
1057
1058
1067 @Override
1068 public DDLRecordVersion findByR_S_Last(long recordId, int status,
1069 OrderByComparator<DDLRecordVersion> orderByComparator)
1070 throws NoSuchRecordVersionException {
1071 DDLRecordVersion ddlRecordVersion = fetchByR_S_Last(recordId, status,
1072 orderByComparator);
1073
1074 if (ddlRecordVersion != null) {
1075 return ddlRecordVersion;
1076 }
1077
1078 StringBundler msg = new StringBundler(6);
1079
1080 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1081
1082 msg.append("recordId=");
1083 msg.append(recordId);
1084
1085 msg.append(", status=");
1086 msg.append(status);
1087
1088 msg.append(StringPool.CLOSE_CURLY_BRACE);
1089
1090 throw new NoSuchRecordVersionException(msg.toString());
1091 }
1092
1093
1101 @Override
1102 public DDLRecordVersion fetchByR_S_Last(long recordId, int status,
1103 OrderByComparator<DDLRecordVersion> orderByComparator) {
1104 int count = countByR_S(recordId, status);
1105
1106 if (count == 0) {
1107 return null;
1108 }
1109
1110 List<DDLRecordVersion> list = findByR_S(recordId, status, count - 1,
1111 count, orderByComparator);
1112
1113 if (!list.isEmpty()) {
1114 return list.get(0);
1115 }
1116
1117 return null;
1118 }
1119
1120
1130 @Override
1131 public DDLRecordVersion[] findByR_S_PrevAndNext(long recordVersionId,
1132 long recordId, int status,
1133 OrderByComparator<DDLRecordVersion> orderByComparator)
1134 throws NoSuchRecordVersionException {
1135 DDLRecordVersion ddlRecordVersion = findByPrimaryKey(recordVersionId);
1136
1137 Session session = null;
1138
1139 try {
1140 session = openSession();
1141
1142 DDLRecordVersion[] array = new DDLRecordVersionImpl[3];
1143
1144 array[0] = getByR_S_PrevAndNext(session, ddlRecordVersion,
1145 recordId, status, orderByComparator, true);
1146
1147 array[1] = ddlRecordVersion;
1148
1149 array[2] = getByR_S_PrevAndNext(session, ddlRecordVersion,
1150 recordId, status, orderByComparator, false);
1151
1152 return array;
1153 }
1154 catch (Exception e) {
1155 throw processException(e);
1156 }
1157 finally {
1158 closeSession(session);
1159 }
1160 }
1161
1162 protected DDLRecordVersion getByR_S_PrevAndNext(Session session,
1163 DDLRecordVersion ddlRecordVersion, long recordId, int status,
1164 OrderByComparator<DDLRecordVersion> orderByComparator, boolean previous) {
1165 StringBundler query = null;
1166
1167 if (orderByComparator != null) {
1168 query = new StringBundler(6 +
1169 (orderByComparator.getOrderByFields().length * 6));
1170 }
1171 else {
1172 query = new StringBundler(3);
1173 }
1174
1175 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
1176
1177 query.append(_FINDER_COLUMN_R_S_RECORDID_2);
1178
1179 query.append(_FINDER_COLUMN_R_S_STATUS_2);
1180
1181 if (orderByComparator != null) {
1182 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1183
1184 if (orderByConditionFields.length > 0) {
1185 query.append(WHERE_AND);
1186 }
1187
1188 for (int i = 0; i < orderByConditionFields.length; i++) {
1189 query.append(_ORDER_BY_ENTITY_ALIAS);
1190 query.append(orderByConditionFields[i]);
1191
1192 if ((i + 1) < orderByConditionFields.length) {
1193 if (orderByComparator.isAscending() ^ previous) {
1194 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1195 }
1196 else {
1197 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1198 }
1199 }
1200 else {
1201 if (orderByComparator.isAscending() ^ previous) {
1202 query.append(WHERE_GREATER_THAN);
1203 }
1204 else {
1205 query.append(WHERE_LESSER_THAN);
1206 }
1207 }
1208 }
1209
1210 query.append(ORDER_BY_CLAUSE);
1211
1212 String[] orderByFields = orderByComparator.getOrderByFields();
1213
1214 for (int i = 0; i < orderByFields.length; i++) {
1215 query.append(_ORDER_BY_ENTITY_ALIAS);
1216 query.append(orderByFields[i]);
1217
1218 if ((i + 1) < orderByFields.length) {
1219 if (orderByComparator.isAscending() ^ previous) {
1220 query.append(ORDER_BY_ASC_HAS_NEXT);
1221 }
1222 else {
1223 query.append(ORDER_BY_DESC_HAS_NEXT);
1224 }
1225 }
1226 else {
1227 if (orderByComparator.isAscending() ^ previous) {
1228 query.append(ORDER_BY_ASC);
1229 }
1230 else {
1231 query.append(ORDER_BY_DESC);
1232 }
1233 }
1234 }
1235 }
1236 else {
1237 query.append(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
1238 }
1239
1240 String sql = query.toString();
1241
1242 Query q = session.createQuery(sql);
1243
1244 q.setFirstResult(0);
1245 q.setMaxResults(2);
1246
1247 QueryPos qPos = QueryPos.getInstance(q);
1248
1249 qPos.add(recordId);
1250
1251 qPos.add(status);
1252
1253 if (orderByComparator != null) {
1254 Object[] values = orderByComparator.getOrderByConditionValues(ddlRecordVersion);
1255
1256 for (Object value : values) {
1257 qPos.add(value);
1258 }
1259 }
1260
1261 List<DDLRecordVersion> list = q.list();
1262
1263 if (list.size() == 2) {
1264 return list.get(1);
1265 }
1266 else {
1267 return null;
1268 }
1269 }
1270
1271
1277 @Override
1278 public void removeByR_S(long recordId, int status) {
1279 for (DDLRecordVersion ddlRecordVersion : findByR_S(recordId, status,
1280 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1281 remove(ddlRecordVersion);
1282 }
1283 }
1284
1285
1292 @Override
1293 public int countByR_S(long recordId, int status) {
1294 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_S;
1295
1296 Object[] finderArgs = new Object[] { recordId, status };
1297
1298 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1299 this);
1300
1301 if (count == null) {
1302 StringBundler query = new StringBundler(3);
1303
1304 query.append(_SQL_COUNT_DDLRECORDVERSION_WHERE);
1305
1306 query.append(_FINDER_COLUMN_R_S_RECORDID_2);
1307
1308 query.append(_FINDER_COLUMN_R_S_STATUS_2);
1309
1310 String sql = query.toString();
1311
1312 Session session = null;
1313
1314 try {
1315 session = openSession();
1316
1317 Query q = session.createQuery(sql);
1318
1319 QueryPos qPos = QueryPos.getInstance(q);
1320
1321 qPos.add(recordId);
1322
1323 qPos.add(status);
1324
1325 count = (Long)q.uniqueResult();
1326
1327 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1328 }
1329 catch (Exception e) {
1330 FinderCacheUtil.removeResult(finderPath, finderArgs);
1331
1332 throw processException(e);
1333 }
1334 finally {
1335 closeSession(session);
1336 }
1337 }
1338
1339 return count.intValue();
1340 }
1341
1342 private static final String _FINDER_COLUMN_R_S_RECORDID_2 = "ddlRecordVersion.recordId = ? AND ";
1343 private static final String _FINDER_COLUMN_R_S_STATUS_2 = "ddlRecordVersion.status = ?";
1344
1345 public DDLRecordVersionPersistenceImpl() {
1346 setModelClass(DDLRecordVersion.class);
1347 }
1348
1349
1354 @Override
1355 public void cacheResult(DDLRecordVersion ddlRecordVersion) {
1356 EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1357 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey(),
1358 ddlRecordVersion);
1359
1360 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V,
1361 new Object[] {
1362 ddlRecordVersion.getRecordId(), ddlRecordVersion.getVersion()
1363 }, ddlRecordVersion);
1364
1365 ddlRecordVersion.resetOriginalValues();
1366 }
1367
1368
1373 @Override
1374 public void cacheResult(List<DDLRecordVersion> ddlRecordVersions) {
1375 for (DDLRecordVersion ddlRecordVersion : ddlRecordVersions) {
1376 if (EntityCacheUtil.getResult(
1377 DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1378 DDLRecordVersionImpl.class,
1379 ddlRecordVersion.getPrimaryKey()) == null) {
1380 cacheResult(ddlRecordVersion);
1381 }
1382 else {
1383 ddlRecordVersion.resetOriginalValues();
1384 }
1385 }
1386 }
1387
1388
1395 @Override
1396 public void clearCache() {
1397 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1398 CacheRegistryUtil.clear(DDLRecordVersionImpl.class.getName());
1399 }
1400
1401 EntityCacheUtil.clearCache(DDLRecordVersionImpl.class);
1402
1403 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1404 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1405 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1406 }
1407
1408
1415 @Override
1416 public void clearCache(DDLRecordVersion ddlRecordVersion) {
1417 EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1418 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey());
1419
1420 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1421 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1422
1423 clearUniqueFindersCache(ddlRecordVersion);
1424 }
1425
1426 @Override
1427 public void clearCache(List<DDLRecordVersion> ddlRecordVersions) {
1428 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1429 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1430
1431 for (DDLRecordVersion ddlRecordVersion : ddlRecordVersions) {
1432 EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1433 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey());
1434
1435 clearUniqueFindersCache(ddlRecordVersion);
1436 }
1437 }
1438
1439 protected void cacheUniqueFindersCache(DDLRecordVersion ddlRecordVersion) {
1440 if (ddlRecordVersion.isNew()) {
1441 Object[] args = new Object[] {
1442 ddlRecordVersion.getRecordId(),
1443 ddlRecordVersion.getVersion()
1444 };
1445
1446 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_V, args,
1447 Long.valueOf(1));
1448 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V, args,
1449 ddlRecordVersion);
1450 }
1451 else {
1452 DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1453
1454 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1455 FINDER_PATH_FETCH_BY_R_V.getColumnBitmask()) != 0) {
1456 Object[] args = new Object[] {
1457 ddlRecordVersion.getRecordId(),
1458 ddlRecordVersion.getVersion()
1459 };
1460
1461 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_V, args,
1462 Long.valueOf(1));
1463 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V, args,
1464 ddlRecordVersion);
1465 }
1466 }
1467 }
1468
1469 protected void clearUniqueFindersCache(DDLRecordVersion ddlRecordVersion) {
1470 DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1471
1472 Object[] args = new Object[] {
1473 ddlRecordVersion.getRecordId(), ddlRecordVersion.getVersion()
1474 };
1475
1476 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_V, args);
1477 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V, args);
1478
1479 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1480 FINDER_PATH_FETCH_BY_R_V.getColumnBitmask()) != 0) {
1481 args = new Object[] {
1482 ddlRecordVersionModelImpl.getOriginalRecordId(),
1483 ddlRecordVersionModelImpl.getOriginalVersion()
1484 };
1485
1486 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_V, args);
1487 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V, args);
1488 }
1489 }
1490
1491
1497 @Override
1498 public DDLRecordVersion create(long recordVersionId) {
1499 DDLRecordVersion ddlRecordVersion = new DDLRecordVersionImpl();
1500
1501 ddlRecordVersion.setNew(true);
1502 ddlRecordVersion.setPrimaryKey(recordVersionId);
1503
1504 return ddlRecordVersion;
1505 }
1506
1507
1514 @Override
1515 public DDLRecordVersion remove(long recordVersionId)
1516 throws NoSuchRecordVersionException {
1517 return remove((Serializable)recordVersionId);
1518 }
1519
1520
1527 @Override
1528 public DDLRecordVersion remove(Serializable primaryKey)
1529 throws NoSuchRecordVersionException {
1530 Session session = null;
1531
1532 try {
1533 session = openSession();
1534
1535 DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1536 primaryKey);
1537
1538 if (ddlRecordVersion == null) {
1539 if (_log.isWarnEnabled()) {
1540 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1541 }
1542
1543 throw new NoSuchRecordVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1544 primaryKey);
1545 }
1546
1547 return remove(ddlRecordVersion);
1548 }
1549 catch (NoSuchRecordVersionException nsee) {
1550 throw nsee;
1551 }
1552 catch (Exception e) {
1553 throw processException(e);
1554 }
1555 finally {
1556 closeSession(session);
1557 }
1558 }
1559
1560 @Override
1561 protected DDLRecordVersion removeImpl(DDLRecordVersion ddlRecordVersion) {
1562 ddlRecordVersion = toUnwrappedModel(ddlRecordVersion);
1563
1564 Session session = null;
1565
1566 try {
1567 session = openSession();
1568
1569 if (!session.contains(ddlRecordVersion)) {
1570 ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1571 ddlRecordVersion.getPrimaryKeyObj());
1572 }
1573
1574 if (ddlRecordVersion != null) {
1575 session.delete(ddlRecordVersion);
1576 }
1577 }
1578 catch (Exception e) {
1579 throw processException(e);
1580 }
1581 finally {
1582 closeSession(session);
1583 }
1584
1585 if (ddlRecordVersion != null) {
1586 clearCache(ddlRecordVersion);
1587 }
1588
1589 return ddlRecordVersion;
1590 }
1591
1592 @Override
1593 public DDLRecordVersion updateImpl(
1594 com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion ddlRecordVersion) {
1595 ddlRecordVersion = toUnwrappedModel(ddlRecordVersion);
1596
1597 boolean isNew = ddlRecordVersion.isNew();
1598
1599 DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1600
1601 Session session = null;
1602
1603 try {
1604 session = openSession();
1605
1606 if (ddlRecordVersion.isNew()) {
1607 session.save(ddlRecordVersion);
1608
1609 ddlRecordVersion.setNew(false);
1610 }
1611 else {
1612 session.merge(ddlRecordVersion);
1613 }
1614 }
1615 catch (Exception e) {
1616 throw processException(e);
1617 }
1618 finally {
1619 closeSession(session);
1620 }
1621
1622 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1623
1624 if (isNew || !DDLRecordVersionModelImpl.COLUMN_BITMASK_ENABLED) {
1625 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1626 }
1627
1628 else {
1629 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1630 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID.getColumnBitmask()) != 0) {
1631 Object[] args = new Object[] {
1632 ddlRecordVersionModelImpl.getOriginalRecordId()
1633 };
1634
1635 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDID, args);
1636 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID,
1637 args);
1638
1639 args = new Object[] { ddlRecordVersionModelImpl.getRecordId() };
1640
1641 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDID, args);
1642 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID,
1643 args);
1644 }
1645
1646 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1647 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
1648 Object[] args = new Object[] {
1649 ddlRecordVersionModelImpl.getOriginalRecordId(),
1650 ddlRecordVersionModelImpl.getOriginalStatus()
1651 };
1652
1653 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
1654 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
1655 args);
1656
1657 args = new Object[] {
1658 ddlRecordVersionModelImpl.getRecordId(),
1659 ddlRecordVersionModelImpl.getStatus()
1660 };
1661
1662 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
1663 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
1664 args);
1665 }
1666 }
1667
1668 EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1669 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey(),
1670 ddlRecordVersion, false);
1671
1672 clearUniqueFindersCache(ddlRecordVersion);
1673 cacheUniqueFindersCache(ddlRecordVersion);
1674
1675 ddlRecordVersion.resetOriginalValues();
1676
1677 return ddlRecordVersion;
1678 }
1679
1680 protected DDLRecordVersion toUnwrappedModel(
1681 DDLRecordVersion ddlRecordVersion) {
1682 if (ddlRecordVersion instanceof DDLRecordVersionImpl) {
1683 return ddlRecordVersion;
1684 }
1685
1686 DDLRecordVersionImpl ddlRecordVersionImpl = new DDLRecordVersionImpl();
1687
1688 ddlRecordVersionImpl.setNew(ddlRecordVersion.isNew());
1689 ddlRecordVersionImpl.setPrimaryKey(ddlRecordVersion.getPrimaryKey());
1690
1691 ddlRecordVersionImpl.setRecordVersionId(ddlRecordVersion.getRecordVersionId());
1692 ddlRecordVersionImpl.setGroupId(ddlRecordVersion.getGroupId());
1693 ddlRecordVersionImpl.setCompanyId(ddlRecordVersion.getCompanyId());
1694 ddlRecordVersionImpl.setUserId(ddlRecordVersion.getUserId());
1695 ddlRecordVersionImpl.setUserName(ddlRecordVersion.getUserName());
1696 ddlRecordVersionImpl.setCreateDate(ddlRecordVersion.getCreateDate());
1697 ddlRecordVersionImpl.setDDMStorageId(ddlRecordVersion.getDDMStorageId());
1698 ddlRecordVersionImpl.setRecordSetId(ddlRecordVersion.getRecordSetId());
1699 ddlRecordVersionImpl.setRecordId(ddlRecordVersion.getRecordId());
1700 ddlRecordVersionImpl.setVersion(ddlRecordVersion.getVersion());
1701 ddlRecordVersionImpl.setDisplayIndex(ddlRecordVersion.getDisplayIndex());
1702 ddlRecordVersionImpl.setStatus(ddlRecordVersion.getStatus());
1703 ddlRecordVersionImpl.setStatusByUserId(ddlRecordVersion.getStatusByUserId());
1704 ddlRecordVersionImpl.setStatusByUserName(ddlRecordVersion.getStatusByUserName());
1705 ddlRecordVersionImpl.setStatusDate(ddlRecordVersion.getStatusDate());
1706
1707 return ddlRecordVersionImpl;
1708 }
1709
1710
1717 @Override
1718 public DDLRecordVersion findByPrimaryKey(Serializable primaryKey)
1719 throws NoSuchRecordVersionException {
1720 DDLRecordVersion ddlRecordVersion = fetchByPrimaryKey(primaryKey);
1721
1722 if (ddlRecordVersion == null) {
1723 if (_log.isWarnEnabled()) {
1724 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1725 }
1726
1727 throw new NoSuchRecordVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1728 primaryKey);
1729 }
1730
1731 return ddlRecordVersion;
1732 }
1733
1734
1741 @Override
1742 public DDLRecordVersion findByPrimaryKey(long recordVersionId)
1743 throws NoSuchRecordVersionException {
1744 return findByPrimaryKey((Serializable)recordVersionId);
1745 }
1746
1747
1753 @Override
1754 public DDLRecordVersion fetchByPrimaryKey(Serializable primaryKey) {
1755 DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)EntityCacheUtil.getResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1756 DDLRecordVersionImpl.class, primaryKey);
1757
1758 if (ddlRecordVersion == _nullDDLRecordVersion) {
1759 return null;
1760 }
1761
1762 if (ddlRecordVersion == null) {
1763 Session session = null;
1764
1765 try {
1766 session = openSession();
1767
1768 ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1769 primaryKey);
1770
1771 if (ddlRecordVersion != null) {
1772 cacheResult(ddlRecordVersion);
1773 }
1774 else {
1775 EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1776 DDLRecordVersionImpl.class, primaryKey,
1777 _nullDDLRecordVersion);
1778 }
1779 }
1780 catch (Exception e) {
1781 EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1782 DDLRecordVersionImpl.class, primaryKey);
1783
1784 throw processException(e);
1785 }
1786 finally {
1787 closeSession(session);
1788 }
1789 }
1790
1791 return ddlRecordVersion;
1792 }
1793
1794
1800 @Override
1801 public DDLRecordVersion fetchByPrimaryKey(long recordVersionId) {
1802 return fetchByPrimaryKey((Serializable)recordVersionId);
1803 }
1804
1805 @Override
1806 public Map<Serializable, DDLRecordVersion> fetchByPrimaryKeys(
1807 Set<Serializable> primaryKeys) {
1808 if (primaryKeys.isEmpty()) {
1809 return Collections.emptyMap();
1810 }
1811
1812 Map<Serializable, DDLRecordVersion> map = new HashMap<Serializable, DDLRecordVersion>();
1813
1814 if (primaryKeys.size() == 1) {
1815 Iterator<Serializable> iterator = primaryKeys.iterator();
1816
1817 Serializable primaryKey = iterator.next();
1818
1819 DDLRecordVersion ddlRecordVersion = fetchByPrimaryKey(primaryKey);
1820
1821 if (ddlRecordVersion != null) {
1822 map.put(primaryKey, ddlRecordVersion);
1823 }
1824
1825 return map;
1826 }
1827
1828 Set<Serializable> uncachedPrimaryKeys = null;
1829
1830 for (Serializable primaryKey : primaryKeys) {
1831 DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)EntityCacheUtil.getResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1832 DDLRecordVersionImpl.class, primaryKey);
1833
1834 if (ddlRecordVersion == null) {
1835 if (uncachedPrimaryKeys == null) {
1836 uncachedPrimaryKeys = new HashSet<Serializable>();
1837 }
1838
1839 uncachedPrimaryKeys.add(primaryKey);
1840 }
1841 else {
1842 map.put(primaryKey, ddlRecordVersion);
1843 }
1844 }
1845
1846 if (uncachedPrimaryKeys == null) {
1847 return map;
1848 }
1849
1850 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1851 1);
1852
1853 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE_PKS_IN);
1854
1855 for (Serializable primaryKey : uncachedPrimaryKeys) {
1856 query.append(String.valueOf(primaryKey));
1857
1858 query.append(StringPool.COMMA);
1859 }
1860
1861 query.setIndex(query.index() - 1);
1862
1863 query.append(StringPool.CLOSE_PARENTHESIS);
1864
1865 String sql = query.toString();
1866
1867 Session session = null;
1868
1869 try {
1870 session = openSession();
1871
1872 Query q = session.createQuery(sql);
1873
1874 for (DDLRecordVersion ddlRecordVersion : (List<DDLRecordVersion>)q.list()) {
1875 map.put(ddlRecordVersion.getPrimaryKeyObj(), ddlRecordVersion);
1876
1877 cacheResult(ddlRecordVersion);
1878
1879 uncachedPrimaryKeys.remove(ddlRecordVersion.getPrimaryKeyObj());
1880 }
1881
1882 for (Serializable primaryKey : uncachedPrimaryKeys) {
1883 EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1884 DDLRecordVersionImpl.class, primaryKey,
1885 _nullDDLRecordVersion);
1886 }
1887 }
1888 catch (Exception e) {
1889 throw processException(e);
1890 }
1891 finally {
1892 closeSession(session);
1893 }
1894
1895 return map;
1896 }
1897
1898
1903 @Override
1904 public List<DDLRecordVersion> findAll() {
1905 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1906 }
1907
1908
1919 @Override
1920 public List<DDLRecordVersion> findAll(int start, int end) {
1921 return findAll(start, end, null);
1922 }
1923
1924
1936 @Override
1937 public List<DDLRecordVersion> findAll(int start, int end,
1938 OrderByComparator<DDLRecordVersion> orderByComparator) {
1939 boolean pagination = true;
1940 FinderPath finderPath = null;
1941 Object[] finderArgs = null;
1942
1943 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1944 (orderByComparator == null)) {
1945 pagination = false;
1946 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1947 finderArgs = FINDER_ARGS_EMPTY;
1948 }
1949 else {
1950 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1951 finderArgs = new Object[] { start, end, orderByComparator };
1952 }
1953
1954 List<DDLRecordVersion> list = (List<DDLRecordVersion>)FinderCacheUtil.getResult(finderPath,
1955 finderArgs, this);
1956
1957 if (list == null) {
1958 StringBundler query = null;
1959 String sql = null;
1960
1961 if (orderByComparator != null) {
1962 query = new StringBundler(2 +
1963 (orderByComparator.getOrderByFields().length * 3));
1964
1965 query.append(_SQL_SELECT_DDLRECORDVERSION);
1966
1967 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1968 orderByComparator);
1969
1970 sql = query.toString();
1971 }
1972 else {
1973 sql = _SQL_SELECT_DDLRECORDVERSION;
1974
1975 if (pagination) {
1976 sql = sql.concat(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
1977 }
1978 }
1979
1980 Session session = null;
1981
1982 try {
1983 session = openSession();
1984
1985 Query q = session.createQuery(sql);
1986
1987 if (!pagination) {
1988 list = (List<DDLRecordVersion>)QueryUtil.list(q,
1989 getDialect(), start, end, false);
1990
1991 Collections.sort(list);
1992
1993 list = Collections.unmodifiableList(list);
1994 }
1995 else {
1996 list = (List<DDLRecordVersion>)QueryUtil.list(q,
1997 getDialect(), start, end);
1998 }
1999
2000 cacheResult(list);
2001
2002 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2003 }
2004 catch (Exception e) {
2005 FinderCacheUtil.removeResult(finderPath, finderArgs);
2006
2007 throw processException(e);
2008 }
2009 finally {
2010 closeSession(session);
2011 }
2012 }
2013
2014 return list;
2015 }
2016
2017
2021 @Override
2022 public void removeAll() {
2023 for (DDLRecordVersion ddlRecordVersion : findAll()) {
2024 remove(ddlRecordVersion);
2025 }
2026 }
2027
2028
2033 @Override
2034 public int countAll() {
2035 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2036 FINDER_ARGS_EMPTY, this);
2037
2038 if (count == null) {
2039 Session session = null;
2040
2041 try {
2042 session = openSession();
2043
2044 Query q = session.createQuery(_SQL_COUNT_DDLRECORDVERSION);
2045
2046 count = (Long)q.uniqueResult();
2047
2048 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2049 FINDER_ARGS_EMPTY, count);
2050 }
2051 catch (Exception e) {
2052 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2053 FINDER_ARGS_EMPTY);
2054
2055 throw processException(e);
2056 }
2057 finally {
2058 closeSession(session);
2059 }
2060 }
2061
2062 return count.intValue();
2063 }
2064
2065
2068 public void afterPropertiesSet() {
2069 }
2070
2071 public void destroy() {
2072 EntityCacheUtil.removeCache(DDLRecordVersionImpl.class.getName());
2073 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2074 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2075 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2076 }
2077
2078 private static final String _SQL_SELECT_DDLRECORDVERSION = "SELECT ddlRecordVersion FROM DDLRecordVersion ddlRecordVersion";
2079 private static final String _SQL_SELECT_DDLRECORDVERSION_WHERE_PKS_IN = "SELECT ddlRecordVersion FROM DDLRecordVersion ddlRecordVersion WHERE recordVersionId IN (";
2080 private static final String _SQL_SELECT_DDLRECORDVERSION_WHERE = "SELECT ddlRecordVersion FROM DDLRecordVersion ddlRecordVersion WHERE ";
2081 private static final String _SQL_COUNT_DDLRECORDVERSION = "SELECT COUNT(ddlRecordVersion) FROM DDLRecordVersion ddlRecordVersion";
2082 private static final String _SQL_COUNT_DDLRECORDVERSION_WHERE = "SELECT COUNT(ddlRecordVersion) FROM DDLRecordVersion ddlRecordVersion WHERE ";
2083 private static final String _ORDER_BY_ENTITY_ALIAS = "ddlRecordVersion.";
2084 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDLRecordVersion exists with the primary key ";
2085 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDLRecordVersion exists with the key {";
2086 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2087 private static final Log _log = LogFactoryUtil.getLog(DDLRecordVersionPersistenceImpl.class);
2088 private static final DDLRecordVersion _nullDDLRecordVersion = new DDLRecordVersionImpl() {
2089 @Override
2090 public Object clone() {
2091 return this;
2092 }
2093
2094 @Override
2095 public CacheModel<DDLRecordVersion> toCacheModel() {
2096 return _nullDDLRecordVersionCacheModel;
2097 }
2098 };
2099
2100 private static final CacheModel<DDLRecordVersion> _nullDDLRecordVersionCacheModel =
2101 new CacheModel<DDLRecordVersion>() {
2102 @Override
2103 public DDLRecordVersion toEntityModel() {
2104 return _nullDDLRecordVersion;
2105 }
2106 };
2107 }