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 cacheUniqueFindersCache(ExpandoRow expandoRow) {
205 if (expandoRow.isNew()) {
206 Object[] args = new Object[] {
207 Long.valueOf(expandoRow.getTableId()),
208 Long.valueOf(expandoRow.getClassPK())
209 };
210
211 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
212 Long.valueOf(1));
213 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args, expandoRow);
214 }
215 else {
216 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
217
218 if ((expandoRowModelImpl.getColumnBitmask() &
219 FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
220 Object[] args = new Object[] {
221 Long.valueOf(expandoRow.getTableId()),
222 Long.valueOf(expandoRow.getClassPK())
223 };
224
225 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
226 Long.valueOf(1));
227 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args,
228 expandoRow);
229 }
230 }
231 }
232
233 protected void clearUniqueFindersCache(ExpandoRow expandoRow) {
234 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
235
236 Object[] args = new Object[] {
237 Long.valueOf(expandoRow.getTableId()),
238 Long.valueOf(expandoRow.getClassPK())
239 };
240
241 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
242 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
243
244 if ((expandoRowModelImpl.getColumnBitmask() &
245 FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
246 args = new Object[] {
247 Long.valueOf(expandoRowModelImpl.getOriginalTableId()),
248 Long.valueOf(expandoRowModelImpl.getOriginalClassPK())
249 };
250
251 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
252 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
253 }
254 }
255
256
262 public ExpandoRow create(long rowId) {
263 ExpandoRow expandoRow = new ExpandoRowImpl();
264
265 expandoRow.setNew(true);
266 expandoRow.setPrimaryKey(rowId);
267
268 return expandoRow;
269 }
270
271
279 public ExpandoRow remove(long rowId)
280 throws NoSuchRowException, SystemException {
281 return remove(Long.valueOf(rowId));
282 }
283
284
292 @Override
293 public ExpandoRow remove(Serializable primaryKey)
294 throws NoSuchRowException, SystemException {
295 Session session = null;
296
297 try {
298 session = openSession();
299
300 ExpandoRow expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
301 primaryKey);
302
303 if (expandoRow == null) {
304 if (_log.isWarnEnabled()) {
305 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
306 }
307
308 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
309 primaryKey);
310 }
311
312 return remove(expandoRow);
313 }
314 catch (NoSuchRowException nsee) {
315 throw nsee;
316 }
317 catch (Exception e) {
318 throw processException(e);
319 }
320 finally {
321 closeSession(session);
322 }
323 }
324
325 @Override
326 protected ExpandoRow removeImpl(ExpandoRow expandoRow)
327 throws SystemException {
328 expandoRow = toUnwrappedModel(expandoRow);
329
330 Session session = null;
331
332 try {
333 session = openSession();
334
335 BatchSessionUtil.delete(session, expandoRow);
336 }
337 catch (Exception e) {
338 throw processException(e);
339 }
340 finally {
341 closeSession(session);
342 }
343
344 clearCache(expandoRow);
345
346 return expandoRow;
347 }
348
349 @Override
350 public ExpandoRow updateImpl(
351 com.liferay.portlet.expando.model.ExpandoRow expandoRow, boolean merge)
352 throws SystemException {
353 expandoRow = toUnwrappedModel(expandoRow);
354
355 boolean isNew = expandoRow.isNew();
356
357 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
358
359 Session session = null;
360
361 try {
362 session = openSession();
363
364 BatchSessionUtil.update(session, expandoRow, merge);
365
366 expandoRow.setNew(false);
367 }
368 catch (Exception e) {
369 throw processException(e);
370 }
371 finally {
372 closeSession(session);
373 }
374
375 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
376
377 if (isNew || !ExpandoRowModelImpl.COLUMN_BITMASK_ENABLED) {
378 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
379 }
380
381 else {
382 if ((expandoRowModelImpl.getColumnBitmask() &
383 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
384 Object[] args = new Object[] {
385 Long.valueOf(expandoRowModelImpl.getOriginalTableId())
386 };
387
388 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
389 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
390 args);
391
392 args = new Object[] {
393 Long.valueOf(expandoRowModelImpl.getTableId())
394 };
395
396 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
397 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
398 args);
399 }
400 }
401
402 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
403 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
404
405 clearUniqueFindersCache(expandoRow);
406 cacheUniqueFindersCache(expandoRow);
407
408 return expandoRow;
409 }
410
411 protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
412 if (expandoRow instanceof ExpandoRowImpl) {
413 return expandoRow;
414 }
415
416 ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
417
418 expandoRowImpl.setNew(expandoRow.isNew());
419 expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
420
421 expandoRowImpl.setRowId(expandoRow.getRowId());
422 expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
423 expandoRowImpl.setTableId(expandoRow.getTableId());
424 expandoRowImpl.setClassPK(expandoRow.getClassPK());
425
426 return expandoRowImpl;
427 }
428
429
437 @Override
438 public ExpandoRow findByPrimaryKey(Serializable primaryKey)
439 throws NoSuchModelException, SystemException {
440 return findByPrimaryKey(((Long)primaryKey).longValue());
441 }
442
443
451 public ExpandoRow findByPrimaryKey(long rowId)
452 throws NoSuchRowException, SystemException {
453 ExpandoRow expandoRow = fetchByPrimaryKey(rowId);
454
455 if (expandoRow == null) {
456 if (_log.isWarnEnabled()) {
457 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + rowId);
458 }
459
460 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
461 rowId);
462 }
463
464 return expandoRow;
465 }
466
467
474 @Override
475 public ExpandoRow fetchByPrimaryKey(Serializable primaryKey)
476 throws SystemException {
477 return fetchByPrimaryKey(((Long)primaryKey).longValue());
478 }
479
480
487 public ExpandoRow fetchByPrimaryKey(long rowId) throws SystemException {
488 ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
489 ExpandoRowImpl.class, rowId);
490
491 if (expandoRow == _nullExpandoRow) {
492 return null;
493 }
494
495 if (expandoRow == null) {
496 Session session = null;
497
498 boolean hasException = false;
499
500 try {
501 session = openSession();
502
503 expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
504 Long.valueOf(rowId));
505 }
506 catch (Exception e) {
507 hasException = true;
508
509 throw processException(e);
510 }
511 finally {
512 if (expandoRow != null) {
513 cacheResult(expandoRow);
514 }
515 else if (!hasException) {
516 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
517 ExpandoRowImpl.class, rowId, _nullExpandoRow);
518 }
519
520 closeSession(session);
521 }
522 }
523
524 return expandoRow;
525 }
526
527
534 public List<ExpandoRow> findByTableId(long tableId)
535 throws SystemException {
536 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
537 }
538
539
552 public List<ExpandoRow> findByTableId(long tableId, int start, int end)
553 throws SystemException {
554 return findByTableId(tableId, start, end, null);
555 }
556
557
571 public List<ExpandoRow> findByTableId(long tableId, int start, int end,
572 OrderByComparator orderByComparator) throws SystemException {
573 FinderPath finderPath = null;
574 Object[] finderArgs = null;
575
576 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
577 (orderByComparator == null)) {
578 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
579 finderArgs = new Object[] { tableId };
580 }
581 else {
582 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
583 finderArgs = new Object[] { tableId, start, end, orderByComparator };
584 }
585
586 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
587 finderArgs, this);
588
589 if ((list != null) && !list.isEmpty()) {
590 for (ExpandoRow expandoRow : list) {
591 if ((tableId != expandoRow.getTableId())) {
592 list = null;
593
594 break;
595 }
596 }
597 }
598
599 if (list == null) {
600 StringBundler query = null;
601
602 if (orderByComparator != null) {
603 query = new StringBundler(3 +
604 (orderByComparator.getOrderByFields().length * 3));
605 }
606 else {
607 query = new StringBundler(2);
608 }
609
610 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
611
612 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
613
614 if (orderByComparator != null) {
615 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
616 orderByComparator);
617 }
618
619 String sql = query.toString();
620
621 Session session = null;
622
623 try {
624 session = openSession();
625
626 Query q = session.createQuery(sql);
627
628 QueryPos qPos = QueryPos.getInstance(q);
629
630 qPos.add(tableId);
631
632 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(), start,
633 end);
634 }
635 catch (Exception e) {
636 throw processException(e);
637 }
638 finally {
639 if (list == null) {
640 FinderCacheUtil.removeResult(finderPath, finderArgs);
641 }
642 else {
643 cacheResult(list);
644
645 FinderCacheUtil.putResult(finderPath, finderArgs, list);
646 }
647
648 closeSession(session);
649 }
650 }
651
652 return list;
653 }
654
655
664 public ExpandoRow findByTableId_First(long tableId,
665 OrderByComparator orderByComparator)
666 throws NoSuchRowException, SystemException {
667 ExpandoRow expandoRow = fetchByTableId_First(tableId, orderByComparator);
668
669 if (expandoRow != null) {
670 return expandoRow;
671 }
672
673 StringBundler msg = new StringBundler(4);
674
675 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
676
677 msg.append("tableId=");
678 msg.append(tableId);
679
680 msg.append(StringPool.CLOSE_CURLY_BRACE);
681
682 throw new NoSuchRowException(msg.toString());
683 }
684
685
693 public ExpandoRow fetchByTableId_First(long tableId,
694 OrderByComparator orderByComparator) throws SystemException {
695 List<ExpandoRow> list = findByTableId(tableId, 0, 1, orderByComparator);
696
697 if (!list.isEmpty()) {
698 return list.get(0);
699 }
700
701 return null;
702 }
703
704
713 public ExpandoRow findByTableId_Last(long tableId,
714 OrderByComparator orderByComparator)
715 throws NoSuchRowException, SystemException {
716 ExpandoRow expandoRow = fetchByTableId_Last(tableId, orderByComparator);
717
718 if (expandoRow != null) {
719 return expandoRow;
720 }
721
722 StringBundler msg = new StringBundler(4);
723
724 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
725
726 msg.append("tableId=");
727 msg.append(tableId);
728
729 msg.append(StringPool.CLOSE_CURLY_BRACE);
730
731 throw new NoSuchRowException(msg.toString());
732 }
733
734
742 public ExpandoRow fetchByTableId_Last(long tableId,
743 OrderByComparator orderByComparator) throws SystemException {
744 int count = countByTableId(tableId);
745
746 List<ExpandoRow> list = findByTableId(tableId, count - 1, count,
747 orderByComparator);
748
749 if (!list.isEmpty()) {
750 return list.get(0);
751 }
752
753 return null;
754 }
755
756
766 public ExpandoRow[] findByTableId_PrevAndNext(long rowId, long tableId,
767 OrderByComparator orderByComparator)
768 throws NoSuchRowException, SystemException {
769 ExpandoRow expandoRow = findByPrimaryKey(rowId);
770
771 Session session = null;
772
773 try {
774 session = openSession();
775
776 ExpandoRow[] array = new ExpandoRowImpl[3];
777
778 array[0] = getByTableId_PrevAndNext(session, expandoRow, tableId,
779 orderByComparator, true);
780
781 array[1] = expandoRow;
782
783 array[2] = getByTableId_PrevAndNext(session, expandoRow, tableId,
784 orderByComparator, false);
785
786 return array;
787 }
788 catch (Exception e) {
789 throw processException(e);
790 }
791 finally {
792 closeSession(session);
793 }
794 }
795
796 protected ExpandoRow getByTableId_PrevAndNext(Session session,
797 ExpandoRow expandoRow, long tableId,
798 OrderByComparator orderByComparator, boolean previous) {
799 StringBundler query = null;
800
801 if (orderByComparator != null) {
802 query = new StringBundler(6 +
803 (orderByComparator.getOrderByFields().length * 6));
804 }
805 else {
806 query = new StringBundler(3);
807 }
808
809 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
810
811 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
812
813 if (orderByComparator != null) {
814 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
815
816 if (orderByConditionFields.length > 0) {
817 query.append(WHERE_AND);
818 }
819
820 for (int i = 0; i < orderByConditionFields.length; i++) {
821 query.append(_ORDER_BY_ENTITY_ALIAS);
822 query.append(orderByConditionFields[i]);
823
824 if ((i + 1) < orderByConditionFields.length) {
825 if (orderByComparator.isAscending() ^ previous) {
826 query.append(WHERE_GREATER_THAN_HAS_NEXT);
827 }
828 else {
829 query.append(WHERE_LESSER_THAN_HAS_NEXT);
830 }
831 }
832 else {
833 if (orderByComparator.isAscending() ^ previous) {
834 query.append(WHERE_GREATER_THAN);
835 }
836 else {
837 query.append(WHERE_LESSER_THAN);
838 }
839 }
840 }
841
842 query.append(ORDER_BY_CLAUSE);
843
844 String[] orderByFields = orderByComparator.getOrderByFields();
845
846 for (int i = 0; i < orderByFields.length; i++) {
847 query.append(_ORDER_BY_ENTITY_ALIAS);
848 query.append(orderByFields[i]);
849
850 if ((i + 1) < orderByFields.length) {
851 if (orderByComparator.isAscending() ^ previous) {
852 query.append(ORDER_BY_ASC_HAS_NEXT);
853 }
854 else {
855 query.append(ORDER_BY_DESC_HAS_NEXT);
856 }
857 }
858 else {
859 if (orderByComparator.isAscending() ^ previous) {
860 query.append(ORDER_BY_ASC);
861 }
862 else {
863 query.append(ORDER_BY_DESC);
864 }
865 }
866 }
867 }
868
869 String sql = query.toString();
870
871 Query q = session.createQuery(sql);
872
873 q.setFirstResult(0);
874 q.setMaxResults(2);
875
876 QueryPos qPos = QueryPos.getInstance(q);
877
878 qPos.add(tableId);
879
880 if (orderByComparator != null) {
881 Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
882
883 for (Object value : values) {
884 qPos.add(value);
885 }
886 }
887
888 List<ExpandoRow> list = q.list();
889
890 if (list.size() == 2) {
891 return list.get(1);
892 }
893 else {
894 return null;
895 }
896 }
897
898
907 public ExpandoRow findByT_C(long tableId, long classPK)
908 throws NoSuchRowException, SystemException {
909 ExpandoRow expandoRow = fetchByT_C(tableId, classPK);
910
911 if (expandoRow == null) {
912 StringBundler msg = new StringBundler(6);
913
914 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
915
916 msg.append("tableId=");
917 msg.append(tableId);
918
919 msg.append(", classPK=");
920 msg.append(classPK);
921
922 msg.append(StringPool.CLOSE_CURLY_BRACE);
923
924 if (_log.isWarnEnabled()) {
925 _log.warn(msg.toString());
926 }
927
928 throw new NoSuchRowException(msg.toString());
929 }
930
931 return expandoRow;
932 }
933
934
942 public ExpandoRow fetchByT_C(long tableId, long classPK)
943 throws SystemException {
944 return fetchByT_C(tableId, classPK, true);
945 }
946
947
956 public ExpandoRow fetchByT_C(long tableId, long classPK,
957 boolean retrieveFromCache) throws SystemException {
958 Object[] finderArgs = new Object[] { tableId, classPK };
959
960 Object result = null;
961
962 if (retrieveFromCache) {
963 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
964 finderArgs, this);
965 }
966
967 if (result instanceof ExpandoRow) {
968 ExpandoRow expandoRow = (ExpandoRow)result;
969
970 if ((tableId != expandoRow.getTableId()) ||
971 (classPK != expandoRow.getClassPK())) {
972 result = null;
973 }
974 }
975
976 if (result == null) {
977 StringBundler query = new StringBundler(3);
978
979 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
980
981 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
982
983 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
984
985 String sql = query.toString();
986
987 Session session = null;
988
989 try {
990 session = openSession();
991
992 Query q = session.createQuery(sql);
993
994 QueryPos qPos = QueryPos.getInstance(q);
995
996 qPos.add(tableId);
997
998 qPos.add(classPK);
999
1000 List<ExpandoRow> list = q.list();
1001
1002 result = list;
1003
1004 ExpandoRow expandoRow = null;
1005
1006 if (list.isEmpty()) {
1007 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1008 finderArgs, list);
1009 }
1010 else {
1011 expandoRow = list.get(0);
1012
1013 cacheResult(expandoRow);
1014
1015 if ((expandoRow.getTableId() != tableId) ||
1016 (expandoRow.getClassPK() != classPK)) {
1017 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1018 finderArgs, expandoRow);
1019 }
1020 }
1021
1022 return expandoRow;
1023 }
1024 catch (Exception e) {
1025 throw processException(e);
1026 }
1027 finally {
1028 if (result == null) {
1029 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
1030 finderArgs);
1031 }
1032
1033 closeSession(session);
1034 }
1035 }
1036 else {
1037 if (result instanceof List<?>) {
1038 return null;
1039 }
1040 else {
1041 return (ExpandoRow)result;
1042 }
1043 }
1044 }
1045
1046
1052 public List<ExpandoRow> findAll() throws SystemException {
1053 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1054 }
1055
1056
1068 public List<ExpandoRow> findAll(int start, int end)
1069 throws SystemException {
1070 return findAll(start, end, null);
1071 }
1072
1073
1086 public List<ExpandoRow> findAll(int start, int end,
1087 OrderByComparator orderByComparator) throws SystemException {
1088 FinderPath finderPath = null;
1089 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1090
1091 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1092 (orderByComparator == null)) {
1093 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1094 finderArgs = FINDER_ARGS_EMPTY;
1095 }
1096 else {
1097 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1098 finderArgs = new Object[] { start, end, orderByComparator };
1099 }
1100
1101 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
1102 finderArgs, this);
1103
1104 if (list == null) {
1105 StringBundler query = null;
1106 String sql = null;
1107
1108 if (orderByComparator != null) {
1109 query = new StringBundler(2 +
1110 (orderByComparator.getOrderByFields().length * 3));
1111
1112 query.append(_SQL_SELECT_EXPANDOROW);
1113
1114 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1115 orderByComparator);
1116
1117 sql = query.toString();
1118 }
1119 else {
1120 sql = _SQL_SELECT_EXPANDOROW;
1121 }
1122
1123 Session session = null;
1124
1125 try {
1126 session = openSession();
1127
1128 Query q = session.createQuery(sql);
1129
1130 if (orderByComparator == null) {
1131 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1132 start, end, false);
1133
1134 Collections.sort(list);
1135 }
1136 else {
1137 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1138 start, end);
1139 }
1140 }
1141 catch (Exception e) {
1142 throw processException(e);
1143 }
1144 finally {
1145 if (list == null) {
1146 FinderCacheUtil.removeResult(finderPath, finderArgs);
1147 }
1148 else {
1149 cacheResult(list);
1150
1151 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1152 }
1153
1154 closeSession(session);
1155 }
1156 }
1157
1158 return list;
1159 }
1160
1161
1167 public void removeByTableId(long tableId) throws SystemException {
1168 for (ExpandoRow expandoRow : findByTableId(tableId)) {
1169 remove(expandoRow);
1170 }
1171 }
1172
1173
1181 public ExpandoRow removeByT_C(long tableId, long classPK)
1182 throws NoSuchRowException, SystemException {
1183 ExpandoRow expandoRow = findByT_C(tableId, classPK);
1184
1185 return remove(expandoRow);
1186 }
1187
1188
1193 public void removeAll() throws SystemException {
1194 for (ExpandoRow expandoRow : findAll()) {
1195 remove(expandoRow);
1196 }
1197 }
1198
1199
1206 public int countByTableId(long tableId) throws SystemException {
1207 Object[] finderArgs = new Object[] { tableId };
1208
1209 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
1210 finderArgs, this);
1211
1212 if (count == null) {
1213 StringBundler query = new StringBundler(2);
1214
1215 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1216
1217 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1218
1219 String sql = query.toString();
1220
1221 Session session = null;
1222
1223 try {
1224 session = openSession();
1225
1226 Query q = session.createQuery(sql);
1227
1228 QueryPos qPos = QueryPos.getInstance(q);
1229
1230 qPos.add(tableId);
1231
1232 count = (Long)q.uniqueResult();
1233 }
1234 catch (Exception e) {
1235 throw processException(e);
1236 }
1237 finally {
1238 if (count == null) {
1239 count = Long.valueOf(0);
1240 }
1241
1242 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
1243 finderArgs, count);
1244
1245 closeSession(session);
1246 }
1247 }
1248
1249 return count.intValue();
1250 }
1251
1252
1260 public int countByT_C(long tableId, long classPK) throws SystemException {
1261 Object[] finderArgs = new Object[] { tableId, classPK };
1262
1263 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
1264 finderArgs, this);
1265
1266 if (count == null) {
1267 StringBundler query = new StringBundler(3);
1268
1269 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1270
1271 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1272
1273 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1274
1275 String sql = query.toString();
1276
1277 Session session = null;
1278
1279 try {
1280 session = openSession();
1281
1282 Query q = session.createQuery(sql);
1283
1284 QueryPos qPos = QueryPos.getInstance(q);
1285
1286 qPos.add(tableId);
1287
1288 qPos.add(classPK);
1289
1290 count = (Long)q.uniqueResult();
1291 }
1292 catch (Exception e) {
1293 throw processException(e);
1294 }
1295 finally {
1296 if (count == null) {
1297 count = Long.valueOf(0);
1298 }
1299
1300 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
1301 count);
1302
1303 closeSession(session);
1304 }
1305 }
1306
1307 return count.intValue();
1308 }
1309
1310
1316 public int countAll() throws SystemException {
1317 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1318 FINDER_ARGS_EMPTY, this);
1319
1320 if (count == null) {
1321 Session session = null;
1322
1323 try {
1324 session = openSession();
1325
1326 Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
1327
1328 count = (Long)q.uniqueResult();
1329 }
1330 catch (Exception e) {
1331 throw processException(e);
1332 }
1333 finally {
1334 if (count == null) {
1335 count = Long.valueOf(0);
1336 }
1337
1338 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1339 FINDER_ARGS_EMPTY, count);
1340
1341 closeSession(session);
1342 }
1343 }
1344
1345 return count.intValue();
1346 }
1347
1348
1351 public void afterPropertiesSet() {
1352 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1353 com.liferay.portal.util.PropsUtil.get(
1354 "value.object.listener.com.liferay.portlet.expando.model.ExpandoRow")));
1355
1356 if (listenerClassNames.length > 0) {
1357 try {
1358 List<ModelListener<ExpandoRow>> listenersList = new ArrayList<ModelListener<ExpandoRow>>();
1359
1360 for (String listenerClassName : listenerClassNames) {
1361 Class<?> clazz = getClass();
1362
1363 listenersList.add((ModelListener<ExpandoRow>)InstanceFactory.newInstance(
1364 clazz.getClassLoader(), listenerClassName));
1365 }
1366
1367 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1368 }
1369 catch (Exception e) {
1370 _log.error(e);
1371 }
1372 }
1373 }
1374
1375 public void destroy() {
1376 EntityCacheUtil.removeCache(ExpandoRowImpl.class.getName());
1377 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1378 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1379 }
1380
1381 @BeanReference(type = ExpandoColumnPersistence.class)
1382 protected ExpandoColumnPersistence expandoColumnPersistence;
1383 @BeanReference(type = ExpandoRowPersistence.class)
1384 protected ExpandoRowPersistence expandoRowPersistence;
1385 @BeanReference(type = ExpandoTablePersistence.class)
1386 protected ExpandoTablePersistence expandoTablePersistence;
1387 @BeanReference(type = ExpandoValuePersistence.class)
1388 protected ExpandoValuePersistence expandoValuePersistence;
1389 @BeanReference(type = ResourcePersistence.class)
1390 protected ResourcePersistence resourcePersistence;
1391 @BeanReference(type = UserPersistence.class)
1392 protected UserPersistence userPersistence;
1393 private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
1394 private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
1395 private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
1396 private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
1397 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoRow.tableId = ?";
1398 private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoRow.tableId = ? AND ";
1399 private static final String _FINDER_COLUMN_T_C_CLASSPK_2 = "expandoRow.classPK = ?";
1400 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1401 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1402 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1403 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1404 private static Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1405 private static ExpandoRow _nullExpandoRow = new ExpandoRowImpl() {
1406 @Override
1407 public Object clone() {
1408 return this;
1409 }
1410
1411 @Override
1412 public CacheModel<ExpandoRow> toCacheModel() {
1413 return _nullExpandoRowCacheModel;
1414 }
1415 };
1416
1417 private static CacheModel<ExpandoRow> _nullExpandoRowCacheModel = new CacheModel<ExpandoRow>() {
1418 public ExpandoRow toEntityModel() {
1419 return _nullExpandoRow;
1420 }
1421 };
1422 }