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