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