001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.expando.NoSuchRowException;
044 import com.liferay.portlet.expando.model.ExpandoRow;
045 import com.liferay.portlet.expando.model.impl.ExpandoRowImpl;
046 import com.liferay.portlet.expando.model.impl.ExpandoRowModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class ExpandoRowPersistenceImpl extends BasePersistenceImpl<ExpandoRow>
067 implements ExpandoRowPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoRowImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
079 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTableId",
081 new String[] {
082 Long.class.getName(),
083
084 "java.lang.Integer", "java.lang.Integer",
085 "com.liferay.portal.kernel.util.OrderByComparator"
086 });
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
088 new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
089 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTableId",
091 new String[] { Long.class.getName() },
092 ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK);
093 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
094 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
096 new String[] { Long.class.getName() });
097 public static final FinderPath FINDER_PATH_FETCH_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
098 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
099 FINDER_CLASS_NAME_ENTITY, "fetchByT_C",
100 new String[] { Long.class.getName(), Long.class.getName() },
101 ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK |
102 ExpandoRowModelImpl.CLASSPK_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
104 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C",
106 new String[] { Long.class.getName(), Long.class.getName() });
107 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
108 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
109 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
110 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
111 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
113 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
114 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
116
117
122 public void cacheResult(ExpandoRow expandoRow) {
123 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
124 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
125
126 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
127 new Object[] {
128 Long.valueOf(expandoRow.getTableId()),
129 Long.valueOf(expandoRow.getClassPK())
130 }, expandoRow);
131
132 expandoRow.resetOriginalValues();
133 }
134
135
140 public void cacheResult(List<ExpandoRow> expandoRows) {
141 for (ExpandoRow expandoRow : expandoRows) {
142 if (EntityCacheUtil.getResult(
143 ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
144 ExpandoRowImpl.class, expandoRow.getPrimaryKey()) == null) {
145 cacheResult(expandoRow);
146 }
147 else {
148 expandoRow.resetOriginalValues();
149 }
150 }
151 }
152
153
160 @Override
161 public void clearCache() {
162 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
163 CacheRegistryUtil.clear(ExpandoRowImpl.class.getName());
164 }
165
166 EntityCacheUtil.clearCache(ExpandoRowImpl.class.getName());
167
168 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
169 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
170 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
171 }
172
173
180 @Override
181 public void clearCache(ExpandoRow expandoRow) {
182 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
183 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
184
185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
187
188 clearUniqueFindersCache(expandoRow);
189 }
190
191 @Override
192 public void clearCache(List<ExpandoRow> expandoRows) {
193 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
195
196 for (ExpandoRow expandoRow : expandoRows) {
197 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
198 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
199
200 clearUniqueFindersCache(expandoRow);
201 }
202 }
203
204 protected void clearUniqueFindersCache(ExpandoRow expandoRow) {
205 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
206 new Object[] {
207 Long.valueOf(expandoRow.getTableId()),
208 Long.valueOf(expandoRow.getClassPK())
209 });
210 }
211
212
218 public ExpandoRow create(long rowId) {
219 ExpandoRow expandoRow = new ExpandoRowImpl();
220
221 expandoRow.setNew(true);
222 expandoRow.setPrimaryKey(rowId);
223
224 return expandoRow;
225 }
226
227
235 public ExpandoRow remove(long rowId)
236 throws NoSuchRowException, SystemException {
237 return remove(Long.valueOf(rowId));
238 }
239
240
248 @Override
249 public ExpandoRow remove(Serializable primaryKey)
250 throws NoSuchRowException, SystemException {
251 Session session = null;
252
253 try {
254 session = openSession();
255
256 ExpandoRow expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
257 primaryKey);
258
259 if (expandoRow == null) {
260 if (_log.isWarnEnabled()) {
261 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
262 }
263
264 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
265 primaryKey);
266 }
267
268 return remove(expandoRow);
269 }
270 catch (NoSuchRowException nsee) {
271 throw nsee;
272 }
273 catch (Exception e) {
274 throw processException(e);
275 }
276 finally {
277 closeSession(session);
278 }
279 }
280
281 @Override
282 protected ExpandoRow removeImpl(ExpandoRow expandoRow)
283 throws SystemException {
284 expandoRow = toUnwrappedModel(expandoRow);
285
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 BatchSessionUtil.delete(session, expandoRow);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 clearCache(expandoRow);
301
302 return expandoRow;
303 }
304
305 @Override
306 public ExpandoRow updateImpl(
307 com.liferay.portlet.expando.model.ExpandoRow expandoRow, boolean merge)
308 throws SystemException {
309 expandoRow = toUnwrappedModel(expandoRow);
310
311 boolean isNew = expandoRow.isNew();
312
313 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
314
315 Session session = null;
316
317 try {
318 session = openSession();
319
320 BatchSessionUtil.update(session, expandoRow, merge);
321
322 expandoRow.setNew(false);
323 }
324 catch (Exception e) {
325 throw processException(e);
326 }
327 finally {
328 closeSession(session);
329 }
330
331 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
332
333 if (isNew || !ExpandoRowModelImpl.COLUMN_BITMASK_ENABLED) {
334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
335 }
336
337 else {
338 if ((expandoRowModelImpl.getColumnBitmask() &
339 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
340 Object[] args = new Object[] {
341 Long.valueOf(expandoRowModelImpl.getOriginalTableId())
342 };
343
344 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
345 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
346 args);
347
348 args = new Object[] {
349 Long.valueOf(expandoRowModelImpl.getTableId())
350 };
351
352 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
353 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
354 args);
355 }
356 }
357
358 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
359 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
360
361 if (isNew) {
362 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
363 new Object[] {
364 Long.valueOf(expandoRow.getTableId()),
365 Long.valueOf(expandoRow.getClassPK())
366 }, expandoRow);
367 }
368 else {
369 if ((expandoRowModelImpl.getColumnBitmask() &
370 FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
371 Object[] args = new Object[] {
372 Long.valueOf(expandoRowModelImpl.getOriginalTableId()),
373 Long.valueOf(expandoRowModelImpl.getOriginalClassPK())
374 };
375
376 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
377
378 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
379
380 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
381 new Object[] {
382 Long.valueOf(expandoRow.getTableId()),
383 Long.valueOf(expandoRow.getClassPK())
384 }, expandoRow);
385 }
386 }
387
388 return expandoRow;
389 }
390
391 protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
392 if (expandoRow instanceof ExpandoRowImpl) {
393 return expandoRow;
394 }
395
396 ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
397
398 expandoRowImpl.setNew(expandoRow.isNew());
399 expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
400
401 expandoRowImpl.setRowId(expandoRow.getRowId());
402 expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
403 expandoRowImpl.setTableId(expandoRow.getTableId());
404 expandoRowImpl.setClassPK(expandoRow.getClassPK());
405
406 return expandoRowImpl;
407 }
408
409
417 @Override
418 public ExpandoRow findByPrimaryKey(Serializable primaryKey)
419 throws NoSuchModelException, SystemException {
420 return findByPrimaryKey(((Long)primaryKey).longValue());
421 }
422
423
431 public ExpandoRow findByPrimaryKey(long rowId)
432 throws NoSuchRowException, SystemException {
433 ExpandoRow expandoRow = fetchByPrimaryKey(rowId);
434
435 if (expandoRow == null) {
436 if (_log.isWarnEnabled()) {
437 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + rowId);
438 }
439
440 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
441 rowId);
442 }
443
444 return expandoRow;
445 }
446
447
454 @Override
455 public ExpandoRow fetchByPrimaryKey(Serializable primaryKey)
456 throws SystemException {
457 return fetchByPrimaryKey(((Long)primaryKey).longValue());
458 }
459
460
467 public ExpandoRow fetchByPrimaryKey(long rowId) throws SystemException {
468 ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
469 ExpandoRowImpl.class, rowId);
470
471 if (expandoRow == _nullExpandoRow) {
472 return null;
473 }
474
475 if (expandoRow == null) {
476 Session session = null;
477
478 boolean hasException = false;
479
480 try {
481 session = openSession();
482
483 expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
484 Long.valueOf(rowId));
485 }
486 catch (Exception e) {
487 hasException = true;
488
489 throw processException(e);
490 }
491 finally {
492 if (expandoRow != null) {
493 cacheResult(expandoRow);
494 }
495 else if (!hasException) {
496 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
497 ExpandoRowImpl.class, rowId, _nullExpandoRow);
498 }
499
500 closeSession(session);
501 }
502 }
503
504 return expandoRow;
505 }
506
507
514 public List<ExpandoRow> findByTableId(long tableId)
515 throws SystemException {
516 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
517 }
518
519
532 public List<ExpandoRow> findByTableId(long tableId, int start, int end)
533 throws SystemException {
534 return findByTableId(tableId, start, end, null);
535 }
536
537
551 public List<ExpandoRow> findByTableId(long tableId, int start, int end,
552 OrderByComparator orderByComparator) throws SystemException {
553 FinderPath finderPath = null;
554 Object[] finderArgs = null;
555
556 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
557 (orderByComparator == null)) {
558 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
559 finderArgs = new Object[] { tableId };
560 }
561 else {
562 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
563 finderArgs = new Object[] { tableId, start, end, orderByComparator };
564 }
565
566 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
567 finderArgs, this);
568
569 if ((list != null) && !list.isEmpty()) {
570 for (ExpandoRow expandoRow : list) {
571 if ((tableId != expandoRow.getTableId())) {
572 list = null;
573
574 break;
575 }
576 }
577 }
578
579 if (list == null) {
580 StringBundler query = null;
581
582 if (orderByComparator != null) {
583 query = new StringBundler(3 +
584 (orderByComparator.getOrderByFields().length * 3));
585 }
586 else {
587 query = new StringBundler(2);
588 }
589
590 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
591
592 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
593
594 if (orderByComparator != null) {
595 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
596 orderByComparator);
597 }
598
599 String sql = query.toString();
600
601 Session session = null;
602
603 try {
604 session = openSession();
605
606 Query q = session.createQuery(sql);
607
608 QueryPos qPos = QueryPos.getInstance(q);
609
610 qPos.add(tableId);
611
612 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(), start,
613 end);
614 }
615 catch (Exception e) {
616 throw processException(e);
617 }
618 finally {
619 if (list == null) {
620 FinderCacheUtil.removeResult(finderPath, finderArgs);
621 }
622 else {
623 cacheResult(list);
624
625 FinderCacheUtil.putResult(finderPath, finderArgs, list);
626 }
627
628 closeSession(session);
629 }
630 }
631
632 return list;
633 }
634
635
644 public ExpandoRow findByTableId_First(long tableId,
645 OrderByComparator orderByComparator)
646 throws NoSuchRowException, SystemException {
647 ExpandoRow expandoRow = fetchByTableId_First(tableId, orderByComparator);
648
649 if (expandoRow != null) {
650 return expandoRow;
651 }
652
653 StringBundler msg = new StringBundler(4);
654
655 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
656
657 msg.append("tableId=");
658 msg.append(tableId);
659
660 msg.append(StringPool.CLOSE_CURLY_BRACE);
661
662 throw new NoSuchRowException(msg.toString());
663 }
664
665
673 public ExpandoRow fetchByTableId_First(long tableId,
674 OrderByComparator orderByComparator) throws SystemException {
675 List<ExpandoRow> list = findByTableId(tableId, 0, 1, orderByComparator);
676
677 if (!list.isEmpty()) {
678 return list.get(0);
679 }
680
681 return null;
682 }
683
684
693 public ExpandoRow findByTableId_Last(long tableId,
694 OrderByComparator orderByComparator)
695 throws NoSuchRowException, SystemException {
696 ExpandoRow expandoRow = fetchByTableId_Last(tableId, orderByComparator);
697
698 if (expandoRow != null) {
699 return expandoRow;
700 }
701
702 StringBundler msg = new StringBundler(4);
703
704 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
705
706 msg.append("tableId=");
707 msg.append(tableId);
708
709 msg.append(StringPool.CLOSE_CURLY_BRACE);
710
711 throw new NoSuchRowException(msg.toString());
712 }
713
714
722 public ExpandoRow fetchByTableId_Last(long tableId,
723 OrderByComparator orderByComparator) throws SystemException {
724 int count = countByTableId(tableId);
725
726 List<ExpandoRow> list = findByTableId(tableId, count - 1, count,
727 orderByComparator);
728
729 if (!list.isEmpty()) {
730 return list.get(0);
731 }
732
733 return null;
734 }
735
736
746 public ExpandoRow[] findByTableId_PrevAndNext(long rowId, long tableId,
747 OrderByComparator orderByComparator)
748 throws NoSuchRowException, SystemException {
749 ExpandoRow expandoRow = findByPrimaryKey(rowId);
750
751 Session session = null;
752
753 try {
754 session = openSession();
755
756 ExpandoRow[] array = new ExpandoRowImpl[3];
757
758 array[0] = getByTableId_PrevAndNext(session, expandoRow, tableId,
759 orderByComparator, true);
760
761 array[1] = expandoRow;
762
763 array[2] = getByTableId_PrevAndNext(session, expandoRow, tableId,
764 orderByComparator, false);
765
766 return array;
767 }
768 catch (Exception e) {
769 throw processException(e);
770 }
771 finally {
772 closeSession(session);
773 }
774 }
775
776 protected ExpandoRow getByTableId_PrevAndNext(Session session,
777 ExpandoRow expandoRow, long tableId,
778 OrderByComparator orderByComparator, boolean previous) {
779 StringBundler query = null;
780
781 if (orderByComparator != null) {
782 query = new StringBundler(6 +
783 (orderByComparator.getOrderByFields().length * 6));
784 }
785 else {
786 query = new StringBundler(3);
787 }
788
789 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
790
791 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
792
793 if (orderByComparator != null) {
794 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
795
796 if (orderByConditionFields.length > 0) {
797 query.append(WHERE_AND);
798 }
799
800 for (int i = 0; i < orderByConditionFields.length; i++) {
801 query.append(_ORDER_BY_ENTITY_ALIAS);
802 query.append(orderByConditionFields[i]);
803
804 if ((i + 1) < orderByConditionFields.length) {
805 if (orderByComparator.isAscending() ^ previous) {
806 query.append(WHERE_GREATER_THAN_HAS_NEXT);
807 }
808 else {
809 query.append(WHERE_LESSER_THAN_HAS_NEXT);
810 }
811 }
812 else {
813 if (orderByComparator.isAscending() ^ previous) {
814 query.append(WHERE_GREATER_THAN);
815 }
816 else {
817 query.append(WHERE_LESSER_THAN);
818 }
819 }
820 }
821
822 query.append(ORDER_BY_CLAUSE);
823
824 String[] orderByFields = orderByComparator.getOrderByFields();
825
826 for (int i = 0; i < orderByFields.length; i++) {
827 query.append(_ORDER_BY_ENTITY_ALIAS);
828 query.append(orderByFields[i]);
829
830 if ((i + 1) < orderByFields.length) {
831 if (orderByComparator.isAscending() ^ previous) {
832 query.append(ORDER_BY_ASC_HAS_NEXT);
833 }
834 else {
835 query.append(ORDER_BY_DESC_HAS_NEXT);
836 }
837 }
838 else {
839 if (orderByComparator.isAscending() ^ previous) {
840 query.append(ORDER_BY_ASC);
841 }
842 else {
843 query.append(ORDER_BY_DESC);
844 }
845 }
846 }
847 }
848
849 String sql = query.toString();
850
851 Query q = session.createQuery(sql);
852
853 q.setFirstResult(0);
854 q.setMaxResults(2);
855
856 QueryPos qPos = QueryPos.getInstance(q);
857
858 qPos.add(tableId);
859
860 if (orderByComparator != null) {
861 Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
862
863 for (Object value : values) {
864 qPos.add(value);
865 }
866 }
867
868 List<ExpandoRow> list = q.list();
869
870 if (list.size() == 2) {
871 return list.get(1);
872 }
873 else {
874 return null;
875 }
876 }
877
878
887 public ExpandoRow findByT_C(long tableId, long classPK)
888 throws NoSuchRowException, SystemException {
889 ExpandoRow expandoRow = fetchByT_C(tableId, classPK);
890
891 if (expandoRow == null) {
892 StringBundler msg = new StringBundler(6);
893
894 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
895
896 msg.append("tableId=");
897 msg.append(tableId);
898
899 msg.append(", classPK=");
900 msg.append(classPK);
901
902 msg.append(StringPool.CLOSE_CURLY_BRACE);
903
904 if (_log.isWarnEnabled()) {
905 _log.warn(msg.toString());
906 }
907
908 throw new NoSuchRowException(msg.toString());
909 }
910
911 return expandoRow;
912 }
913
914
922 public ExpandoRow fetchByT_C(long tableId, long classPK)
923 throws SystemException {
924 return fetchByT_C(tableId, classPK, true);
925 }
926
927
936 public ExpandoRow fetchByT_C(long tableId, long classPK,
937 boolean retrieveFromCache) throws SystemException {
938 Object[] finderArgs = new Object[] { tableId, classPK };
939
940 Object result = null;
941
942 if (retrieveFromCache) {
943 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
944 finderArgs, this);
945 }
946
947 if (result instanceof ExpandoRow) {
948 ExpandoRow expandoRow = (ExpandoRow)result;
949
950 if ((tableId != expandoRow.getTableId()) ||
951 (classPK != expandoRow.getClassPK())) {
952 result = null;
953 }
954 }
955
956 if (result == null) {
957 StringBundler query = new StringBundler(3);
958
959 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
960
961 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
962
963 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
964
965 String sql = query.toString();
966
967 Session session = null;
968
969 try {
970 session = openSession();
971
972 Query q = session.createQuery(sql);
973
974 QueryPos qPos = QueryPos.getInstance(q);
975
976 qPos.add(tableId);
977
978 qPos.add(classPK);
979
980 List<ExpandoRow> list = q.list();
981
982 result = list;
983
984 ExpandoRow expandoRow = null;
985
986 if (list.isEmpty()) {
987 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
988 finderArgs, list);
989 }
990 else {
991 expandoRow = list.get(0);
992
993 cacheResult(expandoRow);
994
995 if ((expandoRow.getTableId() != tableId) ||
996 (expandoRow.getClassPK() != classPK)) {
997 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
998 finderArgs, expandoRow);
999 }
1000 }
1001
1002 return expandoRow;
1003 }
1004 catch (Exception e) {
1005 throw processException(e);
1006 }
1007 finally {
1008 if (result == null) {
1009 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
1010 finderArgs);
1011 }
1012
1013 closeSession(session);
1014 }
1015 }
1016 else {
1017 if (result instanceof List<?>) {
1018 return null;
1019 }
1020 else {
1021 return (ExpandoRow)result;
1022 }
1023 }
1024 }
1025
1026
1032 public List<ExpandoRow> findAll() throws SystemException {
1033 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1034 }
1035
1036
1048 public List<ExpandoRow> findAll(int start, int end)
1049 throws SystemException {
1050 return findAll(start, end, null);
1051 }
1052
1053
1066 public List<ExpandoRow> findAll(int start, int end,
1067 OrderByComparator orderByComparator) throws SystemException {
1068 FinderPath finderPath = null;
1069 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1070
1071 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1072 (orderByComparator == null)) {
1073 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1074 finderArgs = FINDER_ARGS_EMPTY;
1075 }
1076 else {
1077 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1078 finderArgs = new Object[] { start, end, orderByComparator };
1079 }
1080
1081 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
1082 finderArgs, this);
1083
1084 if (list == null) {
1085 StringBundler query = null;
1086 String sql = null;
1087
1088 if (orderByComparator != null) {
1089 query = new StringBundler(2 +
1090 (orderByComparator.getOrderByFields().length * 3));
1091
1092 query.append(_SQL_SELECT_EXPANDOROW);
1093
1094 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1095 orderByComparator);
1096
1097 sql = query.toString();
1098 }
1099 else {
1100 sql = _SQL_SELECT_EXPANDOROW;
1101 }
1102
1103 Session session = null;
1104
1105 try {
1106 session = openSession();
1107
1108 Query q = session.createQuery(sql);
1109
1110 if (orderByComparator == null) {
1111 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1112 start, end, false);
1113
1114 Collections.sort(list);
1115 }
1116 else {
1117 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1118 start, end);
1119 }
1120 }
1121 catch (Exception e) {
1122 throw processException(e);
1123 }
1124 finally {
1125 if (list == null) {
1126 FinderCacheUtil.removeResult(finderPath, finderArgs);
1127 }
1128 else {
1129 cacheResult(list);
1130
1131 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1132 }
1133
1134 closeSession(session);
1135 }
1136 }
1137
1138 return list;
1139 }
1140
1141
1147 public void removeByTableId(long tableId) throws SystemException {
1148 for (ExpandoRow expandoRow : findByTableId(tableId)) {
1149 remove(expandoRow);
1150 }
1151 }
1152
1153
1161 public ExpandoRow removeByT_C(long tableId, long classPK)
1162 throws NoSuchRowException, SystemException {
1163 ExpandoRow expandoRow = findByT_C(tableId, classPK);
1164
1165 return remove(expandoRow);
1166 }
1167
1168
1173 public void removeAll() throws SystemException {
1174 for (ExpandoRow expandoRow : findAll()) {
1175 remove(expandoRow);
1176 }
1177 }
1178
1179
1186 public int countByTableId(long tableId) throws SystemException {
1187 Object[] finderArgs = new Object[] { tableId };
1188
1189 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
1190 finderArgs, this);
1191
1192 if (count == null) {
1193 StringBundler query = new StringBundler(2);
1194
1195 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1196
1197 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1198
1199 String sql = query.toString();
1200
1201 Session session = null;
1202
1203 try {
1204 session = openSession();
1205
1206 Query q = session.createQuery(sql);
1207
1208 QueryPos qPos = QueryPos.getInstance(q);
1209
1210 qPos.add(tableId);
1211
1212 count = (Long)q.uniqueResult();
1213 }
1214 catch (Exception e) {
1215 throw processException(e);
1216 }
1217 finally {
1218 if (count == null) {
1219 count = Long.valueOf(0);
1220 }
1221
1222 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
1223 finderArgs, count);
1224
1225 closeSession(session);
1226 }
1227 }
1228
1229 return count.intValue();
1230 }
1231
1232
1240 public int countByT_C(long tableId, long classPK) throws SystemException {
1241 Object[] finderArgs = new Object[] { tableId, classPK };
1242
1243 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
1244 finderArgs, this);
1245
1246 if (count == null) {
1247 StringBundler query = new StringBundler(3);
1248
1249 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1250
1251 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1252
1253 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1254
1255 String sql = query.toString();
1256
1257 Session session = null;
1258
1259 try {
1260 session = openSession();
1261
1262 Query q = session.createQuery(sql);
1263
1264 QueryPos qPos = QueryPos.getInstance(q);
1265
1266 qPos.add(tableId);
1267
1268 qPos.add(classPK);
1269
1270 count = (Long)q.uniqueResult();
1271 }
1272 catch (Exception e) {
1273 throw processException(e);
1274 }
1275 finally {
1276 if (count == null) {
1277 count = Long.valueOf(0);
1278 }
1279
1280 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
1281 count);
1282
1283 closeSession(session);
1284 }
1285 }
1286
1287 return count.intValue();
1288 }
1289
1290
1296 public int countAll() throws SystemException {
1297 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1298 FINDER_ARGS_EMPTY, this);
1299
1300 if (count == null) {
1301 Session session = null;
1302
1303 try {
1304 session = openSession();
1305
1306 Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
1307
1308 count = (Long)q.uniqueResult();
1309 }
1310 catch (Exception e) {
1311 throw processException(e);
1312 }
1313 finally {
1314 if (count == null) {
1315 count = Long.valueOf(0);
1316 }
1317
1318 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1319 FINDER_ARGS_EMPTY, count);
1320
1321 closeSession(session);
1322 }
1323 }
1324
1325 return count.intValue();
1326 }
1327
1328
1331 public void afterPropertiesSet() {
1332 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1333 com.liferay.portal.util.PropsUtil.get(
1334 "value.object.listener.com.liferay.portlet.expando.model.ExpandoRow")));
1335
1336 if (listenerClassNames.length > 0) {
1337 try {
1338 List<ModelListener<ExpandoRow>> listenersList = new ArrayList<ModelListener<ExpandoRow>>();
1339
1340 for (String listenerClassName : listenerClassNames) {
1341 listenersList.add((ModelListener<ExpandoRow>)InstanceFactory.newInstance(
1342 listenerClassName));
1343 }
1344
1345 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1346 }
1347 catch (Exception e) {
1348 _log.error(e);
1349 }
1350 }
1351 }
1352
1353 public void destroy() {
1354 EntityCacheUtil.removeCache(ExpandoRowImpl.class.getName());
1355 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1356 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1357 }
1358
1359 @BeanReference(type = ExpandoColumnPersistence.class)
1360 protected ExpandoColumnPersistence expandoColumnPersistence;
1361 @BeanReference(type = ExpandoRowPersistence.class)
1362 protected ExpandoRowPersistence expandoRowPersistence;
1363 @BeanReference(type = ExpandoTablePersistence.class)
1364 protected ExpandoTablePersistence expandoTablePersistence;
1365 @BeanReference(type = ExpandoValuePersistence.class)
1366 protected ExpandoValuePersistence expandoValuePersistence;
1367 @BeanReference(type = ResourcePersistence.class)
1368 protected ResourcePersistence resourcePersistence;
1369 @BeanReference(type = UserPersistence.class)
1370 protected UserPersistence userPersistence;
1371 private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
1372 private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
1373 private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
1374 private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
1375 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoRow.tableId = ?";
1376 private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoRow.tableId = ? AND ";
1377 private static final String _FINDER_COLUMN_T_C_CLASSPK_2 = "expandoRow.classPK = ?";
1378 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1379 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1380 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1381 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1382 private static Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1383 private static ExpandoRow _nullExpandoRow = new ExpandoRowImpl() {
1384 @Override
1385 public Object clone() {
1386 return this;
1387 }
1388
1389 @Override
1390 public CacheModel<ExpandoRow> toCacheModel() {
1391 return _nullExpandoRowCacheModel;
1392 }
1393 };
1394
1395 private static CacheModel<ExpandoRow> _nullExpandoRowCacheModel = new CacheModel<ExpandoRow>() {
1396 public ExpandoRow toEntityModel() {
1397 return _nullExpandoRow;
1398 }
1399 };
1400 }