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 clearUniqueFindersCache(expandoTable);
198 }
199
200 @Override
201 public void clearCache(List<ExpandoTable> expandoTables) {
202 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
203 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
204
205 for (ExpandoTable expandoTable : expandoTables) {
206 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
207 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
208
209 clearUniqueFindersCache(expandoTable);
210 }
211 }
212
213 protected void clearUniqueFindersCache(ExpandoTable expandoTable) {
214 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
215 new Object[] {
216 Long.valueOf(expandoTable.getCompanyId()),
217 Long.valueOf(expandoTable.getClassNameId()),
218
219 expandoTable.getName()
220 });
221 }
222
223
229 public ExpandoTable create(long tableId) {
230 ExpandoTable expandoTable = new ExpandoTableImpl();
231
232 expandoTable.setNew(true);
233 expandoTable.setPrimaryKey(tableId);
234
235 return expandoTable;
236 }
237
238
246 public ExpandoTable remove(long tableId)
247 throws NoSuchTableException, SystemException {
248 return remove(Long.valueOf(tableId));
249 }
250
251
259 @Override
260 public ExpandoTable remove(Serializable primaryKey)
261 throws NoSuchTableException, SystemException {
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
268 primaryKey);
269
270 if (expandoTable == null) {
271 if (_log.isWarnEnabled()) {
272 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
273 }
274
275 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
276 primaryKey);
277 }
278
279 return remove(expandoTable);
280 }
281 catch (NoSuchTableException nsee) {
282 throw nsee;
283 }
284 catch (Exception e) {
285 throw processException(e);
286 }
287 finally {
288 closeSession(session);
289 }
290 }
291
292 @Override
293 protected ExpandoTable removeImpl(ExpandoTable expandoTable)
294 throws SystemException {
295 expandoTable = toUnwrappedModel(expandoTable);
296
297 Session session = null;
298
299 try {
300 session = openSession();
301
302 BatchSessionUtil.delete(session, expandoTable);
303 }
304 catch (Exception e) {
305 throw processException(e);
306 }
307 finally {
308 closeSession(session);
309 }
310
311 clearCache(expandoTable);
312
313 return expandoTable;
314 }
315
316 @Override
317 public ExpandoTable updateImpl(
318 com.liferay.portlet.expando.model.ExpandoTable expandoTable,
319 boolean merge) throws SystemException {
320 expandoTable = toUnwrappedModel(expandoTable);
321
322 boolean isNew = expandoTable.isNew();
323
324 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
325
326 Session session = null;
327
328 try {
329 session = openSession();
330
331 BatchSessionUtil.update(session, expandoTable, merge);
332
333 expandoTable.setNew(false);
334 }
335 catch (Exception e) {
336 throw processException(e);
337 }
338 finally {
339 closeSession(session);
340 }
341
342 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
343
344 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
345 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
346 }
347
348 else {
349 if ((expandoTableModelImpl.getColumnBitmask() &
350 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
351 Object[] args = new Object[] {
352 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
353 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId())
354 };
355
356 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
357 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
358 args);
359
360 args = new Object[] {
361 Long.valueOf(expandoTableModelImpl.getCompanyId()),
362 Long.valueOf(expandoTableModelImpl.getClassNameId())
363 };
364
365 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
366 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
367 args);
368 }
369 }
370
371 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
372 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
373
374 if (isNew) {
375 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
376 new Object[] {
377 Long.valueOf(expandoTable.getCompanyId()),
378 Long.valueOf(expandoTable.getClassNameId()),
379
380 expandoTable.getName()
381 }, expandoTable);
382 }
383 else {
384 if ((expandoTableModelImpl.getColumnBitmask() &
385 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
386 Object[] args = new Object[] {
387 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
388 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId()),
389
390 expandoTableModelImpl.getOriginalName()
391 };
392
393 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
394 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
395
396 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
397 new Object[] {
398 Long.valueOf(expandoTable.getCompanyId()),
399 Long.valueOf(expandoTable.getClassNameId()),
400
401 expandoTable.getName()
402 }, expandoTable);
403 }
404 }
405
406 return expandoTable;
407 }
408
409 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
410 if (expandoTable instanceof ExpandoTableImpl) {
411 return expandoTable;
412 }
413
414 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
415
416 expandoTableImpl.setNew(expandoTable.isNew());
417 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
418
419 expandoTableImpl.setTableId(expandoTable.getTableId());
420 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
421 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
422 expandoTableImpl.setName(expandoTable.getName());
423
424 return expandoTableImpl;
425 }
426
427
435 @Override
436 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
437 throws NoSuchModelException, SystemException {
438 return findByPrimaryKey(((Long)primaryKey).longValue());
439 }
440
441
449 public ExpandoTable findByPrimaryKey(long tableId)
450 throws NoSuchTableException, SystemException {
451 ExpandoTable expandoTable = fetchByPrimaryKey(tableId);
452
453 if (expandoTable == null) {
454 if (_log.isWarnEnabled()) {
455 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
456 }
457
458 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
459 tableId);
460 }
461
462 return expandoTable;
463 }
464
465
472 @Override
473 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
474 throws SystemException {
475 return fetchByPrimaryKey(((Long)primaryKey).longValue());
476 }
477
478
485 public ExpandoTable fetchByPrimaryKey(long tableId)
486 throws SystemException {
487 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
488 ExpandoTableImpl.class, tableId);
489
490 if (expandoTable == _nullExpandoTable) {
491 return null;
492 }
493
494 if (expandoTable == null) {
495 Session session = null;
496
497 boolean hasException = false;
498
499 try {
500 session = openSession();
501
502 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
503 Long.valueOf(tableId));
504 }
505 catch (Exception e) {
506 hasException = true;
507
508 throw processException(e);
509 }
510 finally {
511 if (expandoTable != null) {
512 cacheResult(expandoTable);
513 }
514 else if (!hasException) {
515 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
516 ExpandoTableImpl.class, tableId, _nullExpandoTable);
517 }
518
519 closeSession(session);
520 }
521 }
522
523 return expandoTable;
524 }
525
526
534 public List<ExpandoTable> findByC_C(long companyId, long classNameId)
535 throws SystemException {
536 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
537 QueryUtil.ALL_POS, null);
538 }
539
540
554 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
555 int start, int end) throws SystemException {
556 return findByC_C(companyId, classNameId, start, end, null);
557 }
558
559
574 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
575 int start, int end, OrderByComparator orderByComparator)
576 throws SystemException {
577 FinderPath finderPath = null;
578 Object[] finderArgs = null;
579
580 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
581 (orderByComparator == null)) {
582 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
583 finderArgs = new Object[] { companyId, classNameId };
584 }
585 else {
586 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
587 finderArgs = new Object[] {
588 companyId, classNameId,
589
590 start, end, orderByComparator
591 };
592 }
593
594 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
595 finderArgs, this);
596
597 if (list == null) {
598 StringBundler query = null;
599
600 if (orderByComparator != null) {
601 query = new StringBundler(4 +
602 (orderByComparator.getOrderByFields().length * 3));
603 }
604 else {
605 query = new StringBundler(3);
606 }
607
608 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
609
610 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
611
612 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
613
614 if (orderByComparator != null) {
615 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
616 orderByComparator);
617 }
618
619 String sql = query.toString();
620
621 Session session = null;
622
623 try {
624 session = openSession();
625
626 Query q = session.createQuery(sql);
627
628 QueryPos qPos = QueryPos.getInstance(q);
629
630 qPos.add(companyId);
631
632 qPos.add(classNameId);
633
634 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
635 start, end);
636 }
637 catch (Exception e) {
638 throw processException(e);
639 }
640 finally {
641 if (list == null) {
642 FinderCacheUtil.removeResult(finderPath, finderArgs);
643 }
644 else {
645 cacheResult(list);
646
647 FinderCacheUtil.putResult(finderPath, finderArgs, list);
648 }
649
650 closeSession(session);
651 }
652 }
653
654 return list;
655 }
656
657
671 public ExpandoTable findByC_C_First(long companyId, long classNameId,
672 OrderByComparator orderByComparator)
673 throws NoSuchTableException, SystemException {
674 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
675 orderByComparator);
676
677 if (list.isEmpty()) {
678 StringBundler msg = new StringBundler(6);
679
680 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
681
682 msg.append("companyId=");
683 msg.append(companyId);
684
685 msg.append(", classNameId=");
686 msg.append(classNameId);
687
688 msg.append(StringPool.CLOSE_CURLY_BRACE);
689
690 throw new NoSuchTableException(msg.toString());
691 }
692 else {
693 return list.get(0);
694 }
695 }
696
697
711 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
712 OrderByComparator orderByComparator)
713 throws NoSuchTableException, SystemException {
714 int count = countByC_C(companyId, classNameId);
715
716 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
717 count, orderByComparator);
718
719 if (list.isEmpty()) {
720 StringBundler msg = new StringBundler(6);
721
722 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
723
724 msg.append("companyId=");
725 msg.append(companyId);
726
727 msg.append(", classNameId=");
728 msg.append(classNameId);
729
730 msg.append(StringPool.CLOSE_CURLY_BRACE);
731
732 throw new NoSuchTableException(msg.toString());
733 }
734 else {
735 return list.get(0);
736 }
737 }
738
739
754 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
755 long classNameId, OrderByComparator orderByComparator)
756 throws NoSuchTableException, SystemException {
757 ExpandoTable expandoTable = findByPrimaryKey(tableId);
758
759 Session session = null;
760
761 try {
762 session = openSession();
763
764 ExpandoTable[] array = new ExpandoTableImpl[3];
765
766 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
767 classNameId, orderByComparator, true);
768
769 array[1] = expandoTable;
770
771 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
772 classNameId, orderByComparator, false);
773
774 return array;
775 }
776 catch (Exception e) {
777 throw processException(e);
778 }
779 finally {
780 closeSession(session);
781 }
782 }
783
784 protected ExpandoTable getByC_C_PrevAndNext(Session session,
785 ExpandoTable expandoTable, long companyId, long classNameId,
786 OrderByComparator orderByComparator, boolean previous) {
787 StringBundler query = null;
788
789 if (orderByComparator != null) {
790 query = new StringBundler(6 +
791 (orderByComparator.getOrderByFields().length * 6));
792 }
793 else {
794 query = new StringBundler(3);
795 }
796
797 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
798
799 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
800
801 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
802
803 if (orderByComparator != null) {
804 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
805
806 if (orderByConditionFields.length > 0) {
807 query.append(WHERE_AND);
808 }
809
810 for (int i = 0; i < orderByConditionFields.length; i++) {
811 query.append(_ORDER_BY_ENTITY_ALIAS);
812 query.append(orderByConditionFields[i]);
813
814 if ((i + 1) < orderByConditionFields.length) {
815 if (orderByComparator.isAscending() ^ previous) {
816 query.append(WHERE_GREATER_THAN_HAS_NEXT);
817 }
818 else {
819 query.append(WHERE_LESSER_THAN_HAS_NEXT);
820 }
821 }
822 else {
823 if (orderByComparator.isAscending() ^ previous) {
824 query.append(WHERE_GREATER_THAN);
825 }
826 else {
827 query.append(WHERE_LESSER_THAN);
828 }
829 }
830 }
831
832 query.append(ORDER_BY_CLAUSE);
833
834 String[] orderByFields = orderByComparator.getOrderByFields();
835
836 for (int i = 0; i < orderByFields.length; i++) {
837 query.append(_ORDER_BY_ENTITY_ALIAS);
838 query.append(orderByFields[i]);
839
840 if ((i + 1) < orderByFields.length) {
841 if (orderByComparator.isAscending() ^ previous) {
842 query.append(ORDER_BY_ASC_HAS_NEXT);
843 }
844 else {
845 query.append(ORDER_BY_DESC_HAS_NEXT);
846 }
847 }
848 else {
849 if (orderByComparator.isAscending() ^ previous) {
850 query.append(ORDER_BY_ASC);
851 }
852 else {
853 query.append(ORDER_BY_DESC);
854 }
855 }
856 }
857 }
858
859 String sql = query.toString();
860
861 Query q = session.createQuery(sql);
862
863 q.setFirstResult(0);
864 q.setMaxResults(2);
865
866 QueryPos qPos = QueryPos.getInstance(q);
867
868 qPos.add(companyId);
869
870 qPos.add(classNameId);
871
872 if (orderByComparator != null) {
873 Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
874
875 for (Object value : values) {
876 qPos.add(value);
877 }
878 }
879
880 List<ExpandoTable> list = q.list();
881
882 if (list.size() == 2) {
883 return list.get(1);
884 }
885 else {
886 return null;
887 }
888 }
889
890
900 public ExpandoTable findByC_C_N(long companyId, long classNameId,
901 String name) throws NoSuchTableException, SystemException {
902 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
903
904 if (expandoTable == null) {
905 StringBundler msg = new StringBundler(8);
906
907 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
908
909 msg.append("companyId=");
910 msg.append(companyId);
911
912 msg.append(", classNameId=");
913 msg.append(classNameId);
914
915 msg.append(", name=");
916 msg.append(name);
917
918 msg.append(StringPool.CLOSE_CURLY_BRACE);
919
920 if (_log.isWarnEnabled()) {
921 _log.warn(msg.toString());
922 }
923
924 throw new NoSuchTableException(msg.toString());
925 }
926
927 return expandoTable;
928 }
929
930
939 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
940 String name) throws SystemException {
941 return fetchByC_C_N(companyId, classNameId, name, true);
942 }
943
944
954 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
955 String name, boolean retrieveFromCache) throws SystemException {
956 Object[] finderArgs = new Object[] { companyId, classNameId, name };
957
958 Object result = null;
959
960 if (retrieveFromCache) {
961 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
962 finderArgs, this);
963 }
964
965 if (result == null) {
966 StringBundler query = new StringBundler(4);
967
968 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
969
970 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
971
972 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
973
974 if (name == null) {
975 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
976 }
977 else {
978 if (name.equals(StringPool.BLANK)) {
979 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
980 }
981 else {
982 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
983 }
984 }
985
986 String sql = query.toString();
987
988 Session session = null;
989
990 try {
991 session = openSession();
992
993 Query q = session.createQuery(sql);
994
995 QueryPos qPos = QueryPos.getInstance(q);
996
997 qPos.add(companyId);
998
999 qPos.add(classNameId);
1000
1001 if (name != null) {
1002 qPos.add(name);
1003 }
1004
1005 List<ExpandoTable> list = q.list();
1006
1007 result = list;
1008
1009 ExpandoTable expandoTable = null;
1010
1011 if (list.isEmpty()) {
1012 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1013 finderArgs, list);
1014 }
1015 else {
1016 expandoTable = list.get(0);
1017
1018 cacheResult(expandoTable);
1019
1020 if ((expandoTable.getCompanyId() != companyId) ||
1021 (expandoTable.getClassNameId() != classNameId) ||
1022 (expandoTable.getName() == null) ||
1023 !expandoTable.getName().equals(name)) {
1024 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1025 finderArgs, expandoTable);
1026 }
1027 }
1028
1029 return expandoTable;
1030 }
1031 catch (Exception e) {
1032 throw processException(e);
1033 }
1034 finally {
1035 if (result == null) {
1036 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
1037 finderArgs);
1038 }
1039
1040 closeSession(session);
1041 }
1042 }
1043 else {
1044 if (result instanceof List<?>) {
1045 return null;
1046 }
1047 else {
1048 return (ExpandoTable)result;
1049 }
1050 }
1051 }
1052
1053
1059 public List<ExpandoTable> findAll() throws SystemException {
1060 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1061 }
1062
1063
1075 public List<ExpandoTable> findAll(int start, int end)
1076 throws SystemException {
1077 return findAll(start, end, null);
1078 }
1079
1080
1093 public List<ExpandoTable> findAll(int start, int end,
1094 OrderByComparator orderByComparator) throws SystemException {
1095 FinderPath finderPath = null;
1096 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1097
1098 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1099 (orderByComparator == null)) {
1100 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1101 finderArgs = FINDER_ARGS_EMPTY;
1102 }
1103 else {
1104 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1105 finderArgs = new Object[] { start, end, orderByComparator };
1106 }
1107
1108 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
1109 finderArgs, this);
1110
1111 if (list == null) {
1112 StringBundler query = null;
1113 String sql = null;
1114
1115 if (orderByComparator != null) {
1116 query = new StringBundler(2 +
1117 (orderByComparator.getOrderByFields().length * 3));
1118
1119 query.append(_SQL_SELECT_EXPANDOTABLE);
1120
1121 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1122 orderByComparator);
1123
1124 sql = query.toString();
1125 }
1126 else {
1127 sql = _SQL_SELECT_EXPANDOTABLE;
1128 }
1129
1130 Session session = null;
1131
1132 try {
1133 session = openSession();
1134
1135 Query q = session.createQuery(sql);
1136
1137 if (orderByComparator == null) {
1138 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1139 start, end, false);
1140
1141 Collections.sort(list);
1142 }
1143 else {
1144 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1145 start, end);
1146 }
1147 }
1148 catch (Exception e) {
1149 throw processException(e);
1150 }
1151 finally {
1152 if (list == null) {
1153 FinderCacheUtil.removeResult(finderPath, finderArgs);
1154 }
1155 else {
1156 cacheResult(list);
1157
1158 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1159 }
1160
1161 closeSession(session);
1162 }
1163 }
1164
1165 return list;
1166 }
1167
1168
1175 public void removeByC_C(long companyId, long classNameId)
1176 throws SystemException {
1177 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId)) {
1178 remove(expandoTable);
1179 }
1180 }
1181
1182
1190 public void removeByC_C_N(long companyId, long classNameId, String name)
1191 throws NoSuchTableException, SystemException {
1192 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
1193
1194 remove(expandoTable);
1195 }
1196
1197
1202 public void removeAll() throws SystemException {
1203 for (ExpandoTable expandoTable : findAll()) {
1204 remove(expandoTable);
1205 }
1206 }
1207
1208
1216 public int countByC_C(long companyId, long classNameId)
1217 throws SystemException {
1218 Object[] finderArgs = new Object[] { companyId, classNameId };
1219
1220 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1221 finderArgs, this);
1222
1223 if (count == null) {
1224 StringBundler query = new StringBundler(3);
1225
1226 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1227
1228 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1229
1230 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1231
1232 String sql = query.toString();
1233
1234 Session session = null;
1235
1236 try {
1237 session = openSession();
1238
1239 Query q = session.createQuery(sql);
1240
1241 QueryPos qPos = QueryPos.getInstance(q);
1242
1243 qPos.add(companyId);
1244
1245 qPos.add(classNameId);
1246
1247 count = (Long)q.uniqueResult();
1248 }
1249 catch (Exception e) {
1250 throw processException(e);
1251 }
1252 finally {
1253 if (count == null) {
1254 count = Long.valueOf(0);
1255 }
1256
1257 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1258 count);
1259
1260 closeSession(session);
1261 }
1262 }
1263
1264 return count.intValue();
1265 }
1266
1267
1276 public int countByC_C_N(long companyId, long classNameId, String name)
1277 throws SystemException {
1278 Object[] finderArgs = new Object[] { companyId, classNameId, name };
1279
1280 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_N,
1281 finderArgs, this);
1282
1283 if (count == null) {
1284 StringBundler query = new StringBundler(4);
1285
1286 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1287
1288 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1289
1290 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1291
1292 if (name == null) {
1293 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1294 }
1295 else {
1296 if (name.equals(StringPool.BLANK)) {
1297 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1298 }
1299 else {
1300 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1301 }
1302 }
1303
1304 String sql = query.toString();
1305
1306 Session session = null;
1307
1308 try {
1309 session = openSession();
1310
1311 Query q = session.createQuery(sql);
1312
1313 QueryPos qPos = QueryPos.getInstance(q);
1314
1315 qPos.add(companyId);
1316
1317 qPos.add(classNameId);
1318
1319 if (name != null) {
1320 qPos.add(name);
1321 }
1322
1323 count = (Long)q.uniqueResult();
1324 }
1325 catch (Exception e) {
1326 throw processException(e);
1327 }
1328 finally {
1329 if (count == null) {
1330 count = Long.valueOf(0);
1331 }
1332
1333 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N,
1334 finderArgs, count);
1335
1336 closeSession(session);
1337 }
1338 }
1339
1340 return count.intValue();
1341 }
1342
1343
1349 public int countAll() throws SystemException {
1350 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1351 FINDER_ARGS_EMPTY, this);
1352
1353 if (count == null) {
1354 Session session = null;
1355
1356 try {
1357 session = openSession();
1358
1359 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1360
1361 count = (Long)q.uniqueResult();
1362 }
1363 catch (Exception e) {
1364 throw processException(e);
1365 }
1366 finally {
1367 if (count == null) {
1368 count = Long.valueOf(0);
1369 }
1370
1371 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1372 FINDER_ARGS_EMPTY, count);
1373
1374 closeSession(session);
1375 }
1376 }
1377
1378 return count.intValue();
1379 }
1380
1381
1384 public void afterPropertiesSet() {
1385 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1386 com.liferay.portal.util.PropsUtil.get(
1387 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1388
1389 if (listenerClassNames.length > 0) {
1390 try {
1391 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1392
1393 for (String listenerClassName : listenerClassNames) {
1394 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1395 listenerClassName));
1396 }
1397
1398 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1399 }
1400 catch (Exception e) {
1401 _log.error(e);
1402 }
1403 }
1404 }
1405
1406 public void destroy() {
1407 EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1408 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1409 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1410 }
1411
1412 @BeanReference(type = ExpandoColumnPersistence.class)
1413 protected ExpandoColumnPersistence expandoColumnPersistence;
1414 @BeanReference(type = ExpandoRowPersistence.class)
1415 protected ExpandoRowPersistence expandoRowPersistence;
1416 @BeanReference(type = ExpandoTablePersistence.class)
1417 protected ExpandoTablePersistence expandoTablePersistence;
1418 @BeanReference(type = ExpandoValuePersistence.class)
1419 protected ExpandoValuePersistence expandoValuePersistence;
1420 @BeanReference(type = ResourcePersistence.class)
1421 protected ResourcePersistence resourcePersistence;
1422 @BeanReference(type = UserPersistence.class)
1423 protected UserPersistence userPersistence;
1424 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1425 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1426 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1427 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1428 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1429 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
1430 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1431 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
1432 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
1433 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
1434 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = ?)";
1435 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1436 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1437 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1438 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1439 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1440 private static ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1441 @Override
1442 public Object clone() {
1443 return this;
1444 }
1445
1446 @Override
1447 public CacheModel<ExpandoTable> toCacheModel() {
1448 return _nullExpandoTableCacheModel;
1449 }
1450 };
1451
1452 private static CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1453 public ExpandoTable toEntityModel() {
1454 return _nullExpandoTable;
1455 }
1456 };
1457 }