001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
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.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039
040 import com.liferay.portlet.expando.NoSuchRowException;
041 import com.liferay.portlet.expando.model.ExpandoRow;
042 import com.liferay.portlet.expando.model.impl.ExpandoRowImpl;
043 import com.liferay.portlet.expando.model.impl.ExpandoRowModelImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050 import java.util.Set;
051
052
064 public class ExpandoRowPersistenceImpl extends BasePersistenceImpl<ExpandoRow>
065 implements ExpandoRowPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoRowImpl.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(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
077 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
080 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
083 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
086 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTableId",
088 new String[] {
089 Long.class.getName(),
090
091 Integer.class.getName(), Integer.class.getName(),
092 OrderByComparator.class.getName()
093 });
094 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
095 new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
096 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTableId",
098 new String[] { Long.class.getName() },
099 ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
101 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
103 new String[] { Long.class.getName() });
104
105
112 @Override
113 public List<ExpandoRow> findByTableId(long tableId)
114 throws SystemException {
115 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116 }
117
118
131 @Override
132 public List<ExpandoRow> findByTableId(long tableId, int start, int end)
133 throws SystemException {
134 return findByTableId(tableId, start, end, null);
135 }
136
137
151 @Override
152 public List<ExpandoRow> findByTableId(long tableId, int start, int end,
153 OrderByComparator orderByComparator) throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
162 finderArgs = new Object[] { tableId };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
166 finderArgs = new Object[] { tableId, start, end, orderByComparator };
167 }
168
169 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
170 finderArgs, this);
171
172 if ((list != null) && !list.isEmpty()) {
173 for (ExpandoRow expandoRow : list) {
174 if ((tableId != expandoRow.getTableId())) {
175 list = null;
176
177 break;
178 }
179 }
180 }
181
182 if (list == null) {
183 StringBundler query = null;
184
185 if (orderByComparator != null) {
186 query = new StringBundler(3 +
187 (orderByComparator.getOrderByFields().length * 3));
188 }
189 else {
190 query = new StringBundler(3);
191 }
192
193 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
194
195 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
196
197 if (orderByComparator != null) {
198 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
199 orderByComparator);
200 }
201 else
202 if (pagination) {
203 query.append(ExpandoRowModelImpl.ORDER_BY_JPQL);
204 }
205
206 String sql = query.toString();
207
208 Session session = null;
209
210 try {
211 session = openSession();
212
213 Query q = session.createQuery(sql);
214
215 QueryPos qPos = QueryPos.getInstance(q);
216
217 qPos.add(tableId);
218
219 if (!pagination) {
220 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
221 start, end, false);
222
223 Collections.sort(list);
224
225 list = new UnmodifiableList<ExpandoRow>(list);
226 }
227 else {
228 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
229 start, end);
230 }
231
232 cacheResult(list);
233
234 FinderCacheUtil.putResult(finderPath, finderArgs, list);
235 }
236 catch (Exception e) {
237 FinderCacheUtil.removeResult(finderPath, finderArgs);
238
239 throw processException(e);
240 }
241 finally {
242 closeSession(session);
243 }
244 }
245
246 return list;
247 }
248
249
258 @Override
259 public ExpandoRow findByTableId_First(long tableId,
260 OrderByComparator orderByComparator)
261 throws NoSuchRowException, SystemException {
262 ExpandoRow expandoRow = fetchByTableId_First(tableId, orderByComparator);
263
264 if (expandoRow != null) {
265 return expandoRow;
266 }
267
268 StringBundler msg = new StringBundler(4);
269
270 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
271
272 msg.append("tableId=");
273 msg.append(tableId);
274
275 msg.append(StringPool.CLOSE_CURLY_BRACE);
276
277 throw new NoSuchRowException(msg.toString());
278 }
279
280
288 @Override
289 public ExpandoRow fetchByTableId_First(long tableId,
290 OrderByComparator orderByComparator) throws SystemException {
291 List<ExpandoRow> list = findByTableId(tableId, 0, 1, orderByComparator);
292
293 if (!list.isEmpty()) {
294 return list.get(0);
295 }
296
297 return null;
298 }
299
300
309 @Override
310 public ExpandoRow findByTableId_Last(long tableId,
311 OrderByComparator orderByComparator)
312 throws NoSuchRowException, SystemException {
313 ExpandoRow expandoRow = fetchByTableId_Last(tableId, orderByComparator);
314
315 if (expandoRow != null) {
316 return expandoRow;
317 }
318
319 StringBundler msg = new StringBundler(4);
320
321 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322
323 msg.append("tableId=");
324 msg.append(tableId);
325
326 msg.append(StringPool.CLOSE_CURLY_BRACE);
327
328 throw new NoSuchRowException(msg.toString());
329 }
330
331
339 @Override
340 public ExpandoRow fetchByTableId_Last(long tableId,
341 OrderByComparator orderByComparator) throws SystemException {
342 int count = countByTableId(tableId);
343
344 if (count == 0) {
345 return null;
346 }
347
348 List<ExpandoRow> list = findByTableId(tableId, count - 1, count,
349 orderByComparator);
350
351 if (!list.isEmpty()) {
352 return list.get(0);
353 }
354
355 return null;
356 }
357
358
368 @Override
369 public ExpandoRow[] findByTableId_PrevAndNext(long rowId, long tableId,
370 OrderByComparator orderByComparator)
371 throws NoSuchRowException, SystemException {
372 ExpandoRow expandoRow = findByPrimaryKey(rowId);
373
374 Session session = null;
375
376 try {
377 session = openSession();
378
379 ExpandoRow[] array = new ExpandoRowImpl[3];
380
381 array[0] = getByTableId_PrevAndNext(session, expandoRow, tableId,
382 orderByComparator, true);
383
384 array[1] = expandoRow;
385
386 array[2] = getByTableId_PrevAndNext(session, expandoRow, tableId,
387 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 ExpandoRow getByTableId_PrevAndNext(Session session,
400 ExpandoRow expandoRow, long tableId,
401 OrderByComparator 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_EXPANDOROW_WHERE);
413
414 query.append(_FINDER_COLUMN_TABLEID_TABLEID_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(ExpandoRowModelImpl.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(tableId);
485
486 if (orderByComparator != null) {
487 Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
488
489 for (Object value : values) {
490 qPos.add(value);
491 }
492 }
493
494 List<ExpandoRow> list = q.list();
495
496 if (list.size() == 2) {
497 return list.get(1);
498 }
499 else {
500 return null;
501 }
502 }
503
504
510 @Override
511 public void removeByTableId(long tableId) throws SystemException {
512 for (ExpandoRow expandoRow : findByTableId(tableId, QueryUtil.ALL_POS,
513 QueryUtil.ALL_POS, null)) {
514 remove(expandoRow);
515 }
516 }
517
518
525 @Override
526 public int countByTableId(long tableId) throws SystemException {
527 FinderPath finderPath = FINDER_PATH_COUNT_BY_TABLEID;
528
529 Object[] finderArgs = new Object[] { tableId };
530
531 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
532 this);
533
534 if (count == null) {
535 StringBundler query = new StringBundler(2);
536
537 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
538
539 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
540
541 String sql = query.toString();
542
543 Session session = null;
544
545 try {
546 session = openSession();
547
548 Query q = session.createQuery(sql);
549
550 QueryPos qPos = QueryPos.getInstance(q);
551
552 qPos.add(tableId);
553
554 count = (Long)q.uniqueResult();
555
556 FinderCacheUtil.putResult(finderPath, finderArgs, count);
557 }
558 catch (Exception e) {
559 FinderCacheUtil.removeResult(finderPath, finderArgs);
560
561 throw processException(e);
562 }
563 finally {
564 closeSession(session);
565 }
566 }
567
568 return count.intValue();
569 }
570
571 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoRow.tableId = ?";
572 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
573 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
574 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassPK",
575 new String[] {
576 Long.class.getName(),
577
578 Integer.class.getName(), Integer.class.getName(),
579 OrderByComparator.class.getName()
580 });
581 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK =
582 new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
583 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
584 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassPK",
585 new String[] { Long.class.getName() },
586 ExpandoRowModelImpl.CLASSPK_COLUMN_BITMASK);
587 public static final FinderPath FINDER_PATH_COUNT_BY_CLASSPK = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
588 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
589 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassPK",
590 new String[] { Long.class.getName() });
591
592
599 @Override
600 public List<ExpandoRow> findByClassPK(long classPK)
601 throws SystemException {
602 return findByClassPK(classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
603 }
604
605
618 @Override
619 public List<ExpandoRow> findByClassPK(long classPK, int start, int end)
620 throws SystemException {
621 return findByClassPK(classPK, start, end, null);
622 }
623
624
638 @Override
639 public List<ExpandoRow> findByClassPK(long classPK, int start, int end,
640 OrderByComparator orderByComparator) throws SystemException {
641 boolean pagination = true;
642 FinderPath finderPath = null;
643 Object[] finderArgs = null;
644
645 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
646 (orderByComparator == null)) {
647 pagination = false;
648 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK;
649 finderArgs = new Object[] { classPK };
650 }
651 else {
652 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK;
653 finderArgs = new Object[] { classPK, start, end, orderByComparator };
654 }
655
656 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
657 finderArgs, this);
658
659 if ((list != null) && !list.isEmpty()) {
660 for (ExpandoRow expandoRow : list) {
661 if ((classPK != expandoRow.getClassPK())) {
662 list = null;
663
664 break;
665 }
666 }
667 }
668
669 if (list == null) {
670 StringBundler query = null;
671
672 if (orderByComparator != null) {
673 query = new StringBundler(3 +
674 (orderByComparator.getOrderByFields().length * 3));
675 }
676 else {
677 query = new StringBundler(3);
678 }
679
680 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
681
682 query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
683
684 if (orderByComparator != null) {
685 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
686 orderByComparator);
687 }
688 else
689 if (pagination) {
690 query.append(ExpandoRowModelImpl.ORDER_BY_JPQL);
691 }
692
693 String sql = query.toString();
694
695 Session session = null;
696
697 try {
698 session = openSession();
699
700 Query q = session.createQuery(sql);
701
702 QueryPos qPos = QueryPos.getInstance(q);
703
704 qPos.add(classPK);
705
706 if (!pagination) {
707 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
708 start, end, false);
709
710 Collections.sort(list);
711
712 list = new UnmodifiableList<ExpandoRow>(list);
713 }
714 else {
715 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
716 start, end);
717 }
718
719 cacheResult(list);
720
721 FinderCacheUtil.putResult(finderPath, finderArgs, list);
722 }
723 catch (Exception e) {
724 FinderCacheUtil.removeResult(finderPath, finderArgs);
725
726 throw processException(e);
727 }
728 finally {
729 closeSession(session);
730 }
731 }
732
733 return list;
734 }
735
736
745 @Override
746 public ExpandoRow findByClassPK_First(long classPK,
747 OrderByComparator orderByComparator)
748 throws NoSuchRowException, SystemException {
749 ExpandoRow expandoRow = fetchByClassPK_First(classPK, orderByComparator);
750
751 if (expandoRow != null) {
752 return expandoRow;
753 }
754
755 StringBundler msg = new StringBundler(4);
756
757 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
758
759 msg.append("classPK=");
760 msg.append(classPK);
761
762 msg.append(StringPool.CLOSE_CURLY_BRACE);
763
764 throw new NoSuchRowException(msg.toString());
765 }
766
767
775 @Override
776 public ExpandoRow fetchByClassPK_First(long classPK,
777 OrderByComparator orderByComparator) throws SystemException {
778 List<ExpandoRow> list = findByClassPK(classPK, 0, 1, orderByComparator);
779
780 if (!list.isEmpty()) {
781 return list.get(0);
782 }
783
784 return null;
785 }
786
787
796 @Override
797 public ExpandoRow findByClassPK_Last(long classPK,
798 OrderByComparator orderByComparator)
799 throws NoSuchRowException, SystemException {
800 ExpandoRow expandoRow = fetchByClassPK_Last(classPK, orderByComparator);
801
802 if (expandoRow != null) {
803 return expandoRow;
804 }
805
806 StringBundler msg = new StringBundler(4);
807
808 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
809
810 msg.append("classPK=");
811 msg.append(classPK);
812
813 msg.append(StringPool.CLOSE_CURLY_BRACE);
814
815 throw new NoSuchRowException(msg.toString());
816 }
817
818
826 @Override
827 public ExpandoRow fetchByClassPK_Last(long classPK,
828 OrderByComparator orderByComparator) throws SystemException {
829 int count = countByClassPK(classPK);
830
831 if (count == 0) {
832 return null;
833 }
834
835 List<ExpandoRow> list = findByClassPK(classPK, count - 1, count,
836 orderByComparator);
837
838 if (!list.isEmpty()) {
839 return list.get(0);
840 }
841
842 return null;
843 }
844
845
855 @Override
856 public ExpandoRow[] findByClassPK_PrevAndNext(long rowId, long classPK,
857 OrderByComparator orderByComparator)
858 throws NoSuchRowException, SystemException {
859 ExpandoRow expandoRow = findByPrimaryKey(rowId);
860
861 Session session = null;
862
863 try {
864 session = openSession();
865
866 ExpandoRow[] array = new ExpandoRowImpl[3];
867
868 array[0] = getByClassPK_PrevAndNext(session, expandoRow, classPK,
869 orderByComparator, true);
870
871 array[1] = expandoRow;
872
873 array[2] = getByClassPK_PrevAndNext(session, expandoRow, classPK,
874 orderByComparator, false);
875
876 return array;
877 }
878 catch (Exception e) {
879 throw processException(e);
880 }
881 finally {
882 closeSession(session);
883 }
884 }
885
886 protected ExpandoRow getByClassPK_PrevAndNext(Session session,
887 ExpandoRow expandoRow, long classPK,
888 OrderByComparator orderByComparator, boolean previous) {
889 StringBundler query = null;
890
891 if (orderByComparator != null) {
892 query = new StringBundler(6 +
893 (orderByComparator.getOrderByFields().length * 6));
894 }
895 else {
896 query = new StringBundler(3);
897 }
898
899 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
900
901 query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
902
903 if (orderByComparator != null) {
904 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
905
906 if (orderByConditionFields.length > 0) {
907 query.append(WHERE_AND);
908 }
909
910 for (int i = 0; i < orderByConditionFields.length; i++) {
911 query.append(_ORDER_BY_ENTITY_ALIAS);
912 query.append(orderByConditionFields[i]);
913
914 if ((i + 1) < orderByConditionFields.length) {
915 if (orderByComparator.isAscending() ^ previous) {
916 query.append(WHERE_GREATER_THAN_HAS_NEXT);
917 }
918 else {
919 query.append(WHERE_LESSER_THAN_HAS_NEXT);
920 }
921 }
922 else {
923 if (orderByComparator.isAscending() ^ previous) {
924 query.append(WHERE_GREATER_THAN);
925 }
926 else {
927 query.append(WHERE_LESSER_THAN);
928 }
929 }
930 }
931
932 query.append(ORDER_BY_CLAUSE);
933
934 String[] orderByFields = orderByComparator.getOrderByFields();
935
936 for (int i = 0; i < orderByFields.length; i++) {
937 query.append(_ORDER_BY_ENTITY_ALIAS);
938 query.append(orderByFields[i]);
939
940 if ((i + 1) < orderByFields.length) {
941 if (orderByComparator.isAscending() ^ previous) {
942 query.append(ORDER_BY_ASC_HAS_NEXT);
943 }
944 else {
945 query.append(ORDER_BY_DESC_HAS_NEXT);
946 }
947 }
948 else {
949 if (orderByComparator.isAscending() ^ previous) {
950 query.append(ORDER_BY_ASC);
951 }
952 else {
953 query.append(ORDER_BY_DESC);
954 }
955 }
956 }
957 }
958 else {
959 query.append(ExpandoRowModelImpl.ORDER_BY_JPQL);
960 }
961
962 String sql = query.toString();
963
964 Query q = session.createQuery(sql);
965
966 q.setFirstResult(0);
967 q.setMaxResults(2);
968
969 QueryPos qPos = QueryPos.getInstance(q);
970
971 qPos.add(classPK);
972
973 if (orderByComparator != null) {
974 Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
975
976 for (Object value : values) {
977 qPos.add(value);
978 }
979 }
980
981 List<ExpandoRow> list = q.list();
982
983 if (list.size() == 2) {
984 return list.get(1);
985 }
986 else {
987 return null;
988 }
989 }
990
991
997 @Override
998 public void removeByClassPK(long classPK) throws SystemException {
999 for (ExpandoRow expandoRow : findByClassPK(classPK, QueryUtil.ALL_POS,
1000 QueryUtil.ALL_POS, null)) {
1001 remove(expandoRow);
1002 }
1003 }
1004
1005
1012 @Override
1013 public int countByClassPK(long classPK) throws SystemException {
1014 FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSPK;
1015
1016 Object[] finderArgs = new Object[] { classPK };
1017
1018 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1019 this);
1020
1021 if (count == null) {
1022 StringBundler query = new StringBundler(2);
1023
1024 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1025
1026 query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
1027
1028 String sql = query.toString();
1029
1030 Session session = null;
1031
1032 try {
1033 session = openSession();
1034
1035 Query q = session.createQuery(sql);
1036
1037 QueryPos qPos = QueryPos.getInstance(q);
1038
1039 qPos.add(classPK);
1040
1041 count = (Long)q.uniqueResult();
1042
1043 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1044 }
1045 catch (Exception e) {
1046 FinderCacheUtil.removeResult(finderPath, finderArgs);
1047
1048 throw processException(e);
1049 }
1050 finally {
1051 closeSession(session);
1052 }
1053 }
1054
1055 return count.intValue();
1056 }
1057
1058 private static final String _FINDER_COLUMN_CLASSPK_CLASSPK_2 = "expandoRow.classPK = ?";
1059 public static final FinderPath FINDER_PATH_FETCH_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1060 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
1061 FINDER_CLASS_NAME_ENTITY, "fetchByT_C",
1062 new String[] { Long.class.getName(), Long.class.getName() },
1063 ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK |
1064 ExpandoRowModelImpl.CLASSPK_COLUMN_BITMASK);
1065 public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1066 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
1067 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C",
1068 new String[] { Long.class.getName(), Long.class.getName() });
1069
1070
1079 @Override
1080 public ExpandoRow findByT_C(long tableId, long classPK)
1081 throws NoSuchRowException, SystemException {
1082 ExpandoRow expandoRow = fetchByT_C(tableId, classPK);
1083
1084 if (expandoRow == null) {
1085 StringBundler msg = new StringBundler(6);
1086
1087 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1088
1089 msg.append("tableId=");
1090 msg.append(tableId);
1091
1092 msg.append(", classPK=");
1093 msg.append(classPK);
1094
1095 msg.append(StringPool.CLOSE_CURLY_BRACE);
1096
1097 if (_log.isWarnEnabled()) {
1098 _log.warn(msg.toString());
1099 }
1100
1101 throw new NoSuchRowException(msg.toString());
1102 }
1103
1104 return expandoRow;
1105 }
1106
1107
1115 @Override
1116 public ExpandoRow fetchByT_C(long tableId, long classPK)
1117 throws SystemException {
1118 return fetchByT_C(tableId, classPK, true);
1119 }
1120
1121
1130 @Override
1131 public ExpandoRow fetchByT_C(long tableId, long classPK,
1132 boolean retrieveFromCache) throws SystemException {
1133 Object[] finderArgs = new Object[] { tableId, classPK };
1134
1135 Object result = null;
1136
1137 if (retrieveFromCache) {
1138 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
1139 finderArgs, this);
1140 }
1141
1142 if (result instanceof ExpandoRow) {
1143 ExpandoRow expandoRow = (ExpandoRow)result;
1144
1145 if ((tableId != expandoRow.getTableId()) ||
1146 (classPK != expandoRow.getClassPK())) {
1147 result = null;
1148 }
1149 }
1150
1151 if (result == null) {
1152 StringBundler query = new StringBundler(4);
1153
1154 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
1155
1156 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1157
1158 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1159
1160 String sql = query.toString();
1161
1162 Session session = null;
1163
1164 try {
1165 session = openSession();
1166
1167 Query q = session.createQuery(sql);
1168
1169 QueryPos qPos = QueryPos.getInstance(q);
1170
1171 qPos.add(tableId);
1172
1173 qPos.add(classPK);
1174
1175 List<ExpandoRow> list = q.list();
1176
1177 if (list.isEmpty()) {
1178 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1179 finderArgs, list);
1180 }
1181 else {
1182 ExpandoRow expandoRow = list.get(0);
1183
1184 result = expandoRow;
1185
1186 cacheResult(expandoRow);
1187
1188 if ((expandoRow.getTableId() != tableId) ||
1189 (expandoRow.getClassPK() != classPK)) {
1190 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1191 finderArgs, expandoRow);
1192 }
1193 }
1194 }
1195 catch (Exception e) {
1196 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
1197 finderArgs);
1198
1199 throw processException(e);
1200 }
1201 finally {
1202 closeSession(session);
1203 }
1204 }
1205
1206 if (result instanceof List<?>) {
1207 return null;
1208 }
1209 else {
1210 return (ExpandoRow)result;
1211 }
1212 }
1213
1214
1222 @Override
1223 public ExpandoRow removeByT_C(long tableId, long classPK)
1224 throws NoSuchRowException, SystemException {
1225 ExpandoRow expandoRow = findByT_C(tableId, classPK);
1226
1227 return remove(expandoRow);
1228 }
1229
1230
1238 @Override
1239 public int countByT_C(long tableId, long classPK) throws SystemException {
1240 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_C;
1241
1242 Object[] finderArgs = new Object[] { tableId, classPK };
1243
1244 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1245 this);
1246
1247 if (count == null) {
1248 StringBundler query = new StringBundler(3);
1249
1250 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1251
1252 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1253
1254 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1255
1256 String sql = query.toString();
1257
1258 Session session = null;
1259
1260 try {
1261 session = openSession();
1262
1263 Query q = session.createQuery(sql);
1264
1265 QueryPos qPos = QueryPos.getInstance(q);
1266
1267 qPos.add(tableId);
1268
1269 qPos.add(classPK);
1270
1271 count = (Long)q.uniqueResult();
1272
1273 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1274 }
1275 catch (Exception e) {
1276 FinderCacheUtil.removeResult(finderPath, finderArgs);
1277
1278 throw processException(e);
1279 }
1280 finally {
1281 closeSession(session);
1282 }
1283 }
1284
1285 return count.intValue();
1286 }
1287
1288 private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoRow.tableId = ? AND ";
1289 private static final String _FINDER_COLUMN_T_C_CLASSPK_2 = "expandoRow.classPK = ?";
1290
1291
1296 @Override
1297 public void cacheResult(ExpandoRow expandoRow) {
1298 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1299 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
1300
1301 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1302 new Object[] { expandoRow.getTableId(), expandoRow.getClassPK() },
1303 expandoRow);
1304
1305 expandoRow.resetOriginalValues();
1306 }
1307
1308
1313 @Override
1314 public void cacheResult(List<ExpandoRow> expandoRows) {
1315 for (ExpandoRow expandoRow : expandoRows) {
1316 if (EntityCacheUtil.getResult(
1317 ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1318 ExpandoRowImpl.class, expandoRow.getPrimaryKey()) == null) {
1319 cacheResult(expandoRow);
1320 }
1321 else {
1322 expandoRow.resetOriginalValues();
1323 }
1324 }
1325 }
1326
1327
1334 @Override
1335 public void clearCache() {
1336 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1337 CacheRegistryUtil.clear(ExpandoRowImpl.class.getName());
1338 }
1339
1340 EntityCacheUtil.clearCache(ExpandoRowImpl.class.getName());
1341
1342 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1343 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1344 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1345 }
1346
1347
1354 @Override
1355 public void clearCache(ExpandoRow expandoRow) {
1356 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1357 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
1358
1359 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1360 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1361
1362 clearUniqueFindersCache(expandoRow);
1363 }
1364
1365 @Override
1366 public void clearCache(List<ExpandoRow> expandoRows) {
1367 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1368 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1369
1370 for (ExpandoRow expandoRow : expandoRows) {
1371 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1372 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
1373
1374 clearUniqueFindersCache(expandoRow);
1375 }
1376 }
1377
1378 protected void cacheUniqueFindersCache(ExpandoRow expandoRow) {
1379 if (expandoRow.isNew()) {
1380 Object[] args = new Object[] {
1381 expandoRow.getTableId(), expandoRow.getClassPK()
1382 };
1383
1384 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1385 Long.valueOf(1));
1386 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args, expandoRow);
1387 }
1388 else {
1389 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1390
1391 if ((expandoRowModelImpl.getColumnBitmask() &
1392 FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1393 Object[] args = new Object[] {
1394 expandoRow.getTableId(), expandoRow.getClassPK()
1395 };
1396
1397 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1398 Long.valueOf(1));
1399 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args,
1400 expandoRow);
1401 }
1402 }
1403 }
1404
1405 protected void clearUniqueFindersCache(ExpandoRow expandoRow) {
1406 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1407
1408 Object[] args = new Object[] {
1409 expandoRow.getTableId(), expandoRow.getClassPK()
1410 };
1411
1412 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1413 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1414
1415 if ((expandoRowModelImpl.getColumnBitmask() &
1416 FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1417 args = new Object[] {
1418 expandoRowModelImpl.getOriginalTableId(),
1419 expandoRowModelImpl.getOriginalClassPK()
1420 };
1421
1422 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1423 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1424 }
1425 }
1426
1427
1433 @Override
1434 public ExpandoRow create(long rowId) {
1435 ExpandoRow expandoRow = new ExpandoRowImpl();
1436
1437 expandoRow.setNew(true);
1438 expandoRow.setPrimaryKey(rowId);
1439
1440 return expandoRow;
1441 }
1442
1443
1451 @Override
1452 public ExpandoRow remove(long rowId)
1453 throws NoSuchRowException, SystemException {
1454 return remove((Serializable)rowId);
1455 }
1456
1457
1465 @Override
1466 public ExpandoRow remove(Serializable primaryKey)
1467 throws NoSuchRowException, SystemException {
1468 Session session = null;
1469
1470 try {
1471 session = openSession();
1472
1473 ExpandoRow expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1474 primaryKey);
1475
1476 if (expandoRow == null) {
1477 if (_log.isWarnEnabled()) {
1478 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1479 }
1480
1481 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1482 primaryKey);
1483 }
1484
1485 return remove(expandoRow);
1486 }
1487 catch (NoSuchRowException nsee) {
1488 throw nsee;
1489 }
1490 catch (Exception e) {
1491 throw processException(e);
1492 }
1493 finally {
1494 closeSession(session);
1495 }
1496 }
1497
1498 @Override
1499 protected ExpandoRow removeImpl(ExpandoRow expandoRow)
1500 throws SystemException {
1501 expandoRow = toUnwrappedModel(expandoRow);
1502
1503 Session session = null;
1504
1505 try {
1506 session = openSession();
1507
1508 if (!session.contains(expandoRow)) {
1509 expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1510 expandoRow.getPrimaryKeyObj());
1511 }
1512
1513 if (expandoRow != null) {
1514 session.delete(expandoRow);
1515 }
1516 }
1517 catch (Exception e) {
1518 throw processException(e);
1519 }
1520 finally {
1521 closeSession(session);
1522 }
1523
1524 if (expandoRow != null) {
1525 clearCache(expandoRow);
1526 }
1527
1528 return expandoRow;
1529 }
1530
1531 @Override
1532 public ExpandoRow updateImpl(
1533 com.liferay.portlet.expando.model.ExpandoRow expandoRow)
1534 throws SystemException {
1535 expandoRow = toUnwrappedModel(expandoRow);
1536
1537 boolean isNew = expandoRow.isNew();
1538
1539 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1540
1541 Session session = null;
1542
1543 try {
1544 session = openSession();
1545
1546 if (expandoRow.isNew()) {
1547 session.save(expandoRow);
1548
1549 expandoRow.setNew(false);
1550 }
1551 else {
1552 session.merge(expandoRow);
1553 }
1554 }
1555 catch (Exception e) {
1556 throw processException(e);
1557 }
1558 finally {
1559 closeSession(session);
1560 }
1561
1562 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1563
1564 if (isNew || !ExpandoRowModelImpl.COLUMN_BITMASK_ENABLED) {
1565 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1566 }
1567
1568 else {
1569 if ((expandoRowModelImpl.getColumnBitmask() &
1570 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
1571 Object[] args = new Object[] {
1572 expandoRowModelImpl.getOriginalTableId()
1573 };
1574
1575 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1576 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1577 args);
1578
1579 args = new Object[] { expandoRowModelImpl.getTableId() };
1580
1581 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1582 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1583 args);
1584 }
1585
1586 if ((expandoRowModelImpl.getColumnBitmask() &
1587 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK.getColumnBitmask()) != 0) {
1588 Object[] args = new Object[] {
1589 expandoRowModelImpl.getOriginalClassPK()
1590 };
1591
1592 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1593 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
1594 args);
1595
1596 args = new Object[] { expandoRowModelImpl.getClassPK() };
1597
1598 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1599 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
1600 args);
1601 }
1602 }
1603
1604 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1605 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
1606
1607 clearUniqueFindersCache(expandoRow);
1608 cacheUniqueFindersCache(expandoRow);
1609
1610 return expandoRow;
1611 }
1612
1613 protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
1614 if (expandoRow instanceof ExpandoRowImpl) {
1615 return expandoRow;
1616 }
1617
1618 ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
1619
1620 expandoRowImpl.setNew(expandoRow.isNew());
1621 expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
1622
1623 expandoRowImpl.setRowId(expandoRow.getRowId());
1624 expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
1625 expandoRowImpl.setModifiedDate(expandoRow.getModifiedDate());
1626 expandoRowImpl.setTableId(expandoRow.getTableId());
1627 expandoRowImpl.setClassPK(expandoRow.getClassPK());
1628
1629 return expandoRowImpl;
1630 }
1631
1632
1640 @Override
1641 public ExpandoRow findByPrimaryKey(Serializable primaryKey)
1642 throws NoSuchRowException, SystemException {
1643 ExpandoRow expandoRow = fetchByPrimaryKey(primaryKey);
1644
1645 if (expandoRow == null) {
1646 if (_log.isWarnEnabled()) {
1647 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1648 }
1649
1650 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1651 primaryKey);
1652 }
1653
1654 return expandoRow;
1655 }
1656
1657
1665 @Override
1666 public ExpandoRow findByPrimaryKey(long rowId)
1667 throws NoSuchRowException, SystemException {
1668 return findByPrimaryKey((Serializable)rowId);
1669 }
1670
1671
1678 @Override
1679 public ExpandoRow fetchByPrimaryKey(Serializable primaryKey)
1680 throws SystemException {
1681 ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1682 ExpandoRowImpl.class, primaryKey);
1683
1684 if (expandoRow == _nullExpandoRow) {
1685 return null;
1686 }
1687
1688 if (expandoRow == null) {
1689 Session session = null;
1690
1691 try {
1692 session = openSession();
1693
1694 expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1695 primaryKey);
1696
1697 if (expandoRow != null) {
1698 cacheResult(expandoRow);
1699 }
1700 else {
1701 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1702 ExpandoRowImpl.class, primaryKey, _nullExpandoRow);
1703 }
1704 }
1705 catch (Exception e) {
1706 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1707 ExpandoRowImpl.class, primaryKey);
1708
1709 throw processException(e);
1710 }
1711 finally {
1712 closeSession(session);
1713 }
1714 }
1715
1716 return expandoRow;
1717 }
1718
1719
1726 @Override
1727 public ExpandoRow fetchByPrimaryKey(long rowId) throws SystemException {
1728 return fetchByPrimaryKey((Serializable)rowId);
1729 }
1730
1731
1737 @Override
1738 public List<ExpandoRow> findAll() throws SystemException {
1739 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1740 }
1741
1742
1754 @Override
1755 public List<ExpandoRow> findAll(int start, int end)
1756 throws SystemException {
1757 return findAll(start, end, null);
1758 }
1759
1760
1773 @Override
1774 public List<ExpandoRow> findAll(int start, int end,
1775 OrderByComparator orderByComparator) throws SystemException {
1776 boolean pagination = true;
1777 FinderPath finderPath = null;
1778 Object[] finderArgs = null;
1779
1780 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1781 (orderByComparator == null)) {
1782 pagination = false;
1783 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1784 finderArgs = FINDER_ARGS_EMPTY;
1785 }
1786 else {
1787 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1788 finderArgs = new Object[] { start, end, orderByComparator };
1789 }
1790
1791 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
1792 finderArgs, this);
1793
1794 if (list == null) {
1795 StringBundler query = null;
1796 String sql = null;
1797
1798 if (orderByComparator != null) {
1799 query = new StringBundler(2 +
1800 (orderByComparator.getOrderByFields().length * 3));
1801
1802 query.append(_SQL_SELECT_EXPANDOROW);
1803
1804 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1805 orderByComparator);
1806
1807 sql = query.toString();
1808 }
1809 else {
1810 sql = _SQL_SELECT_EXPANDOROW;
1811
1812 if (pagination) {
1813 sql = sql.concat(ExpandoRowModelImpl.ORDER_BY_JPQL);
1814 }
1815 }
1816
1817 Session session = null;
1818
1819 try {
1820 session = openSession();
1821
1822 Query q = session.createQuery(sql);
1823
1824 if (!pagination) {
1825 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1826 start, end, false);
1827
1828 Collections.sort(list);
1829
1830 list = new UnmodifiableList<ExpandoRow>(list);
1831 }
1832 else {
1833 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1834 start, end);
1835 }
1836
1837 cacheResult(list);
1838
1839 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1840 }
1841 catch (Exception e) {
1842 FinderCacheUtil.removeResult(finderPath, finderArgs);
1843
1844 throw processException(e);
1845 }
1846 finally {
1847 closeSession(session);
1848 }
1849 }
1850
1851 return list;
1852 }
1853
1854
1859 @Override
1860 public void removeAll() throws SystemException {
1861 for (ExpandoRow expandoRow : findAll()) {
1862 remove(expandoRow);
1863 }
1864 }
1865
1866
1872 @Override
1873 public int countAll() throws SystemException {
1874 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1875 FINDER_ARGS_EMPTY, this);
1876
1877 if (count == null) {
1878 Session session = null;
1879
1880 try {
1881 session = openSession();
1882
1883 Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
1884
1885 count = (Long)q.uniqueResult();
1886
1887 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1888 FINDER_ARGS_EMPTY, count);
1889 }
1890 catch (Exception e) {
1891 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1892 FINDER_ARGS_EMPTY);
1893
1894 throw processException(e);
1895 }
1896 finally {
1897 closeSession(session);
1898 }
1899 }
1900
1901 return count.intValue();
1902 }
1903
1904 @Override
1905 protected Set<String> getBadColumnNames() {
1906 return _badColumnNames;
1907 }
1908
1909
1912 public void afterPropertiesSet() {
1913 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1914 com.liferay.portal.util.PropsUtil.get(
1915 "value.object.listener.com.liferay.portlet.expando.model.ExpandoRow")));
1916
1917 if (listenerClassNames.length > 0) {
1918 try {
1919 List<ModelListener<ExpandoRow>> listenersList = new ArrayList<ModelListener<ExpandoRow>>();
1920
1921 for (String listenerClassName : listenerClassNames) {
1922 listenersList.add((ModelListener<ExpandoRow>)InstanceFactory.newInstance(
1923 getClassLoader(), listenerClassName));
1924 }
1925
1926 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1927 }
1928 catch (Exception e) {
1929 _log.error(e);
1930 }
1931 }
1932 }
1933
1934 public void destroy() {
1935 EntityCacheUtil.removeCache(ExpandoRowImpl.class.getName());
1936 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1937 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1938 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1939 }
1940
1941 private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
1942 private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
1943 private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
1944 private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
1945 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1946 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1947 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1948 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1949 private static Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1950 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1951 "rowId"
1952 });
1953 private static ExpandoRow _nullExpandoRow = new ExpandoRowImpl() {
1954 @Override
1955 public Object clone() {
1956 return this;
1957 }
1958
1959 @Override
1960 public CacheModel<ExpandoRow> toCacheModel() {
1961 return _nullExpandoRowCacheModel;
1962 }
1963 };
1964
1965 private static CacheModel<ExpandoRow> _nullExpandoRowCacheModel = new CacheModel<ExpandoRow>() {
1966 @Override
1967 public ExpandoRow toEntityModel() {
1968 return _nullExpandoRow;
1969 }
1970 };
1971 }