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 * 3));
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(6 +
456 (orderByComparator.getOrderByFields().length * 6));
457 }
458 else {
459 query = new StringBundler(3);
460 }
461
462 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
463
464 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
465
466 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
467
468 if (orderByComparator != null) {
469 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
470
471 if (orderByConditionFields.length > 0) {
472 query.append(WHERE_AND);
473 }
474
475 for (int i = 0; i < orderByConditionFields.length; i++) {
476 query.append(_ORDER_BY_ENTITY_ALIAS);
477 query.append(orderByConditionFields[i]);
478
479 if ((i + 1) < orderByConditionFields.length) {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(WHERE_GREATER_THAN_HAS_NEXT);
482 }
483 else {
484 query.append(WHERE_LESSER_THAN_HAS_NEXT);
485 }
486 }
487 else {
488 if (orderByComparator.isAscending() ^ previous) {
489 query.append(WHERE_GREATER_THAN);
490 }
491 else {
492 query.append(WHERE_LESSER_THAN);
493 }
494 }
495 }
496
497 query.append(ORDER_BY_CLAUSE);
498
499 String[] orderByFields = orderByComparator.getOrderByFields();
500
501 for (int i = 0; i < orderByFields.length; i++) {
502 query.append(_ORDER_BY_ENTITY_ALIAS);
503 query.append(orderByFields[i]);
504
505 if ((i + 1) < orderByFields.length) {
506 if (orderByComparator.isAscending() ^ previous) {
507 query.append(ORDER_BY_ASC_HAS_NEXT);
508 }
509 else {
510 query.append(ORDER_BY_DESC_HAS_NEXT);
511 }
512 }
513 else {
514 if (orderByComparator.isAscending() ^ previous) {
515 query.append(ORDER_BY_ASC);
516 }
517 else {
518 query.append(ORDER_BY_DESC);
519 }
520 }
521 }
522 }
523 else {
524 query.append(ExpandoTableModelImpl.ORDER_BY_JPQL);
525 }
526
527 String sql = query.toString();
528
529 Query q = session.createQuery(sql);
530
531 q.setFirstResult(0);
532 q.setMaxResults(2);
533
534 QueryPos qPos = QueryPos.getInstance(q);
535
536 qPos.add(companyId);
537
538 qPos.add(classNameId);
539
540 if (orderByComparator != null) {
541 Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
542
543 for (Object value : values) {
544 qPos.add(value);
545 }
546 }
547
548 List<ExpandoTable> list = q.list();
549
550 if (list.size() == 2) {
551 return list.get(1);
552 }
553 else {
554 return null;
555 }
556 }
557
558
564 @Override
565 public void removeByC_C(long companyId, long classNameId) {
566 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId,
567 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
568 remove(expandoTable);
569 }
570 }
571
572
579 @Override
580 public int countByC_C(long companyId, long classNameId) {
581 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
582
583 Object[] finderArgs = new Object[] { companyId, classNameId };
584
585 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
586
587 if (count == null) {
588 StringBundler query = new StringBundler(3);
589
590 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
591
592 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
593
594 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
595
596 String sql = query.toString();
597
598 Session session = null;
599
600 try {
601 session = openSession();
602
603 Query q = session.createQuery(sql);
604
605 QueryPos qPos = QueryPos.getInstance(q);
606
607 qPos.add(companyId);
608
609 qPos.add(classNameId);
610
611 count = (Long)q.uniqueResult();
612
613 finderCache.putResult(finderPath, finderArgs, count);
614 }
615 catch (Exception e) {
616 finderCache.removeResult(finderPath, finderArgs);
617
618 throw processException(e);
619 }
620 finally {
621 closeSession(session);
622 }
623 }
624
625 return count.intValue();
626 }
627
628 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
629 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
630 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
631 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
632 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_N",
633 new String[] {
634 Long.class.getName(), Long.class.getName(),
635 String.class.getName()
636 },
637 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
638 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK |
639 ExpandoTableModelImpl.NAME_COLUMN_BITMASK);
640 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
641 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
642 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_N",
643 new String[] {
644 Long.class.getName(), Long.class.getName(),
645 String.class.getName()
646 });
647
648
657 @Override
658 public ExpandoTable findByC_C_N(long companyId, long classNameId,
659 String name) throws NoSuchTableException {
660 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
661
662 if (expandoTable == null) {
663 StringBundler msg = new StringBundler(8);
664
665 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
666
667 msg.append("companyId=");
668 msg.append(companyId);
669
670 msg.append(", classNameId=");
671 msg.append(classNameId);
672
673 msg.append(", name=");
674 msg.append(name);
675
676 msg.append(StringPool.CLOSE_CURLY_BRACE);
677
678 if (_log.isWarnEnabled()) {
679 _log.warn(msg.toString());
680 }
681
682 throw new NoSuchTableException(msg.toString());
683 }
684
685 return expandoTable;
686 }
687
688
696 @Override
697 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
698 String name) {
699 return fetchByC_C_N(companyId, classNameId, name, true);
700 }
701
702
711 @Override
712 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
713 String name, boolean retrieveFromCache) {
714 Object[] finderArgs = new Object[] { companyId, classNameId, name };
715
716 Object result = null;
717
718 if (retrieveFromCache) {
719 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C_N,
720 finderArgs, this);
721 }
722
723 if (result instanceof ExpandoTable) {
724 ExpandoTable expandoTable = (ExpandoTable)result;
725
726 if ((companyId != expandoTable.getCompanyId()) ||
727 (classNameId != expandoTable.getClassNameId()) ||
728 !Validator.equals(name, expandoTable.getName())) {
729 result = null;
730 }
731 }
732
733 if (result == null) {
734 StringBundler query = new StringBundler(5);
735
736 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
737
738 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
739
740 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
741
742 boolean bindName = false;
743
744 if (name == null) {
745 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
746 }
747 else if (name.equals(StringPool.BLANK)) {
748 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
749 }
750 else {
751 bindName = true;
752
753 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
754 }
755
756 String sql = query.toString();
757
758 Session session = null;
759
760 try {
761 session = openSession();
762
763 Query q = session.createQuery(sql);
764
765 QueryPos qPos = QueryPos.getInstance(q);
766
767 qPos.add(companyId);
768
769 qPos.add(classNameId);
770
771 if (bindName) {
772 qPos.add(name);
773 }
774
775 List<ExpandoTable> list = q.list();
776
777 if (list.isEmpty()) {
778 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N,
779 finderArgs, list);
780 }
781 else {
782 ExpandoTable expandoTable = list.get(0);
783
784 result = expandoTable;
785
786 cacheResult(expandoTable);
787
788 if ((expandoTable.getCompanyId() != companyId) ||
789 (expandoTable.getClassNameId() != classNameId) ||
790 (expandoTable.getName() == null) ||
791 !expandoTable.getName().equals(name)) {
792 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N,
793 finderArgs, expandoTable);
794 }
795 }
796 }
797 catch (Exception e) {
798 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_N, finderArgs);
799
800 throw processException(e);
801 }
802 finally {
803 closeSession(session);
804 }
805 }
806
807 if (result instanceof List<?>) {
808 return null;
809 }
810 else {
811 return (ExpandoTable)result;
812 }
813 }
814
815
823 @Override
824 public ExpandoTable removeByC_C_N(long companyId, long classNameId,
825 String name) throws NoSuchTableException {
826 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
827
828 return remove(expandoTable);
829 }
830
831
839 @Override
840 public int countByC_C_N(long companyId, long classNameId, String name) {
841 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_N;
842
843 Object[] finderArgs = new Object[] { companyId, classNameId, name };
844
845 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
846
847 if (count == null) {
848 StringBundler query = new StringBundler(4);
849
850 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
851
852 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
853
854 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
855
856 boolean bindName = false;
857
858 if (name == null) {
859 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
860 }
861 else if (name.equals(StringPool.BLANK)) {
862 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
863 }
864 else {
865 bindName = true;
866
867 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
868 }
869
870 String sql = query.toString();
871
872 Session session = null;
873
874 try {
875 session = openSession();
876
877 Query q = session.createQuery(sql);
878
879 QueryPos qPos = QueryPos.getInstance(q);
880
881 qPos.add(companyId);
882
883 qPos.add(classNameId);
884
885 if (bindName) {
886 qPos.add(name);
887 }
888
889 count = (Long)q.uniqueResult();
890
891 finderCache.putResult(finderPath, finderArgs, count);
892 }
893 catch (Exception e) {
894 finderCache.removeResult(finderPath, finderArgs);
895
896 throw processException(e);
897 }
898 finally {
899 closeSession(session);
900 }
901 }
902
903 return count.intValue();
904 }
905
906 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
907 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
908 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
909 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
910 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = '')";
911
912 public ExpandoTablePersistenceImpl() {
913 setModelClass(ExpandoTable.class);
914 }
915
916
921 @Override
922 public void cacheResult(ExpandoTable expandoTable) {
923 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
924 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
925
926 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N,
927 new Object[] {
928 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
929 expandoTable.getName()
930 }, expandoTable);
931
932 expandoTable.resetOriginalValues();
933 }
934
935
940 @Override
941 public void cacheResult(List<ExpandoTable> expandoTables) {
942 for (ExpandoTable expandoTable : expandoTables) {
943 if (entityCache.getResult(
944 ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
945 ExpandoTableImpl.class, expandoTable.getPrimaryKey()) == null) {
946 cacheResult(expandoTable);
947 }
948 else {
949 expandoTable.resetOriginalValues();
950 }
951 }
952 }
953
954
961 @Override
962 public void clearCache() {
963 entityCache.clearCache(ExpandoTableImpl.class);
964
965 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
966 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
967 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
968 }
969
970
977 @Override
978 public void clearCache(ExpandoTable expandoTable) {
979 entityCache.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
980 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
981
982 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
983 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
984
985 clearUniqueFindersCache((ExpandoTableModelImpl)expandoTable);
986 }
987
988 @Override
989 public void clearCache(List<ExpandoTable> expandoTables) {
990 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
991 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
992
993 for (ExpandoTable expandoTable : expandoTables) {
994 entityCache.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
995 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
996
997 clearUniqueFindersCache((ExpandoTableModelImpl)expandoTable);
998 }
999 }
1000
1001 protected void cacheUniqueFindersCache(
1002 ExpandoTableModelImpl expandoTableModelImpl, boolean isNew) {
1003 if (isNew) {
1004 Object[] args = new Object[] {
1005 expandoTableModelImpl.getCompanyId(),
1006 expandoTableModelImpl.getClassNameId(),
1007 expandoTableModelImpl.getName()
1008 };
1009
1010 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
1011 Long.valueOf(1));
1012 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1013 expandoTableModelImpl);
1014 }
1015 else {
1016 if ((expandoTableModelImpl.getColumnBitmask() &
1017 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1018 Object[] args = new Object[] {
1019 expandoTableModelImpl.getCompanyId(),
1020 expandoTableModelImpl.getClassNameId(),
1021 expandoTableModelImpl.getName()
1022 };
1023
1024 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
1025 Long.valueOf(1));
1026 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1027 expandoTableModelImpl);
1028 }
1029 }
1030 }
1031
1032 protected void clearUniqueFindersCache(
1033 ExpandoTableModelImpl expandoTableModelImpl) {
1034 Object[] args = new Object[] {
1035 expandoTableModelImpl.getCompanyId(),
1036 expandoTableModelImpl.getClassNameId(),
1037 expandoTableModelImpl.getName()
1038 };
1039
1040 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1041 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1042
1043 if ((expandoTableModelImpl.getColumnBitmask() &
1044 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1045 args = new Object[] {
1046 expandoTableModelImpl.getOriginalCompanyId(),
1047 expandoTableModelImpl.getOriginalClassNameId(),
1048 expandoTableModelImpl.getOriginalName()
1049 };
1050
1051 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1052 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1053 }
1054 }
1055
1056
1062 @Override
1063 public ExpandoTable create(long tableId) {
1064 ExpandoTable expandoTable = new ExpandoTableImpl();
1065
1066 expandoTable.setNew(true);
1067 expandoTable.setPrimaryKey(tableId);
1068
1069 expandoTable.setCompanyId(companyProvider.getCompanyId());
1070
1071 return expandoTable;
1072 }
1073
1074
1081 @Override
1082 public ExpandoTable remove(long tableId) throws NoSuchTableException {
1083 return remove((Serializable)tableId);
1084 }
1085
1086
1093 @Override
1094 public ExpandoTable remove(Serializable primaryKey)
1095 throws NoSuchTableException {
1096 Session session = null;
1097
1098 try {
1099 session = openSession();
1100
1101 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1102 primaryKey);
1103
1104 if (expandoTable == null) {
1105 if (_log.isWarnEnabled()) {
1106 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1107 }
1108
1109 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1110 primaryKey);
1111 }
1112
1113 return remove(expandoTable);
1114 }
1115 catch (NoSuchTableException nsee) {
1116 throw nsee;
1117 }
1118 catch (Exception e) {
1119 throw processException(e);
1120 }
1121 finally {
1122 closeSession(session);
1123 }
1124 }
1125
1126 @Override
1127 protected ExpandoTable removeImpl(ExpandoTable expandoTable) {
1128 expandoTable = toUnwrappedModel(expandoTable);
1129
1130 Session session = null;
1131
1132 try {
1133 session = openSession();
1134
1135 if (!session.contains(expandoTable)) {
1136 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1137 expandoTable.getPrimaryKeyObj());
1138 }
1139
1140 if (expandoTable != null) {
1141 session.delete(expandoTable);
1142 }
1143 }
1144 catch (Exception e) {
1145 throw processException(e);
1146 }
1147 finally {
1148 closeSession(session);
1149 }
1150
1151 if (expandoTable != null) {
1152 clearCache(expandoTable);
1153 }
1154
1155 return expandoTable;
1156 }
1157
1158 @Override
1159 public ExpandoTable updateImpl(ExpandoTable expandoTable) {
1160 expandoTable = toUnwrappedModel(expandoTable);
1161
1162 boolean isNew = expandoTable.isNew();
1163
1164 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1165
1166 Session session = null;
1167
1168 try {
1169 session = openSession();
1170
1171 if (expandoTable.isNew()) {
1172 session.save(expandoTable);
1173
1174 expandoTable.setNew(false);
1175 }
1176 else {
1177 expandoTable = (ExpandoTable)session.merge(expandoTable);
1178 }
1179 }
1180 catch (Exception e) {
1181 throw processException(e);
1182 }
1183 finally {
1184 closeSession(session);
1185 }
1186
1187 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1188
1189 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
1190 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1191 }
1192
1193 else {
1194 if ((expandoTableModelImpl.getColumnBitmask() &
1195 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1196 Object[] args = new Object[] {
1197 expandoTableModelImpl.getOriginalCompanyId(),
1198 expandoTableModelImpl.getOriginalClassNameId()
1199 };
1200
1201 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1202 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1203 args);
1204
1205 args = new Object[] {
1206 expandoTableModelImpl.getCompanyId(),
1207 expandoTableModelImpl.getClassNameId()
1208 };
1209
1210 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1211 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1212 args);
1213 }
1214 }
1215
1216 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1217 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable,
1218 false);
1219
1220 clearUniqueFindersCache(expandoTableModelImpl);
1221 cacheUniqueFindersCache(expandoTableModelImpl, isNew);
1222
1223 expandoTable.resetOriginalValues();
1224
1225 return expandoTable;
1226 }
1227
1228 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
1229 if (expandoTable instanceof ExpandoTableImpl) {
1230 return expandoTable;
1231 }
1232
1233 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
1234
1235 expandoTableImpl.setNew(expandoTable.isNew());
1236 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
1237
1238 expandoTableImpl.setTableId(expandoTable.getTableId());
1239 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
1240 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
1241 expandoTableImpl.setName(expandoTable.getName());
1242
1243 return expandoTableImpl;
1244 }
1245
1246
1253 @Override
1254 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
1255 throws NoSuchTableException {
1256 ExpandoTable expandoTable = fetchByPrimaryKey(primaryKey);
1257
1258 if (expandoTable == null) {
1259 if (_log.isWarnEnabled()) {
1260 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1261 }
1262
1263 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1264 primaryKey);
1265 }
1266
1267 return expandoTable;
1268 }
1269
1270
1277 @Override
1278 public ExpandoTable findByPrimaryKey(long tableId)
1279 throws NoSuchTableException {
1280 return findByPrimaryKey((Serializable)tableId);
1281 }
1282
1283
1289 @Override
1290 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey) {
1291 ExpandoTable expandoTable = (ExpandoTable)entityCache.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1292 ExpandoTableImpl.class, primaryKey);
1293
1294 if (expandoTable == _nullExpandoTable) {
1295 return null;
1296 }
1297
1298 if (expandoTable == null) {
1299 Session session = null;
1300
1301 try {
1302 session = openSession();
1303
1304 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1305 primaryKey);
1306
1307 if (expandoTable != null) {
1308 cacheResult(expandoTable);
1309 }
1310 else {
1311 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1312 ExpandoTableImpl.class, primaryKey, _nullExpandoTable);
1313 }
1314 }
1315 catch (Exception e) {
1316 entityCache.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1317 ExpandoTableImpl.class, primaryKey);
1318
1319 throw processException(e);
1320 }
1321 finally {
1322 closeSession(session);
1323 }
1324 }
1325
1326 return expandoTable;
1327 }
1328
1329
1335 @Override
1336 public ExpandoTable fetchByPrimaryKey(long tableId) {
1337 return fetchByPrimaryKey((Serializable)tableId);
1338 }
1339
1340 @Override
1341 public Map<Serializable, ExpandoTable> fetchByPrimaryKeys(
1342 Set<Serializable> primaryKeys) {
1343 if (primaryKeys.isEmpty()) {
1344 return Collections.emptyMap();
1345 }
1346
1347 Map<Serializable, ExpandoTable> map = new HashMap<Serializable, ExpandoTable>();
1348
1349 if (primaryKeys.size() == 1) {
1350 Iterator<Serializable> iterator = primaryKeys.iterator();
1351
1352 Serializable primaryKey = iterator.next();
1353
1354 ExpandoTable expandoTable = fetchByPrimaryKey(primaryKey);
1355
1356 if (expandoTable != null) {
1357 map.put(primaryKey, expandoTable);
1358 }
1359
1360 return map;
1361 }
1362
1363 Set<Serializable> uncachedPrimaryKeys = null;
1364
1365 for (Serializable primaryKey : primaryKeys) {
1366 ExpandoTable expandoTable = (ExpandoTable)entityCache.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1367 ExpandoTableImpl.class, primaryKey);
1368
1369 if (expandoTable == null) {
1370 if (uncachedPrimaryKeys == null) {
1371 uncachedPrimaryKeys = new HashSet<Serializable>();
1372 }
1373
1374 uncachedPrimaryKeys.add(primaryKey);
1375 }
1376 else {
1377 map.put(primaryKey, expandoTable);
1378 }
1379 }
1380
1381 if (uncachedPrimaryKeys == null) {
1382 return map;
1383 }
1384
1385 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1386 1);
1387
1388 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE_PKS_IN);
1389
1390 for (Serializable primaryKey : uncachedPrimaryKeys) {
1391 query.append(String.valueOf(primaryKey));
1392
1393 query.append(StringPool.COMMA);
1394 }
1395
1396 query.setIndex(query.index() - 1);
1397
1398 query.append(StringPool.CLOSE_PARENTHESIS);
1399
1400 String sql = query.toString();
1401
1402 Session session = null;
1403
1404 try {
1405 session = openSession();
1406
1407 Query q = session.createQuery(sql);
1408
1409 for (ExpandoTable expandoTable : (List<ExpandoTable>)q.list()) {
1410 map.put(expandoTable.getPrimaryKeyObj(), expandoTable);
1411
1412 cacheResult(expandoTable);
1413
1414 uncachedPrimaryKeys.remove(expandoTable.getPrimaryKeyObj());
1415 }
1416
1417 for (Serializable primaryKey : uncachedPrimaryKeys) {
1418 entityCache.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1419 ExpandoTableImpl.class, primaryKey, _nullExpandoTable);
1420 }
1421 }
1422 catch (Exception e) {
1423 throw processException(e);
1424 }
1425 finally {
1426 closeSession(session);
1427 }
1428
1429 return map;
1430 }
1431
1432
1437 @Override
1438 public List<ExpandoTable> findAll() {
1439 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1440 }
1441
1442
1453 @Override
1454 public List<ExpandoTable> findAll(int start, int end) {
1455 return findAll(start, end, null);
1456 }
1457
1458
1470 @Override
1471 public List<ExpandoTable> findAll(int start, int end,
1472 OrderByComparator<ExpandoTable> orderByComparator) {
1473 return findAll(start, end, orderByComparator, true);
1474 }
1475
1476
1489 @Override
1490 public List<ExpandoTable> findAll(int start, int end,
1491 OrderByComparator<ExpandoTable> orderByComparator,
1492 boolean retrieveFromCache) {
1493 boolean pagination = true;
1494 FinderPath finderPath = null;
1495 Object[] finderArgs = null;
1496
1497 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1498 (orderByComparator == null)) {
1499 pagination = false;
1500 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1501 finderArgs = FINDER_ARGS_EMPTY;
1502 }
1503 else {
1504 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1505 finderArgs = new Object[] { start, end, orderByComparator };
1506 }
1507
1508 List<ExpandoTable> list = null;
1509
1510 if (retrieveFromCache) {
1511 list = (List<ExpandoTable>)finderCache.getResult(finderPath,
1512 finderArgs, this);
1513 }
1514
1515 if (list == null) {
1516 StringBundler query = null;
1517 String sql = null;
1518
1519 if (orderByComparator != null) {
1520 query = new StringBundler(2 +
1521 (orderByComparator.getOrderByFields().length * 3));
1522
1523 query.append(_SQL_SELECT_EXPANDOTABLE);
1524
1525 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1526 orderByComparator);
1527
1528 sql = query.toString();
1529 }
1530 else {
1531 sql = _SQL_SELECT_EXPANDOTABLE;
1532
1533 if (pagination) {
1534 sql = sql.concat(ExpandoTableModelImpl.ORDER_BY_JPQL);
1535 }
1536 }
1537
1538 Session session = null;
1539
1540 try {
1541 session = openSession();
1542
1543 Query q = session.createQuery(sql);
1544
1545 if (!pagination) {
1546 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1547 start, end, false);
1548
1549 Collections.sort(list);
1550
1551 list = Collections.unmodifiableList(list);
1552 }
1553 else {
1554 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1555 start, end);
1556 }
1557
1558 cacheResult(list);
1559
1560 finderCache.putResult(finderPath, finderArgs, list);
1561 }
1562 catch (Exception e) {
1563 finderCache.removeResult(finderPath, finderArgs);
1564
1565 throw processException(e);
1566 }
1567 finally {
1568 closeSession(session);
1569 }
1570 }
1571
1572 return list;
1573 }
1574
1575
1579 @Override
1580 public void removeAll() {
1581 for (ExpandoTable expandoTable : findAll()) {
1582 remove(expandoTable);
1583 }
1584 }
1585
1586
1591 @Override
1592 public int countAll() {
1593 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1594 FINDER_ARGS_EMPTY, this);
1595
1596 if (count == null) {
1597 Session session = null;
1598
1599 try {
1600 session = openSession();
1601
1602 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1603
1604 count = (Long)q.uniqueResult();
1605
1606 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1607 count);
1608 }
1609 catch (Exception e) {
1610 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1611 FINDER_ARGS_EMPTY);
1612
1613 throw processException(e);
1614 }
1615 finally {
1616 closeSession(session);
1617 }
1618 }
1619
1620 return count.intValue();
1621 }
1622
1623 @Override
1624 protected Map<String, Integer> getTableColumnsMap() {
1625 return ExpandoTableModelImpl.TABLE_COLUMNS_MAP;
1626 }
1627
1628
1631 public void afterPropertiesSet() {
1632 }
1633
1634 public void destroy() {
1635 entityCache.removeCache(ExpandoTableImpl.class.getName());
1636 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1637 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1638 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1639 }
1640
1641 @BeanReference(type = CompanyProviderWrapper.class)
1642 protected CompanyProvider companyProvider;
1643 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1644 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1645 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1646 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE_PKS_IN = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE tableId IN (";
1647 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1648 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1649 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1650 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1651 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1652 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1653 private static final Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1654 private static final ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1655 @Override
1656 public Object clone() {
1657 return this;
1658 }
1659
1660 @Override
1661 public CacheModel<ExpandoTable> toCacheModel() {
1662 return _nullExpandoTableCacheModel;
1663 }
1664 };
1665
1666 private static final CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1667 @Override
1668 public ExpandoTable toEntityModel() {
1669 return _nullExpandoTable;
1670 }
1671 };
1672 }