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