001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.expando.NoSuchTableException;
044 import com.liferay.portlet.expando.model.ExpandoTable;
045 import com.liferay.portlet.expando.model.impl.ExpandoTableImpl;
046 import com.liferay.portlet.expando.model.impl.ExpandoTableModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class ExpandoTablePersistenceImpl extends BasePersistenceImpl<ExpandoTable>
067 implements ExpandoTablePersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoTableImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
079 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
081 new String[] {
082 Long.class.getName(), Long.class.getName(),
083
084 "java.lang.Integer", "java.lang.Integer",
085 "com.liferay.portal.kernel.util.OrderByComparator"
086 });
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
088 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
090 new String[] { Long.class.getName(), Long.class.getName() },
091 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
092 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK);
093 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
094 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
096 new String[] { Long.class.getName(), Long.class.getName() });
097 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
098 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
099 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_N",
100 new String[] {
101 Long.class.getName(), Long.class.getName(),
102 String.class.getName()
103 },
104 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
105 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK |
106 ExpandoTableModelImpl.NAME_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
108 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_N",
110 new String[] {
111 Long.class.getName(), Long.class.getName(),
112 String.class.getName()
113 });
114 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
115 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
117 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
118 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
119 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
120 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
121 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
122 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
123
124
129 public void cacheResult(ExpandoTable expandoTable) {
130 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
131 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
132
133 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
134 new Object[] {
135 Long.valueOf(expandoTable.getCompanyId()),
136 Long.valueOf(expandoTable.getClassNameId()),
137
138 expandoTable.getName()
139 }, expandoTable);
140
141 expandoTable.resetOriginalValues();
142 }
143
144
149 public void cacheResult(List<ExpandoTable> expandoTables) {
150 for (ExpandoTable expandoTable : expandoTables) {
151 if (EntityCacheUtil.getResult(
152 ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
153 ExpandoTableImpl.class, expandoTable.getPrimaryKey()) == null) {
154 cacheResult(expandoTable);
155 }
156 else {
157 expandoTable.resetOriginalValues();
158 }
159 }
160 }
161
162
169 @Override
170 public void clearCache() {
171 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
172 CacheRegistryUtil.clear(ExpandoTableImpl.class.getName());
173 }
174
175 EntityCacheUtil.clearCache(ExpandoTableImpl.class.getName());
176
177 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
180 }
181
182
189 @Override
190 public void clearCache(ExpandoTable expandoTable) {
191 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
192 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
193
194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
195 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
196
197 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
198 new Object[] {
199 Long.valueOf(expandoTable.getCompanyId()),
200 Long.valueOf(expandoTable.getClassNameId()),
201
202 expandoTable.getName()
203 });
204 }
205
206
212 public ExpandoTable create(long tableId) {
213 ExpandoTable expandoTable = new ExpandoTableImpl();
214
215 expandoTable.setNew(true);
216 expandoTable.setPrimaryKey(tableId);
217
218 return expandoTable;
219 }
220
221
229 @Override
230 public ExpandoTable remove(Serializable primaryKey)
231 throws NoSuchModelException, SystemException {
232 return remove(((Long)primaryKey).longValue());
233 }
234
235
243 public ExpandoTable remove(long tableId)
244 throws NoSuchTableException, SystemException {
245 Session session = null;
246
247 try {
248 session = openSession();
249
250 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
251 Long.valueOf(tableId));
252
253 if (expandoTable == null) {
254 if (_log.isWarnEnabled()) {
255 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
256 }
257
258 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
259 tableId);
260 }
261
262 return expandoTablePersistence.remove(expandoTable);
263 }
264 catch (NoSuchTableException nsee) {
265 throw nsee;
266 }
267 catch (Exception e) {
268 throw processException(e);
269 }
270 finally {
271 closeSession(session);
272 }
273 }
274
275
282 @Override
283 public ExpandoTable remove(ExpandoTable expandoTable)
284 throws SystemException {
285 return super.remove(expandoTable);
286 }
287
288 @Override
289 protected ExpandoTable removeImpl(ExpandoTable expandoTable)
290 throws SystemException {
291 expandoTable = toUnwrappedModel(expandoTable);
292
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 BatchSessionUtil.delete(session, expandoTable);
299 }
300 catch (Exception e) {
301 throw processException(e);
302 }
303 finally {
304 closeSession(session);
305 }
306
307 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
308 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
309
310 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
311
312 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
313 new Object[] {
314 Long.valueOf(expandoTableModelImpl.getCompanyId()),
315 Long.valueOf(expandoTableModelImpl.getClassNameId()),
316
317 expandoTableModelImpl.getName()
318 });
319
320 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
321 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
322
323 return expandoTable;
324 }
325
326 @Override
327 public ExpandoTable updateImpl(
328 com.liferay.portlet.expando.model.ExpandoTable expandoTable,
329 boolean merge) throws SystemException {
330 expandoTable = toUnwrappedModel(expandoTable);
331
332 boolean isNew = expandoTable.isNew();
333
334 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
335
336 Session session = null;
337
338 try {
339 session = openSession();
340
341 BatchSessionUtil.update(session, expandoTable, merge);
342
343 expandoTable.setNew(false);
344 }
345 catch (Exception e) {
346 throw processException(e);
347 }
348 finally {
349 closeSession(session);
350 }
351
352 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
353
354 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
355 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
356 }
357
358 else {
359 if ((expandoTableModelImpl.getColumnBitmask() &
360 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
361 Object[] args = new Object[] {
362 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
363 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId())
364 };
365
366 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
367 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
368 args);
369
370 args = new Object[] {
371 Long.valueOf(expandoTableModelImpl.getCompanyId()),
372 Long.valueOf(expandoTableModelImpl.getClassNameId())
373 };
374
375 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
376 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
377 args);
378 }
379 }
380
381 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
382 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
383
384 if (isNew) {
385 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
386 new Object[] {
387 Long.valueOf(expandoTable.getCompanyId()),
388 Long.valueOf(expandoTable.getClassNameId()),
389
390 expandoTable.getName()
391 }, expandoTable);
392 }
393 else {
394 if ((expandoTableModelImpl.getColumnBitmask() &
395 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
396 Object[] args = new Object[] {
397 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
398 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId()),
399
400 expandoTableModelImpl.getOriginalName()
401 };
402
403 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
404 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
405
406 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
407 new Object[] {
408 Long.valueOf(expandoTable.getCompanyId()),
409 Long.valueOf(expandoTable.getClassNameId()),
410
411 expandoTable.getName()
412 }, expandoTable);
413 }
414 }
415
416 return expandoTable;
417 }
418
419 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
420 if (expandoTable instanceof ExpandoTableImpl) {
421 return expandoTable;
422 }
423
424 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
425
426 expandoTableImpl.setNew(expandoTable.isNew());
427 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
428
429 expandoTableImpl.setTableId(expandoTable.getTableId());
430 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
431 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
432 expandoTableImpl.setName(expandoTable.getName());
433
434 return expandoTableImpl;
435 }
436
437
445 @Override
446 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
447 throws NoSuchModelException, SystemException {
448 return findByPrimaryKey(((Long)primaryKey).longValue());
449 }
450
451
459 public ExpandoTable findByPrimaryKey(long tableId)
460 throws NoSuchTableException, SystemException {
461 ExpandoTable expandoTable = fetchByPrimaryKey(tableId);
462
463 if (expandoTable == null) {
464 if (_log.isWarnEnabled()) {
465 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
466 }
467
468 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
469 tableId);
470 }
471
472 return expandoTable;
473 }
474
475
482 @Override
483 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
484 throws SystemException {
485 return fetchByPrimaryKey(((Long)primaryKey).longValue());
486 }
487
488
495 public ExpandoTable fetchByPrimaryKey(long tableId)
496 throws SystemException {
497 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
498 ExpandoTableImpl.class, tableId);
499
500 if (expandoTable == _nullExpandoTable) {
501 return null;
502 }
503
504 if (expandoTable == null) {
505 Session session = null;
506
507 boolean hasException = false;
508
509 try {
510 session = openSession();
511
512 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
513 Long.valueOf(tableId));
514 }
515 catch (Exception e) {
516 hasException = true;
517
518 throw processException(e);
519 }
520 finally {
521 if (expandoTable != null) {
522 cacheResult(expandoTable);
523 }
524 else if (!hasException) {
525 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
526 ExpandoTableImpl.class, tableId, _nullExpandoTable);
527 }
528
529 closeSession(session);
530 }
531 }
532
533 return expandoTable;
534 }
535
536
544 public List<ExpandoTable> findByC_C(long companyId, long classNameId)
545 throws SystemException {
546 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
547 QueryUtil.ALL_POS, null);
548 }
549
550
564 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
565 int start, int end) throws SystemException {
566 return findByC_C(companyId, classNameId, start, end, null);
567 }
568
569
584 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
585 int start, int end, OrderByComparator orderByComparator)
586 throws SystemException {
587 FinderPath finderPath = null;
588 Object[] finderArgs = null;
589
590 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
591 (orderByComparator == null)) {
592 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
593 finderArgs = new Object[] { companyId, classNameId };
594 }
595 else {
596 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
597 finderArgs = new Object[] {
598 companyId, classNameId,
599
600 start, end, orderByComparator
601 };
602 }
603
604 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
605 finderArgs, this);
606
607 if (list == null) {
608 StringBundler query = null;
609
610 if (orderByComparator != null) {
611 query = new StringBundler(4 +
612 (orderByComparator.getOrderByFields().length * 3));
613 }
614 else {
615 query = new StringBundler(3);
616 }
617
618 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
619
620 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
621
622 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
623
624 if (orderByComparator != null) {
625 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
626 orderByComparator);
627 }
628
629 String sql = query.toString();
630
631 Session session = null;
632
633 try {
634 session = openSession();
635
636 Query q = session.createQuery(sql);
637
638 QueryPos qPos = QueryPos.getInstance(q);
639
640 qPos.add(companyId);
641
642 qPos.add(classNameId);
643
644 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
645 start, end);
646 }
647 catch (Exception e) {
648 throw processException(e);
649 }
650 finally {
651 if (list == null) {
652 FinderCacheUtil.removeResult(finderPath, finderArgs);
653 }
654 else {
655 cacheResult(list);
656
657 FinderCacheUtil.putResult(finderPath, finderArgs, list);
658 }
659
660 closeSession(session);
661 }
662 }
663
664 return list;
665 }
666
667
681 public ExpandoTable findByC_C_First(long companyId, long classNameId,
682 OrderByComparator orderByComparator)
683 throws NoSuchTableException, SystemException {
684 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
685 orderByComparator);
686
687 if (list.isEmpty()) {
688 StringBundler msg = new StringBundler(6);
689
690 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
691
692 msg.append("companyId=");
693 msg.append(companyId);
694
695 msg.append(", classNameId=");
696 msg.append(classNameId);
697
698 msg.append(StringPool.CLOSE_CURLY_BRACE);
699
700 throw new NoSuchTableException(msg.toString());
701 }
702 else {
703 return list.get(0);
704 }
705 }
706
707
721 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
722 OrderByComparator orderByComparator)
723 throws NoSuchTableException, SystemException {
724 int count = countByC_C(companyId, classNameId);
725
726 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
727 count, orderByComparator);
728
729 if (list.isEmpty()) {
730 StringBundler msg = new StringBundler(6);
731
732 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
733
734 msg.append("companyId=");
735 msg.append(companyId);
736
737 msg.append(", classNameId=");
738 msg.append(classNameId);
739
740 msg.append(StringPool.CLOSE_CURLY_BRACE);
741
742 throw new NoSuchTableException(msg.toString());
743 }
744 else {
745 return list.get(0);
746 }
747 }
748
749
764 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
765 long classNameId, OrderByComparator orderByComparator)
766 throws NoSuchTableException, SystemException {
767 ExpandoTable expandoTable = findByPrimaryKey(tableId);
768
769 Session session = null;
770
771 try {
772 session = openSession();
773
774 ExpandoTable[] array = new ExpandoTableImpl[3];
775
776 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
777 classNameId, orderByComparator, true);
778
779 array[1] = expandoTable;
780
781 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
782 classNameId, orderByComparator, false);
783
784 return array;
785 }
786 catch (Exception e) {
787 throw processException(e);
788 }
789 finally {
790 closeSession(session);
791 }
792 }
793
794 protected ExpandoTable getByC_C_PrevAndNext(Session session,
795 ExpandoTable expandoTable, long companyId, long classNameId,
796 OrderByComparator orderByComparator, boolean previous) {
797 StringBundler query = null;
798
799 if (orderByComparator != null) {
800 query = new StringBundler(6 +
801 (orderByComparator.getOrderByFields().length * 6));
802 }
803 else {
804 query = new StringBundler(3);
805 }
806
807 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
808
809 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
810
811 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
812
813 if (orderByComparator != null) {
814 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
815
816 if (orderByConditionFields.length > 0) {
817 query.append(WHERE_AND);
818 }
819
820 for (int i = 0; i < orderByConditionFields.length; i++) {
821 query.append(_ORDER_BY_ENTITY_ALIAS);
822 query.append(orderByConditionFields[i]);
823
824 if ((i + 1) < orderByConditionFields.length) {
825 if (orderByComparator.isAscending() ^ previous) {
826 query.append(WHERE_GREATER_THAN_HAS_NEXT);
827 }
828 else {
829 query.append(WHERE_LESSER_THAN_HAS_NEXT);
830 }
831 }
832 else {
833 if (orderByComparator.isAscending() ^ previous) {
834 query.append(WHERE_GREATER_THAN);
835 }
836 else {
837 query.append(WHERE_LESSER_THAN);
838 }
839 }
840 }
841
842 query.append(ORDER_BY_CLAUSE);
843
844 String[] orderByFields = orderByComparator.getOrderByFields();
845
846 for (int i = 0; i < orderByFields.length; i++) {
847 query.append(_ORDER_BY_ENTITY_ALIAS);
848 query.append(orderByFields[i]);
849
850 if ((i + 1) < orderByFields.length) {
851 if (orderByComparator.isAscending() ^ previous) {
852 query.append(ORDER_BY_ASC_HAS_NEXT);
853 }
854 else {
855 query.append(ORDER_BY_DESC_HAS_NEXT);
856 }
857 }
858 else {
859 if (orderByComparator.isAscending() ^ previous) {
860 query.append(ORDER_BY_ASC);
861 }
862 else {
863 query.append(ORDER_BY_DESC);
864 }
865 }
866 }
867 }
868
869 String sql = query.toString();
870
871 Query q = session.createQuery(sql);
872
873 q.setFirstResult(0);
874 q.setMaxResults(2);
875
876 QueryPos qPos = QueryPos.getInstance(q);
877
878 qPos.add(companyId);
879
880 qPos.add(classNameId);
881
882 if (orderByComparator != null) {
883 Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
884
885 for (Object value : values) {
886 qPos.add(value);
887 }
888 }
889
890 List<ExpandoTable> list = q.list();
891
892 if (list.size() == 2) {
893 return list.get(1);
894 }
895 else {
896 return null;
897 }
898 }
899
900
910 public ExpandoTable findByC_C_N(long companyId, long classNameId,
911 String name) throws NoSuchTableException, SystemException {
912 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
913
914 if (expandoTable == null) {
915 StringBundler msg = new StringBundler(8);
916
917 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
918
919 msg.append("companyId=");
920 msg.append(companyId);
921
922 msg.append(", classNameId=");
923 msg.append(classNameId);
924
925 msg.append(", name=");
926 msg.append(name);
927
928 msg.append(StringPool.CLOSE_CURLY_BRACE);
929
930 if (_log.isWarnEnabled()) {
931 _log.warn(msg.toString());
932 }
933
934 throw new NoSuchTableException(msg.toString());
935 }
936
937 return expandoTable;
938 }
939
940
949 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
950 String name) throws SystemException {
951 return fetchByC_C_N(companyId, classNameId, name, true);
952 }
953
954
964 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
965 String name, boolean retrieveFromCache) throws SystemException {
966 Object[] finderArgs = new Object[] { companyId, classNameId, name };
967
968 Object result = null;
969
970 if (retrieveFromCache) {
971 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
972 finderArgs, this);
973 }
974
975 if (result == null) {
976 StringBundler query = new StringBundler(4);
977
978 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
979
980 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
981
982 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
983
984 if (name == null) {
985 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
986 }
987 else {
988 if (name.equals(StringPool.BLANK)) {
989 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
990 }
991 else {
992 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
993 }
994 }
995
996 String sql = query.toString();
997
998 Session session = null;
999
1000 try {
1001 session = openSession();
1002
1003 Query q = session.createQuery(sql);
1004
1005 QueryPos qPos = QueryPos.getInstance(q);
1006
1007 qPos.add(companyId);
1008
1009 qPos.add(classNameId);
1010
1011 if (name != null) {
1012 qPos.add(name);
1013 }
1014
1015 List<ExpandoTable> list = q.list();
1016
1017 result = list;
1018
1019 ExpandoTable expandoTable = null;
1020
1021 if (list.isEmpty()) {
1022 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1023 finderArgs, list);
1024 }
1025 else {
1026 expandoTable = list.get(0);
1027
1028 cacheResult(expandoTable);
1029
1030 if ((expandoTable.getCompanyId() != companyId) ||
1031 (expandoTable.getClassNameId() != classNameId) ||
1032 (expandoTable.getName() == null) ||
1033 !expandoTable.getName().equals(name)) {
1034 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1035 finderArgs, expandoTable);
1036 }
1037 }
1038
1039 return expandoTable;
1040 }
1041 catch (Exception e) {
1042 throw processException(e);
1043 }
1044 finally {
1045 if (result == null) {
1046 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
1047 finderArgs);
1048 }
1049
1050 closeSession(session);
1051 }
1052 }
1053 else {
1054 if (result instanceof List<?>) {
1055 return null;
1056 }
1057 else {
1058 return (ExpandoTable)result;
1059 }
1060 }
1061 }
1062
1063
1069 public List<ExpandoTable> findAll() throws SystemException {
1070 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1071 }
1072
1073
1085 public List<ExpandoTable> findAll(int start, int end)
1086 throws SystemException {
1087 return findAll(start, end, null);
1088 }
1089
1090
1103 public List<ExpandoTable> findAll(int start, int end,
1104 OrderByComparator orderByComparator) throws SystemException {
1105 FinderPath finderPath = null;
1106 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1107
1108 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1109 (orderByComparator == null)) {
1110 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1111 finderArgs = FINDER_ARGS_EMPTY;
1112 }
1113 else {
1114 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1115 finderArgs = new Object[] { start, end, orderByComparator };
1116 }
1117
1118 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
1119 finderArgs, this);
1120
1121 if (list == null) {
1122 StringBundler query = null;
1123 String sql = null;
1124
1125 if (orderByComparator != null) {
1126 query = new StringBundler(2 +
1127 (orderByComparator.getOrderByFields().length * 3));
1128
1129 query.append(_SQL_SELECT_EXPANDOTABLE);
1130
1131 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1132 orderByComparator);
1133
1134 sql = query.toString();
1135 }
1136 else {
1137 sql = _SQL_SELECT_EXPANDOTABLE;
1138 }
1139
1140 Session session = null;
1141
1142 try {
1143 session = openSession();
1144
1145 Query q = session.createQuery(sql);
1146
1147 if (orderByComparator == null) {
1148 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1149 start, end, false);
1150
1151 Collections.sort(list);
1152 }
1153 else {
1154 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1155 start, end);
1156 }
1157 }
1158 catch (Exception e) {
1159 throw processException(e);
1160 }
1161 finally {
1162 if (list == null) {
1163 FinderCacheUtil.removeResult(finderPath, finderArgs);
1164 }
1165 else {
1166 cacheResult(list);
1167
1168 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1169 }
1170
1171 closeSession(session);
1172 }
1173 }
1174
1175 return list;
1176 }
1177
1178
1185 public void removeByC_C(long companyId, long classNameId)
1186 throws SystemException {
1187 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId)) {
1188 expandoTablePersistence.remove(expandoTable);
1189 }
1190 }
1191
1192
1200 public void removeByC_C_N(long companyId, long classNameId, String name)
1201 throws NoSuchTableException, SystemException {
1202 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
1203
1204 expandoTablePersistence.remove(expandoTable);
1205 }
1206
1207
1212 public void removeAll() throws SystemException {
1213 for (ExpandoTable expandoTable : findAll()) {
1214 expandoTablePersistence.remove(expandoTable);
1215 }
1216 }
1217
1218
1226 public int countByC_C(long companyId, long classNameId)
1227 throws SystemException {
1228 Object[] finderArgs = new Object[] { companyId, classNameId };
1229
1230 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1231 finderArgs, this);
1232
1233 if (count == null) {
1234 StringBundler query = new StringBundler(3);
1235
1236 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1237
1238 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1239
1240 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1241
1242 String sql = query.toString();
1243
1244 Session session = null;
1245
1246 try {
1247 session = openSession();
1248
1249 Query q = session.createQuery(sql);
1250
1251 QueryPos qPos = QueryPos.getInstance(q);
1252
1253 qPos.add(companyId);
1254
1255 qPos.add(classNameId);
1256
1257 count = (Long)q.uniqueResult();
1258 }
1259 catch (Exception e) {
1260 throw processException(e);
1261 }
1262 finally {
1263 if (count == null) {
1264 count = Long.valueOf(0);
1265 }
1266
1267 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1268 count);
1269
1270 closeSession(session);
1271 }
1272 }
1273
1274 return count.intValue();
1275 }
1276
1277
1286 public int countByC_C_N(long companyId, long classNameId, String name)
1287 throws SystemException {
1288 Object[] finderArgs = new Object[] { companyId, classNameId, name };
1289
1290 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_N,
1291 finderArgs, this);
1292
1293 if (count == null) {
1294 StringBundler query = new StringBundler(4);
1295
1296 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1297
1298 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1299
1300 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1301
1302 if (name == null) {
1303 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1304 }
1305 else {
1306 if (name.equals(StringPool.BLANK)) {
1307 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1308 }
1309 else {
1310 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1311 }
1312 }
1313
1314 String sql = query.toString();
1315
1316 Session session = null;
1317
1318 try {
1319 session = openSession();
1320
1321 Query q = session.createQuery(sql);
1322
1323 QueryPos qPos = QueryPos.getInstance(q);
1324
1325 qPos.add(companyId);
1326
1327 qPos.add(classNameId);
1328
1329 if (name != null) {
1330 qPos.add(name);
1331 }
1332
1333 count = (Long)q.uniqueResult();
1334 }
1335 catch (Exception e) {
1336 throw processException(e);
1337 }
1338 finally {
1339 if (count == null) {
1340 count = Long.valueOf(0);
1341 }
1342
1343 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N,
1344 finderArgs, count);
1345
1346 closeSession(session);
1347 }
1348 }
1349
1350 return count.intValue();
1351 }
1352
1353
1359 public int countAll() throws SystemException {
1360 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1361 FINDER_ARGS_EMPTY, this);
1362
1363 if (count == null) {
1364 Session session = null;
1365
1366 try {
1367 session = openSession();
1368
1369 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1370
1371 count = (Long)q.uniqueResult();
1372 }
1373 catch (Exception e) {
1374 throw processException(e);
1375 }
1376 finally {
1377 if (count == null) {
1378 count = Long.valueOf(0);
1379 }
1380
1381 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1382 FINDER_ARGS_EMPTY, count);
1383
1384 closeSession(session);
1385 }
1386 }
1387
1388 return count.intValue();
1389 }
1390
1391
1394 public void afterPropertiesSet() {
1395 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1396 com.liferay.portal.util.PropsUtil.get(
1397 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1398
1399 if (listenerClassNames.length > 0) {
1400 try {
1401 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1402
1403 for (String listenerClassName : listenerClassNames) {
1404 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1405 listenerClassName));
1406 }
1407
1408 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1409 }
1410 catch (Exception e) {
1411 _log.error(e);
1412 }
1413 }
1414 }
1415
1416 public void destroy() {
1417 EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1418 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1419 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1420 }
1421
1422 @BeanReference(type = ExpandoColumnPersistence.class)
1423 protected ExpandoColumnPersistence expandoColumnPersistence;
1424 @BeanReference(type = ExpandoRowPersistence.class)
1425 protected ExpandoRowPersistence expandoRowPersistence;
1426 @BeanReference(type = ExpandoTablePersistence.class)
1427 protected ExpandoTablePersistence expandoTablePersistence;
1428 @BeanReference(type = ExpandoValuePersistence.class)
1429 protected ExpandoValuePersistence expandoValuePersistence;
1430 @BeanReference(type = ResourcePersistence.class)
1431 protected ResourcePersistence resourcePersistence;
1432 @BeanReference(type = UserPersistence.class)
1433 protected UserPersistence userPersistence;
1434 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1435 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1436 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1437 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1438 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1439 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
1440 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1441 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
1442 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
1443 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
1444 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = ?)";
1445 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1446 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1447 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1448 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1449 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1450 private static ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1451 @Override
1452 public Object clone() {
1453 return this;
1454 }
1455
1456 @Override
1457 public CacheModel<ExpandoTable> toCacheModel() {
1458 return _nullExpandoTableCacheModel;
1459 }
1460 };
1461
1462 private static CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1463 public ExpandoTable toEntityModel() {
1464 return _nullExpandoTable;
1465 }
1466 };
1467 }