001
014
015 package com.liferay.portlet.expando.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.service.persistence.CompanyProvider;
037 import com.liferay.portal.service.persistence.CompanyProviderWrapper;
038 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039
040 import com.liferay.portlet.expando.exception.NoSuchTableException;
041 import com.liferay.portlet.expando.model.ExpandoTable;
042 import com.liferay.portlet.expando.model.impl.ExpandoTableImpl;
043 import com.liferay.portlet.expando.model.impl.ExpandoTableModelImpl;
044 import com.liferay.portlet.expando.service.persistence.ExpandoTablePersistence;
045
046 import java.io.Serializable;
047
048 import java.util.Collections;
049 import java.util.HashMap;
050 import java.util.HashSet;
051 import java.util.Iterator;
052 import java.util.List;
053 import java.util.Map;
054 import java.util.Set;
055
056
068 @ProviderType
069 public class ExpandoTablePersistenceImpl extends BasePersistenceImpl<ExpandoTable>
070 implements ExpandoTablePersistence {
071
076 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoTableImpl.class.getName();
077 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List1";
079 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List2";
081 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
082 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
083 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
085 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
088 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
091 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
092 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
093 new String[] {
094 Long.class.getName(), Long.class.getName(),
095
096 Integer.class.getName(), Integer.class.getName(),
097 OrderByComparator.class.getName()
098 });
099 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
100 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
102 new String[] { Long.class.getName(), Long.class.getName() },
103 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
104 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
106 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
108 new String[] { Long.class.getName(), Long.class.getName() });
109
110
117 @Override
118 public List<ExpandoTable> findByC_C(long companyId, long classNameId) {
119 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
120 QueryUtil.ALL_POS, null);
121 }
122
123
136 @Override
137 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
138 int start, int end) {
139 return findByC_C(companyId, classNameId, start, end, null);
140 }
141
142
156 @Override
157 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
158 int start, int end, OrderByComparator<ExpandoTable> orderByComparator) {
159 return findByC_C(companyId, classNameId, start, end, orderByComparator,
160 true);
161 }
162
163
178 @Override
179 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
180 int start, int end, OrderByComparator<ExpandoTable> orderByComparator,
181 boolean retrieveFromCache) {
182 boolean pagination = true;
183 FinderPath finderPath = null;
184 Object[] finderArgs = null;
185
186 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
187 (orderByComparator == null)) {
188 pagination = false;
189 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
190 finderArgs = new Object[] { companyId, classNameId };
191 }
192 else {
193 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
194 finderArgs = new Object[] {
195 companyId, classNameId,
196
197 start, end, orderByComparator
198 };
199 }
200
201 List<ExpandoTable> list = null;
202
203 if (retrieveFromCache) {
204 list = (List<ExpandoTable>)finderCache.getResult(finderPath,
205 finderArgs, this);
206
207 if ((list != null) && !list.isEmpty()) {
208 for (ExpandoTable expandoTable : list) {
209 if ((companyId != expandoTable.getCompanyId()) ||
210 (classNameId != expandoTable.getClassNameId())) {
211 list = null;
212
213 break;
214 }
215 }
216 }
217 }
218
219 if (list == null) {
220 StringBundler query = null;
221
222 if (orderByComparator != null) {
223 query = new StringBundler(4 +
224 (orderByComparator.getOrderByFields().length * 2));
225 }
226 else {
227 query = new StringBundler(4);
228 }
229
230 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
231
232 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
233
234 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
235
236 if (orderByComparator != null) {
237 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
238 orderByComparator);
239 }
240 else
241 if (pagination) {
242 query.append(ExpandoTableModelImpl.ORDER_BY_JPQL);
243 }
244
245 String sql = query.toString();
246
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 Query q = session.createQuery(sql);
253
254 QueryPos qPos = QueryPos.getInstance(q);
255
256 qPos.add(companyId);
257
258 qPos.add(classNameId);
259
260 if (!pagination) {
261 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
262 start, end, false);
263
264 Collections.sort(list);
265
266 list = Collections.unmodifiableList(list);
267 }
268 else {
269 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
270 start, end);
271 }
272
273 cacheResult(list);
274
275 finderCache.putResult(finderPath, finderArgs, list);
276 }
277 catch (Exception e) {
278 finderCache.removeResult(finderPath, finderArgs);
279
280 throw processException(e);
281 }
282 finally {
283 closeSession(session);
284 }
285 }
286
287 return list;
288 }
289
290
299 @Override
300 public ExpandoTable findByC_C_First(long companyId, long classNameId,
301 OrderByComparator<ExpandoTable> orderByComparator)
302 throws NoSuchTableException {
303 ExpandoTable expandoTable = fetchByC_C_First(companyId, classNameId,
304 orderByComparator);
305
306 if (expandoTable != null) {
307 return expandoTable;
308 }
309
310 StringBundler msg = new StringBundler(6);
311
312 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
313
314 msg.append("companyId=");
315 msg.append(companyId);
316
317 msg.append(", classNameId=");
318 msg.append(classNameId);
319
320 msg.append(StringPool.CLOSE_CURLY_BRACE);
321
322 throw new NoSuchTableException(msg.toString());
323 }
324
325
333 @Override
334 public ExpandoTable fetchByC_C_First(long companyId, long classNameId,
335 OrderByComparator<ExpandoTable> orderByComparator) {
336 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
337 orderByComparator);
338
339 if (!list.isEmpty()) {
340 return list.get(0);
341 }
342
343 return null;
344 }
345
346
355 @Override
356 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
357 OrderByComparator<ExpandoTable> orderByComparator)
358 throws NoSuchTableException {
359 ExpandoTable expandoTable = fetchByC_C_Last(companyId, classNameId,
360 orderByComparator);
361
362 if (expandoTable != null) {
363 return expandoTable;
364 }
365
366 StringBundler msg = new StringBundler(6);
367
368 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
369
370 msg.append("companyId=");
371 msg.append(companyId);
372
373 msg.append(", classNameId=");
374 msg.append(classNameId);
375
376 msg.append(StringPool.CLOSE_CURLY_BRACE);
377
378 throw new NoSuchTableException(msg.toString());
379 }
380
381
389 @Override
390 public ExpandoTable fetchByC_C_Last(long companyId, long classNameId,
391 OrderByComparator<ExpandoTable> orderByComparator) {
392 int count = countByC_C(companyId, classNameId);
393
394 if (count == 0) {
395 return null;
396 }
397
398 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
399 count, orderByComparator);
400
401 if (!list.isEmpty()) {
402 return list.get(0);
403 }
404
405 return null;
406 }
407
408
418 @Override
419 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
420 long classNameId, OrderByComparator<ExpandoTable> orderByComparator)
421 throws NoSuchTableException {
422 ExpandoTable expandoTable = findByPrimaryKey(tableId);
423
424 Session session = null;
425
426 try {
427 session = openSession();
428
429 ExpandoTable[] array = new ExpandoTableImpl[3];
430
431 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
432 classNameId, orderByComparator, true);
433
434 array[1] = expandoTable;
435
436 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
437 classNameId, orderByComparator, false);
438
439 return array;
440 }
441 catch (Exception e) {
442 throw processException(e);
443 }
444 finally {
445 closeSession(session);
446 }
447 }
448
449 protected ExpandoTable getByC_C_PrevAndNext(Session session,
450 ExpandoTable expandoTable, long companyId, long classNameId,
451 OrderByComparator<ExpandoTable> orderByComparator, boolean previous) {
452 StringBundler query = null;
453
454 if (orderByComparator != null) {
455 query = new StringBundler(5 +
456 (orderByComparator.getOrderByConditionFields().length * 3) +
457 (orderByComparator.getOrderByFields().length * 3));
458 }
459 else {
460 query = new StringBundler(4);
461 }
462
463 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
464
465 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
466
467 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
468
469 if (orderByComparator != null) {
470 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
471
472 if (orderByConditionFields.length > 0) {
473 query.append(WHERE_AND);
474 }
475
476 for (int i = 0; i < orderByConditionFields.length; i++) {
477 query.append(_ORDER_BY_ENTITY_ALIAS);
478 query.append(orderByConditionFields[i]);
479
480 if ((i + 1) < orderByConditionFields.length) {
481 if (orderByComparator.isAscending() ^ previous) {
482 query.append(WHERE_GREATER_THAN_HAS_NEXT);
483 }
484 else {
485 query.append(WHERE_LESSER_THAN_HAS_NEXT);
486 }
487 }
488 else {
489 if (orderByComparator.isAscending() ^ previous) {
490 query.append(WHERE_GREATER_THAN);
491 }
492 else {
493 query.append(WHERE_LESSER_THAN);
494 }
495 }
496 }
497
498 query.append(ORDER_BY_CLAUSE);
499
500 String[] orderByFields = orderByComparator.getOrderByFields();
501
502 for (int i = 0; i < orderByFields.length; i++) {
503 query.append(_ORDER_BY_ENTITY_ALIAS);
504 query.append(orderByFields[i]);
505
506 if ((i + 1) < orderByFields.length) {
507 if (orderByComparator.isAscending() ^ previous) {
508 query.append(ORDER_BY_ASC_HAS_NEXT);
509 }
510 else {
511 query.append(ORDER_BY_DESC_HAS_NEXT);
512 }
513 }
514 else {
515 if (orderByComparator.isAscending() ^ previous) {
516 query.append(ORDER_BY_ASC);
517 }
518 else {
519 query.append(ORDER_BY_DESC);
520 }
521 }
522 }
523 }
524 else {
525 query.append(ExpandoTableModelImpl.ORDER_BY_JPQL);
526 }
527
528 String sql = query.toString();
529
530 Query q = session.createQuery(sql);
531
532 q.setFirstResult(0);
533 q.setMaxResults(2);
534
535 QueryPos qPos = QueryPos.getInstance(q);
536
537 qPos.add(companyId);
538
539 qPos.add(classNameId);
540
541 if (orderByComparator != null) {
542 Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
543
544 for (Object value : values) {
545 qPos.add(value);
546 }
547 }
548
549 List<ExpandoTable> list = q.list();
550
551 if (list.size() == 2) {
552 return list.get(1);
553 }
554 else {
555 return null;
556 }
557 }
558
559
565 @Override
566 public void removeByC_C(long companyId, long classNameId) {
567 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId,
568 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
569 remove(expandoTable);
570 }
571 }
572
573
580 @Override
581 public int countByC_C(long companyId, long classNameId) {
582 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
583
584 Object[] finderArgs = new Object[] { companyId, classNameId };
585
586 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
587
588 if (count == null) {
589 StringBundler query = new StringBundler(3);
590
591 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
592
593 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
594
595 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
596
597 String sql = query.toString();
598
599 Session session = null;
600
601 try {
602 session = openSession();
603
604 Query q = session.createQuery(sql);
605
606 QueryPos qPos = QueryPos.getInstance(q);
607
608 qPos.add(companyId);
609
610 qPos.add(classNameId);
611
612 count = (Long)q.uniqueResult();
613
614 finderCache.putResult(finderPath, finderArgs, count);
615 }
616 catch (Exception e) {
617 finderCache.removeResult(finderPath, finderArgs);
618
619 throw processException(e);
620 }
621 finally {
622 closeSession(session);
623 }
624 }
625
626 return count.intValue();
627 }
628
629 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
630 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
631 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
632 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
633 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_N",
634 new String[] {
635 Long.class.getName(), Long.class.getName(),
636 String.class.getName()
637 },
638 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
639 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK |
640 ExpandoTableModelImpl.NAME_COLUMN_BITMASK);
641 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
642 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
643 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_N",
644 new String[] {
645 Long.class.getName(), Long.class.getName(),
646 String.class.getName()
647 });
648
649
658 @Override
659 public ExpandoTable findByC_C_N(long companyId, long classNameId,
660 String name) throws NoSuchTableException {
661 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
662
663 if (expandoTable == null) {
664 StringBundler msg = new StringBundler(8);
665
666 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
667
668 msg.append("companyId=");
669 msg.append(companyId);
670
671 msg.append(", classNameId=");
672 msg.append(classNameId);
673
674 msg.append(", name=");
675 msg.append(name);
676
677 msg.append(StringPool.CLOSE_CURLY_BRACE);
678
679 if (_log.isWarnEnabled()) {
680 _log.warn(msg.toString());
681 }
682
683 throw new NoSuchTableException(msg.toString());
684 }
685
686 return expandoTable;
687 }
688
689
697 @Override
698 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
699 String name) {
700 return fetchByC_C_N(companyId, classNameId, name, true);
701 }
702
703
712 @Override
713 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
714 String name, boolean retrieveFromCache) {
715 Object[] finderArgs = new Object[] { companyId, classNameId, name };
716
717 Object result = null;
718
719 if (retrieveFromCache) {
720 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C_N,
721 finderArgs, this);
722 }
723
724 if (result instanceof ExpandoTable) {
725 ExpandoTable expandoTable = (ExpandoTable)result;
726
727 if ((companyId != expandoTable.getCompanyId()) ||
728 (classNameId != expandoTable.getClassNameId()) ||
729 !Validator.equals(name, expandoTable.getName())) {
730 result = null;
731 }
732 }
733
734 if (result == null) {
735 StringBundler query = new StringBundler(5);
736
737 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
738
739 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
740
741 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
742
743 boolean bindName = false;
744
745 if (name == null) {
746 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
747 }
748 else if (name.equals(StringPool.BLANK)) {
749 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
750 }
751 else {
752 bindName = true;
753
754 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
755 }
756
757 String sql = query.toString();
758
759 Session session = null;
760
761 try {
762 session = openSession();
763
764 Query q = session.createQuery(sql);
765
766 QueryPos qPos = QueryPos.getInstance(q);
767
768 qPos.add(companyId);
769
770 qPos.add(classNameId);
771
772 if (bindName) {
773 qPos.add(name);
774 }
775
776 List<ExpandoTable> list = q.list();
777
778 if (list.isEmpty()) {
779 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N,
780 finderArgs, list);
781 }
782 else {
783 ExpandoTable expandoTable = list.get(0);
784
785 result = expandoTable;
786
787 cacheResult(expandoTable);
788
789 if ((expandoTable.getCompanyId() != companyId) ||
790 (expandoTable.getClassNameId() != classNameId) ||
791 (expandoTable.getName() == null) ||
792 !expandoTable.getName().equals(name)) {
793 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N,
794 finderArgs, expandoTable);
795 }
796 }
797 }
798 catch (Exception e) {
799 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_N, finderArgs);
800
801 throw processException(e);
802 }
803 finally {
804 closeSession(session);
805 }
806 }
807
808 if (result instanceof List<?>) {
809 return null;
810 }
811 else {
812 return (ExpandoTable)result;
813 }
814 }
815
816
824 @Override
825 public ExpandoTable removeByC_C_N(long companyId, long classNameId,
826 String name) throws NoSuchTableException {
827 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
828
829 return remove(expandoTable);
830 }
831
832
840 @Override
841 public int countByC_C_N(long companyId, long classNameId, String name) {
842 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_N;
843
844 Object[] finderArgs = new Object[] { companyId, classNameId, name };
845
846 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
847
848 if (count == null) {
849 StringBundler query = new StringBundler(4);
850
851 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
852
853 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
854
855 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
856
857 boolean bindName = false;
858
859 if (name == null) {
860 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
861 }
862 else if (name.equals(StringPool.BLANK)) {
863 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
864 }
865 else {
866 bindName = true;
867
868 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
869 }
870
871 String sql = query.toString();
872
873 Session session = null;
874
875 try {
876 session = openSession();
877
878 Query q = session.createQuery(sql);
879
880 QueryPos qPos = QueryPos.getInstance(q);
881
882 qPos.add(companyId);
883
884 qPos.add(classNameId);
885
886 if (bindName) {
887 qPos.add(name);
888 }
889
890 count = (Long)q.uniqueResult();
891
892 finderCache.putResult(finderPath, finderArgs, count);
893 }
894 catch (Exception e) {
895 finderCache.removeResult(finderPath, finderArgs);
896
897 throw processException(e);
898 }
899 finally {
900 closeSession(session);
901 }
902 }
903
904 return count.intValue();
905 }
906
907 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
908 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
909 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
910 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
911 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = '')";
912
913 public ExpandoTablePersistenceImpl() {
914 setModelClass(ExpandoTable.class);
915 }
916
917
922 @Override
923 public void cacheResult(ExpandoTable expandoTable) {
924 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
925 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
926
927 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N,
928 new Object[] {
929 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
930 expandoTable.getName()
931 }, expandoTable);
932
933 expandoTable.resetOriginalValues();
934 }
935
936
941 @Override
942 public void cacheResult(List<ExpandoTable> expandoTables) {
943 for (ExpandoTable expandoTable : expandoTables) {
944 if (entityCache.getResult(
945 ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
946 ExpandoTableImpl.class, expandoTable.getPrimaryKey()) == null) {
947 cacheResult(expandoTable);
948 }
949 else {
950 expandoTable.resetOriginalValues();
951 }
952 }
953 }
954
955
962 @Override
963 public void clearCache() {
964 entityCache.clearCache(ExpandoTableImpl.class);
965
966 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
967 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
968 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
969 }
970
971
978 @Override
979 public void clearCache(ExpandoTable expandoTable) {
980 entityCache.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
981 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
982
983 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
984 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
985
986 clearUniqueFindersCache((ExpandoTableModelImpl)expandoTable);
987 }
988
989 @Override
990 public void clearCache(List<ExpandoTable> expandoTables) {
991 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
992 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
993
994 for (ExpandoTable expandoTable : expandoTables) {
995 entityCache.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
996 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
997
998 clearUniqueFindersCache((ExpandoTableModelImpl)expandoTable);
999 }
1000 }
1001
1002 protected void cacheUniqueFindersCache(
1003 ExpandoTableModelImpl expandoTableModelImpl, boolean isNew) {
1004 if (isNew) {
1005 Object[] args = new Object[] {
1006 expandoTableModelImpl.getCompanyId(),
1007 expandoTableModelImpl.getClassNameId(),
1008 expandoTableModelImpl.getName()
1009 };
1010
1011 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
1012 Long.valueOf(1));
1013 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1014 expandoTableModelImpl);
1015 }
1016 else {
1017 if ((expandoTableModelImpl.getColumnBitmask() &
1018 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1019 Object[] args = new Object[] {
1020 expandoTableModelImpl.getCompanyId(),
1021 expandoTableModelImpl.getClassNameId(),
1022 expandoTableModelImpl.getName()
1023 };
1024
1025 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
1026 Long.valueOf(1));
1027 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1028 expandoTableModelImpl);
1029 }
1030 }
1031 }
1032
1033 protected void clearUniqueFindersCache(
1034 ExpandoTableModelImpl expandoTableModelImpl) {
1035 Object[] args = new Object[] {
1036 expandoTableModelImpl.getCompanyId(),
1037 expandoTableModelImpl.getClassNameId(),
1038 expandoTableModelImpl.getName()
1039 };
1040
1041 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1042 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1043
1044 if ((expandoTableModelImpl.getColumnBitmask() &
1045 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1046 args = new Object[] {
1047 expandoTableModelImpl.getOriginalCompanyId(),
1048 expandoTableModelImpl.getOriginalClassNameId(),
1049 expandoTableModelImpl.getOriginalName()
1050 };
1051
1052 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1053 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1054 }
1055 }
1056
1057
1063 @Override
1064 public ExpandoTable create(long tableId) {
1065 ExpandoTable expandoTable = new ExpandoTableImpl();
1066
1067 expandoTable.setNew(true);
1068 expandoTable.setPrimaryKey(tableId);
1069
1070 expandoTable.setCompanyId(companyProvider.getCompanyId());
1071
1072 return expandoTable;
1073 }
1074
1075
1082 @Override
1083 public ExpandoTable remove(long tableId) throws NoSuchTableException {
1084 return remove((Serializable)tableId);
1085 }
1086
1087
1094 @Override
1095 public ExpandoTable remove(Serializable primaryKey)
1096 throws NoSuchTableException {
1097 Session session = null;
1098
1099 try {
1100 session = openSession();
1101
1102 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1103 primaryKey);
1104
1105 if (expandoTable == null) {
1106 if (_log.isWarnEnabled()) {
1107 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1108 }
1109
1110 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1111 primaryKey);
1112 }
1113
1114 return remove(expandoTable);
1115 }
1116 catch (NoSuchTableException nsee) {
1117 throw nsee;
1118 }
1119 catch (Exception e) {
1120 throw processException(e);
1121 }
1122 finally {
1123 closeSession(session);
1124 }
1125 }
1126
1127 @Override
1128 protected ExpandoTable removeImpl(ExpandoTable expandoTable) {
1129 expandoTable = toUnwrappedModel(expandoTable);
1130
1131 Session session = null;
1132
1133 try {
1134 session = openSession();
1135
1136 if (!session.contains(expandoTable)) {
1137 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1138 expandoTable.getPrimaryKeyObj());
1139 }
1140
1141 if (expandoTable != null) {
1142 session.delete(expandoTable);
1143 }
1144 }
1145 catch (Exception e) {
1146 throw processException(e);
1147 }
1148 finally {
1149 closeSession(session);
1150 }
1151
1152 if (expandoTable != null) {
1153 clearCache(expandoTable);
1154 }
1155
1156 return expandoTable;
1157 }
1158
1159 @Override
1160 public ExpandoTable updateImpl(ExpandoTable expandoTable) {
1161 expandoTable = toUnwrappedModel(expandoTable);
1162
1163 boolean isNew = expandoTable.isNew();
1164
1165 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1166
1167 Session session = null;
1168
1169 try {
1170 session = openSession();
1171
1172 if (expandoTable.isNew()) {
1173 session.save(expandoTable);
1174
1175 expandoTable.setNew(false);
1176 }
1177 else {
1178 expandoTable = (ExpandoTable)session.merge(expandoTable);
1179 }
1180 }
1181 catch (Exception e) {
1182 throw processException(e);
1183 }
1184 finally {
1185 closeSession(session);
1186 }
1187
1188 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1189
1190 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
1191 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1192 }
1193
1194 else {
1195 if ((expandoTableModelImpl.getColumnBitmask() &
1196 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1197 Object[] args = new Object[] {
1198 expandoTableModelImpl.getOriginalCompanyId(),
1199 expandoTableModelImpl.getOriginalClassNameId()
1200 };
1201
1202 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1203 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1204 args);
1205
1206 args = new Object[] {
1207 expandoTableModelImpl.getCompanyId(),
1208 expandoTableModelImpl.getClassNameId()
1209 };
1210
1211 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1212 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1213 args);
1214 }
1215 }
1216
1217 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1218 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable,
1219 false);
1220
1221 clearUniqueFindersCache(expandoTableModelImpl);
1222 cacheUniqueFindersCache(expandoTableModelImpl, isNew);
1223
1224 expandoTable.resetOriginalValues();
1225
1226 return expandoTable;
1227 }
1228
1229 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
1230 if (expandoTable instanceof ExpandoTableImpl) {
1231 return expandoTable;
1232 }
1233
1234 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
1235
1236 expandoTableImpl.setNew(expandoTable.isNew());
1237 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
1238
1239 expandoTableImpl.setTableId(expandoTable.getTableId());
1240 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
1241 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
1242 expandoTableImpl.setName(expandoTable.getName());
1243
1244 return expandoTableImpl;
1245 }
1246
1247
1254 @Override
1255 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
1256 throws NoSuchTableException {
1257 ExpandoTable expandoTable = fetchByPrimaryKey(primaryKey);
1258
1259 if (expandoTable == null) {
1260 if (_log.isWarnEnabled()) {
1261 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1262 }
1263
1264 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1265 primaryKey);
1266 }
1267
1268 return expandoTable;
1269 }
1270
1271
1278 @Override
1279 public ExpandoTable findByPrimaryKey(long tableId)
1280 throws NoSuchTableException {
1281 return findByPrimaryKey((Serializable)tableId);
1282 }
1283
1284
1290 @Override
1291 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey) {
1292 ExpandoTable expandoTable = (ExpandoTable)entityCache.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1293 ExpandoTableImpl.class, primaryKey);
1294
1295 if (expandoTable == _nullExpandoTable) {
1296 return null;
1297 }
1298
1299 if (expandoTable == null) {
1300 Session session = null;
1301
1302 try {
1303 session = openSession();
1304
1305 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1306 primaryKey);
1307
1308 if (expandoTable != null) {
1309 cacheResult(expandoTable);
1310 }
1311 else {
1312 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1313 ExpandoTableImpl.class, primaryKey, _nullExpandoTable);
1314 }
1315 }
1316 catch (Exception e) {
1317 entityCache.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1318 ExpandoTableImpl.class, primaryKey);
1319
1320 throw processException(e);
1321 }
1322 finally {
1323 closeSession(session);
1324 }
1325 }
1326
1327 return expandoTable;
1328 }
1329
1330
1336 @Override
1337 public ExpandoTable fetchByPrimaryKey(long tableId) {
1338 return fetchByPrimaryKey((Serializable)tableId);
1339 }
1340
1341 @Override
1342 public Map<Serializable, ExpandoTable> fetchByPrimaryKeys(
1343 Set<Serializable> primaryKeys) {
1344 if (primaryKeys.isEmpty()) {
1345 return Collections.emptyMap();
1346 }
1347
1348 Map<Serializable, ExpandoTable> map = new HashMap<Serializable, ExpandoTable>();
1349
1350 if (primaryKeys.size() == 1) {
1351 Iterator<Serializable> iterator = primaryKeys.iterator();
1352
1353 Serializable primaryKey = iterator.next();
1354
1355 ExpandoTable expandoTable = fetchByPrimaryKey(primaryKey);
1356
1357 if (expandoTable != null) {
1358 map.put(primaryKey, expandoTable);
1359 }
1360
1361 return map;
1362 }
1363
1364 Set<Serializable> uncachedPrimaryKeys = null;
1365
1366 for (Serializable primaryKey : primaryKeys) {
1367 ExpandoTable expandoTable = (ExpandoTable)entityCache.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1368 ExpandoTableImpl.class, primaryKey);
1369
1370 if (expandoTable == null) {
1371 if (uncachedPrimaryKeys == null) {
1372 uncachedPrimaryKeys = new HashSet<Serializable>();
1373 }
1374
1375 uncachedPrimaryKeys.add(primaryKey);
1376 }
1377 else {
1378 map.put(primaryKey, expandoTable);
1379 }
1380 }
1381
1382 if (uncachedPrimaryKeys == null) {
1383 return map;
1384 }
1385
1386 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1387 1);
1388
1389 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE_PKS_IN);
1390
1391 for (Serializable primaryKey : uncachedPrimaryKeys) {
1392 query.append(String.valueOf(primaryKey));
1393
1394 query.append(StringPool.COMMA);
1395 }
1396
1397 query.setIndex(query.index() - 1);
1398
1399 query.append(StringPool.CLOSE_PARENTHESIS);
1400
1401 String sql = query.toString();
1402
1403 Session session = null;
1404
1405 try {
1406 session = openSession();
1407
1408 Query q = session.createQuery(sql);
1409
1410 for (ExpandoTable expandoTable : (List<ExpandoTable>)q.list()) {
1411 map.put(expandoTable.getPrimaryKeyObj(), expandoTable);
1412
1413 cacheResult(expandoTable);
1414
1415 uncachedPrimaryKeys.remove(expandoTable.getPrimaryKeyObj());
1416 }
1417
1418 for (Serializable primaryKey : uncachedPrimaryKeys) {
1419 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1420 ExpandoTableImpl.class, primaryKey, _nullExpandoTable);
1421 }
1422 }
1423 catch (Exception e) {
1424 throw processException(e);
1425 }
1426 finally {
1427 closeSession(session);
1428 }
1429
1430 return map;
1431 }
1432
1433
1438 @Override
1439 public List<ExpandoTable> findAll() {
1440 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1441 }
1442
1443
1454 @Override
1455 public List<ExpandoTable> findAll(int start, int end) {
1456 return findAll(start, end, null);
1457 }
1458
1459
1471 @Override
1472 public List<ExpandoTable> findAll(int start, int end,
1473 OrderByComparator<ExpandoTable> orderByComparator) {
1474 return findAll(start, end, orderByComparator, true);
1475 }
1476
1477
1490 @Override
1491 public List<ExpandoTable> findAll(int start, int end,
1492 OrderByComparator<ExpandoTable> orderByComparator,
1493 boolean retrieveFromCache) {
1494 boolean pagination = true;
1495 FinderPath finderPath = null;
1496 Object[] finderArgs = null;
1497
1498 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1499 (orderByComparator == null)) {
1500 pagination = false;
1501 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1502 finderArgs = FINDER_ARGS_EMPTY;
1503 }
1504 else {
1505 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1506 finderArgs = new Object[] { start, end, orderByComparator };
1507 }
1508
1509 List<ExpandoTable> list = null;
1510
1511 if (retrieveFromCache) {
1512 list = (List<ExpandoTable>)finderCache.getResult(finderPath,
1513 finderArgs, this);
1514 }
1515
1516 if (list == null) {
1517 StringBundler query = null;
1518 String sql = null;
1519
1520 if (orderByComparator != null) {
1521 query = new StringBundler(2 +
1522 (orderByComparator.getOrderByFields().length * 2));
1523
1524 query.append(_SQL_SELECT_EXPANDOTABLE);
1525
1526 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1527 orderByComparator);
1528
1529 sql = query.toString();
1530 }
1531 else {
1532 sql = _SQL_SELECT_EXPANDOTABLE;
1533
1534 if (pagination) {
1535 sql = sql.concat(ExpandoTableModelImpl.ORDER_BY_JPQL);
1536 }
1537 }
1538
1539 Session session = null;
1540
1541 try {
1542 session = openSession();
1543
1544 Query q = session.createQuery(sql);
1545
1546 if (!pagination) {
1547 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1548 start, end, false);
1549
1550 Collections.sort(list);
1551
1552 list = Collections.unmodifiableList(list);
1553 }
1554 else {
1555 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1556 start, end);
1557 }
1558
1559 cacheResult(list);
1560
1561 finderCache.putResult(finderPath, finderArgs, list);
1562 }
1563 catch (Exception e) {
1564 finderCache.removeResult(finderPath, finderArgs);
1565
1566 throw processException(e);
1567 }
1568 finally {
1569 closeSession(session);
1570 }
1571 }
1572
1573 return list;
1574 }
1575
1576
1580 @Override
1581 public void removeAll() {
1582 for (ExpandoTable expandoTable : findAll()) {
1583 remove(expandoTable);
1584 }
1585 }
1586
1587
1592 @Override
1593 public int countAll() {
1594 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1595 FINDER_ARGS_EMPTY, this);
1596
1597 if (count == null) {
1598 Session session = null;
1599
1600 try {
1601 session = openSession();
1602
1603 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1604
1605 count = (Long)q.uniqueResult();
1606
1607 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1608 count);
1609 }
1610 catch (Exception e) {
1611 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1612 FINDER_ARGS_EMPTY);
1613
1614 throw processException(e);
1615 }
1616 finally {
1617 closeSession(session);
1618 }
1619 }
1620
1621 return count.intValue();
1622 }
1623
1624 @Override
1625 protected Map<String, Integer> getTableColumnsMap() {
1626 return ExpandoTableModelImpl.TABLE_COLUMNS_MAP;
1627 }
1628
1629
1632 public void afterPropertiesSet() {
1633 }
1634
1635 public void destroy() {
1636 entityCache.removeCache(ExpandoTableImpl.class.getName());
1637 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1638 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1639 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1640 }
1641
1642 @BeanReference(type = CompanyProviderWrapper.class)
1643 protected CompanyProvider companyProvider;
1644 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1645 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1646 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1647 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE_PKS_IN = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE tableId IN (";
1648 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1649 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1650 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1651 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1652 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1653 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1654 private static final Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1655 private static final ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1656 @Override
1657 public Object clone() {
1658 return this;
1659 }
1660
1661 @Override
1662 public CacheModel<ExpandoTable> toCacheModel() {
1663 return _nullExpandoTableCacheModel;
1664 }
1665 };
1666
1667 private static final CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1668 @Override
1669 public ExpandoTable toEntityModel() {
1670 return _nullExpandoTable;
1671 }
1672 };
1673 }