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