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