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