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 cacheUniqueFindersCache(ExpandoTable expandoTable) {
215 if (expandoTable.isNew()) {
216 Object[] args = new Object[] {
217 Long.valueOf(expandoTable.getCompanyId()),
218 Long.valueOf(expandoTable.getClassNameId()),
219
220 expandoTable.getName()
221 };
222
223 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
224 Long.valueOf(1));
225 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
226 expandoTable);
227 }
228 else {
229 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
230
231 if ((expandoTableModelImpl.getColumnBitmask() &
232 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
233 Object[] args = new Object[] {
234 Long.valueOf(expandoTable.getCompanyId()),
235 Long.valueOf(expandoTable.getClassNameId()),
236
237 expandoTable.getName()
238 };
239
240 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N, args,
241 Long.valueOf(1));
242 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N, args,
243 expandoTable);
244 }
245 }
246 }
247
248 protected void clearUniqueFindersCache(ExpandoTable expandoTable) {
249 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
250
251 Object[] args = new Object[] {
252 Long.valueOf(expandoTable.getCompanyId()),
253 Long.valueOf(expandoTable.getClassNameId()),
254
255 expandoTable.getName()
256 };
257
258 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
259 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
260
261 if ((expandoTableModelImpl.getColumnBitmask() &
262 FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
263 args = new Object[] {
264 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
265 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId()),
266
267 expandoTableModelImpl.getOriginalName()
268 };
269
270 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
271 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
272 }
273 }
274
275
281 public ExpandoTable create(long tableId) {
282 ExpandoTable expandoTable = new ExpandoTableImpl();
283
284 expandoTable.setNew(true);
285 expandoTable.setPrimaryKey(tableId);
286
287 return expandoTable;
288 }
289
290
298 public ExpandoTable remove(long tableId)
299 throws NoSuchTableException, SystemException {
300 return remove(Long.valueOf(tableId));
301 }
302
303
311 @Override
312 public ExpandoTable remove(Serializable primaryKey)
313 throws NoSuchTableException, SystemException {
314 Session session = null;
315
316 try {
317 session = openSession();
318
319 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
320 primaryKey);
321
322 if (expandoTable == null) {
323 if (_log.isWarnEnabled()) {
324 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
325 }
326
327 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
328 primaryKey);
329 }
330
331 return remove(expandoTable);
332 }
333 catch (NoSuchTableException nsee) {
334 throw nsee;
335 }
336 catch (Exception e) {
337 throw processException(e);
338 }
339 finally {
340 closeSession(session);
341 }
342 }
343
344 @Override
345 protected ExpandoTable removeImpl(ExpandoTable expandoTable)
346 throws SystemException {
347 expandoTable = toUnwrappedModel(expandoTable);
348
349 Session session = null;
350
351 try {
352 session = openSession();
353
354 BatchSessionUtil.delete(session, expandoTable);
355 }
356 catch (Exception e) {
357 throw processException(e);
358 }
359 finally {
360 closeSession(session);
361 }
362
363 clearCache(expandoTable);
364
365 return expandoTable;
366 }
367
368 @Override
369 public ExpandoTable updateImpl(
370 com.liferay.portlet.expando.model.ExpandoTable expandoTable,
371 boolean merge) throws SystemException {
372 expandoTable = toUnwrappedModel(expandoTable);
373
374 boolean isNew = expandoTable.isNew();
375
376 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
377
378 Session session = null;
379
380 try {
381 session = openSession();
382
383 BatchSessionUtil.update(session, expandoTable, merge);
384
385 expandoTable.setNew(false);
386 }
387 catch (Exception e) {
388 throw processException(e);
389 }
390 finally {
391 closeSession(session);
392 }
393
394 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
395
396 if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
397 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
398 }
399
400 else {
401 if ((expandoTableModelImpl.getColumnBitmask() &
402 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
403 Object[] args = new Object[] {
404 Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
405 Long.valueOf(expandoTableModelImpl.getOriginalClassNameId())
406 };
407
408 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
409 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
410 args);
411
412 args = new Object[] {
413 Long.valueOf(expandoTableModelImpl.getCompanyId()),
414 Long.valueOf(expandoTableModelImpl.getClassNameId())
415 };
416
417 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
418 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
419 args);
420 }
421 }
422
423 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
424 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
425
426 clearUniqueFindersCache(expandoTable);
427 cacheUniqueFindersCache(expandoTable);
428
429 return expandoTable;
430 }
431
432 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
433 if (expandoTable instanceof ExpandoTableImpl) {
434 return expandoTable;
435 }
436
437 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
438
439 expandoTableImpl.setNew(expandoTable.isNew());
440 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
441
442 expandoTableImpl.setTableId(expandoTable.getTableId());
443 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
444 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
445 expandoTableImpl.setName(expandoTable.getName());
446
447 return expandoTableImpl;
448 }
449
450
458 @Override
459 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
460 throws NoSuchModelException, SystemException {
461 return findByPrimaryKey(((Long)primaryKey).longValue());
462 }
463
464
472 public ExpandoTable findByPrimaryKey(long tableId)
473 throws NoSuchTableException, SystemException {
474 ExpandoTable expandoTable = fetchByPrimaryKey(tableId);
475
476 if (expandoTable == null) {
477 if (_log.isWarnEnabled()) {
478 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
479 }
480
481 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
482 tableId);
483 }
484
485 return expandoTable;
486 }
487
488
495 @Override
496 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
497 throws SystemException {
498 return fetchByPrimaryKey(((Long)primaryKey).longValue());
499 }
500
501
508 public ExpandoTable fetchByPrimaryKey(long tableId)
509 throws SystemException {
510 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
511 ExpandoTableImpl.class, tableId);
512
513 if (expandoTable == _nullExpandoTable) {
514 return null;
515 }
516
517 if (expandoTable == null) {
518 Session session = null;
519
520 boolean hasException = false;
521
522 try {
523 session = openSession();
524
525 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
526 Long.valueOf(tableId));
527 }
528 catch (Exception e) {
529 hasException = true;
530
531 throw processException(e);
532 }
533 finally {
534 if (expandoTable != null) {
535 cacheResult(expandoTable);
536 }
537 else if (!hasException) {
538 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
539 ExpandoTableImpl.class, tableId, _nullExpandoTable);
540 }
541
542 closeSession(session);
543 }
544 }
545
546 return expandoTable;
547 }
548
549
557 public List<ExpandoTable> findByC_C(long companyId, long classNameId)
558 throws SystemException {
559 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
560 QueryUtil.ALL_POS, null);
561 }
562
563
577 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
578 int start, int end) throws SystemException {
579 return findByC_C(companyId, classNameId, start, end, null);
580 }
581
582
597 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
598 int start, int end, OrderByComparator orderByComparator)
599 throws SystemException {
600 FinderPath finderPath = null;
601 Object[] finderArgs = null;
602
603 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
604 (orderByComparator == null)) {
605 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
606 finderArgs = new Object[] { companyId, classNameId };
607 }
608 else {
609 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
610 finderArgs = new Object[] {
611 companyId, classNameId,
612
613 start, end, orderByComparator
614 };
615 }
616
617 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
618 finderArgs, this);
619
620 if ((list != null) && !list.isEmpty()) {
621 for (ExpandoTable expandoTable : list) {
622 if ((companyId != expandoTable.getCompanyId()) ||
623 (classNameId != expandoTable.getClassNameId())) {
624 list = null;
625
626 break;
627 }
628 }
629 }
630
631 if (list == null) {
632 StringBundler query = null;
633
634 if (orderByComparator != null) {
635 query = new StringBundler(4 +
636 (orderByComparator.getOrderByFields().length * 3));
637 }
638 else {
639 query = new StringBundler(3);
640 }
641
642 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
643
644 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
645
646 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
647
648 if (orderByComparator != null) {
649 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
650 orderByComparator);
651 }
652
653 String sql = query.toString();
654
655 Session session = null;
656
657 try {
658 session = openSession();
659
660 Query q = session.createQuery(sql);
661
662 QueryPos qPos = QueryPos.getInstance(q);
663
664 qPos.add(companyId);
665
666 qPos.add(classNameId);
667
668 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
669 start, end);
670 }
671 catch (Exception e) {
672 throw processException(e);
673 }
674 finally {
675 if (list == null) {
676 FinderCacheUtil.removeResult(finderPath, finderArgs);
677 }
678 else {
679 cacheResult(list);
680
681 FinderCacheUtil.putResult(finderPath, finderArgs, list);
682 }
683
684 closeSession(session);
685 }
686 }
687
688 return list;
689 }
690
691
701 public ExpandoTable findByC_C_First(long companyId, long classNameId,
702 OrderByComparator orderByComparator)
703 throws NoSuchTableException, SystemException {
704 ExpandoTable expandoTable = fetchByC_C_First(companyId, classNameId,
705 orderByComparator);
706
707 if (expandoTable != null) {
708 return expandoTable;
709 }
710
711 StringBundler msg = new StringBundler(6);
712
713 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
714
715 msg.append("companyId=");
716 msg.append(companyId);
717
718 msg.append(", classNameId=");
719 msg.append(classNameId);
720
721 msg.append(StringPool.CLOSE_CURLY_BRACE);
722
723 throw new NoSuchTableException(msg.toString());
724 }
725
726
735 public ExpandoTable fetchByC_C_First(long companyId, long classNameId,
736 OrderByComparator orderByComparator) throws SystemException {
737 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
738 orderByComparator);
739
740 if (!list.isEmpty()) {
741 return list.get(0);
742 }
743
744 return null;
745 }
746
747
757 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
758 OrderByComparator orderByComparator)
759 throws NoSuchTableException, SystemException {
760 ExpandoTable expandoTable = fetchByC_C_Last(companyId, classNameId,
761 orderByComparator);
762
763 if (expandoTable != null) {
764 return expandoTable;
765 }
766
767 StringBundler msg = new StringBundler(6);
768
769 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
770
771 msg.append("companyId=");
772 msg.append(companyId);
773
774 msg.append(", classNameId=");
775 msg.append(classNameId);
776
777 msg.append(StringPool.CLOSE_CURLY_BRACE);
778
779 throw new NoSuchTableException(msg.toString());
780 }
781
782
791 public ExpandoTable fetchByC_C_Last(long companyId, long classNameId,
792 OrderByComparator orderByComparator) throws SystemException {
793 int count = countByC_C(companyId, classNameId);
794
795 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
796 count, orderByComparator);
797
798 if (!list.isEmpty()) {
799 return list.get(0);
800 }
801
802 return null;
803 }
804
805
816 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
817 long classNameId, OrderByComparator orderByComparator)
818 throws NoSuchTableException, SystemException {
819 ExpandoTable expandoTable = findByPrimaryKey(tableId);
820
821 Session session = null;
822
823 try {
824 session = openSession();
825
826 ExpandoTable[] array = new ExpandoTableImpl[3];
827
828 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
829 classNameId, orderByComparator, true);
830
831 array[1] = expandoTable;
832
833 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
834 classNameId, orderByComparator, false);
835
836 return array;
837 }
838 catch (Exception e) {
839 throw processException(e);
840 }
841 finally {
842 closeSession(session);
843 }
844 }
845
846 protected ExpandoTable getByC_C_PrevAndNext(Session session,
847 ExpandoTable expandoTable, long companyId, long classNameId,
848 OrderByComparator orderByComparator, boolean previous) {
849 StringBundler query = null;
850
851 if (orderByComparator != null) {
852 query = new StringBundler(6 +
853 (orderByComparator.getOrderByFields().length * 6));
854 }
855 else {
856 query = new StringBundler(3);
857 }
858
859 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
860
861 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
862
863 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
864
865 if (orderByComparator != null) {
866 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
867
868 if (orderByConditionFields.length > 0) {
869 query.append(WHERE_AND);
870 }
871
872 for (int i = 0; i < orderByConditionFields.length; i++) {
873 query.append(_ORDER_BY_ENTITY_ALIAS);
874 query.append(orderByConditionFields[i]);
875
876 if ((i + 1) < orderByConditionFields.length) {
877 if (orderByComparator.isAscending() ^ previous) {
878 query.append(WHERE_GREATER_THAN_HAS_NEXT);
879 }
880 else {
881 query.append(WHERE_LESSER_THAN_HAS_NEXT);
882 }
883 }
884 else {
885 if (orderByComparator.isAscending() ^ previous) {
886 query.append(WHERE_GREATER_THAN);
887 }
888 else {
889 query.append(WHERE_LESSER_THAN);
890 }
891 }
892 }
893
894 query.append(ORDER_BY_CLAUSE);
895
896 String[] orderByFields = orderByComparator.getOrderByFields();
897
898 for (int i = 0; i < orderByFields.length; i++) {
899 query.append(_ORDER_BY_ENTITY_ALIAS);
900 query.append(orderByFields[i]);
901
902 if ((i + 1) < orderByFields.length) {
903 if (orderByComparator.isAscending() ^ previous) {
904 query.append(ORDER_BY_ASC_HAS_NEXT);
905 }
906 else {
907 query.append(ORDER_BY_DESC_HAS_NEXT);
908 }
909 }
910 else {
911 if (orderByComparator.isAscending() ^ previous) {
912 query.append(ORDER_BY_ASC);
913 }
914 else {
915 query.append(ORDER_BY_DESC);
916 }
917 }
918 }
919 }
920
921 String sql = query.toString();
922
923 Query q = session.createQuery(sql);
924
925 q.setFirstResult(0);
926 q.setMaxResults(2);
927
928 QueryPos qPos = QueryPos.getInstance(q);
929
930 qPos.add(companyId);
931
932 qPos.add(classNameId);
933
934 if (orderByComparator != null) {
935 Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
936
937 for (Object value : values) {
938 qPos.add(value);
939 }
940 }
941
942 List<ExpandoTable> list = q.list();
943
944 if (list.size() == 2) {
945 return list.get(1);
946 }
947 else {
948 return null;
949 }
950 }
951
952
962 public ExpandoTable findByC_C_N(long companyId, long classNameId,
963 String name) throws NoSuchTableException, SystemException {
964 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
965
966 if (expandoTable == null) {
967 StringBundler msg = new StringBundler(8);
968
969 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
970
971 msg.append("companyId=");
972 msg.append(companyId);
973
974 msg.append(", classNameId=");
975 msg.append(classNameId);
976
977 msg.append(", name=");
978 msg.append(name);
979
980 msg.append(StringPool.CLOSE_CURLY_BRACE);
981
982 if (_log.isWarnEnabled()) {
983 _log.warn(msg.toString());
984 }
985
986 throw new NoSuchTableException(msg.toString());
987 }
988
989 return expandoTable;
990 }
991
992
1001 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
1002 String name) throws SystemException {
1003 return fetchByC_C_N(companyId, classNameId, name, true);
1004 }
1005
1006
1016 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
1017 String name, boolean retrieveFromCache) throws SystemException {
1018 Object[] finderArgs = new Object[] { companyId, classNameId, name };
1019
1020 Object result = null;
1021
1022 if (retrieveFromCache) {
1023 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
1024 finderArgs, this);
1025 }
1026
1027 if (result instanceof ExpandoTable) {
1028 ExpandoTable expandoTable = (ExpandoTable)result;
1029
1030 if ((companyId != expandoTable.getCompanyId()) ||
1031 (classNameId != expandoTable.getClassNameId()) ||
1032 !Validator.equals(name, expandoTable.getName())) {
1033 result = null;
1034 }
1035 }
1036
1037 if (result == null) {
1038 StringBundler query = new StringBundler(4);
1039
1040 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
1041
1042 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1043
1044 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1045
1046 if (name == null) {
1047 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1048 }
1049 else {
1050 if (name.equals(StringPool.BLANK)) {
1051 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1052 }
1053 else {
1054 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1055 }
1056 }
1057
1058 String sql = query.toString();
1059
1060 Session session = null;
1061
1062 try {
1063 session = openSession();
1064
1065 Query q = session.createQuery(sql);
1066
1067 QueryPos qPos = QueryPos.getInstance(q);
1068
1069 qPos.add(companyId);
1070
1071 qPos.add(classNameId);
1072
1073 if (name != null) {
1074 qPos.add(name);
1075 }
1076
1077 List<ExpandoTable> list = q.list();
1078
1079 result = list;
1080
1081 ExpandoTable expandoTable = null;
1082
1083 if (list.isEmpty()) {
1084 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1085 finderArgs, list);
1086 }
1087 else {
1088 expandoTable = list.get(0);
1089
1090 cacheResult(expandoTable);
1091
1092 if ((expandoTable.getCompanyId() != companyId) ||
1093 (expandoTable.getClassNameId() != classNameId) ||
1094 (expandoTable.getName() == null) ||
1095 !expandoTable.getName().equals(name)) {
1096 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1097 finderArgs, expandoTable);
1098 }
1099 }
1100
1101 return expandoTable;
1102 }
1103 catch (Exception e) {
1104 throw processException(e);
1105 }
1106 finally {
1107 if (result == null) {
1108 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
1109 finderArgs);
1110 }
1111
1112 closeSession(session);
1113 }
1114 }
1115 else {
1116 if (result instanceof List<?>) {
1117 return null;
1118 }
1119 else {
1120 return (ExpandoTable)result;
1121 }
1122 }
1123 }
1124
1125
1131 public List<ExpandoTable> findAll() throws SystemException {
1132 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1133 }
1134
1135
1147 public List<ExpandoTable> findAll(int start, int end)
1148 throws SystemException {
1149 return findAll(start, end, null);
1150 }
1151
1152
1165 public List<ExpandoTable> findAll(int start, int end,
1166 OrderByComparator orderByComparator) throws SystemException {
1167 FinderPath finderPath = null;
1168 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1169
1170 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1171 (orderByComparator == null)) {
1172 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1173 finderArgs = FINDER_ARGS_EMPTY;
1174 }
1175 else {
1176 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1177 finderArgs = new Object[] { start, end, orderByComparator };
1178 }
1179
1180 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
1181 finderArgs, this);
1182
1183 if (list == null) {
1184 StringBundler query = null;
1185 String sql = null;
1186
1187 if (orderByComparator != null) {
1188 query = new StringBundler(2 +
1189 (orderByComparator.getOrderByFields().length * 3));
1190
1191 query.append(_SQL_SELECT_EXPANDOTABLE);
1192
1193 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1194 orderByComparator);
1195
1196 sql = query.toString();
1197 }
1198 else {
1199 sql = _SQL_SELECT_EXPANDOTABLE;
1200 }
1201
1202 Session session = null;
1203
1204 try {
1205 session = openSession();
1206
1207 Query q = session.createQuery(sql);
1208
1209 if (orderByComparator == null) {
1210 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1211 start, end, false);
1212
1213 Collections.sort(list);
1214 }
1215 else {
1216 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1217 start, end);
1218 }
1219 }
1220 catch (Exception e) {
1221 throw processException(e);
1222 }
1223 finally {
1224 if (list == null) {
1225 FinderCacheUtil.removeResult(finderPath, finderArgs);
1226 }
1227 else {
1228 cacheResult(list);
1229
1230 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1231 }
1232
1233 closeSession(session);
1234 }
1235 }
1236
1237 return list;
1238 }
1239
1240
1247 public void removeByC_C(long companyId, long classNameId)
1248 throws SystemException {
1249 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId)) {
1250 remove(expandoTable);
1251 }
1252 }
1253
1254
1263 public ExpandoTable removeByC_C_N(long companyId, long classNameId,
1264 String name) throws NoSuchTableException, SystemException {
1265 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
1266
1267 return remove(expandoTable);
1268 }
1269
1270
1275 public void removeAll() throws SystemException {
1276 for (ExpandoTable expandoTable : findAll()) {
1277 remove(expandoTable);
1278 }
1279 }
1280
1281
1289 public int countByC_C(long companyId, long classNameId)
1290 throws SystemException {
1291 Object[] finderArgs = new Object[] { companyId, classNameId };
1292
1293 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1294 finderArgs, this);
1295
1296 if (count == null) {
1297 StringBundler query = new StringBundler(3);
1298
1299 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1300
1301 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1302
1303 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1304
1305 String sql = query.toString();
1306
1307 Session session = null;
1308
1309 try {
1310 session = openSession();
1311
1312 Query q = session.createQuery(sql);
1313
1314 QueryPos qPos = QueryPos.getInstance(q);
1315
1316 qPos.add(companyId);
1317
1318 qPos.add(classNameId);
1319
1320 count = (Long)q.uniqueResult();
1321 }
1322 catch (Exception e) {
1323 throw processException(e);
1324 }
1325 finally {
1326 if (count == null) {
1327 count = Long.valueOf(0);
1328 }
1329
1330 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1331 count);
1332
1333 closeSession(session);
1334 }
1335 }
1336
1337 return count.intValue();
1338 }
1339
1340
1349 public int countByC_C_N(long companyId, long classNameId, String name)
1350 throws SystemException {
1351 Object[] finderArgs = new Object[] { companyId, classNameId, name };
1352
1353 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_N,
1354 finderArgs, this);
1355
1356 if (count == null) {
1357 StringBundler query = new StringBundler(4);
1358
1359 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1360
1361 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1362
1363 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1364
1365 if (name == null) {
1366 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1367 }
1368 else {
1369 if (name.equals(StringPool.BLANK)) {
1370 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1371 }
1372 else {
1373 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1374 }
1375 }
1376
1377 String sql = query.toString();
1378
1379 Session session = null;
1380
1381 try {
1382 session = openSession();
1383
1384 Query q = session.createQuery(sql);
1385
1386 QueryPos qPos = QueryPos.getInstance(q);
1387
1388 qPos.add(companyId);
1389
1390 qPos.add(classNameId);
1391
1392 if (name != null) {
1393 qPos.add(name);
1394 }
1395
1396 count = (Long)q.uniqueResult();
1397 }
1398 catch (Exception e) {
1399 throw processException(e);
1400 }
1401 finally {
1402 if (count == null) {
1403 count = Long.valueOf(0);
1404 }
1405
1406 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N,
1407 finderArgs, count);
1408
1409 closeSession(session);
1410 }
1411 }
1412
1413 return count.intValue();
1414 }
1415
1416
1422 public int countAll() throws SystemException {
1423 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1424 FINDER_ARGS_EMPTY, this);
1425
1426 if (count == null) {
1427 Session session = null;
1428
1429 try {
1430 session = openSession();
1431
1432 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1433
1434 count = (Long)q.uniqueResult();
1435 }
1436 catch (Exception e) {
1437 throw processException(e);
1438 }
1439 finally {
1440 if (count == null) {
1441 count = Long.valueOf(0);
1442 }
1443
1444 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1445 FINDER_ARGS_EMPTY, count);
1446
1447 closeSession(session);
1448 }
1449 }
1450
1451 return count.intValue();
1452 }
1453
1454
1457 public void afterPropertiesSet() {
1458 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1459 com.liferay.portal.util.PropsUtil.get(
1460 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1461
1462 if (listenerClassNames.length > 0) {
1463 try {
1464 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1465
1466 for (String listenerClassName : listenerClassNames) {
1467 Class<?> clazz = getClass();
1468
1469 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1470 clazz.getClassLoader(), listenerClassName));
1471 }
1472
1473 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1474 }
1475 catch (Exception e) {
1476 _log.error(e);
1477 }
1478 }
1479 }
1480
1481 public void destroy() {
1482 EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1483 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1484 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1485 }
1486
1487 @BeanReference(type = ExpandoColumnPersistence.class)
1488 protected ExpandoColumnPersistence expandoColumnPersistence;
1489 @BeanReference(type = ExpandoRowPersistence.class)
1490 protected ExpandoRowPersistence expandoRowPersistence;
1491 @BeanReference(type = ExpandoTablePersistence.class)
1492 protected ExpandoTablePersistence expandoTablePersistence;
1493 @BeanReference(type = ExpandoValuePersistence.class)
1494 protected ExpandoValuePersistence expandoValuePersistence;
1495 @BeanReference(type = ResourcePersistence.class)
1496 protected ResourcePersistence resourcePersistence;
1497 @BeanReference(type = UserPersistence.class)
1498 protected UserPersistence userPersistence;
1499 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1500 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1501 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1502 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1503 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1504 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
1505 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1506 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
1507 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
1508 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
1509 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = ?)";
1510 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1511 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1512 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1513 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1514 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1515 private static ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1516 @Override
1517 public Object clone() {
1518 return this;
1519 }
1520
1521 @Override
1522 public CacheModel<ExpandoTable> toCacheModel() {
1523 return _nullExpandoTableCacheModel;
1524 }
1525 };
1526
1527 private static CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1528 public ExpandoTable toEntityModel() {
1529 return _nullExpandoTable;
1530 }
1531 };
1532 }