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