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 public ExpandoTablePersistenceImpl() {
903 setModelClass(ExpandoTable.class);
904 }
905
906
911 @Override
912 public void cacheResult(ExpandoTable expandoTable) {
913 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
914 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
915
916 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
917 new Object[] {
918 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
919 expandoTable.getName()
920 }, expandoTable);
921
922 expandoTable.resetOriginalValues();
923 }
924
925
930 @Override
931 public void cacheResult(List<ExpandoTable> expandoTables) {
932 for (ExpandoTable expandoTable : expandoTables) {
933 if (EntityCacheUtil.getResult(
934 ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
935 ExpandoTableImpl.class, expandoTable.getPrimaryKey()) == null) {
936 cacheResult(expandoTable);
937 }
938 else {
939 expandoTable.resetOriginalValues();
940 }
941 }
942 }
943
944
951 @Override
952 public void clearCache() {
953 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
954 CacheRegistryUtil.clear(ExpandoTableImpl.class.getName());
955 }
956
957 EntityCacheUtil.clearCache(ExpandoTableImpl.class.getName());
958
959 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
960 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
961 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
962 }
963
964
971 @Override
972 public void clearCache(ExpandoTable expandoTable) {
973 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
974 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
975
976 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
977 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
978
979 clearUniqueFindersCache(expandoTable);
980 }
981
982 @Override
983 public void clearCache(List<ExpandoTable> expandoTables) {
984 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
985 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
986
987 for (ExpandoTable expandoTable : expandoTables) {
988 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
989 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
990
991 clearUniqueFindersCache(expandoTable);
992 }
993 }
994
995 protected void cacheUniqueFindersCache(ExpandoTable expandoTable) {
996 if (expandoTable.isNew()) {
997 Object[] args = new Object[] {
998 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
999 expandoTable.getName()
1000 };
1001
1002 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
1003 Long.valueOf(1));
1004 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1005 expandoTable);
1006 }
1007 else {
1008 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1009
1010 if ((expandoTableModelImpl.getColumnBitmask() &
1011 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1012 Object[] args = new Object[] {
1013 expandoTable.getCompanyId(),
1014 expandoTable.getClassNameId(), expandoTable.getName()
1015 };
1016
1017 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
1018 Long.valueOf(1));
1019 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
1020 expandoTable);
1021 }
1022 }
1023 }
1024
1025 protected void clearUniqueFindersCache(ExpandoTable expandoTable) {
1026 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1027
1028 Object[] args = new Object[] {
1029 expandoTable.getCompanyId(), expandoTable.getClassNameId(),
1030 expandoTable.getName()
1031 };
1032
1033 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1034 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1035
1036 if ((expandoTableModelImpl.getColumnBitmask() &
1037 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
1038 args = new Object[] {
1039 expandoTableModelImpl.getOriginalCompanyId(),
1040 expandoTableModelImpl.getOriginalClassNameId(),
1041 expandoTableModelImpl.getOriginalName()
1042 };
1043
1044 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
1045 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
1046 }
1047 }
1048
1049
1055 @Override
1056 public ExpandoTable create(long tableId) {
1057 ExpandoTable expandoTable = new ExpandoTableImpl();
1058
1059 expandoTable.setNew(true);
1060 expandoTable.setPrimaryKey(tableId);
1061
1062 return expandoTable;
1063 }
1064
1065
1073 @Override
1074 public ExpandoTable remove(long tableId)
1075 throws NoSuchTableException, SystemException {
1076 return remove((Serializable)tableId);
1077 }
1078
1079
1087 @Override
1088 public ExpandoTable remove(Serializable primaryKey)
1089 throws NoSuchTableException, SystemException {
1090 Session session = null;
1091
1092 try {
1093 session = openSession();
1094
1095 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1096 primaryKey);
1097
1098 if (expandoTable == null) {
1099 if (_log.isWarnEnabled()) {
1100 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1101 }
1102
1103 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1104 primaryKey);
1105 }
1106
1107 return remove(expandoTable);
1108 }
1109 catch (NoSuchTableException nsee) {
1110 throw nsee;
1111 }
1112 catch (Exception e) {
1113 throw processException(e);
1114 }
1115 finally {
1116 closeSession(session);
1117 }
1118 }
1119
1120 @Override
1121 protected ExpandoTable removeImpl(ExpandoTable expandoTable)
1122 throws SystemException {
1123 expandoTable = toUnwrappedModel(expandoTable);
1124
1125 Session session = null;
1126
1127 try {
1128 session = openSession();
1129
1130 if (!session.contains(expandoTable)) {
1131 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1132 expandoTable.getPrimaryKeyObj());
1133 }
1134
1135 if (expandoTable != null) {
1136 session.delete(expandoTable);
1137 }
1138 }
1139 catch (Exception e) {
1140 throw processException(e);
1141 }
1142 finally {
1143 closeSession(session);
1144 }
1145
1146 if (expandoTable != null) {
1147 clearCache(expandoTable);
1148 }
1149
1150 return expandoTable;
1151 }
1152
1153 @Override
1154 public ExpandoTable updateImpl(
1155 com.liferay.portlet.expando.model.ExpandoTable expandoTable)
1156 throws SystemException {
1157 expandoTable = toUnwrappedModel(expandoTable);
1158
1159 boolean isNew = expandoTable.isNew();
1160
1161 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
1162
1163 Session session = null;
1164
1165 try {
1166 session = openSession();
1167
1168 if (expandoTable.isNew()) {
1169 session.save(expandoTable);
1170
1171 expandoTable.setNew(false);
1172 }
1173 else {
1174 session.merge(expandoTable);
1175 }
1176 }
1177 catch (Exception e) {
1178 throw processException(e);
1179 }
1180 finally {
1181 closeSession(session);
1182 }
1183
1184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1185
1186 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
1187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1188 }
1189
1190 else {
1191 if ((expandoTableModelImpl.getColumnBitmask() &
1192 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1193 Object[] args = new Object[] {
1194 expandoTableModelImpl.getOriginalCompanyId(),
1195 expandoTableModelImpl.getOriginalClassNameId()
1196 };
1197
1198 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1199 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1200 args);
1201
1202 args = new Object[] {
1203 expandoTableModelImpl.getCompanyId(),
1204 expandoTableModelImpl.getClassNameId()
1205 };
1206
1207 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1208 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1209 args);
1210 }
1211 }
1212
1213 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1214 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
1215
1216 clearUniqueFindersCache(expandoTable);
1217 cacheUniqueFindersCache(expandoTable);
1218
1219 return expandoTable;
1220 }
1221
1222 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
1223 if (expandoTable instanceof ExpandoTableImpl) {
1224 return expandoTable;
1225 }
1226
1227 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
1228
1229 expandoTableImpl.setNew(expandoTable.isNew());
1230 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
1231
1232 expandoTableImpl.setTableId(expandoTable.getTableId());
1233 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
1234 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
1235 expandoTableImpl.setName(expandoTable.getName());
1236
1237 return expandoTableImpl;
1238 }
1239
1240
1248 @Override
1249 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
1250 throws NoSuchTableException, SystemException {
1251 ExpandoTable expandoTable = fetchByPrimaryKey(primaryKey);
1252
1253 if (expandoTable == null) {
1254 if (_log.isWarnEnabled()) {
1255 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1256 }
1257
1258 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1259 primaryKey);
1260 }
1261
1262 return expandoTable;
1263 }
1264
1265
1273 @Override
1274 public ExpandoTable findByPrimaryKey(long tableId)
1275 throws NoSuchTableException, SystemException {
1276 return findByPrimaryKey((Serializable)tableId);
1277 }
1278
1279
1286 @Override
1287 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
1288 throws SystemException {
1289 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1290 ExpandoTableImpl.class, primaryKey);
1291
1292 if (expandoTable == _nullExpandoTable) {
1293 return null;
1294 }
1295
1296 if (expandoTable == null) {
1297 Session session = null;
1298
1299 try {
1300 session = openSession();
1301
1302 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
1303 primaryKey);
1304
1305 if (expandoTable != null) {
1306 cacheResult(expandoTable);
1307 }
1308 else {
1309 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1310 ExpandoTableImpl.class, primaryKey, _nullExpandoTable);
1311 }
1312 }
1313 catch (Exception e) {
1314 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
1315 ExpandoTableImpl.class, primaryKey);
1316
1317 throw processException(e);
1318 }
1319 finally {
1320 closeSession(session);
1321 }
1322 }
1323
1324 return expandoTable;
1325 }
1326
1327
1334 @Override
1335 public ExpandoTable fetchByPrimaryKey(long tableId)
1336 throws SystemException {
1337 return fetchByPrimaryKey((Serializable)tableId);
1338 }
1339
1340
1346 @Override
1347 public List<ExpandoTable> findAll() throws SystemException {
1348 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1349 }
1350
1351
1363 @Override
1364 public List<ExpandoTable> findAll(int start, int end)
1365 throws SystemException {
1366 return findAll(start, end, null);
1367 }
1368
1369
1382 @Override
1383 public List<ExpandoTable> findAll(int start, int end,
1384 OrderByComparator orderByComparator) throws SystemException {
1385 boolean pagination = true;
1386 FinderPath finderPath = null;
1387 Object[] finderArgs = null;
1388
1389 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1390 (orderByComparator == null)) {
1391 pagination = false;
1392 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1393 finderArgs = FINDER_ARGS_EMPTY;
1394 }
1395 else {
1396 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1397 finderArgs = new Object[] { start, end, orderByComparator };
1398 }
1399
1400 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
1401 finderArgs, this);
1402
1403 if (list == null) {
1404 StringBundler query = null;
1405 String sql = null;
1406
1407 if (orderByComparator != null) {
1408 query = new StringBundler(2 +
1409 (orderByComparator.getOrderByFields().length * 3));
1410
1411 query.append(_SQL_SELECT_EXPANDOTABLE);
1412
1413 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1414 orderByComparator);
1415
1416 sql = query.toString();
1417 }
1418 else {
1419 sql = _SQL_SELECT_EXPANDOTABLE;
1420
1421 if (pagination) {
1422 sql = sql.concat(ExpandoTableModelImpl.ORDER_BY_JPQL);
1423 }
1424 }
1425
1426 Session session = null;
1427
1428 try {
1429 session = openSession();
1430
1431 Query q = session.createQuery(sql);
1432
1433 if (!pagination) {
1434 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1435 start, end, false);
1436
1437 Collections.sort(list);
1438
1439 list = new UnmodifiableList<ExpandoTable>(list);
1440 }
1441 else {
1442 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1443 start, end);
1444 }
1445
1446 cacheResult(list);
1447
1448 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1449 }
1450 catch (Exception e) {
1451 FinderCacheUtil.removeResult(finderPath, finderArgs);
1452
1453 throw processException(e);
1454 }
1455 finally {
1456 closeSession(session);
1457 }
1458 }
1459
1460 return list;
1461 }
1462
1463
1468 @Override
1469 public void removeAll() throws SystemException {
1470 for (ExpandoTable expandoTable : findAll()) {
1471 remove(expandoTable);
1472 }
1473 }
1474
1475
1481 @Override
1482 public int countAll() throws SystemException {
1483 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1484 FINDER_ARGS_EMPTY, this);
1485
1486 if (count == null) {
1487 Session session = null;
1488
1489 try {
1490 session = openSession();
1491
1492 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1493
1494 count = (Long)q.uniqueResult();
1495
1496 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1497 FINDER_ARGS_EMPTY, count);
1498 }
1499 catch (Exception e) {
1500 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1501 FINDER_ARGS_EMPTY);
1502
1503 throw processException(e);
1504 }
1505 finally {
1506 closeSession(session);
1507 }
1508 }
1509
1510 return count.intValue();
1511 }
1512
1513
1516 public void afterPropertiesSet() {
1517 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1518 com.liferay.portal.util.PropsUtil.get(
1519 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1520
1521 if (listenerClassNames.length > 0) {
1522 try {
1523 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1524
1525 for (String listenerClassName : listenerClassNames) {
1526 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1527 getClassLoader(), listenerClassName));
1528 }
1529
1530 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1531 }
1532 catch (Exception e) {
1533 _log.error(e);
1534 }
1535 }
1536 }
1537
1538 public void destroy() {
1539 EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1540 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1541 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1542 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1543 }
1544
1545 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1546 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1547 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1548 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1549 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1550 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1551 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1552 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1553 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1554 private static ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1555 @Override
1556 public Object clone() {
1557 return this;
1558 }
1559
1560 @Override
1561 public CacheModel<ExpandoTable> toCacheModel() {
1562 return _nullExpandoTableCacheModel;
1563 }
1564 };
1565
1566 private static CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1567 @Override
1568 public ExpandoTable toEntityModel() {
1569 return _nullExpandoTable;
1570 }
1571 };
1572 }