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