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