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 public ExpandoRowPersistenceImpl() {
1292 setModelClass(ExpandoRow.class);
1293 }
1294
1295
1300 @Override
1301 public void cacheResult(ExpandoRow expandoRow) {
1302 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1303 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
1304
1305 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1306 new Object[] { expandoRow.getTableId(), expandoRow.getClassPK() },
1307 expandoRow);
1308
1309 expandoRow.resetOriginalValues();
1310 }
1311
1312
1317 @Override
1318 public void cacheResult(List<ExpandoRow> expandoRows) {
1319 for (ExpandoRow expandoRow : expandoRows) {
1320 if (EntityCacheUtil.getResult(
1321 ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1322 ExpandoRowImpl.class, expandoRow.getPrimaryKey()) == null) {
1323 cacheResult(expandoRow);
1324 }
1325 else {
1326 expandoRow.resetOriginalValues();
1327 }
1328 }
1329 }
1330
1331
1338 @Override
1339 public void clearCache() {
1340 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1341 CacheRegistryUtil.clear(ExpandoRowImpl.class.getName());
1342 }
1343
1344 EntityCacheUtil.clearCache(ExpandoRowImpl.class.getName());
1345
1346 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1347 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1348 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1349 }
1350
1351
1358 @Override
1359 public void clearCache(ExpandoRow expandoRow) {
1360 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1361 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
1362
1363 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1364 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1365
1366 clearUniqueFindersCache(expandoRow);
1367 }
1368
1369 @Override
1370 public void clearCache(List<ExpandoRow> expandoRows) {
1371 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1372 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1373
1374 for (ExpandoRow expandoRow : expandoRows) {
1375 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1376 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
1377
1378 clearUniqueFindersCache(expandoRow);
1379 }
1380 }
1381
1382 protected void cacheUniqueFindersCache(ExpandoRow expandoRow) {
1383 if (expandoRow.isNew()) {
1384 Object[] args = new Object[] {
1385 expandoRow.getTableId(), expandoRow.getClassPK()
1386 };
1387
1388 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1389 Long.valueOf(1));
1390 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args, expandoRow);
1391 }
1392 else {
1393 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1394
1395 if ((expandoRowModelImpl.getColumnBitmask() &
1396 FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1397 Object[] args = new Object[] {
1398 expandoRow.getTableId(), expandoRow.getClassPK()
1399 };
1400
1401 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1402 Long.valueOf(1));
1403 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args,
1404 expandoRow);
1405 }
1406 }
1407 }
1408
1409 protected void clearUniqueFindersCache(ExpandoRow expandoRow) {
1410 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1411
1412 Object[] args = new Object[] {
1413 expandoRow.getTableId(), expandoRow.getClassPK()
1414 };
1415
1416 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1417 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1418
1419 if ((expandoRowModelImpl.getColumnBitmask() &
1420 FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1421 args = new Object[] {
1422 expandoRowModelImpl.getOriginalTableId(),
1423 expandoRowModelImpl.getOriginalClassPK()
1424 };
1425
1426 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1427 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1428 }
1429 }
1430
1431
1437 @Override
1438 public ExpandoRow create(long rowId) {
1439 ExpandoRow expandoRow = new ExpandoRowImpl();
1440
1441 expandoRow.setNew(true);
1442 expandoRow.setPrimaryKey(rowId);
1443
1444 return expandoRow;
1445 }
1446
1447
1455 @Override
1456 public ExpandoRow remove(long rowId)
1457 throws NoSuchRowException, SystemException {
1458 return remove((Serializable)rowId);
1459 }
1460
1461
1469 @Override
1470 public ExpandoRow remove(Serializable primaryKey)
1471 throws NoSuchRowException, SystemException {
1472 Session session = null;
1473
1474 try {
1475 session = openSession();
1476
1477 ExpandoRow expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1478 primaryKey);
1479
1480 if (expandoRow == null) {
1481 if (_log.isWarnEnabled()) {
1482 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1483 }
1484
1485 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1486 primaryKey);
1487 }
1488
1489 return remove(expandoRow);
1490 }
1491 catch (NoSuchRowException nsee) {
1492 throw nsee;
1493 }
1494 catch (Exception e) {
1495 throw processException(e);
1496 }
1497 finally {
1498 closeSession(session);
1499 }
1500 }
1501
1502 @Override
1503 protected ExpandoRow removeImpl(ExpandoRow expandoRow)
1504 throws SystemException {
1505 expandoRow = toUnwrappedModel(expandoRow);
1506
1507 Session session = null;
1508
1509 try {
1510 session = openSession();
1511
1512 if (!session.contains(expandoRow)) {
1513 expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1514 expandoRow.getPrimaryKeyObj());
1515 }
1516
1517 if (expandoRow != null) {
1518 session.delete(expandoRow);
1519 }
1520 }
1521 catch (Exception e) {
1522 throw processException(e);
1523 }
1524 finally {
1525 closeSession(session);
1526 }
1527
1528 if (expandoRow != null) {
1529 clearCache(expandoRow);
1530 }
1531
1532 return expandoRow;
1533 }
1534
1535 @Override
1536 public ExpandoRow updateImpl(
1537 com.liferay.portlet.expando.model.ExpandoRow expandoRow)
1538 throws SystemException {
1539 expandoRow = toUnwrappedModel(expandoRow);
1540
1541 boolean isNew = expandoRow.isNew();
1542
1543 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1544
1545 Session session = null;
1546
1547 try {
1548 session = openSession();
1549
1550 if (expandoRow.isNew()) {
1551 session.save(expandoRow);
1552
1553 expandoRow.setNew(false);
1554 }
1555 else {
1556 session.merge(expandoRow);
1557 }
1558 }
1559 catch (Exception e) {
1560 throw processException(e);
1561 }
1562 finally {
1563 closeSession(session);
1564 }
1565
1566 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1567
1568 if (isNew || !ExpandoRowModelImpl.COLUMN_BITMASK_ENABLED) {
1569 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1570 }
1571
1572 else {
1573 if ((expandoRowModelImpl.getColumnBitmask() &
1574 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
1575 Object[] args = new Object[] {
1576 expandoRowModelImpl.getOriginalTableId()
1577 };
1578
1579 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1580 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1581 args);
1582
1583 args = new Object[] { expandoRowModelImpl.getTableId() };
1584
1585 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1586 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1587 args);
1588 }
1589
1590 if ((expandoRowModelImpl.getColumnBitmask() &
1591 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK.getColumnBitmask()) != 0) {
1592 Object[] args = new Object[] {
1593 expandoRowModelImpl.getOriginalClassPK()
1594 };
1595
1596 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1597 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
1598 args);
1599
1600 args = new Object[] { expandoRowModelImpl.getClassPK() };
1601
1602 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1603 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
1604 args);
1605 }
1606 }
1607
1608 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1609 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
1610
1611 clearUniqueFindersCache(expandoRow);
1612 cacheUniqueFindersCache(expandoRow);
1613
1614 return expandoRow;
1615 }
1616
1617 protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
1618 if (expandoRow instanceof ExpandoRowImpl) {
1619 return expandoRow;
1620 }
1621
1622 ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
1623
1624 expandoRowImpl.setNew(expandoRow.isNew());
1625 expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
1626
1627 expandoRowImpl.setRowId(expandoRow.getRowId());
1628 expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
1629 expandoRowImpl.setModifiedDate(expandoRow.getModifiedDate());
1630 expandoRowImpl.setTableId(expandoRow.getTableId());
1631 expandoRowImpl.setClassPK(expandoRow.getClassPK());
1632
1633 return expandoRowImpl;
1634 }
1635
1636
1644 @Override
1645 public ExpandoRow findByPrimaryKey(Serializable primaryKey)
1646 throws NoSuchRowException, SystemException {
1647 ExpandoRow expandoRow = fetchByPrimaryKey(primaryKey);
1648
1649 if (expandoRow == null) {
1650 if (_log.isWarnEnabled()) {
1651 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1652 }
1653
1654 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1655 primaryKey);
1656 }
1657
1658 return expandoRow;
1659 }
1660
1661
1669 @Override
1670 public ExpandoRow findByPrimaryKey(long rowId)
1671 throws NoSuchRowException, SystemException {
1672 return findByPrimaryKey((Serializable)rowId);
1673 }
1674
1675
1682 @Override
1683 public ExpandoRow fetchByPrimaryKey(Serializable primaryKey)
1684 throws SystemException {
1685 ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1686 ExpandoRowImpl.class, primaryKey);
1687
1688 if (expandoRow == _nullExpandoRow) {
1689 return null;
1690 }
1691
1692 if (expandoRow == null) {
1693 Session session = null;
1694
1695 try {
1696 session = openSession();
1697
1698 expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1699 primaryKey);
1700
1701 if (expandoRow != null) {
1702 cacheResult(expandoRow);
1703 }
1704 else {
1705 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1706 ExpandoRowImpl.class, primaryKey, _nullExpandoRow);
1707 }
1708 }
1709 catch (Exception e) {
1710 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1711 ExpandoRowImpl.class, primaryKey);
1712
1713 throw processException(e);
1714 }
1715 finally {
1716 closeSession(session);
1717 }
1718 }
1719
1720 return expandoRow;
1721 }
1722
1723
1730 @Override
1731 public ExpandoRow fetchByPrimaryKey(long rowId) throws SystemException {
1732 return fetchByPrimaryKey((Serializable)rowId);
1733 }
1734
1735
1741 @Override
1742 public List<ExpandoRow> findAll() throws SystemException {
1743 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1744 }
1745
1746
1758 @Override
1759 public List<ExpandoRow> findAll(int start, int end)
1760 throws SystemException {
1761 return findAll(start, end, null);
1762 }
1763
1764
1777 @Override
1778 public List<ExpandoRow> findAll(int start, int end,
1779 OrderByComparator orderByComparator) throws SystemException {
1780 boolean pagination = true;
1781 FinderPath finderPath = null;
1782 Object[] finderArgs = null;
1783
1784 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1785 (orderByComparator == null)) {
1786 pagination = false;
1787 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1788 finderArgs = FINDER_ARGS_EMPTY;
1789 }
1790 else {
1791 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1792 finderArgs = new Object[] { start, end, orderByComparator };
1793 }
1794
1795 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
1796 finderArgs, this);
1797
1798 if (list == null) {
1799 StringBundler query = null;
1800 String sql = null;
1801
1802 if (orderByComparator != null) {
1803 query = new StringBundler(2 +
1804 (orderByComparator.getOrderByFields().length * 3));
1805
1806 query.append(_SQL_SELECT_EXPANDOROW);
1807
1808 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1809 orderByComparator);
1810
1811 sql = query.toString();
1812 }
1813 else {
1814 sql = _SQL_SELECT_EXPANDOROW;
1815
1816 if (pagination) {
1817 sql = sql.concat(ExpandoRowModelImpl.ORDER_BY_JPQL);
1818 }
1819 }
1820
1821 Session session = null;
1822
1823 try {
1824 session = openSession();
1825
1826 Query q = session.createQuery(sql);
1827
1828 if (!pagination) {
1829 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1830 start, end, false);
1831
1832 Collections.sort(list);
1833
1834 list = new UnmodifiableList<ExpandoRow>(list);
1835 }
1836 else {
1837 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1838 start, end);
1839 }
1840
1841 cacheResult(list);
1842
1843 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1844 }
1845 catch (Exception e) {
1846 FinderCacheUtil.removeResult(finderPath, finderArgs);
1847
1848 throw processException(e);
1849 }
1850 finally {
1851 closeSession(session);
1852 }
1853 }
1854
1855 return list;
1856 }
1857
1858
1863 @Override
1864 public void removeAll() throws SystemException {
1865 for (ExpandoRow expandoRow : findAll()) {
1866 remove(expandoRow);
1867 }
1868 }
1869
1870
1876 @Override
1877 public int countAll() throws SystemException {
1878 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1879 FINDER_ARGS_EMPTY, this);
1880
1881 if (count == null) {
1882 Session session = null;
1883
1884 try {
1885 session = openSession();
1886
1887 Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
1888
1889 count = (Long)q.uniqueResult();
1890
1891 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1892 FINDER_ARGS_EMPTY, count);
1893 }
1894 catch (Exception e) {
1895 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1896 FINDER_ARGS_EMPTY);
1897
1898 throw processException(e);
1899 }
1900 finally {
1901 closeSession(session);
1902 }
1903 }
1904
1905 return count.intValue();
1906 }
1907
1908 @Override
1909 protected Set<String> getBadColumnNames() {
1910 return _badColumnNames;
1911 }
1912
1913
1916 public void afterPropertiesSet() {
1917 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1918 com.liferay.portal.util.PropsUtil.get(
1919 "value.object.listener.com.liferay.portlet.expando.model.ExpandoRow")));
1920
1921 if (listenerClassNames.length > 0) {
1922 try {
1923 List<ModelListener<ExpandoRow>> listenersList = new ArrayList<ModelListener<ExpandoRow>>();
1924
1925 for (String listenerClassName : listenerClassNames) {
1926 listenersList.add((ModelListener<ExpandoRow>)InstanceFactory.newInstance(
1927 getClassLoader(), listenerClassName));
1928 }
1929
1930 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1931 }
1932 catch (Exception e) {
1933 _log.error(e);
1934 }
1935 }
1936 }
1937
1938 public void destroy() {
1939 EntityCacheUtil.removeCache(ExpandoRowImpl.class.getName());
1940 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1941 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1942 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1943 }
1944
1945 private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
1946 private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
1947 private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
1948 private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
1949 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1950 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1951 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1952 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1953 private static Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1954 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1955 "rowId"
1956 });
1957 private static ExpandoRow _nullExpandoRow = new ExpandoRowImpl() {
1958 @Override
1959 public Object clone() {
1960 return this;
1961 }
1962
1963 @Override
1964 public CacheModel<ExpandoRow> toCacheModel() {
1965 return _nullExpandoRowCacheModel;
1966 }
1967 };
1968
1969 private static CacheModel<ExpandoRow> _nullExpandoRowCacheModel = new CacheModel<ExpandoRow>() {
1970 @Override
1971 public ExpandoRow toEntityModel() {
1972 return _nullExpandoRow;
1973 }
1974 };
1975 }