001
014
015 package com.liferay.portlet.dynamicdatalists.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
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.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.dynamicdatalists.NoSuchRecordVersionException;
042 import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
043 import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordVersionImpl;
044 import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordVersionModelImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class DDLRecordVersionPersistenceImpl extends BasePersistenceImpl<DDLRecordVersion>
065 implements DDLRecordVersionPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = DDLRecordVersionImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
077 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
078 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079 "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
081 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
082 DDLRecordVersionImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
085 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECORDID = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
088 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
089 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090 "findByRecordId",
091 new String[] {
092 Long.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID =
098 new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
099 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
100 DDLRecordVersionImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRecordId",
102 new String[] { Long.class.getName() },
103 DDLRecordVersionModelImpl.RECORDID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_RECORDID = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
105 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRecordId",
107 new String[] { Long.class.getName() });
108
109
116 public List<DDLRecordVersion> findByRecordId(long recordId)
117 throws SystemException {
118 return findByRecordId(recordId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
119 null);
120 }
121
122
135 public List<DDLRecordVersion> findByRecordId(long recordId, int start,
136 int end) throws SystemException {
137 return findByRecordId(recordId, start, end, null);
138 }
139
140
154 public List<DDLRecordVersion> findByRecordId(long recordId, int start,
155 int end, OrderByComparator orderByComparator) throws SystemException {
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 = new UnmodifiableList<DDLRecordVersion>(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
260 public DDLRecordVersion findByRecordId_First(long recordId,
261 OrderByComparator orderByComparator)
262 throws NoSuchRecordVersionException, SystemException {
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
290 public DDLRecordVersion fetchByRecordId_First(long recordId,
291 OrderByComparator orderByComparator) throws SystemException {
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
311 public DDLRecordVersion findByRecordId_Last(long recordId,
312 OrderByComparator orderByComparator)
313 throws NoSuchRecordVersionException, SystemException {
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
341 public DDLRecordVersion fetchByRecordId_Last(long recordId,
342 OrderByComparator orderByComparator) throws SystemException {
343 int count = countByRecordId(recordId);
344
345 List<DDLRecordVersion> list = findByRecordId(recordId, count - 1,
346 count, orderByComparator);
347
348 if (!list.isEmpty()) {
349 return list.get(0);
350 }
351
352 return null;
353 }
354
355
365 public DDLRecordVersion[] findByRecordId_PrevAndNext(long recordVersionId,
366 long recordId, OrderByComparator orderByComparator)
367 throws NoSuchRecordVersionException, SystemException {
368 DDLRecordVersion ddlRecordVersion = findByPrimaryKey(recordVersionId);
369
370 Session session = null;
371
372 try {
373 session = openSession();
374
375 DDLRecordVersion[] array = new DDLRecordVersionImpl[3];
376
377 array[0] = getByRecordId_PrevAndNext(session, ddlRecordVersion,
378 recordId, orderByComparator, true);
379
380 array[1] = ddlRecordVersion;
381
382 array[2] = getByRecordId_PrevAndNext(session, ddlRecordVersion,
383 recordId, orderByComparator, false);
384
385 return array;
386 }
387 catch (Exception e) {
388 throw processException(e);
389 }
390 finally {
391 closeSession(session);
392 }
393 }
394
395 protected DDLRecordVersion getByRecordId_PrevAndNext(Session session,
396 DDLRecordVersion ddlRecordVersion, long recordId,
397 OrderByComparator orderByComparator, boolean previous) {
398 StringBundler query = null;
399
400 if (orderByComparator != null) {
401 query = new StringBundler(6 +
402 (orderByComparator.getOrderByFields().length * 6));
403 }
404 else {
405 query = new StringBundler(3);
406 }
407
408 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
409
410 query.append(_FINDER_COLUMN_RECORDID_RECORDID_2);
411
412 if (orderByComparator != null) {
413 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
414
415 if (orderByConditionFields.length > 0) {
416 query.append(WHERE_AND);
417 }
418
419 for (int i = 0; i < orderByConditionFields.length; i++) {
420 query.append(_ORDER_BY_ENTITY_ALIAS);
421 query.append(orderByConditionFields[i]);
422
423 if ((i + 1) < orderByConditionFields.length) {
424 if (orderByComparator.isAscending() ^ previous) {
425 query.append(WHERE_GREATER_THAN_HAS_NEXT);
426 }
427 else {
428 query.append(WHERE_LESSER_THAN_HAS_NEXT);
429 }
430 }
431 else {
432 if (orderByComparator.isAscending() ^ previous) {
433 query.append(WHERE_GREATER_THAN);
434 }
435 else {
436 query.append(WHERE_LESSER_THAN);
437 }
438 }
439 }
440
441 query.append(ORDER_BY_CLAUSE);
442
443 String[] orderByFields = orderByComparator.getOrderByFields();
444
445 for (int i = 0; i < orderByFields.length; i++) {
446 query.append(_ORDER_BY_ENTITY_ALIAS);
447 query.append(orderByFields[i]);
448
449 if ((i + 1) < orderByFields.length) {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(ORDER_BY_ASC_HAS_NEXT);
452 }
453 else {
454 query.append(ORDER_BY_DESC_HAS_NEXT);
455 }
456 }
457 else {
458 if (orderByComparator.isAscending() ^ previous) {
459 query.append(ORDER_BY_ASC);
460 }
461 else {
462 query.append(ORDER_BY_DESC);
463 }
464 }
465 }
466 }
467 else {
468 query.append(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
469 }
470
471 String sql = query.toString();
472
473 Query q = session.createQuery(sql);
474
475 q.setFirstResult(0);
476 q.setMaxResults(2);
477
478 QueryPos qPos = QueryPos.getInstance(q);
479
480 qPos.add(recordId);
481
482 if (orderByComparator != null) {
483 Object[] values = orderByComparator.getOrderByConditionValues(ddlRecordVersion);
484
485 for (Object value : values) {
486 qPos.add(value);
487 }
488 }
489
490 List<DDLRecordVersion> list = q.list();
491
492 if (list.size() == 2) {
493 return list.get(1);
494 }
495 else {
496 return null;
497 }
498 }
499
500
506 public void removeByRecordId(long recordId) throws SystemException {
507 for (DDLRecordVersion ddlRecordVersion : findByRecordId(recordId,
508 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
509 remove(ddlRecordVersion);
510 }
511 }
512
513
520 public int countByRecordId(long recordId) throws SystemException {
521 FinderPath finderPath = FINDER_PATH_COUNT_BY_RECORDID;
522
523 Object[] finderArgs = new Object[] { recordId };
524
525 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
526 this);
527
528 if (count == null) {
529 StringBundler query = new StringBundler(2);
530
531 query.append(_SQL_COUNT_DDLRECORDVERSION_WHERE);
532
533 query.append(_FINDER_COLUMN_RECORDID_RECORDID_2);
534
535 String sql = query.toString();
536
537 Session session = null;
538
539 try {
540 session = openSession();
541
542 Query q = session.createQuery(sql);
543
544 QueryPos qPos = QueryPos.getInstance(q);
545
546 qPos.add(recordId);
547
548 count = (Long)q.uniqueResult();
549
550 FinderCacheUtil.putResult(finderPath, finderArgs, count);
551 }
552 catch (Exception e) {
553 FinderCacheUtil.removeResult(finderPath, finderArgs);
554
555 throw processException(e);
556 }
557 finally {
558 closeSession(session);
559 }
560 }
561
562 return count.intValue();
563 }
564
565 private static final String _FINDER_COLUMN_RECORDID_RECORDID_2 = "ddlRecordVersion.recordId = ?";
566 public static final FinderPath FINDER_PATH_FETCH_BY_R_V = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
567 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
568 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByR_V",
569 new String[] { Long.class.getName(), String.class.getName() },
570 DDLRecordVersionModelImpl.RECORDID_COLUMN_BITMASK |
571 DDLRecordVersionModelImpl.VERSION_COLUMN_BITMASK);
572 public static final FinderPath FINDER_PATH_COUNT_BY_R_V = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
573 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
574 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_V",
575 new String[] { Long.class.getName(), String.class.getName() });
576
577
586 public DDLRecordVersion findByR_V(long recordId, String version)
587 throws NoSuchRecordVersionException, SystemException {
588 DDLRecordVersion ddlRecordVersion = fetchByR_V(recordId, version);
589
590 if (ddlRecordVersion == null) {
591 StringBundler msg = new StringBundler(6);
592
593 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
594
595 msg.append("recordId=");
596 msg.append(recordId);
597
598 msg.append(", version=");
599 msg.append(version);
600
601 msg.append(StringPool.CLOSE_CURLY_BRACE);
602
603 if (_log.isWarnEnabled()) {
604 _log.warn(msg.toString());
605 }
606
607 throw new NoSuchRecordVersionException(msg.toString());
608 }
609
610 return ddlRecordVersion;
611 }
612
613
621 public DDLRecordVersion fetchByR_V(long recordId, String version)
622 throws SystemException {
623 return fetchByR_V(recordId, version, true);
624 }
625
626
635 public DDLRecordVersion fetchByR_V(long recordId, String version,
636 boolean retrieveFromCache) throws SystemException {
637 Object[] finderArgs = new Object[] { recordId, version };
638
639 Object result = null;
640
641 if (retrieveFromCache) {
642 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_V,
643 finderArgs, this);
644 }
645
646 if (result instanceof DDLRecordVersion) {
647 DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)result;
648
649 if ((recordId != ddlRecordVersion.getRecordId()) ||
650 !Validator.equals(version, ddlRecordVersion.getVersion())) {
651 result = null;
652 }
653 }
654
655 if (result == null) {
656 StringBundler query = new StringBundler(4);
657
658 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
659
660 query.append(_FINDER_COLUMN_R_V_RECORDID_2);
661
662 if (version == null) {
663 query.append(_FINDER_COLUMN_R_V_VERSION_1);
664 }
665 else {
666 if (version.equals(StringPool.BLANK)) {
667 query.append(_FINDER_COLUMN_R_V_VERSION_3);
668 }
669 else {
670 query.append(_FINDER_COLUMN_R_V_VERSION_2);
671 }
672 }
673
674 String sql = query.toString();
675
676 Session session = null;
677
678 try {
679 session = openSession();
680
681 Query q = session.createQuery(sql);
682
683 QueryPos qPos = QueryPos.getInstance(q);
684
685 qPos.add(recordId);
686
687 if (version != null) {
688 qPos.add(version);
689 }
690
691 List<DDLRecordVersion> list = q.list();
692
693 if (list.isEmpty()) {
694 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V,
695 finderArgs, list);
696 }
697 else {
698 DDLRecordVersion ddlRecordVersion = list.get(0);
699
700 result = ddlRecordVersion;
701
702 cacheResult(ddlRecordVersion);
703
704 if ((ddlRecordVersion.getRecordId() != recordId) ||
705 (ddlRecordVersion.getVersion() == null) ||
706 !ddlRecordVersion.getVersion().equals(version)) {
707 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V,
708 finderArgs, ddlRecordVersion);
709 }
710 }
711 }
712 catch (Exception e) {
713 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V,
714 finderArgs);
715
716 throw processException(e);
717 }
718 finally {
719 closeSession(session);
720 }
721 }
722
723 if (result instanceof List<?>) {
724 return null;
725 }
726 else {
727 return (DDLRecordVersion)result;
728 }
729 }
730
731
739 public DDLRecordVersion removeByR_V(long recordId, String version)
740 throws NoSuchRecordVersionException, SystemException {
741 DDLRecordVersion ddlRecordVersion = findByR_V(recordId, version);
742
743 return remove(ddlRecordVersion);
744 }
745
746
754 public int countByR_V(long recordId, String version)
755 throws SystemException {
756 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_V;
757
758 Object[] finderArgs = new Object[] { recordId, version };
759
760 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
761 this);
762
763 if (count == null) {
764 StringBundler query = new StringBundler(3);
765
766 query.append(_SQL_COUNT_DDLRECORDVERSION_WHERE);
767
768 query.append(_FINDER_COLUMN_R_V_RECORDID_2);
769
770 if (version == null) {
771 query.append(_FINDER_COLUMN_R_V_VERSION_1);
772 }
773 else {
774 if (version.equals(StringPool.BLANK)) {
775 query.append(_FINDER_COLUMN_R_V_VERSION_3);
776 }
777 else {
778 query.append(_FINDER_COLUMN_R_V_VERSION_2);
779 }
780 }
781
782 String sql = query.toString();
783
784 Session session = null;
785
786 try {
787 session = openSession();
788
789 Query q = session.createQuery(sql);
790
791 QueryPos qPos = QueryPos.getInstance(q);
792
793 qPos.add(recordId);
794
795 if (version != null) {
796 qPos.add(version);
797 }
798
799 count = (Long)q.uniqueResult();
800
801 FinderCacheUtil.putResult(finderPath, finderArgs, count);
802 }
803 catch (Exception e) {
804 FinderCacheUtil.removeResult(finderPath, finderArgs);
805
806 throw processException(e);
807 }
808 finally {
809 closeSession(session);
810 }
811 }
812
813 return count.intValue();
814 }
815
816 private static final String _FINDER_COLUMN_R_V_RECORDID_2 = "ddlRecordVersion.recordId = ? AND ";
817 private static final String _FINDER_COLUMN_R_V_VERSION_1 = "ddlRecordVersion.version IS NULL";
818 private static final String _FINDER_COLUMN_R_V_VERSION_2 = "ddlRecordVersion.version = ?";
819 private static final String _FINDER_COLUMN_R_V_VERSION_3 = "(ddlRecordVersion.version IS NULL OR ddlRecordVersion.version = ?)";
820 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
821 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
822 DDLRecordVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
823 "findByR_S",
824 new String[] {
825 Long.class.getName(), Integer.class.getName(),
826
827 Integer.class.getName(), Integer.class.getName(),
828 OrderByComparator.class.getName()
829 });
830 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
831 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED,
832 DDLRecordVersionImpl.class,
833 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_S",
834 new String[] { Long.class.getName(), Integer.class.getName() },
835 DDLRecordVersionModelImpl.RECORDID_COLUMN_BITMASK |
836 DDLRecordVersionModelImpl.STATUS_COLUMN_BITMASK);
837 public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
838 DDLRecordVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
839 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_S",
840 new String[] { Long.class.getName(), Integer.class.getName() });
841
842
850 public List<DDLRecordVersion> findByR_S(long recordId, int status)
851 throws SystemException {
852 return findByR_S(recordId, status, QueryUtil.ALL_POS,
853 QueryUtil.ALL_POS, null);
854 }
855
856
870 public List<DDLRecordVersion> findByR_S(long recordId, int status,
871 int start, int end) throws SystemException {
872 return findByR_S(recordId, status, start, end, null);
873 }
874
875
890 public List<DDLRecordVersion> findByR_S(long recordId, int status,
891 int start, int end, OrderByComparator orderByComparator)
892 throws SystemException {
893 boolean pagination = true;
894 FinderPath finderPath = null;
895 Object[] finderArgs = null;
896
897 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
898 (orderByComparator == null)) {
899 pagination = false;
900 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S;
901 finderArgs = new Object[] { recordId, status };
902 }
903 else {
904 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S;
905 finderArgs = new Object[] {
906 recordId, status,
907
908 start, end, orderByComparator
909 };
910 }
911
912 List<DDLRecordVersion> list = (List<DDLRecordVersion>)FinderCacheUtil.getResult(finderPath,
913 finderArgs, this);
914
915 if ((list != null) && !list.isEmpty()) {
916 for (DDLRecordVersion ddlRecordVersion : list) {
917 if ((recordId != ddlRecordVersion.getRecordId()) ||
918 (status != ddlRecordVersion.getStatus())) {
919 list = null;
920
921 break;
922 }
923 }
924 }
925
926 if (list == null) {
927 StringBundler query = null;
928
929 if (orderByComparator != null) {
930 query = new StringBundler(4 +
931 (orderByComparator.getOrderByFields().length * 3));
932 }
933 else {
934 query = new StringBundler(4);
935 }
936
937 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
938
939 query.append(_FINDER_COLUMN_R_S_RECORDID_2);
940
941 query.append(_FINDER_COLUMN_R_S_STATUS_2);
942
943 if (orderByComparator != null) {
944 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
945 orderByComparator);
946 }
947 else
948 if (pagination) {
949 query.append(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
950 }
951
952 String sql = query.toString();
953
954 Session session = null;
955
956 try {
957 session = openSession();
958
959 Query q = session.createQuery(sql);
960
961 QueryPos qPos = QueryPos.getInstance(q);
962
963 qPos.add(recordId);
964
965 qPos.add(status);
966
967 if (!pagination) {
968 list = (List<DDLRecordVersion>)QueryUtil.list(q,
969 getDialect(), start, end, false);
970
971 Collections.sort(list);
972
973 list = new UnmodifiableList<DDLRecordVersion>(list);
974 }
975 else {
976 list = (List<DDLRecordVersion>)QueryUtil.list(q,
977 getDialect(), start, end);
978 }
979
980 cacheResult(list);
981
982 FinderCacheUtil.putResult(finderPath, finderArgs, list);
983 }
984 catch (Exception e) {
985 FinderCacheUtil.removeResult(finderPath, finderArgs);
986
987 throw processException(e);
988 }
989 finally {
990 closeSession(session);
991 }
992 }
993
994 return list;
995 }
996
997
1007 public DDLRecordVersion findByR_S_First(long recordId, int status,
1008 OrderByComparator orderByComparator)
1009 throws NoSuchRecordVersionException, SystemException {
1010 DDLRecordVersion ddlRecordVersion = fetchByR_S_First(recordId, status,
1011 orderByComparator);
1012
1013 if (ddlRecordVersion != null) {
1014 return ddlRecordVersion;
1015 }
1016
1017 StringBundler msg = new StringBundler(6);
1018
1019 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1020
1021 msg.append("recordId=");
1022 msg.append(recordId);
1023
1024 msg.append(", status=");
1025 msg.append(status);
1026
1027 msg.append(StringPool.CLOSE_CURLY_BRACE);
1028
1029 throw new NoSuchRecordVersionException(msg.toString());
1030 }
1031
1032
1041 public DDLRecordVersion fetchByR_S_First(long recordId, int status,
1042 OrderByComparator orderByComparator) throws SystemException {
1043 List<DDLRecordVersion> list = findByR_S(recordId, status, 0, 1,
1044 orderByComparator);
1045
1046 if (!list.isEmpty()) {
1047 return list.get(0);
1048 }
1049
1050 return null;
1051 }
1052
1053
1063 public DDLRecordVersion findByR_S_Last(long recordId, int status,
1064 OrderByComparator orderByComparator)
1065 throws NoSuchRecordVersionException, SystemException {
1066 DDLRecordVersion ddlRecordVersion = fetchByR_S_Last(recordId, status,
1067 orderByComparator);
1068
1069 if (ddlRecordVersion != null) {
1070 return ddlRecordVersion;
1071 }
1072
1073 StringBundler msg = new StringBundler(6);
1074
1075 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1076
1077 msg.append("recordId=");
1078 msg.append(recordId);
1079
1080 msg.append(", status=");
1081 msg.append(status);
1082
1083 msg.append(StringPool.CLOSE_CURLY_BRACE);
1084
1085 throw new NoSuchRecordVersionException(msg.toString());
1086 }
1087
1088
1097 public DDLRecordVersion fetchByR_S_Last(long recordId, int status,
1098 OrderByComparator orderByComparator) throws SystemException {
1099 int count = countByR_S(recordId, status);
1100
1101 List<DDLRecordVersion> list = findByR_S(recordId, status, count - 1,
1102 count, orderByComparator);
1103
1104 if (!list.isEmpty()) {
1105 return list.get(0);
1106 }
1107
1108 return null;
1109 }
1110
1111
1122 public DDLRecordVersion[] findByR_S_PrevAndNext(long recordVersionId,
1123 long recordId, int status, OrderByComparator orderByComparator)
1124 throws NoSuchRecordVersionException, SystemException {
1125 DDLRecordVersion ddlRecordVersion = findByPrimaryKey(recordVersionId);
1126
1127 Session session = null;
1128
1129 try {
1130 session = openSession();
1131
1132 DDLRecordVersion[] array = new DDLRecordVersionImpl[3];
1133
1134 array[0] = getByR_S_PrevAndNext(session, ddlRecordVersion,
1135 recordId, status, orderByComparator, true);
1136
1137 array[1] = ddlRecordVersion;
1138
1139 array[2] = getByR_S_PrevAndNext(session, ddlRecordVersion,
1140 recordId, status, orderByComparator, false);
1141
1142 return array;
1143 }
1144 catch (Exception e) {
1145 throw processException(e);
1146 }
1147 finally {
1148 closeSession(session);
1149 }
1150 }
1151
1152 protected DDLRecordVersion getByR_S_PrevAndNext(Session session,
1153 DDLRecordVersion ddlRecordVersion, long recordId, int status,
1154 OrderByComparator orderByComparator, boolean previous) {
1155 StringBundler query = null;
1156
1157 if (orderByComparator != null) {
1158 query = new StringBundler(6 +
1159 (orderByComparator.getOrderByFields().length * 6));
1160 }
1161 else {
1162 query = new StringBundler(3);
1163 }
1164
1165 query.append(_SQL_SELECT_DDLRECORDVERSION_WHERE);
1166
1167 query.append(_FINDER_COLUMN_R_S_RECORDID_2);
1168
1169 query.append(_FINDER_COLUMN_R_S_STATUS_2);
1170
1171 if (orderByComparator != null) {
1172 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1173
1174 if (orderByConditionFields.length > 0) {
1175 query.append(WHERE_AND);
1176 }
1177
1178 for (int i = 0; i < orderByConditionFields.length; i++) {
1179 query.append(_ORDER_BY_ENTITY_ALIAS);
1180 query.append(orderByConditionFields[i]);
1181
1182 if ((i + 1) < orderByConditionFields.length) {
1183 if (orderByComparator.isAscending() ^ previous) {
1184 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1185 }
1186 else {
1187 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1188 }
1189 }
1190 else {
1191 if (orderByComparator.isAscending() ^ previous) {
1192 query.append(WHERE_GREATER_THAN);
1193 }
1194 else {
1195 query.append(WHERE_LESSER_THAN);
1196 }
1197 }
1198 }
1199
1200 query.append(ORDER_BY_CLAUSE);
1201
1202 String[] orderByFields = orderByComparator.getOrderByFields();
1203
1204 for (int i = 0; i < orderByFields.length; i++) {
1205 query.append(_ORDER_BY_ENTITY_ALIAS);
1206 query.append(orderByFields[i]);
1207
1208 if ((i + 1) < orderByFields.length) {
1209 if (orderByComparator.isAscending() ^ previous) {
1210 query.append(ORDER_BY_ASC_HAS_NEXT);
1211 }
1212 else {
1213 query.append(ORDER_BY_DESC_HAS_NEXT);
1214 }
1215 }
1216 else {
1217 if (orderByComparator.isAscending() ^ previous) {
1218 query.append(ORDER_BY_ASC);
1219 }
1220 else {
1221 query.append(ORDER_BY_DESC);
1222 }
1223 }
1224 }
1225 }
1226 else {
1227 query.append(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
1228 }
1229
1230 String sql = query.toString();
1231
1232 Query q = session.createQuery(sql);
1233
1234 q.setFirstResult(0);
1235 q.setMaxResults(2);
1236
1237 QueryPos qPos = QueryPos.getInstance(q);
1238
1239 qPos.add(recordId);
1240
1241 qPos.add(status);
1242
1243 if (orderByComparator != null) {
1244 Object[] values = orderByComparator.getOrderByConditionValues(ddlRecordVersion);
1245
1246 for (Object value : values) {
1247 qPos.add(value);
1248 }
1249 }
1250
1251 List<DDLRecordVersion> list = q.list();
1252
1253 if (list.size() == 2) {
1254 return list.get(1);
1255 }
1256 else {
1257 return null;
1258 }
1259 }
1260
1261
1268 public void removeByR_S(long recordId, int status)
1269 throws SystemException {
1270 for (DDLRecordVersion ddlRecordVersion : findByR_S(recordId, status,
1271 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1272 remove(ddlRecordVersion);
1273 }
1274 }
1275
1276
1284 public int countByR_S(long recordId, int status) throws SystemException {
1285 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_S;
1286
1287 Object[] finderArgs = new Object[] { recordId, status };
1288
1289 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1290 this);
1291
1292 if (count == null) {
1293 StringBundler query = new StringBundler(3);
1294
1295 query.append(_SQL_COUNT_DDLRECORDVERSION_WHERE);
1296
1297 query.append(_FINDER_COLUMN_R_S_RECORDID_2);
1298
1299 query.append(_FINDER_COLUMN_R_S_STATUS_2);
1300
1301 String sql = query.toString();
1302
1303 Session session = null;
1304
1305 try {
1306 session = openSession();
1307
1308 Query q = session.createQuery(sql);
1309
1310 QueryPos qPos = QueryPos.getInstance(q);
1311
1312 qPos.add(recordId);
1313
1314 qPos.add(status);
1315
1316 count = (Long)q.uniqueResult();
1317
1318 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1319 }
1320 catch (Exception e) {
1321 FinderCacheUtil.removeResult(finderPath, finderArgs);
1322
1323 throw processException(e);
1324 }
1325 finally {
1326 closeSession(session);
1327 }
1328 }
1329
1330 return count.intValue();
1331 }
1332
1333 private static final String _FINDER_COLUMN_R_S_RECORDID_2 = "ddlRecordVersion.recordId = ? AND ";
1334 private static final String _FINDER_COLUMN_R_S_STATUS_2 = "ddlRecordVersion.status = ?";
1335
1336
1341 public void cacheResult(DDLRecordVersion ddlRecordVersion) {
1342 EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1343 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey(),
1344 ddlRecordVersion);
1345
1346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V,
1347 new Object[] {
1348 Long.valueOf(ddlRecordVersion.getRecordId()),
1349
1350 ddlRecordVersion.getVersion()
1351 }, ddlRecordVersion);
1352
1353 ddlRecordVersion.resetOriginalValues();
1354 }
1355
1356
1361 public void cacheResult(List<DDLRecordVersion> ddlRecordVersions) {
1362 for (DDLRecordVersion ddlRecordVersion : ddlRecordVersions) {
1363 if (EntityCacheUtil.getResult(
1364 DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1365 DDLRecordVersionImpl.class,
1366 ddlRecordVersion.getPrimaryKey()) == null) {
1367 cacheResult(ddlRecordVersion);
1368 }
1369 else {
1370 ddlRecordVersion.resetOriginalValues();
1371 }
1372 }
1373 }
1374
1375
1382 @Override
1383 public void clearCache() {
1384 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1385 CacheRegistryUtil.clear(DDLRecordVersionImpl.class.getName());
1386 }
1387
1388 EntityCacheUtil.clearCache(DDLRecordVersionImpl.class.getName());
1389
1390 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1391 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1392 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1393 }
1394
1395
1402 @Override
1403 public void clearCache(DDLRecordVersion ddlRecordVersion) {
1404 EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1405 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey());
1406
1407 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1408 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1409
1410 clearUniqueFindersCache(ddlRecordVersion);
1411 }
1412
1413 @Override
1414 public void clearCache(List<DDLRecordVersion> ddlRecordVersions) {
1415 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1416 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1417
1418 for (DDLRecordVersion ddlRecordVersion : ddlRecordVersions) {
1419 EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1420 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey());
1421
1422 clearUniqueFindersCache(ddlRecordVersion);
1423 }
1424 }
1425
1426 protected void cacheUniqueFindersCache(DDLRecordVersion ddlRecordVersion) {
1427 if (ddlRecordVersion.isNew()) {
1428 Object[] args = new Object[] {
1429 Long.valueOf(ddlRecordVersion.getRecordId()),
1430
1431 ddlRecordVersion.getVersion()
1432 };
1433
1434 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_V, args,
1435 Long.valueOf(1));
1436 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V, args,
1437 ddlRecordVersion);
1438 }
1439 else {
1440 DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1441
1442 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1443 FINDER_PATH_FETCH_BY_R_V.getColumnBitmask()) != 0) {
1444 Object[] args = new Object[] {
1445 Long.valueOf(ddlRecordVersion.getRecordId()),
1446
1447 ddlRecordVersion.getVersion()
1448 };
1449
1450 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_V, args,
1451 Long.valueOf(1));
1452 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V, args,
1453 ddlRecordVersion);
1454 }
1455 }
1456 }
1457
1458 protected void clearUniqueFindersCache(DDLRecordVersion ddlRecordVersion) {
1459 DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1460
1461 Object[] args = new Object[] {
1462 Long.valueOf(ddlRecordVersion.getRecordId()),
1463
1464 ddlRecordVersion.getVersion()
1465 };
1466
1467 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_V, args);
1468 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V, args);
1469
1470 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1471 FINDER_PATH_FETCH_BY_R_V.getColumnBitmask()) != 0) {
1472 args = new Object[] {
1473 Long.valueOf(ddlRecordVersionModelImpl.getOriginalRecordId()),
1474
1475 ddlRecordVersionModelImpl.getOriginalVersion()
1476 };
1477
1478 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_V, args);
1479 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V, args);
1480 }
1481 }
1482
1483
1489 public DDLRecordVersion create(long recordVersionId) {
1490 DDLRecordVersion ddlRecordVersion = new DDLRecordVersionImpl();
1491
1492 ddlRecordVersion.setNew(true);
1493 ddlRecordVersion.setPrimaryKey(recordVersionId);
1494
1495 return ddlRecordVersion;
1496 }
1497
1498
1506 public DDLRecordVersion remove(long recordVersionId)
1507 throws NoSuchRecordVersionException, SystemException {
1508 return remove(Long.valueOf(recordVersionId));
1509 }
1510
1511
1519 @Override
1520 public DDLRecordVersion remove(Serializable primaryKey)
1521 throws NoSuchRecordVersionException, SystemException {
1522 Session session = null;
1523
1524 try {
1525 session = openSession();
1526
1527 DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1528 primaryKey);
1529
1530 if (ddlRecordVersion == null) {
1531 if (_log.isWarnEnabled()) {
1532 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1533 }
1534
1535 throw new NoSuchRecordVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1536 primaryKey);
1537 }
1538
1539 return remove(ddlRecordVersion);
1540 }
1541 catch (NoSuchRecordVersionException nsee) {
1542 throw nsee;
1543 }
1544 catch (Exception e) {
1545 throw processException(e);
1546 }
1547 finally {
1548 closeSession(session);
1549 }
1550 }
1551
1552 @Override
1553 protected DDLRecordVersion removeImpl(DDLRecordVersion ddlRecordVersion)
1554 throws SystemException {
1555 ddlRecordVersion = toUnwrappedModel(ddlRecordVersion);
1556
1557 Session session = null;
1558
1559 try {
1560 session = openSession();
1561
1562 if (!session.contains(ddlRecordVersion)) {
1563 ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1564 ddlRecordVersion.getPrimaryKeyObj());
1565 }
1566
1567 if (ddlRecordVersion != null) {
1568 session.delete(ddlRecordVersion);
1569 }
1570 }
1571 catch (Exception e) {
1572 throw processException(e);
1573 }
1574 finally {
1575 closeSession(session);
1576 }
1577
1578 if (ddlRecordVersion != null) {
1579 clearCache(ddlRecordVersion);
1580 }
1581
1582 return ddlRecordVersion;
1583 }
1584
1585 @Override
1586 public DDLRecordVersion updateImpl(
1587 com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion ddlRecordVersion)
1588 throws SystemException {
1589 ddlRecordVersion = toUnwrappedModel(ddlRecordVersion);
1590
1591 boolean isNew = ddlRecordVersion.isNew();
1592
1593 DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1594
1595 Session session = null;
1596
1597 try {
1598 session = openSession();
1599
1600 if (ddlRecordVersion.isNew()) {
1601 session.save(ddlRecordVersion);
1602
1603 ddlRecordVersion.setNew(false);
1604 }
1605 else {
1606 session.merge(ddlRecordVersion);
1607 }
1608 }
1609 catch (Exception e) {
1610 throw processException(e);
1611 }
1612 finally {
1613 closeSession(session);
1614 }
1615
1616 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1617
1618 if (isNew || !DDLRecordVersionModelImpl.COLUMN_BITMASK_ENABLED) {
1619 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1620 }
1621
1622 else {
1623 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1624 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID.getColumnBitmask()) != 0) {
1625 Object[] args = new Object[] {
1626 Long.valueOf(ddlRecordVersionModelImpl.getOriginalRecordId())
1627 };
1628
1629 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDID, args);
1630 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID,
1631 args);
1632
1633 args = new Object[] {
1634 Long.valueOf(ddlRecordVersionModelImpl.getRecordId())
1635 };
1636
1637 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDID, args);
1638 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID,
1639 args);
1640 }
1641
1642 if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1643 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
1644 Object[] args = new Object[] {
1645 Long.valueOf(ddlRecordVersionModelImpl.getOriginalRecordId()),
1646 Integer.valueOf(ddlRecordVersionModelImpl.getOriginalStatus())
1647 };
1648
1649 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
1650 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
1651 args);
1652
1653 args = new Object[] {
1654 Long.valueOf(ddlRecordVersionModelImpl.getRecordId()),
1655 Integer.valueOf(ddlRecordVersionModelImpl.getStatus())
1656 };
1657
1658 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
1659 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
1660 args);
1661 }
1662 }
1663
1664 EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1665 DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey(),
1666 ddlRecordVersion);
1667
1668 clearUniqueFindersCache(ddlRecordVersion);
1669 cacheUniqueFindersCache(ddlRecordVersion);
1670
1671 return ddlRecordVersion;
1672 }
1673
1674 protected DDLRecordVersion toUnwrappedModel(
1675 DDLRecordVersion ddlRecordVersion) {
1676 if (ddlRecordVersion instanceof DDLRecordVersionImpl) {
1677 return ddlRecordVersion;
1678 }
1679
1680 DDLRecordVersionImpl ddlRecordVersionImpl = new DDLRecordVersionImpl();
1681
1682 ddlRecordVersionImpl.setNew(ddlRecordVersion.isNew());
1683 ddlRecordVersionImpl.setPrimaryKey(ddlRecordVersion.getPrimaryKey());
1684
1685 ddlRecordVersionImpl.setRecordVersionId(ddlRecordVersion.getRecordVersionId());
1686 ddlRecordVersionImpl.setGroupId(ddlRecordVersion.getGroupId());
1687 ddlRecordVersionImpl.setCompanyId(ddlRecordVersion.getCompanyId());
1688 ddlRecordVersionImpl.setUserId(ddlRecordVersion.getUserId());
1689 ddlRecordVersionImpl.setUserName(ddlRecordVersion.getUserName());
1690 ddlRecordVersionImpl.setCreateDate(ddlRecordVersion.getCreateDate());
1691 ddlRecordVersionImpl.setDDMStorageId(ddlRecordVersion.getDDMStorageId());
1692 ddlRecordVersionImpl.setRecordSetId(ddlRecordVersion.getRecordSetId());
1693 ddlRecordVersionImpl.setRecordId(ddlRecordVersion.getRecordId());
1694 ddlRecordVersionImpl.setVersion(ddlRecordVersion.getVersion());
1695 ddlRecordVersionImpl.setDisplayIndex(ddlRecordVersion.getDisplayIndex());
1696 ddlRecordVersionImpl.setStatus(ddlRecordVersion.getStatus());
1697 ddlRecordVersionImpl.setStatusByUserId(ddlRecordVersion.getStatusByUserId());
1698 ddlRecordVersionImpl.setStatusByUserName(ddlRecordVersion.getStatusByUserName());
1699 ddlRecordVersionImpl.setStatusDate(ddlRecordVersion.getStatusDate());
1700
1701 return ddlRecordVersionImpl;
1702 }
1703
1704
1712 @Override
1713 public DDLRecordVersion findByPrimaryKey(Serializable primaryKey)
1714 throws NoSuchModelException, SystemException {
1715 return findByPrimaryKey(((Long)primaryKey).longValue());
1716 }
1717
1718
1726 public DDLRecordVersion findByPrimaryKey(long recordVersionId)
1727 throws NoSuchRecordVersionException, SystemException {
1728 DDLRecordVersion ddlRecordVersion = fetchByPrimaryKey(recordVersionId);
1729
1730 if (ddlRecordVersion == null) {
1731 if (_log.isWarnEnabled()) {
1732 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + recordVersionId);
1733 }
1734
1735 throw new NoSuchRecordVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1736 recordVersionId);
1737 }
1738
1739 return ddlRecordVersion;
1740 }
1741
1742
1749 @Override
1750 public DDLRecordVersion fetchByPrimaryKey(Serializable primaryKey)
1751 throws SystemException {
1752 return fetchByPrimaryKey(((Long)primaryKey).longValue());
1753 }
1754
1755
1762 public DDLRecordVersion fetchByPrimaryKey(long recordVersionId)
1763 throws SystemException {
1764 DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)EntityCacheUtil.getResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1765 DDLRecordVersionImpl.class, recordVersionId);
1766
1767 if (ddlRecordVersion == _nullDDLRecordVersion) {
1768 return null;
1769 }
1770
1771 if (ddlRecordVersion == null) {
1772 Session session = null;
1773
1774 try {
1775 session = openSession();
1776
1777 ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1778 Long.valueOf(recordVersionId));
1779
1780 if (ddlRecordVersion != null) {
1781 cacheResult(ddlRecordVersion);
1782 }
1783 else {
1784 EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1785 DDLRecordVersionImpl.class, recordVersionId,
1786 _nullDDLRecordVersion);
1787 }
1788 }
1789 catch (Exception e) {
1790 EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1791 DDLRecordVersionImpl.class, recordVersionId);
1792
1793 throw processException(e);
1794 }
1795 finally {
1796 closeSession(session);
1797 }
1798 }
1799
1800 return ddlRecordVersion;
1801 }
1802
1803
1809 public List<DDLRecordVersion> findAll() throws SystemException {
1810 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1811 }
1812
1813
1825 public List<DDLRecordVersion> findAll(int start, int end)
1826 throws SystemException {
1827 return findAll(start, end, null);
1828 }
1829
1830
1843 public List<DDLRecordVersion> findAll(int start, int end,
1844 OrderByComparator orderByComparator) throws SystemException {
1845 boolean pagination = true;
1846 FinderPath finderPath = null;
1847 Object[] finderArgs = null;
1848
1849 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1850 (orderByComparator == null)) {
1851 pagination = false;
1852 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1853 finderArgs = FINDER_ARGS_EMPTY;
1854 }
1855 else {
1856 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1857 finderArgs = new Object[] { start, end, orderByComparator };
1858 }
1859
1860 List<DDLRecordVersion> list = (List<DDLRecordVersion>)FinderCacheUtil.getResult(finderPath,
1861 finderArgs, this);
1862
1863 if (list == null) {
1864 StringBundler query = null;
1865 String sql = null;
1866
1867 if (orderByComparator != null) {
1868 query = new StringBundler(2 +
1869 (orderByComparator.getOrderByFields().length * 3));
1870
1871 query.append(_SQL_SELECT_DDLRECORDVERSION);
1872
1873 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1874 orderByComparator);
1875
1876 sql = query.toString();
1877 }
1878 else {
1879 sql = _SQL_SELECT_DDLRECORDVERSION;
1880
1881 if (pagination) {
1882 sql = sql.concat(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
1883 }
1884 }
1885
1886 Session session = null;
1887
1888 try {
1889 session = openSession();
1890
1891 Query q = session.createQuery(sql);
1892
1893 if (!pagination) {
1894 list = (List<DDLRecordVersion>)QueryUtil.list(q,
1895 getDialect(), start, end, false);
1896
1897 Collections.sort(list);
1898
1899 list = new UnmodifiableList<DDLRecordVersion>(list);
1900 }
1901 else {
1902 list = (List<DDLRecordVersion>)QueryUtil.list(q,
1903 getDialect(), start, end);
1904 }
1905
1906 cacheResult(list);
1907
1908 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1909 }
1910 catch (Exception e) {
1911 FinderCacheUtil.removeResult(finderPath, finderArgs);
1912
1913 throw processException(e);
1914 }
1915 finally {
1916 closeSession(session);
1917 }
1918 }
1919
1920 return list;
1921 }
1922
1923
1928 public void removeAll() throws SystemException {
1929 for (DDLRecordVersion ddlRecordVersion : findAll()) {
1930 remove(ddlRecordVersion);
1931 }
1932 }
1933
1934
1940 public int countAll() throws SystemException {
1941 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1942 FINDER_ARGS_EMPTY, this);
1943
1944 if (count == null) {
1945 Session session = null;
1946
1947 try {
1948 session = openSession();
1949
1950 Query q = session.createQuery(_SQL_COUNT_DDLRECORDVERSION);
1951
1952 count = (Long)q.uniqueResult();
1953
1954 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1955 FINDER_ARGS_EMPTY, count);
1956 }
1957 catch (Exception e) {
1958 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1959 FINDER_ARGS_EMPTY);
1960
1961 throw processException(e);
1962 }
1963 finally {
1964 closeSession(session);
1965 }
1966 }
1967
1968 return count.intValue();
1969 }
1970
1971
1974 public void afterPropertiesSet() {
1975 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1976 com.liferay.portal.util.PropsUtil.get(
1977 "value.object.listener.com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion")));
1978
1979 if (listenerClassNames.length > 0) {
1980 try {
1981 List<ModelListener<DDLRecordVersion>> listenersList = new ArrayList<ModelListener<DDLRecordVersion>>();
1982
1983 for (String listenerClassName : listenerClassNames) {
1984 listenersList.add((ModelListener<DDLRecordVersion>)InstanceFactory.newInstance(
1985 listenerClassName));
1986 }
1987
1988 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1989 }
1990 catch (Exception e) {
1991 _log.error(e);
1992 }
1993 }
1994 }
1995
1996 public void destroy() {
1997 EntityCacheUtil.removeCache(DDLRecordVersionImpl.class.getName());
1998 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1999 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2000 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2001 }
2002
2003 private static final String _SQL_SELECT_DDLRECORDVERSION = "SELECT ddlRecordVersion FROM DDLRecordVersion ddlRecordVersion";
2004 private static final String _SQL_SELECT_DDLRECORDVERSION_WHERE = "SELECT ddlRecordVersion FROM DDLRecordVersion ddlRecordVersion WHERE ";
2005 private static final String _SQL_COUNT_DDLRECORDVERSION = "SELECT COUNT(ddlRecordVersion) FROM DDLRecordVersion ddlRecordVersion";
2006 private static final String _SQL_COUNT_DDLRECORDVERSION_WHERE = "SELECT COUNT(ddlRecordVersion) FROM DDLRecordVersion ddlRecordVersion WHERE ";
2007 private static final String _ORDER_BY_ENTITY_ALIAS = "ddlRecordVersion.";
2008 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDLRecordVersion exists with the primary key ";
2009 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDLRecordVersion exists with the key {";
2010 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2011 private static Log _log = LogFactoryUtil.getLog(DDLRecordVersionPersistenceImpl.class);
2012 private static DDLRecordVersion _nullDDLRecordVersion = new DDLRecordVersionImpl() {
2013 @Override
2014 public Object clone() {
2015 return this;
2016 }
2017
2018 @Override
2019 public CacheModel<DDLRecordVersion> toCacheModel() {
2020 return _nullDDLRecordVersionCacheModel;
2021 }
2022 };
2023
2024 private static CacheModel<DDLRecordVersion> _nullDDLRecordVersionCacheModel = new CacheModel<DDLRecordVersion>() {
2025 public DDLRecordVersion toEntityModel() {
2026 return _nullDDLRecordVersion;
2027 }
2028 };
2029 }