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