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