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