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.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.BatchSessionUtil;
040 import com.liferay.portal.service.persistence.ResourcePersistence;
041 import com.liferay.portal.service.persistence.UserPersistence;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.expando.NoSuchTableException;
045 import com.liferay.portlet.expando.model.ExpandoTable;
046 import com.liferay.portlet.expando.model.impl.ExpandoTableImpl;
047 import com.liferay.portlet.expando.model.impl.ExpandoTableModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
067 public class ExpandoTablePersistenceImpl extends BasePersistenceImpl<ExpandoTable>
068 implements ExpandoTablePersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoTableImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
080 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
082 new String[] {
083 Long.class.getName(), Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
089 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
091 new String[] { Long.class.getName(), Long.class.getName() },
092 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
093 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
095 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
097 new String[] { Long.class.getName(), Long.class.getName() });
098 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
099 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
100 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_N",
101 new String[] {
102 Long.class.getName(), Long.class.getName(),
103 String.class.getName()
104 },
105 ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
106 ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK |
107 ExpandoTableModelImpl.NAME_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
109 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_N",
111 new String[] {
112 Long.class.getName(), Long.class.getName(),
113 String.class.getName()
114 });
115 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
116 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
117 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
118 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
119 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
121 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
122 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
123 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
124
125
130 public void cacheResult(ExpandoTable expandoTable) {
131 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
132 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
133
134 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
135 new Object[] {
136 Long.valueOf(expandoTable.getCompanyId()),
137 Long.valueOf(expandoTable.getClassNameId()),
138
139 expandoTable.getName()
140 }, expandoTable);
141
142 expandoTable.resetOriginalValues();
143 }
144
145
150 public void cacheResult(List<ExpandoTable> expandoTables) {
151 for (ExpandoTable expandoTable : expandoTables) {
152 if (EntityCacheUtil.getResult(
153 ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
154 ExpandoTableImpl.class, expandoTable.getPrimaryKey()) == null) {
155 cacheResult(expandoTable);
156 }
157 else {
158 expandoTable.resetOriginalValues();
159 }
160 }
161 }
162
163
170 @Override
171 public void clearCache() {
172 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
173 CacheRegistryUtil.clear(ExpandoTableImpl.class.getName());
174 }
175
176 EntityCacheUtil.clearCache(ExpandoTableImpl.class.getName());
177
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
181 }
182
183
190 @Override
191 public void clearCache(ExpandoTable expandoTable) {
192 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
193 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
194
195 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
196 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
197
198 clearUniqueFindersCache(expandoTable);
199 }
200
201 @Override
202 public void clearCache(List<ExpandoTable> expandoTables) {
203 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
204 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
205
206 for (ExpandoTable expandoTable : expandoTables) {
207 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
208 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
209
210 clearUniqueFindersCache(expandoTable);
211 }
212 }
213
214 protected void clearUniqueFindersCache(ExpandoTable expandoTable) {
215 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
216 new Object[] {
217 Long.valueOf(expandoTable.getCompanyId()),
218 Long.valueOf(expandoTable.getClassNameId()),
219
220 expandoTable.getName()
221 });
222 }
223
224
230 public ExpandoTable create(long tableId) {
231 ExpandoTable expandoTable = new ExpandoTableImpl();
232
233 expandoTable.setNew(true);
234 expandoTable.setPrimaryKey(tableId);
235
236 return expandoTable;
237 }
238
239
247 public ExpandoTable remove(long tableId)
248 throws NoSuchTableException, SystemException {
249 return remove(Long.valueOf(tableId));
250 }
251
252
260 @Override
261 public ExpandoTable remove(Serializable primaryKey)
262 throws NoSuchTableException, SystemException {
263 Session session = null;
264
265 try {
266 session = openSession();
267
268 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
269 primaryKey);
270
271 if (expandoTable == null) {
272 if (_log.isWarnEnabled()) {
273 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
274 }
275
276 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
277 primaryKey);
278 }
279
280 return remove(expandoTable);
281 }
282 catch (NoSuchTableException nsee) {
283 throw nsee;
284 }
285 catch (Exception e) {
286 throw processException(e);
287 }
288 finally {
289 closeSession(session);
290 }
291 }
292
293 @Override
294 protected ExpandoTable removeImpl(ExpandoTable expandoTable)
295 throws SystemException {
296 expandoTable = toUnwrappedModel(expandoTable);
297
298 Session session = null;
299
300 try {
301 session = openSession();
302
303 BatchSessionUtil.delete(session, expandoTable);
304 }
305 catch (Exception e) {
306 throw processException(e);
307 }
308 finally {
309 closeSession(session);
310 }
311
312 clearCache(expandoTable);
313
314 return expandoTable;
315 }
316
317 @Override
318 public ExpandoTable updateImpl(
319 com.liferay.portlet.expando.model.ExpandoTable expandoTable,
320 boolean merge) throws SystemException {
321 expandoTable = toUnwrappedModel(expandoTable);
322
323 boolean isNew = expandoTable.isNew();
324
325 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
326
327 Session session = null;
328
329 try {
330 session = openSession();
331
332 BatchSessionUtil.update(session, expandoTable, merge);
333
334 expandoTable.setNew(false);
335 }
336 catch (Exception e) {
337 throw processException(e);
338 }
339 finally {
340 closeSession(session);
341 }
342
343 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
344
345 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
346 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
347 }
348
349 else {
350 if ((expandoTableModelImpl.getColumnBitmask() &
351 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
352 Object[] args = new Object[] {
353 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
354 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId())
355 };
356
357 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
358 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
359 args);
360
361 args = new Object[] {
362 Long.valueOf(expandoTableModelImpl.getCompanyId()),
363 Long.valueOf(expandoTableModelImpl.getClassNameId())
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 }
371
372 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
373 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
374
375 if (isNew) {
376 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
377 new Object[] {
378 Long.valueOf(expandoTable.getCompanyId()),
379 Long.valueOf(expandoTable.getClassNameId()),
380
381 expandoTable.getName()
382 }, expandoTable);
383 }
384 else {
385 if ((expandoTableModelImpl.getColumnBitmask() &
386 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
387 Object[] args = new Object[] {
388 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
389 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId()),
390
391 expandoTableModelImpl.getOriginalName()
392 };
393
394 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
395
396 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
397
398 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
399 new Object[] {
400 Long.valueOf(expandoTable.getCompanyId()),
401 Long.valueOf(expandoTable.getClassNameId()),
402
403 expandoTable.getName()
404 }, expandoTable);
405 }
406 }
407
408 return expandoTable;
409 }
410
411 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
412 if (expandoTable instanceof ExpandoTableImpl) {
413 return expandoTable;
414 }
415
416 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
417
418 expandoTableImpl.setNew(expandoTable.isNew());
419 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
420
421 expandoTableImpl.setTableId(expandoTable.getTableId());
422 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
423 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
424 expandoTableImpl.setName(expandoTable.getName());
425
426 return expandoTableImpl;
427 }
428
429
437 @Override
438 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
439 throws NoSuchModelException, SystemException {
440 return findByPrimaryKey(((Long)primaryKey).longValue());
441 }
442
443
451 public ExpandoTable findByPrimaryKey(long tableId)
452 throws NoSuchTableException, SystemException {
453 ExpandoTable expandoTable = fetchByPrimaryKey(tableId);
454
455 if (expandoTable == null) {
456 if (_log.isWarnEnabled()) {
457 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
458 }
459
460 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
461 tableId);
462 }
463
464 return expandoTable;
465 }
466
467
474 @Override
475 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
476 throws SystemException {
477 return fetchByPrimaryKey(((Long)primaryKey).longValue());
478 }
479
480
487 public ExpandoTable fetchByPrimaryKey(long tableId)
488 throws SystemException {
489 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
490 ExpandoTableImpl.class, tableId);
491
492 if (expandoTable == _nullExpandoTable) {
493 return null;
494 }
495
496 if (expandoTable == null) {
497 Session session = null;
498
499 boolean hasException = false;
500
501 try {
502 session = openSession();
503
504 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
505 Long.valueOf(tableId));
506 }
507 catch (Exception e) {
508 hasException = true;
509
510 throw processException(e);
511 }
512 finally {
513 if (expandoTable != null) {
514 cacheResult(expandoTable);
515 }
516 else if (!hasException) {
517 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
518 ExpandoTableImpl.class, tableId, _nullExpandoTable);
519 }
520
521 closeSession(session);
522 }
523 }
524
525 return expandoTable;
526 }
527
528
536 public List<ExpandoTable> findByC_C(long companyId, long classNameId)
537 throws SystemException {
538 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
539 QueryUtil.ALL_POS, null);
540 }
541
542
556 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
557 int start, int end) throws SystemException {
558 return findByC_C(companyId, classNameId, start, end, null);
559 }
560
561
576 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
577 int start, int end, OrderByComparator orderByComparator)
578 throws SystemException {
579 FinderPath finderPath = null;
580 Object[] finderArgs = null;
581
582 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
583 (orderByComparator == null)) {
584 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
585 finderArgs = new Object[] { companyId, classNameId };
586 }
587 else {
588 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
589 finderArgs = new Object[] {
590 companyId, classNameId,
591
592 start, end, orderByComparator
593 };
594 }
595
596 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
597 finderArgs, this);
598
599 if ((list != null) && !list.isEmpty()) {
600 for (ExpandoTable expandoTable : list) {
601 if ((companyId != expandoTable.getCompanyId()) ||
602 (classNameId != expandoTable.getClassNameId())) {
603 list = null;
604
605 break;
606 }
607 }
608 }
609
610 if (list == null) {
611 StringBundler query = null;
612
613 if (orderByComparator != null) {
614 query = new StringBundler(4 +
615 (orderByComparator.getOrderByFields().length * 3));
616 }
617 else {
618 query = new StringBundler(3);
619 }
620
621 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
622
623 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
624
625 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
626
627 if (orderByComparator != null) {
628 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
629 orderByComparator);
630 }
631
632 String sql = query.toString();
633
634 Session session = null;
635
636 try {
637 session = openSession();
638
639 Query q = session.createQuery(sql);
640
641 QueryPos qPos = QueryPos.getInstance(q);
642
643 qPos.add(companyId);
644
645 qPos.add(classNameId);
646
647 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
648 start, end);
649 }
650 catch (Exception e) {
651 throw processException(e);
652 }
653 finally {
654 if (list == null) {
655 FinderCacheUtil.removeResult(finderPath, finderArgs);
656 }
657 else {
658 cacheResult(list);
659
660 FinderCacheUtil.putResult(finderPath, finderArgs, list);
661 }
662
663 closeSession(session);
664 }
665 }
666
667 return list;
668 }
669
670
680 public ExpandoTable findByC_C_First(long companyId, long classNameId,
681 OrderByComparator orderByComparator)
682 throws NoSuchTableException, SystemException {
683 ExpandoTable expandoTable = fetchByC_C_First(companyId, classNameId,
684 orderByComparator);
685
686 if (expandoTable != null) {
687 return expandoTable;
688 }
689
690 StringBundler msg = new StringBundler(6);
691
692 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
693
694 msg.append("companyId=");
695 msg.append(companyId);
696
697 msg.append(", classNameId=");
698 msg.append(classNameId);
699
700 msg.append(StringPool.CLOSE_CURLY_BRACE);
701
702 throw new NoSuchTableException(msg.toString());
703 }
704
705
714 public ExpandoTable fetchByC_C_First(long companyId, long classNameId,
715 OrderByComparator orderByComparator) throws SystemException {
716 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
717 orderByComparator);
718
719 if (!list.isEmpty()) {
720 return list.get(0);
721 }
722
723 return null;
724 }
725
726
736 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
737 OrderByComparator orderByComparator)
738 throws NoSuchTableException, SystemException {
739 ExpandoTable expandoTable = fetchByC_C_Last(companyId, classNameId,
740 orderByComparator);
741
742 if (expandoTable != null) {
743 return expandoTable;
744 }
745
746 StringBundler msg = new StringBundler(6);
747
748 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
749
750 msg.append("companyId=");
751 msg.append(companyId);
752
753 msg.append(", classNameId=");
754 msg.append(classNameId);
755
756 msg.append(StringPool.CLOSE_CURLY_BRACE);
757
758 throw new NoSuchTableException(msg.toString());
759 }
760
761
770 public ExpandoTable fetchByC_C_Last(long companyId, long classNameId,
771 OrderByComparator orderByComparator) throws SystemException {
772 int count = countByC_C(companyId, classNameId);
773
774 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
775 count, orderByComparator);
776
777 if (!list.isEmpty()) {
778 return list.get(0);
779 }
780
781 return null;
782 }
783
784
795 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
796 long classNameId, OrderByComparator orderByComparator)
797 throws NoSuchTableException, SystemException {
798 ExpandoTable expandoTable = findByPrimaryKey(tableId);
799
800 Session session = null;
801
802 try {
803 session = openSession();
804
805 ExpandoTable[] array = new ExpandoTableImpl[3];
806
807 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
808 classNameId, orderByComparator, true);
809
810 array[1] = expandoTable;
811
812 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
813 classNameId, orderByComparator, false);
814
815 return array;
816 }
817 catch (Exception e) {
818 throw processException(e);
819 }
820 finally {
821 closeSession(session);
822 }
823 }
824
825 protected ExpandoTable getByC_C_PrevAndNext(Session session,
826 ExpandoTable expandoTable, long companyId, long classNameId,
827 OrderByComparator orderByComparator, boolean previous) {
828 StringBundler query = null;
829
830 if (orderByComparator != null) {
831 query = new StringBundler(6 +
832 (orderByComparator.getOrderByFields().length * 6));
833 }
834 else {
835 query = new StringBundler(3);
836 }
837
838 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
839
840 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
841
842 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
843
844 if (orderByComparator != null) {
845 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
846
847 if (orderByConditionFields.length > 0) {
848 query.append(WHERE_AND);
849 }
850
851 for (int i = 0; i < orderByConditionFields.length; i++) {
852 query.append(_ORDER_BY_ENTITY_ALIAS);
853 query.append(orderByConditionFields[i]);
854
855 if ((i + 1) < orderByConditionFields.length) {
856 if (orderByComparator.isAscending() ^ previous) {
857 query.append(WHERE_GREATER_THAN_HAS_NEXT);
858 }
859 else {
860 query.append(WHERE_LESSER_THAN_HAS_NEXT);
861 }
862 }
863 else {
864 if (orderByComparator.isAscending() ^ previous) {
865 query.append(WHERE_GREATER_THAN);
866 }
867 else {
868 query.append(WHERE_LESSER_THAN);
869 }
870 }
871 }
872
873 query.append(ORDER_BY_CLAUSE);
874
875 String[] orderByFields = orderByComparator.getOrderByFields();
876
877 for (int i = 0; i < orderByFields.length; i++) {
878 query.append(_ORDER_BY_ENTITY_ALIAS);
879 query.append(orderByFields[i]);
880
881 if ((i + 1) < orderByFields.length) {
882 if (orderByComparator.isAscending() ^ previous) {
883 query.append(ORDER_BY_ASC_HAS_NEXT);
884 }
885 else {
886 query.append(ORDER_BY_DESC_HAS_NEXT);
887 }
888 }
889 else {
890 if (orderByComparator.isAscending() ^ previous) {
891 query.append(ORDER_BY_ASC);
892 }
893 else {
894 query.append(ORDER_BY_DESC);
895 }
896 }
897 }
898 }
899
900 String sql = query.toString();
901
902 Query q = session.createQuery(sql);
903
904 q.setFirstResult(0);
905 q.setMaxResults(2);
906
907 QueryPos qPos = QueryPos.getInstance(q);
908
909 qPos.add(companyId);
910
911 qPos.add(classNameId);
912
913 if (orderByComparator != null) {
914 Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
915
916 for (Object value : values) {
917 qPos.add(value);
918 }
919 }
920
921 List<ExpandoTable> list = q.list();
922
923 if (list.size() == 2) {
924 return list.get(1);
925 }
926 else {
927 return null;
928 }
929 }
930
931
941 public ExpandoTable findByC_C_N(long companyId, long classNameId,
942 String name) throws NoSuchTableException, SystemException {
943 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
944
945 if (expandoTable == null) {
946 StringBundler msg = new StringBundler(8);
947
948 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
949
950 msg.append("companyId=");
951 msg.append(companyId);
952
953 msg.append(", classNameId=");
954 msg.append(classNameId);
955
956 msg.append(", name=");
957 msg.append(name);
958
959 msg.append(StringPool.CLOSE_CURLY_BRACE);
960
961 if (_log.isWarnEnabled()) {
962 _log.warn(msg.toString());
963 }
964
965 throw new NoSuchTableException(msg.toString());
966 }
967
968 return expandoTable;
969 }
970
971
980 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
981 String name) throws SystemException {
982 return fetchByC_C_N(companyId, classNameId, name, true);
983 }
984
985
995 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
996 String name, boolean retrieveFromCache) throws SystemException {
997 Object[] finderArgs = new Object[] { companyId, classNameId, name };
998
999 Object result = null;
1000
1001 if (retrieveFromCache) {
1002 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
1003 finderArgs, this);
1004 }
1005
1006 if (result instanceof ExpandoTable) {
1007 ExpandoTable expandoTable = (ExpandoTable)result;
1008
1009 if ((companyId != expandoTable.getCompanyId()) ||
1010 (classNameId != expandoTable.getClassNameId()) ||
1011 !Validator.equals(name, expandoTable.getName())) {
1012 result = null;
1013 }
1014 }
1015
1016 if (result == null) {
1017 StringBundler query = new StringBundler(4);
1018
1019 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
1020
1021 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1022
1023 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1024
1025 if (name == null) {
1026 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1027 }
1028 else {
1029 if (name.equals(StringPool.BLANK)) {
1030 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1031 }
1032 else {
1033 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1034 }
1035 }
1036
1037 String sql = query.toString();
1038
1039 Session session = null;
1040
1041 try {
1042 session = openSession();
1043
1044 Query q = session.createQuery(sql);
1045
1046 QueryPos qPos = QueryPos.getInstance(q);
1047
1048 qPos.add(companyId);
1049
1050 qPos.add(classNameId);
1051
1052 if (name != null) {
1053 qPos.add(name);
1054 }
1055
1056 List<ExpandoTable> list = q.list();
1057
1058 result = list;
1059
1060 ExpandoTable expandoTable = null;
1061
1062 if (list.isEmpty()) {
1063 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1064 finderArgs, list);
1065 }
1066 else {
1067 expandoTable = list.get(0);
1068
1069 cacheResult(expandoTable);
1070
1071 if ((expandoTable.getCompanyId() != companyId) ||
1072 (expandoTable.getClassNameId() != classNameId) ||
1073 (expandoTable.getName() == null) ||
1074 !expandoTable.getName().equals(name)) {
1075 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1076 finderArgs, expandoTable);
1077 }
1078 }
1079
1080 return expandoTable;
1081 }
1082 catch (Exception e) {
1083 throw processException(e);
1084 }
1085 finally {
1086 if (result == null) {
1087 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
1088 finderArgs);
1089 }
1090
1091 closeSession(session);
1092 }
1093 }
1094 else {
1095 if (result instanceof List<?>) {
1096 return null;
1097 }
1098 else {
1099 return (ExpandoTable)result;
1100 }
1101 }
1102 }
1103
1104
1110 public List<ExpandoTable> findAll() throws SystemException {
1111 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1112 }
1113
1114
1126 public List<ExpandoTable> findAll(int start, int end)
1127 throws SystemException {
1128 return findAll(start, end, null);
1129 }
1130
1131
1144 public List<ExpandoTable> findAll(int start, int end,
1145 OrderByComparator orderByComparator) throws SystemException {
1146 FinderPath finderPath = null;
1147 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1148
1149 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1150 (orderByComparator == null)) {
1151 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1152 finderArgs = FINDER_ARGS_EMPTY;
1153 }
1154 else {
1155 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1156 finderArgs = new Object[] { start, end, orderByComparator };
1157 }
1158
1159 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
1160 finderArgs, this);
1161
1162 if (list == null) {
1163 StringBundler query = null;
1164 String sql = null;
1165
1166 if (orderByComparator != null) {
1167 query = new StringBundler(2 +
1168 (orderByComparator.getOrderByFields().length * 3));
1169
1170 query.append(_SQL_SELECT_EXPANDOTABLE);
1171
1172 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1173 orderByComparator);
1174
1175 sql = query.toString();
1176 }
1177 else {
1178 sql = _SQL_SELECT_EXPANDOTABLE;
1179 }
1180
1181 Session session = null;
1182
1183 try {
1184 session = openSession();
1185
1186 Query q = session.createQuery(sql);
1187
1188 if (orderByComparator == null) {
1189 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1190 start, end, false);
1191
1192 Collections.sort(list);
1193 }
1194 else {
1195 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1196 start, end);
1197 }
1198 }
1199 catch (Exception e) {
1200 throw processException(e);
1201 }
1202 finally {
1203 if (list == null) {
1204 FinderCacheUtil.removeResult(finderPath, finderArgs);
1205 }
1206 else {
1207 cacheResult(list);
1208
1209 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1210 }
1211
1212 closeSession(session);
1213 }
1214 }
1215
1216 return list;
1217 }
1218
1219
1226 public void removeByC_C(long companyId, long classNameId)
1227 throws SystemException {
1228 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId)) {
1229 remove(expandoTable);
1230 }
1231 }
1232
1233
1242 public ExpandoTable removeByC_C_N(long companyId, long classNameId,
1243 String name) throws NoSuchTableException, SystemException {
1244 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
1245
1246 return remove(expandoTable);
1247 }
1248
1249
1254 public void removeAll() throws SystemException {
1255 for (ExpandoTable expandoTable : findAll()) {
1256 remove(expandoTable);
1257 }
1258 }
1259
1260
1268 public int countByC_C(long companyId, long classNameId)
1269 throws SystemException {
1270 Object[] finderArgs = new Object[] { companyId, classNameId };
1271
1272 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1273 finderArgs, this);
1274
1275 if (count == null) {
1276 StringBundler query = new StringBundler(3);
1277
1278 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1279
1280 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1281
1282 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1283
1284 String sql = query.toString();
1285
1286 Session session = null;
1287
1288 try {
1289 session = openSession();
1290
1291 Query q = session.createQuery(sql);
1292
1293 QueryPos qPos = QueryPos.getInstance(q);
1294
1295 qPos.add(companyId);
1296
1297 qPos.add(classNameId);
1298
1299 count = (Long)q.uniqueResult();
1300 }
1301 catch (Exception e) {
1302 throw processException(e);
1303 }
1304 finally {
1305 if (count == null) {
1306 count = Long.valueOf(0);
1307 }
1308
1309 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1310 count);
1311
1312 closeSession(session);
1313 }
1314 }
1315
1316 return count.intValue();
1317 }
1318
1319
1328 public int countByC_C_N(long companyId, long classNameId, String name)
1329 throws SystemException {
1330 Object[] finderArgs = new Object[] { companyId, classNameId, name };
1331
1332 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_N,
1333 finderArgs, this);
1334
1335 if (count == null) {
1336 StringBundler query = new StringBundler(4);
1337
1338 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1339
1340 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1341
1342 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1343
1344 if (name == null) {
1345 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1346 }
1347 else {
1348 if (name.equals(StringPool.BLANK)) {
1349 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1350 }
1351 else {
1352 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1353 }
1354 }
1355
1356 String sql = query.toString();
1357
1358 Session session = null;
1359
1360 try {
1361 session = openSession();
1362
1363 Query q = session.createQuery(sql);
1364
1365 QueryPos qPos = QueryPos.getInstance(q);
1366
1367 qPos.add(companyId);
1368
1369 qPos.add(classNameId);
1370
1371 if (name != null) {
1372 qPos.add(name);
1373 }
1374
1375 count = (Long)q.uniqueResult();
1376 }
1377 catch (Exception e) {
1378 throw processException(e);
1379 }
1380 finally {
1381 if (count == null) {
1382 count = Long.valueOf(0);
1383 }
1384
1385 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N,
1386 finderArgs, count);
1387
1388 closeSession(session);
1389 }
1390 }
1391
1392 return count.intValue();
1393 }
1394
1395
1401 public int countAll() throws SystemException {
1402 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1403 FINDER_ARGS_EMPTY, this);
1404
1405 if (count == null) {
1406 Session session = null;
1407
1408 try {
1409 session = openSession();
1410
1411 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1412
1413 count = (Long)q.uniqueResult();
1414 }
1415 catch (Exception e) {
1416 throw processException(e);
1417 }
1418 finally {
1419 if (count == null) {
1420 count = Long.valueOf(0);
1421 }
1422
1423 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1424 FINDER_ARGS_EMPTY, count);
1425
1426 closeSession(session);
1427 }
1428 }
1429
1430 return count.intValue();
1431 }
1432
1433
1436 public void afterPropertiesSet() {
1437 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1438 com.liferay.portal.util.PropsUtil.get(
1439 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1440
1441 if (listenerClassNames.length > 0) {
1442 try {
1443 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1444
1445 for (String listenerClassName : listenerClassNames) {
1446 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1447 listenerClassName));
1448 }
1449
1450 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1451 }
1452 catch (Exception e) {
1453 _log.error(e);
1454 }
1455 }
1456 }
1457
1458 public void destroy() {
1459 EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1460 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1461 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1462 }
1463
1464 @BeanReference(type = ExpandoColumnPersistence.class)
1465 protected ExpandoColumnPersistence expandoColumnPersistence;
1466 @BeanReference(type = ExpandoRowPersistence.class)
1467 protected ExpandoRowPersistence expandoRowPersistence;
1468 @BeanReference(type = ExpandoTablePersistence.class)
1469 protected ExpandoTablePersistence expandoTablePersistence;
1470 @BeanReference(type = ExpandoValuePersistence.class)
1471 protected ExpandoValuePersistence expandoValuePersistence;
1472 @BeanReference(type = ResourcePersistence.class)
1473 protected ResourcePersistence resourcePersistence;
1474 @BeanReference(type = UserPersistence.class)
1475 protected UserPersistence userPersistence;
1476 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1477 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1478 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1479 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1480 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1481 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
1482 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1483 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
1484 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
1485 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
1486 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = ?)";
1487 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1488 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1489 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1490 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1491 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1492 private static ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1493 @Override
1494 public Object clone() {
1495 return this;
1496 }
1497
1498 @Override
1499 public CacheModel<ExpandoTable> toCacheModel() {
1500 return _nullExpandoTableCacheModel;
1501 }
1502 };
1503
1504 private static CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1505 public ExpandoTable toEntityModel() {
1506 return _nullExpandoTable;
1507 }
1508 };
1509 }