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