001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039
040 import com.liferay.portlet.expando.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
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class ExpandoTablePersistenceImpl extends BasePersistenceImpl<ExpandoTable>
064 implements ExpandoTablePersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoTableImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
076 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
079 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
082 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
085 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
086 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
087 new String[] {
088 Long.class.getName(), Long.class.getName(),
089
090 Integer.class.getName(), Integer.class.getName(),
091 OrderByComparator.class.getName()
092 });
093 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
094 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
096 new String[] { Long.class.getName(), Long.class.getName() },
097 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
098 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK);
099 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
100 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
102 new String[] { Long.class.getName(), Long.class.getName() });
103
104
112 @Override
113 public List<ExpandoTable> findByC_C(long companyId, long classNameId)
114 throws SystemException {
115 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
116 QueryUtil.ALL_POS, null);
117 }
118
119
133 @Override
134 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
135 int start, int end) throws SystemException {
136 return findByC_C(companyId, classNameId, start, end, null);
137 }
138
139
154 @Override
155 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
156 int start, int end, OrderByComparator orderByComparator)
157 throws SystemException {
158 boolean pagination = true;
159 FinderPath finderPath = null;
160 Object[] finderArgs = null;
161
162 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163 (orderByComparator == null)) {
164 pagination = false;
165 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
166 finderArgs = new Object[] { companyId, classNameId };
167 }
168 else {
169 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
170 finderArgs = new Object[] {
171 companyId, classNameId,
172
173 start, end, orderByComparator
174 };
175 }
176
177 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
178 finderArgs, this);
179
180 if ((list != null) && !list.isEmpty()) {
181 for (ExpandoTable expandoTable : list) {
182 if ((companyId != expandoTable.getCompanyId()) ||
183 (classNameId != expandoTable.getClassNameId())) {
184 list = null;
185
186 break;
187 }
188 }
189 }
190
191 if (list == null) {
192 StringBundler query = null;
193
194 if (orderByComparator != null) {
195 query = new StringBundler(4 +
196 (orderByComparator.getOrderByFields().length * 3));
197 }
198 else {
199 query = new StringBundler(4);
200 }
201
202 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
203
204 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
205
206 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(ExpandoTableModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 qPos.add(companyId);
229
230 qPos.add(classNameId);
231
232 if (!pagination) {
233 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
234 start, end, false);
235
236 Collections.sort(list);
237
238 list = new UnmodifiableList<ExpandoTable>(list);
239 }
240 else {
241 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
242 start, end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
272 @Override
273 public ExpandoTable findByC_C_First(long companyId, long classNameId,
274 OrderByComparator orderByComparator)
275 throws NoSuchTableException, SystemException {
276 ExpandoTable expandoTable = fetchByC_C_First(companyId, classNameId,
277 orderByComparator);
278
279 if (expandoTable != null) {
280 return expandoTable;
281 }
282
283 StringBundler msg = new StringBundler(6);
284
285 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
286
287 msg.append("companyId=");
288 msg.append(companyId);
289
290 msg.append(", classNameId=");
291 msg.append(classNameId);
292
293 msg.append(StringPool.CLOSE_CURLY_BRACE);
294
295 throw new NoSuchTableException(msg.toString());
296 }
297
298
307 @Override
308 public ExpandoTable fetchByC_C_First(long companyId, long classNameId,
309 OrderByComparator orderByComparator) throws SystemException {
310 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
311 orderByComparator);
312
313 if (!list.isEmpty()) {
314 return list.get(0);
315 }
316
317 return null;
318 }
319
320
330 @Override
331 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
332 OrderByComparator orderByComparator)
333 throws NoSuchTableException, SystemException {
334 ExpandoTable expandoTable = fetchByC_C_Last(companyId, classNameId,
335 orderByComparator);
336
337 if (expandoTable != null) {
338 return expandoTable;
339 }
340
341 StringBundler msg = new StringBundler(6);
342
343 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
344
345 msg.append("companyId=");
346 msg.append(companyId);
347
348 msg.append(", classNameId=");
349 msg.append(classNameId);
350
351 msg.append(StringPool.CLOSE_CURLY_BRACE);
352
353 throw new NoSuchTableException(msg.toString());
354 }
355
356
365 @Override
366 public ExpandoTable fetchByC_C_Last(long companyId, long classNameId,
367 OrderByComparator orderByComparator) throws SystemException {
368 int count = countByC_C(companyId, classNameId);
369
370 if (count == 0) {
371 return null;
372 }
373
374 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
375 count, orderByComparator);
376
377 if (!list.isEmpty()) {
378 return list.get(0);
379 }
380
381 return null;
382 }
383
384
395 @Override
396 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
397 long classNameId, OrderByComparator orderByComparator)
398 throws NoSuchTableException, SystemException {
399 ExpandoTable expandoTable = findByPrimaryKey(tableId);
400
401 Session session = null;
402
403 try {
404 session = openSession();
405
406 ExpandoTable[] array = new ExpandoTableImpl[3];
407
408 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
409 classNameId, orderByComparator, true);
410
411 array[1] = expandoTable;
412
413 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
414 classNameId, orderByComparator, false);
415
416 return array;
417 }
418 catch (Exception e) {
419 throw processException(e);
420 }
421 finally {
422 closeSession(session);
423 }
424 }
425
426 protected ExpandoTable getByC_C_PrevAndNext(Session session,
427 ExpandoTable expandoTable, long companyId, long classNameId,
428 OrderByComparator orderByComparator, boolean previous) {
429 StringBundler query = null;
430
431 if (orderByComparator != null) {
432 query = new StringBundler(6 +
433 (orderByComparator.getOrderByFields().length * 6));
434 }
435 else {
436 query = new StringBundler(3);
437 }
438
439 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
440
441 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
442
443 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
444
445 if (orderByComparator != null) {
446 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
447
448 if (orderByConditionFields.length > 0) {
449 query.append(WHERE_AND);
450 }
451
452 for (int i = 0; i < orderByConditionFields.length; i++) {
453 query.append(_ORDER_BY_ENTITY_ALIAS);
454 query.append(orderByConditionFields[i]);
455
456 if ((i + 1) < orderByConditionFields.length) {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(WHERE_GREATER_THAN_HAS_NEXT);
459 }
460 else {
461 query.append(WHERE_LESSER_THAN_HAS_NEXT);
462 }
463 }
464 else {
465 if (orderByComparator.isAscending() ^ previous) {
466 query.append(WHERE_GREATER_THAN);
467 }
468 else {
469 query.append(WHERE_LESSER_THAN);
470 }
471 }
472 }
473
474 query.append(ORDER_BY_CLAUSE);
475
476 String[] orderByFields = orderByComparator.getOrderByFields();
477
478 for (int i = 0; i < orderByFields.length; i++) {
479 query.append(_ORDER_BY_ENTITY_ALIAS);
480 query.append(orderByFields[i]);
481
482 if ((i + 1) < orderByFields.length) {
483 if (orderByComparator.isAscending() ^ previous) {
484 query.append(ORDER_BY_ASC_HAS_NEXT);
485 }
486 else {
487 query.append(ORDER_BY_DESC_HAS_NEXT);
488 }
489 }
490 else {
491 if (orderByComparator.isAscending() ^ previous) {
492 query.append(ORDER_BY_ASC);
493 }
494 else {
495 query.append(ORDER_BY_DESC);
496 }
497 }
498 }
499 }
500 else {
501 query.append(ExpandoTableModelImpl.ORDER_BY_JPQL);
502 }
503
504 String sql = query.toString();
505
506 Query q = session.createQuery(sql);
507
508 q.setFirstResult(0);
509 q.setMaxResults(2);
510
511 QueryPos qPos = QueryPos.getInstance(q);
512
513 qPos.add(companyId);
514
515 qPos.add(classNameId);
516
517 if (orderByComparator != null) {
518 Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
519
520 for (Object value : values) {
521 qPos.add(value);
522 }
523 }
524
525 List<ExpandoTable> list = q.list();
526
527 if (list.size() == 2) {
528 return list.get(1);
529 }
530 else {
531 return null;
532 }
533 }
534
535
542 @Override
543 public void removeByC_C(long companyId, long classNameId)
544 throws SystemException {
545 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId,
546 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
547 remove(expandoTable);
548 }
549 }
550
551
559 @Override
560 public int countByC_C(long companyId, long classNameId)
561 throws SystemException {
562 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
563
564 Object[] finderArgs = new Object[] { companyId, classNameId };
565
566 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
567 this);
568
569 if (count == null) {
570 StringBundler query = new StringBundler(3);
571
572 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
573
574 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
575
576 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
577
578 String sql = query.toString();
579
580 Session session = null;
581
582 try {
583 session = openSession();
584
585 Query q = session.createQuery(sql);
586
587 QueryPos qPos = QueryPos.getInstance(q);
588
589 qPos.add(companyId);
590
591 qPos.add(classNameId);
592
593 count = (Long)q.uniqueResult();
594
595 FinderCacheUtil.putResult(finderPath, finderArgs, count);
596 }
597 catch (Exception e) {
598 FinderCacheUtil.removeResult(finderPath, finderArgs);
599
600 throw processException(e);
601 }
602 finally {
603 closeSession(session);
604 }
605 }
606
607 return count.intValue();
608 }
609
610 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
611 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
612 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
613 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
614 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_N",
615 new String[] {
616 Long.class.getName(), Long.class.getName(),
617 String.class.getName()
618 },
619 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
620 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK |
621 ExpandoTableModelImpl.NAME_COLUMN_BITMASK);
622 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
623 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
624 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_N",
625 new String[] {
626 Long.class.getName(), Long.class.getName(),
627 String.class.getName()
628 });
629
630
640 @Override
641 public ExpandoTable findByC_C_N(long companyId, long classNameId,
642 String name) throws NoSuchTableException, SystemException {
643 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
644
645 if (expandoTable == null) {
646 StringBundler msg = new StringBundler(8);
647
648 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
649
650 msg.append("companyId=");
651 msg.append(companyId);
652
653 msg.append(", classNameId=");
654 msg.append(classNameId);
655
656 msg.append(", name=");
657 msg.append(name);
658
659 msg.append(StringPool.CLOSE_CURLY_BRACE);
660
661 if (_log.isWarnEnabled()) {
662 _log.warn(msg.toString());
663 }
664
665 throw new NoSuchTableException(msg.toString());
666 }
667
668 return expandoTable;
669 }
670
671
680 @Override
681 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
682 String name) throws SystemException {
683 return fetchByC_C_N(companyId, classNameId, name, true);
684 }
685
686
696 @Override
697 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
698 String name, boolean retrieveFromCache) throws SystemException {
699 Object[] finderArgs = new Object[] { companyId, classNameId, name };
700
701 Object result = null;
702
703 if (retrieveFromCache) {
704 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
705 finderArgs, this);
706 }
707
708 if (result instanceof ExpandoTable) {
709 ExpandoTable expandoTable = (ExpandoTable)result;
710
711 if ((companyId != expandoTable.getCompanyId()) ||
712 (classNameId != expandoTable.getClassNameId()) ||
713 !Validator.equals(name, expandoTable.getName())) {
714 result = null;
715 }
716 }
717
718 if (result == null) {
719 StringBundler query = new StringBundler(5);
720
721 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
722
723 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
724
725 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
726
727 boolean bindName = false;
728
729 if (name == null) {
730 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
731 }
732 else if (name.equals(StringPool.BLANK)) {
733 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
734 }
735 else {
736 bindName = true;
737
738 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
739 }
740
741 String sql = query.toString();
742
743 Session session = null;
744
745 try {
746 session = openSession();
747
748 Query q = session.createQuery(sql);
749
750 QueryPos qPos = QueryPos.getInstance(q);
751
752 qPos.add(companyId);
753
754 qPos.add(classNameId);
755
756 if (bindName) {
757 qPos.add(name);
758 }
759
760 List<ExpandoTable> list = q.list();
761
762 if (list.isEmpty()) {
763 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
764 finderArgs, list);
765 }
766 else {
767 ExpandoTable expandoTable = list.get(0);
768
769 result = expandoTable;
770
771 cacheResult(expandoTable);
772
773 if ((expandoTable.getCompanyId() != companyId) ||
774 (expandoTable.getClassNameId() != classNameId) ||
775 (expandoTable.getName() == null) ||
776 !expandoTable.getName().equals(name)) {
777 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
778 finderArgs, expandoTable);
779 }
780 }
781 }
782 catch (Exception e) {
783 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
784 finderArgs);
785
786 throw processException(e);
787 }
788 finally {
789 closeSession(session);
790 }
791 }
792
793 if (result instanceof List<?>) {
794 return null;
795 }
796 else {
797 return (ExpandoTable)result;
798 }
799 }
800
801
810 @Override
811 public ExpandoTable removeByC_C_N(long companyId, long classNameId,
812 String name) throws NoSuchTableException, SystemException {
813 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
814
815 return remove(expandoTable);
816 }
817
818
827 @Override
828 public int countByC_C_N(long companyId, long classNameId, String name)
829 throws SystemException {
830 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_N;
831
832 Object[] finderArgs = new Object[] { companyId, classNameId, name };
833
834 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
835 this);
836
837 if (count == null) {
838 StringBundler query = new StringBundler(4);
839
840 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
841
842 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
843
844 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
845
846 boolean bindName = false;
847
848 if (name == null) {
849 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
850 }
851 else if (name.equals(StringPool.BLANK)) {
852 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
853 }
854 else {
855 bindName = true;
856
857 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
858 }
859
860 String sql = query.toString();
861
862 Session session = null;
863
864 try {
865 session = openSession();
866
867 Query q = session.createQuery(sql);
868
869 QueryPos qPos = QueryPos.getInstance(q);
870
871 qPos.add(companyId);
872
873 qPos.add(classNameId);
874
875 if (bindName) {
876 qPos.add(name);
877 }
878
879 count = (Long)q.uniqueResult();
880
881 FinderCacheUtil.putResult(finderPath, finderArgs, count);
882 }
883 catch (Exception e) {
884 FinderCacheUtil.removeResult(finderPath, finderArgs);
885
886 throw processException(e);
887 }
888 finally {
889 closeSession(session);
890 }
891 }
892
893 return count.intValue();
894 }
895
896 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
897 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
898 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
899 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
900 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = '')";
901
902
907 @Override
908 public void cacheResult(ExpandoTable expandoTable) {
909 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
910 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
911
912 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
913 new Object[] {
914 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
915 expandoTable.getName()
916 }, expandoTable);
917
918 expandoTable.resetOriginalValues();
919 }
920
921
926 @Override
927 public void cacheResult(List<ExpandoTable> expandoTables) {
928 for (ExpandoTable expandoTable : expandoTables) {
929 if (EntityCacheUtil.getResult(
930 ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
931 ExpandoTableImpl.class, expandoTable.getPrimaryKey()) == null) {
932 cacheResult(expandoTable);
933 }
934 else {
935 expandoTable.resetOriginalValues();
936 }
937 }
938 }
939
940
947 @Override
948 public void clearCache() {
949 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
950 CacheRegistryUtil.clear(ExpandoTableImpl.class.getName());
951 }
952
953 EntityCacheUtil.clearCache(ExpandoTableImpl.class.getName());
954
955 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
956 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
957 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
958 }
959
960
967 @Override
968 public void clearCache(ExpandoTable expandoTable) {
969 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
970 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
971
972 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
973 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
974
975 clearUniqueFindersCache(expandoTable);
976 }
977
978 @Override
979 public void clearCache(List<ExpandoTable> expandoTables) {
980 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
981 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
982
983 for (ExpandoTable expandoTable : expandoTables) {
984 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
985 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
986
987 clearUniqueFindersCache(expandoTable);
988 }
989 }
990
991 protected void cacheUniqueFindersCache(ExpandoTable expandoTable) {
992 if (expandoTable.isNew()) {
993 Object[] args = new Object[] {
994 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
995 expandoTable.getName()
996 };
997
998 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
999 Long.valueOf(1));
1000 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1001 expandoTable);
1002 }
1003 else {
1004 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1005
1006 if ((expandoTableModelImpl.getColumnBitmask() &
1007 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1008 Object[] args = new Object[] {
1009 expandoTable.getCompanyId(),
1010 expandoTable.getClassNameId(), expandoTable.getName()
1011 };
1012
1013 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
1014 Long.valueOf(1));
1015 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1016 expandoTable);
1017 }
1018 }
1019 }
1020
1021 protected void clearUniqueFindersCache(ExpandoTable expandoTable) {
1022 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1023
1024 Object[] args = new Object[] {
1025 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
1026 expandoTable.getName()
1027 };
1028
1029 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1030 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1031
1032 if ((expandoTableModelImpl.getColumnBitmask() &
1033 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1034 args = new Object[] {
1035 expandoTableModelImpl.getOriginalCompanyId(),
1036 expandoTableModelImpl.getOriginalClassNameId(),
1037 expandoTableModelImpl.getOriginalName()
1038 };
1039
1040 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1041 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1042 }
1043 }
1044
1045
1051 @Override
1052 public ExpandoTable create(long tableId) {
1053 ExpandoTable expandoTable = new ExpandoTableImpl();
1054
1055 expandoTable.setNew(true);
1056 expandoTable.setPrimaryKey(tableId);
1057
1058 return expandoTable;
1059 }
1060
1061
1069 @Override
1070 public ExpandoTable remove(long tableId)
1071 throws NoSuchTableException, SystemException {
1072 return remove((Serializable)tableId);
1073 }
1074
1075
1083 @Override
1084 public ExpandoTable remove(Serializable primaryKey)
1085 throws NoSuchTableException, SystemException {
1086 Session session = null;
1087
1088 try {
1089 session = openSession();
1090
1091 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1092 primaryKey);
1093
1094 if (expandoTable == null) {
1095 if (_log.isWarnEnabled()) {
1096 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1097 }
1098
1099 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1100 primaryKey);
1101 }
1102
1103 return remove(expandoTable);
1104 }
1105 catch (NoSuchTableException nsee) {
1106 throw nsee;
1107 }
1108 catch (Exception e) {
1109 throw processException(e);
1110 }
1111 finally {
1112 closeSession(session);
1113 }
1114 }
1115
1116 @Override
1117 protected ExpandoTable removeImpl(ExpandoTable expandoTable)
1118 throws SystemException {
1119 expandoTable = toUnwrappedModel(expandoTable);
1120
1121 Session session = null;
1122
1123 try {
1124 session = openSession();
1125
1126 if (!session.contains(expandoTable)) {
1127 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1128 expandoTable.getPrimaryKeyObj());
1129 }
1130
1131 if (expandoTable != null) {
1132 session.delete(expandoTable);
1133 }
1134 }
1135 catch (Exception e) {
1136 throw processException(e);
1137 }
1138 finally {
1139 closeSession(session);
1140 }
1141
1142 if (expandoTable != null) {
1143 clearCache(expandoTable);
1144 }
1145
1146 return expandoTable;
1147 }
1148
1149 @Override
1150 public ExpandoTable updateImpl(
1151 com.liferay.portlet.expando.model.ExpandoTable expandoTable)
1152 throws SystemException {
1153 expandoTable = toUnwrappedModel(expandoTable);
1154
1155 boolean isNew = expandoTable.isNew();
1156
1157 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1158
1159 Session session = null;
1160
1161 try {
1162 session = openSession();
1163
1164 if (expandoTable.isNew()) {
1165 session.save(expandoTable);
1166
1167 expandoTable.setNew(false);
1168 }
1169 else {
1170 session.merge(expandoTable);
1171 }
1172 }
1173 catch (Exception e) {
1174 throw processException(e);
1175 }
1176 finally {
1177 closeSession(session);
1178 }
1179
1180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1181
1182 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
1183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1184 }
1185
1186 else {
1187 if ((expandoTableModelImpl.getColumnBitmask() &
1188 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1189 Object[] args = new Object[] {
1190 expandoTableModelImpl.getOriginalCompanyId(),
1191 expandoTableModelImpl.getOriginalClassNameId()
1192 };
1193
1194 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1195 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1196 args);
1197
1198 args = new Object[] {
1199 expandoTableModelImpl.getCompanyId(),
1200 expandoTableModelImpl.getClassNameId()
1201 };
1202
1203 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1204 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1205 args);
1206 }
1207 }
1208
1209 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1210 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
1211
1212 clearUniqueFindersCache(expandoTable);
1213 cacheUniqueFindersCache(expandoTable);
1214
1215 return expandoTable;
1216 }
1217
1218 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
1219 if (expandoTable instanceof ExpandoTableImpl) {
1220 return expandoTable;
1221 }
1222
1223 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
1224
1225 expandoTableImpl.setNew(expandoTable.isNew());
1226 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
1227
1228 expandoTableImpl.setTableId(expandoTable.getTableId());
1229 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
1230 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
1231 expandoTableImpl.setName(expandoTable.getName());
1232
1233 return expandoTableImpl;
1234 }
1235
1236
1244 @Override
1245 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
1246 throws NoSuchTableException, SystemException {
1247 ExpandoTable expandoTable = fetchByPrimaryKey(primaryKey);
1248
1249 if (expandoTable == null) {
1250 if (_log.isWarnEnabled()) {
1251 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1252 }
1253
1254 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1255 primaryKey);
1256 }
1257
1258 return expandoTable;
1259 }
1260
1261
1269 @Override
1270 public ExpandoTable findByPrimaryKey(long tableId)
1271 throws NoSuchTableException, SystemException {
1272 return findByPrimaryKey((Serializable)tableId);
1273 }
1274
1275
1282 @Override
1283 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
1284 throws SystemException {
1285 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1286 ExpandoTableImpl.class, primaryKey);
1287
1288 if (expandoTable == _nullExpandoTable) {
1289 return null;
1290 }
1291
1292 if (expandoTable == null) {
1293 Session session = null;
1294
1295 try {
1296 session = openSession();
1297
1298 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1299 primaryKey);
1300
1301 if (expandoTable != null) {
1302 cacheResult(expandoTable);
1303 }
1304 else {
1305 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1306 ExpandoTableImpl.class, primaryKey, _nullExpandoTable);
1307 }
1308 }
1309 catch (Exception e) {
1310 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1311 ExpandoTableImpl.class, primaryKey);
1312
1313 throw processException(e);
1314 }
1315 finally {
1316 closeSession(session);
1317 }
1318 }
1319
1320 return expandoTable;
1321 }
1322
1323
1330 @Override
1331 public ExpandoTable fetchByPrimaryKey(long tableId)
1332 throws SystemException {
1333 return fetchByPrimaryKey((Serializable)tableId);
1334 }
1335
1336
1342 @Override
1343 public List<ExpandoTable> findAll() throws SystemException {
1344 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1345 }
1346
1347
1359 @Override
1360 public List<ExpandoTable> findAll(int start, int end)
1361 throws SystemException {
1362 return findAll(start, end, null);
1363 }
1364
1365
1378 @Override
1379 public List<ExpandoTable> findAll(int start, int end,
1380 OrderByComparator orderByComparator) throws SystemException {
1381 boolean pagination = true;
1382 FinderPath finderPath = null;
1383 Object[] finderArgs = null;
1384
1385 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1386 (orderByComparator == null)) {
1387 pagination = false;
1388 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1389 finderArgs = FINDER_ARGS_EMPTY;
1390 }
1391 else {
1392 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1393 finderArgs = new Object[] { start, end, orderByComparator };
1394 }
1395
1396 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
1397 finderArgs, this);
1398
1399 if (list == null) {
1400 StringBundler query = null;
1401 String sql = null;
1402
1403 if (orderByComparator != null) {
1404 query = new StringBundler(2 +
1405 (orderByComparator.getOrderByFields().length * 3));
1406
1407 query.append(_SQL_SELECT_EXPANDOTABLE);
1408
1409 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1410 orderByComparator);
1411
1412 sql = query.toString();
1413 }
1414 else {
1415 sql = _SQL_SELECT_EXPANDOTABLE;
1416
1417 if (pagination) {
1418 sql = sql.concat(ExpandoTableModelImpl.ORDER_BY_JPQL);
1419 }
1420 }
1421
1422 Session session = null;
1423
1424 try {
1425 session = openSession();
1426
1427 Query q = session.createQuery(sql);
1428
1429 if (!pagination) {
1430 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1431 start, end, false);
1432
1433 Collections.sort(list);
1434
1435 list = new UnmodifiableList<ExpandoTable>(list);
1436 }
1437 else {
1438 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1439 start, end);
1440 }
1441
1442 cacheResult(list);
1443
1444 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1445 }
1446 catch (Exception e) {
1447 FinderCacheUtil.removeResult(finderPath, finderArgs);
1448
1449 throw processException(e);
1450 }
1451 finally {
1452 closeSession(session);
1453 }
1454 }
1455
1456 return list;
1457 }
1458
1459
1464 @Override
1465 public void removeAll() throws SystemException {
1466 for (ExpandoTable expandoTable : findAll()) {
1467 remove(expandoTable);
1468 }
1469 }
1470
1471
1477 @Override
1478 public int countAll() throws SystemException {
1479 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1480 FINDER_ARGS_EMPTY, this);
1481
1482 if (count == null) {
1483 Session session = null;
1484
1485 try {
1486 session = openSession();
1487
1488 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1489
1490 count = (Long)q.uniqueResult();
1491
1492 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1493 FINDER_ARGS_EMPTY, count);
1494 }
1495 catch (Exception e) {
1496 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1497 FINDER_ARGS_EMPTY);
1498
1499 throw processException(e);
1500 }
1501 finally {
1502 closeSession(session);
1503 }
1504 }
1505
1506 return count.intValue();
1507 }
1508
1509
1512 public void afterPropertiesSet() {
1513 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1514 com.liferay.portal.util.PropsUtil.get(
1515 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1516
1517 if (listenerClassNames.length > 0) {
1518 try {
1519 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1520
1521 for (String listenerClassName : listenerClassNames) {
1522 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1523 getClassLoader(), listenerClassName));
1524 }
1525
1526 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1527 }
1528 catch (Exception e) {
1529 _log.error(e);
1530 }
1531 }
1532 }
1533
1534 public void destroy() {
1535 EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1536 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1537 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1538 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1539 }
1540
1541 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1542 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1543 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1544 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1545 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1546 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1547 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1548 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1549 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1550 private static ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1551 @Override
1552 public Object clone() {
1553 return this;
1554 }
1555
1556 @Override
1557 public CacheModel<ExpandoTable> toCacheModel() {
1558 return _nullExpandoTableCacheModel;
1559 }
1560 };
1561
1562 private static CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1563 @Override
1564 public ExpandoTable toEntityModel() {
1565 return _nullExpandoTable;
1566 }
1567 };
1568 }