1
14
15 package com.liferay.portlet.expando.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.kernel.annotation.BeanReference;
19 import com.liferay.portal.kernel.cache.CacheRegistry;
20 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderPath;
23 import com.liferay.portal.kernel.dao.orm.Query;
24 import com.liferay.portal.kernel.dao.orm.QueryPos;
25 import com.liferay.portal.kernel.dao.orm.QueryUtil;
26 import com.liferay.portal.kernel.dao.orm.Session;
27 import com.liferay.portal.kernel.exception.SystemException;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30 import com.liferay.portal.kernel.util.GetterUtil;
31 import com.liferay.portal.kernel.util.InstanceFactory;
32 import com.liferay.portal.kernel.util.OrderByComparator;
33 import com.liferay.portal.kernel.util.StringBundler;
34 import com.liferay.portal.kernel.util.StringPool;
35 import com.liferay.portal.kernel.util.StringUtil;
36 import com.liferay.portal.model.ModelListener;
37 import com.liferay.portal.service.persistence.BatchSessionUtil;
38 import com.liferay.portal.service.persistence.ResourcePersistence;
39 import com.liferay.portal.service.persistence.UserPersistence;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import com.liferay.portlet.expando.NoSuchRowException;
43 import com.liferay.portlet.expando.model.ExpandoRow;
44 import com.liferay.portlet.expando.model.impl.ExpandoRowImpl;
45 import com.liferay.portlet.expando.model.impl.ExpandoRowModelImpl;
46
47 import java.io.Serializable;
48
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.List;
52
53
66 public class ExpandoRowPersistenceImpl extends BasePersistenceImpl<ExpandoRow>
67 implements ExpandoRowPersistence {
68 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoRowImpl.class.getName();
69 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70 ".List";
71 public static final FinderPath FINDER_PATH_FIND_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
72 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73 "findByTableId",
74 new String[] {
75 Long.class.getName(),
76
77 "java.lang.Integer", "java.lang.Integer",
78 "com.liferay.portal.kernel.util.OrderByComparator"
79 });
80 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
81 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
82 "countByTableId", new String[] { Long.class.getName() });
83 public static final FinderPath FINDER_PATH_FETCH_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
84 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
85 "fetchByT_C",
86 new String[] { Long.class.getName(), Long.class.getName() });
87 public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
88 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89 "countByT_C",
90 new String[] { Long.class.getName(), Long.class.getName() });
91 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
92 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93 "findAll", new String[0]);
94 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
95 ExpandoRowModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96 "countAll", new String[0]);
97
98 public void cacheResult(ExpandoRow expandoRow) {
99 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
100 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
101
102 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
103 new Object[] {
104 new Long(expandoRow.getTableId()),
105 new Long(expandoRow.getClassPK())
106 }, expandoRow);
107 }
108
109 public void cacheResult(List<ExpandoRow> expandoRows) {
110 for (ExpandoRow expandoRow : expandoRows) {
111 if (EntityCacheUtil.getResult(
112 ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
113 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), this) == null) {
114 cacheResult(expandoRow);
115 }
116 }
117 }
118
119 public void clearCache() {
120 CacheRegistry.clear(ExpandoRowImpl.class.getName());
121 EntityCacheUtil.clearCache(ExpandoRowImpl.class.getName());
122 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
123 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
124 }
125
126 public void clearCache(ExpandoRow expandoRow) {
127 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
128 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
129
130 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
131 new Object[] {
132 new Long(expandoRow.getTableId()),
133 new Long(expandoRow.getClassPK())
134 });
135 }
136
137 public ExpandoRow create(long rowId) {
138 ExpandoRow expandoRow = new ExpandoRowImpl();
139
140 expandoRow.setNew(true);
141 expandoRow.setPrimaryKey(rowId);
142
143 return expandoRow;
144 }
145
146 public ExpandoRow remove(Serializable primaryKey)
147 throws NoSuchModelException, SystemException {
148 return remove(((Long)primaryKey).longValue());
149 }
150
151 public ExpandoRow remove(long rowId)
152 throws NoSuchRowException, SystemException {
153 Session session = null;
154
155 try {
156 session = openSession();
157
158 ExpandoRow expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
159 new Long(rowId));
160
161 if (expandoRow == null) {
162 if (_log.isWarnEnabled()) {
163 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + rowId);
164 }
165
166 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
167 rowId);
168 }
169
170 return remove(expandoRow);
171 }
172 catch (NoSuchRowException nsee) {
173 throw nsee;
174 }
175 catch (Exception e) {
176 throw processException(e);
177 }
178 finally {
179 closeSession(session);
180 }
181 }
182
183 public ExpandoRow remove(ExpandoRow expandoRow) throws SystemException {
184 for (ModelListener<ExpandoRow> listener : listeners) {
185 listener.onBeforeRemove(expandoRow);
186 }
187
188 expandoRow = removeImpl(expandoRow);
189
190 for (ModelListener<ExpandoRow> listener : listeners) {
191 listener.onAfterRemove(expandoRow);
192 }
193
194 return expandoRow;
195 }
196
197 protected ExpandoRow removeImpl(ExpandoRow expandoRow)
198 throws SystemException {
199 expandoRow = toUnwrappedModel(expandoRow);
200
201 Session session = null;
202
203 try {
204 session = openSession();
205
206 if (expandoRow.isCachedModel() || BatchSessionUtil.isEnabled()) {
207 Object staleObject = session.get(ExpandoRowImpl.class,
208 expandoRow.getPrimaryKeyObj());
209
210 if (staleObject != null) {
211 session.evict(staleObject);
212 }
213 }
214
215 session.delete(expandoRow);
216
217 session.flush();
218 }
219 catch (Exception e) {
220 throw processException(e);
221 }
222 finally {
223 closeSession(session);
224 }
225
226 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
227
228 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
229
230 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
231 new Object[] {
232 new Long(expandoRowModelImpl.getOriginalTableId()),
233 new Long(expandoRowModelImpl.getOriginalClassPK())
234 });
235
236 EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
237 ExpandoRowImpl.class, expandoRow.getPrimaryKey());
238
239 return expandoRow;
240 }
241
242 public ExpandoRow updateImpl(
243 com.liferay.portlet.expando.model.ExpandoRow expandoRow, boolean merge)
244 throws SystemException {
245 expandoRow = toUnwrappedModel(expandoRow);
246
247 boolean isNew = expandoRow.isNew();
248
249 ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
250
251 Session session = null;
252
253 try {
254 session = openSession();
255
256 BatchSessionUtil.update(session, expandoRow, merge);
257
258 expandoRow.setNew(false);
259 }
260 catch (Exception e) {
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266
267 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
268
269 EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
270 ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
271
272 if (!isNew &&
273 ((expandoRow.getTableId() != expandoRowModelImpl.getOriginalTableId()) ||
274 (expandoRow.getClassPK() != expandoRowModelImpl.getOriginalClassPK()))) {
275 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
276 new Object[] {
277 new Long(expandoRowModelImpl.getOriginalTableId()),
278 new Long(expandoRowModelImpl.getOriginalClassPK())
279 });
280 }
281
282 if (isNew ||
283 ((expandoRow.getTableId() != expandoRowModelImpl.getOriginalTableId()) ||
284 (expandoRow.getClassPK() != expandoRowModelImpl.getOriginalClassPK()))) {
285 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
286 new Object[] {
287 new Long(expandoRow.getTableId()),
288 new Long(expandoRow.getClassPK())
289 }, expandoRow);
290 }
291
292 return expandoRow;
293 }
294
295 protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
296 if (expandoRow instanceof ExpandoRowImpl) {
297 return expandoRow;
298 }
299
300 ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
301
302 expandoRowImpl.setNew(expandoRow.isNew());
303 expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
304
305 expandoRowImpl.setRowId(expandoRow.getRowId());
306 expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
307 expandoRowImpl.setTableId(expandoRow.getTableId());
308 expandoRowImpl.setClassPK(expandoRow.getClassPK());
309
310 return expandoRowImpl;
311 }
312
313 public ExpandoRow findByPrimaryKey(Serializable primaryKey)
314 throws NoSuchModelException, SystemException {
315 return findByPrimaryKey(((Long)primaryKey).longValue());
316 }
317
318 public ExpandoRow findByPrimaryKey(long rowId)
319 throws NoSuchRowException, SystemException {
320 ExpandoRow expandoRow = fetchByPrimaryKey(rowId);
321
322 if (expandoRow == null) {
323 if (_log.isWarnEnabled()) {
324 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + rowId);
325 }
326
327 throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
328 rowId);
329 }
330
331 return expandoRow;
332 }
333
334 public ExpandoRow fetchByPrimaryKey(Serializable primaryKey)
335 throws SystemException {
336 return fetchByPrimaryKey(((Long)primaryKey).longValue());
337 }
338
339 public ExpandoRow fetchByPrimaryKey(long rowId) throws SystemException {
340 ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
341 ExpandoRowImpl.class, rowId, this);
342
343 if (expandoRow == null) {
344 Session session = null;
345
346 try {
347 session = openSession();
348
349 expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
350 new Long(rowId));
351 }
352 catch (Exception e) {
353 throw processException(e);
354 }
355 finally {
356 if (expandoRow != null) {
357 cacheResult(expandoRow);
358 }
359
360 closeSession(session);
361 }
362 }
363
364 return expandoRow;
365 }
366
367 public List<ExpandoRow> findByTableId(long tableId)
368 throws SystemException {
369 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
370 }
371
372 public List<ExpandoRow> findByTableId(long tableId, int start, int end)
373 throws SystemException {
374 return findByTableId(tableId, start, end, null);
375 }
376
377 public List<ExpandoRow> findByTableId(long tableId, int start, int end,
378 OrderByComparator orderByComparator) throws SystemException {
379 Object[] finderArgs = new Object[] {
380 new Long(tableId),
381
382 String.valueOf(start), String.valueOf(end),
383 String.valueOf(orderByComparator)
384 };
385
386 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TABLEID,
387 finderArgs, this);
388
389 if (list == null) {
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 StringBundler query = null;
396
397 if (orderByComparator != null) {
398 query = new StringBundler(3 +
399 (orderByComparator.getOrderByFields().length * 3));
400 }
401 else {
402 query = new StringBundler(2);
403 }
404
405 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
406
407 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
408
409 if (orderByComparator != null) {
410 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
411 orderByComparator);
412 }
413
414 String sql = query.toString();
415
416 Query q = session.createQuery(sql);
417
418 QueryPos qPos = QueryPos.getInstance(q);
419
420 qPos.add(tableId);
421
422 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(), start,
423 end);
424 }
425 catch (Exception e) {
426 throw processException(e);
427 }
428 finally {
429 if (list == null) {
430 list = new ArrayList<ExpandoRow>();
431 }
432
433 cacheResult(list);
434
435 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TABLEID,
436 finderArgs, list);
437
438 closeSession(session);
439 }
440 }
441
442 return list;
443 }
444
445 public ExpandoRow findByTableId_First(long tableId,
446 OrderByComparator orderByComparator)
447 throws NoSuchRowException, SystemException {
448 List<ExpandoRow> list = findByTableId(tableId, 0, 1, orderByComparator);
449
450 if (list.isEmpty()) {
451 StringBundler msg = new StringBundler(4);
452
453 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
454
455 msg.append("tableId=");
456 msg.append(tableId);
457
458 msg.append(StringPool.CLOSE_CURLY_BRACE);
459
460 throw new NoSuchRowException(msg.toString());
461 }
462 else {
463 return list.get(0);
464 }
465 }
466
467 public ExpandoRow findByTableId_Last(long tableId,
468 OrderByComparator orderByComparator)
469 throws NoSuchRowException, SystemException {
470 int count = countByTableId(tableId);
471
472 List<ExpandoRow> list = findByTableId(tableId, count - 1, count,
473 orderByComparator);
474
475 if (list.isEmpty()) {
476 StringBundler msg = new StringBundler(4);
477
478 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
479
480 msg.append("tableId=");
481 msg.append(tableId);
482
483 msg.append(StringPool.CLOSE_CURLY_BRACE);
484
485 throw new NoSuchRowException(msg.toString());
486 }
487 else {
488 return list.get(0);
489 }
490 }
491
492 public ExpandoRow[] findByTableId_PrevAndNext(long rowId, long tableId,
493 OrderByComparator orderByComparator)
494 throws NoSuchRowException, SystemException {
495 ExpandoRow expandoRow = findByPrimaryKey(rowId);
496
497 Session session = null;
498
499 try {
500 session = openSession();
501
502 ExpandoRow[] array = new ExpandoRowImpl[3];
503
504 array[0] = getByTableId_PrevAndNext(session, expandoRow, tableId,
505 orderByComparator, true);
506
507 array[1] = expandoRow;
508
509 array[2] = getByTableId_PrevAndNext(session, expandoRow, tableId,
510 orderByComparator, false);
511
512 return array;
513 }
514 catch (Exception e) {
515 throw processException(e);
516 }
517 finally {
518 closeSession(session);
519 }
520 }
521
522 protected ExpandoRow getByTableId_PrevAndNext(Session session,
523 ExpandoRow expandoRow, long tableId,
524 OrderByComparator orderByComparator, boolean previous) {
525 StringBundler query = null;
526
527 if (orderByComparator != null) {
528 query = new StringBundler(6 +
529 (orderByComparator.getOrderByFields().length * 6));
530 }
531 else {
532 query = new StringBundler(3);
533 }
534
535 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
536
537 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
538
539 if (orderByComparator != null) {
540 String[] orderByFields = orderByComparator.getOrderByFields();
541
542 if (orderByFields.length > 0) {
543 query.append(WHERE_AND);
544 }
545
546 for (int i = 0; i < orderByFields.length; i++) {
547 query.append(_ORDER_BY_ENTITY_ALIAS);
548 query.append(orderByFields[i]);
549
550 if ((i + 1) < orderByFields.length) {
551 if (orderByComparator.isAscending() ^ previous) {
552 query.append(WHERE_GREATER_THAN_HAS_NEXT);
553 }
554 else {
555 query.append(WHERE_LESSER_THAN_HAS_NEXT);
556 }
557 }
558 else {
559 if (orderByComparator.isAscending() ^ previous) {
560 query.append(WHERE_GREATER_THAN);
561 }
562 else {
563 query.append(WHERE_LESSER_THAN);
564 }
565 }
566 }
567
568 query.append(ORDER_BY_CLAUSE);
569
570 for (int i = 0; i < orderByFields.length; i++) {
571 query.append(_ORDER_BY_ENTITY_ALIAS);
572 query.append(orderByFields[i]);
573
574 if ((i + 1) < orderByFields.length) {
575 if (orderByComparator.isAscending() ^ previous) {
576 query.append(ORDER_BY_ASC_HAS_NEXT);
577 }
578 else {
579 query.append(ORDER_BY_DESC_HAS_NEXT);
580 }
581 }
582 else {
583 if (orderByComparator.isAscending() ^ previous) {
584 query.append(ORDER_BY_ASC);
585 }
586 else {
587 query.append(ORDER_BY_DESC);
588 }
589 }
590 }
591 }
592
593 String sql = query.toString();
594
595 Query q = session.createQuery(sql);
596
597 q.setFirstResult(0);
598 q.setMaxResults(2);
599
600 QueryPos qPos = QueryPos.getInstance(q);
601
602 qPos.add(tableId);
603
604 if (orderByComparator != null) {
605 Object[] values = orderByComparator.getOrderByValues(expandoRow);
606
607 for (Object value : values) {
608 qPos.add(value);
609 }
610 }
611
612 List<ExpandoRow> list = q.list();
613
614 if (list.size() == 2) {
615 return list.get(1);
616 }
617 else {
618 return null;
619 }
620 }
621
622 public ExpandoRow findByT_C(long tableId, long classPK)
623 throws NoSuchRowException, SystemException {
624 ExpandoRow expandoRow = fetchByT_C(tableId, classPK);
625
626 if (expandoRow == null) {
627 StringBundler msg = new StringBundler(6);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("tableId=");
632 msg.append(tableId);
633
634 msg.append(", classPK=");
635 msg.append(classPK);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 if (_log.isWarnEnabled()) {
640 _log.warn(msg.toString());
641 }
642
643 throw new NoSuchRowException(msg.toString());
644 }
645
646 return expandoRow;
647 }
648
649 public ExpandoRow fetchByT_C(long tableId, long classPK)
650 throws SystemException {
651 return fetchByT_C(tableId, classPK, true);
652 }
653
654 public ExpandoRow fetchByT_C(long tableId, long classPK,
655 boolean retrieveFromCache) throws SystemException {
656 Object[] finderArgs = new Object[] { new Long(tableId), new Long(classPK) };
657
658 Object result = null;
659
660 if (retrieveFromCache) {
661 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
662 finderArgs, this);
663 }
664
665 if (result == null) {
666 Session session = null;
667
668 try {
669 session = openSession();
670
671 StringBundler query = new StringBundler(3);
672
673 query.append(_SQL_SELECT_EXPANDOROW_WHERE);
674
675 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
676
677 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
678
679 String sql = query.toString();
680
681 Query q = session.createQuery(sql);
682
683 QueryPos qPos = QueryPos.getInstance(q);
684
685 qPos.add(tableId);
686
687 qPos.add(classPK);
688
689 List<ExpandoRow> list = q.list();
690
691 result = list;
692
693 ExpandoRow expandoRow = null;
694
695 if (list.isEmpty()) {
696 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
697 finderArgs, list);
698 }
699 else {
700 expandoRow = list.get(0);
701
702 cacheResult(expandoRow);
703
704 if ((expandoRow.getTableId() != tableId) ||
705 (expandoRow.getClassPK() != classPK)) {
706 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
707 finderArgs, expandoRow);
708 }
709 }
710
711 return expandoRow;
712 }
713 catch (Exception e) {
714 throw processException(e);
715 }
716 finally {
717 if (result == null) {
718 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
719 finderArgs, new ArrayList<ExpandoRow>());
720 }
721
722 closeSession(session);
723 }
724 }
725 else {
726 if (result instanceof List<?>) {
727 return null;
728 }
729 else {
730 return (ExpandoRow)result;
731 }
732 }
733 }
734
735 public List<ExpandoRow> findAll() throws SystemException {
736 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
737 }
738
739 public List<ExpandoRow> findAll(int start, int end)
740 throws SystemException {
741 return findAll(start, end, null);
742 }
743
744 public List<ExpandoRow> findAll(int start, int end,
745 OrderByComparator orderByComparator) throws SystemException {
746 Object[] finderArgs = new Object[] {
747 String.valueOf(start), String.valueOf(end),
748 String.valueOf(orderByComparator)
749 };
750
751 List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
752 finderArgs, this);
753
754 if (list == null) {
755 Session session = null;
756
757 try {
758 session = openSession();
759
760 StringBundler query = null;
761 String sql = null;
762
763 if (orderByComparator != null) {
764 query = new StringBundler(2 +
765 (orderByComparator.getOrderByFields().length * 3));
766
767 query.append(_SQL_SELECT_EXPANDOROW);
768
769 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
770 orderByComparator);
771
772 sql = query.toString();
773 }
774
775 sql = _SQL_SELECT_EXPANDOROW;
776
777 Query q = session.createQuery(sql);
778
779 if (orderByComparator == null) {
780 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
781 start, end, false);
782
783 Collections.sort(list);
784 }
785 else {
786 list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
787 start, end);
788 }
789 }
790 catch (Exception e) {
791 throw processException(e);
792 }
793 finally {
794 if (list == null) {
795 list = new ArrayList<ExpandoRow>();
796 }
797
798 cacheResult(list);
799
800 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
801
802 closeSession(session);
803 }
804 }
805
806 return list;
807 }
808
809 public void removeByTableId(long tableId) throws SystemException {
810 for (ExpandoRow expandoRow : findByTableId(tableId)) {
811 remove(expandoRow);
812 }
813 }
814
815 public void removeByT_C(long tableId, long classPK)
816 throws NoSuchRowException, SystemException {
817 ExpandoRow expandoRow = findByT_C(tableId, classPK);
818
819 remove(expandoRow);
820 }
821
822 public void removeAll() throws SystemException {
823 for (ExpandoRow expandoRow : findAll()) {
824 remove(expandoRow);
825 }
826 }
827
828 public int countByTableId(long tableId) throws SystemException {
829 Object[] finderArgs = new Object[] { new Long(tableId) };
830
831 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
832 finderArgs, this);
833
834 if (count == null) {
835 Session session = null;
836
837 try {
838 session = openSession();
839
840 StringBundler query = new StringBundler(2);
841
842 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
843
844 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
845
846 String sql = query.toString();
847
848 Query q = session.createQuery(sql);
849
850 QueryPos qPos = QueryPos.getInstance(q);
851
852 qPos.add(tableId);
853
854 count = (Long)q.uniqueResult();
855 }
856 catch (Exception e) {
857 throw processException(e);
858 }
859 finally {
860 if (count == null) {
861 count = Long.valueOf(0);
862 }
863
864 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
865 finderArgs, count);
866
867 closeSession(session);
868 }
869 }
870
871 return count.intValue();
872 }
873
874 public int countByT_C(long tableId, long classPK) throws SystemException {
875 Object[] finderArgs = new Object[] { new Long(tableId), new Long(classPK) };
876
877 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
878 finderArgs, this);
879
880 if (count == null) {
881 Session session = null;
882
883 try {
884 session = openSession();
885
886 StringBundler query = new StringBundler(3);
887
888 query.append(_SQL_COUNT_EXPANDOROW_WHERE);
889
890 query.append(_FINDER_COLUMN_T_C_TABLEID_2);
891
892 query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
893
894 String sql = query.toString();
895
896 Query q = session.createQuery(sql);
897
898 QueryPos qPos = QueryPos.getInstance(q);
899
900 qPos.add(tableId);
901
902 qPos.add(classPK);
903
904 count = (Long)q.uniqueResult();
905 }
906 catch (Exception e) {
907 throw processException(e);
908 }
909 finally {
910 if (count == null) {
911 count = Long.valueOf(0);
912 }
913
914 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
915 count);
916
917 closeSession(session);
918 }
919 }
920
921 return count.intValue();
922 }
923
924 public int countAll() throws SystemException {
925 Object[] finderArgs = new Object[0];
926
927 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
928 finderArgs, this);
929
930 if (count == null) {
931 Session session = null;
932
933 try {
934 session = openSession();
935
936 Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
937
938 count = (Long)q.uniqueResult();
939 }
940 catch (Exception e) {
941 throw processException(e);
942 }
943 finally {
944 if (count == null) {
945 count = Long.valueOf(0);
946 }
947
948 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
949 count);
950
951 closeSession(session);
952 }
953 }
954
955 return count.intValue();
956 }
957
958 public void afterPropertiesSet() {
959 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
960 com.liferay.portal.util.PropsUtil.get(
961 "value.object.listener.com.liferay.portlet.expando.model.ExpandoRow")));
962
963 if (listenerClassNames.length > 0) {
964 try {
965 List<ModelListener<ExpandoRow>> listenersList = new ArrayList<ModelListener<ExpandoRow>>();
966
967 for (String listenerClassName : listenerClassNames) {
968 listenersList.add((ModelListener<ExpandoRow>)InstanceFactory.newInstance(
969 listenerClassName));
970 }
971
972 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
973 }
974 catch (Exception e) {
975 _log.error(e);
976 }
977 }
978 }
979
980 @BeanReference(type = ExpandoColumnPersistence.class)
981 protected ExpandoColumnPersistence expandoColumnPersistence;
982 @BeanReference(type = ExpandoRowPersistence.class)
983 protected ExpandoRowPersistence expandoRowPersistence;
984 @BeanReference(type = ExpandoTablePersistence.class)
985 protected ExpandoTablePersistence expandoTablePersistence;
986 @BeanReference(type = ExpandoValuePersistence.class)
987 protected ExpandoValuePersistence expandoValuePersistence;
988 @BeanReference(type = ResourcePersistence.class)
989 protected ResourcePersistence resourcePersistence;
990 @BeanReference(type = UserPersistence.class)
991 protected UserPersistence userPersistence;
992 private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
993 private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
994 private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
995 private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
996 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoRow.tableId = ?";
997 private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoRow.tableId = ? AND ";
998 private static final String _FINDER_COLUMN_T_C_CLASSPK_2 = "expandoRow.classPK = ?";
999 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1000 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1001 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1002 private static Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1003}