001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.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.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
070 public class ExpandoTablePersistenceImpl extends BasePersistenceImpl<ExpandoTable>
071 implements ExpandoTablePersistence {
072 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoTableImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
074 ".List";
075 public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
076 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
077 "findByC_C",
078 new String[] {
079 Long.class.getName(), Long.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
085 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
086 "countByC_C",
087 new String[] { Long.class.getName(), Long.class.getName() });
088 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
089 ExpandoTableModelImpl.FINDER_CACHE_ENABLED,
090 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_N",
091 new String[] {
092 Long.class.getName(), Long.class.getName(),
093 String.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
096 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097 "countByC_C_N",
098 new String[] {
099 Long.class.getName(), Long.class.getName(),
100 String.class.getName()
101 });
102 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
103 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "findAll", new String[0]);
105 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
106 ExpandoTableModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "countAll", new String[0]);
108
109
114 public void cacheResult(ExpandoTable expandoTable) {
115 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
116 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
117
118 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
119 new Object[] {
120 new Long(expandoTable.getCompanyId()),
121 new Long(expandoTable.getClassNameId()),
122
123 expandoTable.getName()
124 }, expandoTable);
125 }
126
127
132 public void cacheResult(List<ExpandoTable> expandoTables) {
133 for (ExpandoTable expandoTable : expandoTables) {
134 if (EntityCacheUtil.getResult(
135 ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
136 ExpandoTableImpl.class, expandoTable.getPrimaryKey(),
137 this) == null) {
138 cacheResult(expandoTable);
139 }
140 }
141 }
142
143
150 public void clearCache() {
151 CacheRegistryUtil.clear(ExpandoTableImpl.class.getName());
152 EntityCacheUtil.clearCache(ExpandoTableImpl.class.getName());
153 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
154 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
155 }
156
157
164 public void clearCache(ExpandoTable expandoTable) {
165 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
166 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
167
168 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
169 new Object[] {
170 new Long(expandoTable.getCompanyId()),
171 new Long(expandoTable.getClassNameId()),
172
173 expandoTable.getName()
174 });
175 }
176
177
183 public ExpandoTable create(long tableId) {
184 ExpandoTable expandoTable = new ExpandoTableImpl();
185
186 expandoTable.setNew(true);
187 expandoTable.setPrimaryKey(tableId);
188
189 return expandoTable;
190 }
191
192
200 public ExpandoTable remove(Serializable primaryKey)
201 throws NoSuchModelException, SystemException {
202 return remove(((Long)primaryKey).longValue());
203 }
204
205
213 public ExpandoTable remove(long tableId)
214 throws NoSuchTableException, SystemException {
215 Session session = null;
216
217 try {
218 session = openSession();
219
220 ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
221 new Long(tableId));
222
223 if (expandoTable == null) {
224 if (_log.isWarnEnabled()) {
225 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
226 }
227
228 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
229 tableId);
230 }
231
232 return remove(expandoTable);
233 }
234 catch (NoSuchTableException nsee) {
235 throw nsee;
236 }
237 catch (Exception e) {
238 throw processException(e);
239 }
240 finally {
241 closeSession(session);
242 }
243 }
244
245 protected ExpandoTable removeImpl(ExpandoTable expandoTable)
246 throws SystemException {
247 expandoTable = toUnwrappedModel(expandoTable);
248
249 Session session = null;
250
251 try {
252 session = openSession();
253
254 BatchSessionUtil.delete(session, expandoTable);
255 }
256 catch (Exception e) {
257 throw processException(e);
258 }
259 finally {
260 closeSession(session);
261 }
262
263 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
264
265 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
266
267 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
268 new Object[] {
269 new Long(expandoTableModelImpl.getOriginalCompanyId()),
270 new Long(expandoTableModelImpl.getOriginalClassNameId()),
271
272 expandoTableModelImpl.getOriginalName()
273 });
274
275 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
276 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
277
278 return expandoTable;
279 }
280
281 public ExpandoTable updateImpl(
282 com.liferay.portlet.expando.model.ExpandoTable expandoTable,
283 boolean merge) throws SystemException {
284 expandoTable = toUnwrappedModel(expandoTable);
285
286 boolean isNew = expandoTable.isNew();
287
288 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
289
290 Session session = null;
291
292 try {
293 session = openSession();
294
295 BatchSessionUtil.update(session, expandoTable, merge);
296
297 expandoTable.setNew(false);
298 }
299 catch (Exception e) {
300 throw processException(e);
301 }
302 finally {
303 closeSession(session);
304 }
305
306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
307
308 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
309 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
310
311 if (!isNew &&
312 ((expandoTable.getCompanyId() != expandoTableModelImpl.getOriginalCompanyId()) ||
313 (expandoTable.getClassNameId() != expandoTableModelImpl.getOriginalClassNameId()) ||
314 !Validator.equals(expandoTable.getName(),
315 expandoTableModelImpl.getOriginalName()))) {
316 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
317 new Object[] {
318 new Long(expandoTableModelImpl.getOriginalCompanyId()),
319 new Long(expandoTableModelImpl.getOriginalClassNameId()),
320
321 expandoTableModelImpl.getOriginalName()
322 });
323 }
324
325 if (isNew ||
326 ((expandoTable.getCompanyId() != expandoTableModelImpl.getOriginalCompanyId()) ||
327 (expandoTable.getClassNameId() != expandoTableModelImpl.getOriginalClassNameId()) ||
328 !Validator.equals(expandoTable.getName(),
329 expandoTableModelImpl.getOriginalName()))) {
330 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
331 new Object[] {
332 new Long(expandoTable.getCompanyId()),
333 new Long(expandoTable.getClassNameId()),
334
335 expandoTable.getName()
336 }, expandoTable);
337 }
338
339 return expandoTable;
340 }
341
342 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
343 if (expandoTable instanceof ExpandoTableImpl) {
344 return expandoTable;
345 }
346
347 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
348
349 expandoTableImpl.setNew(expandoTable.isNew());
350 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
351
352 expandoTableImpl.setTableId(expandoTable.getTableId());
353 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
354 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
355 expandoTableImpl.setName(expandoTable.getName());
356
357 return expandoTableImpl;
358 }
359
360
368 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
369 throws NoSuchModelException, SystemException {
370 return findByPrimaryKey(((Long)primaryKey).longValue());
371 }
372
373
381 public ExpandoTable findByPrimaryKey(long tableId)
382 throws NoSuchTableException, SystemException {
383 ExpandoTable expandoTable = fetchByPrimaryKey(tableId);
384
385 if (expandoTable == null) {
386 if (_log.isWarnEnabled()) {
387 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
388 }
389
390 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
391 tableId);
392 }
393
394 return expandoTable;
395 }
396
397
404 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
405 throws SystemException {
406 return fetchByPrimaryKey(((Long)primaryKey).longValue());
407 }
408
409
416 public ExpandoTable fetchByPrimaryKey(long tableId)
417 throws SystemException {
418 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
419 ExpandoTableImpl.class, tableId, this);
420
421 if (expandoTable == null) {
422 Session session = null;
423
424 try {
425 session = openSession();
426
427 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
428 new Long(tableId));
429 }
430 catch (Exception e) {
431 throw processException(e);
432 }
433 finally {
434 if (expandoTable != null) {
435 cacheResult(expandoTable);
436 }
437
438 closeSession(session);
439 }
440 }
441
442 return expandoTable;
443 }
444
445
453 public List<ExpandoTable> findByC_C(long companyId, long classNameId)
454 throws SystemException {
455 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
456 QueryUtil.ALL_POS, null);
457 }
458
459
473 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
474 int start, int end) throws SystemException {
475 return findByC_C(companyId, classNameId, start, end, null);
476 }
477
478
493 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
494 int start, int end, OrderByComparator orderByComparator)
495 throws SystemException {
496 Object[] finderArgs = new Object[] {
497 companyId, classNameId,
498
499 String.valueOf(start), String.valueOf(end),
500 String.valueOf(orderByComparator)
501 };
502
503 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
504 finderArgs, this);
505
506 if (list == null) {
507 Session session = null;
508
509 try {
510 session = openSession();
511
512 StringBundler query = null;
513
514 if (orderByComparator != null) {
515 query = new StringBundler(4 +
516 (orderByComparator.getOrderByFields().length * 3));
517 }
518 else {
519 query = new StringBundler(3);
520 }
521
522 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
523
524 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
525
526 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
527
528 if (orderByComparator != null) {
529 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
530 orderByComparator);
531 }
532
533 String sql = query.toString();
534
535 Query q = session.createQuery(sql);
536
537 QueryPos qPos = QueryPos.getInstance(q);
538
539 qPos.add(companyId);
540
541 qPos.add(classNameId);
542
543 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
544 start, end);
545 }
546 catch (Exception e) {
547 throw processException(e);
548 }
549 finally {
550 if (list == null) {
551 list = new ArrayList<ExpandoTable>();
552 }
553
554 cacheResult(list);
555
556 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
557 list);
558
559 closeSession(session);
560 }
561 }
562
563 return list;
564 }
565
566
580 public ExpandoTable findByC_C_First(long companyId, long classNameId,
581 OrderByComparator orderByComparator)
582 throws NoSuchTableException, SystemException {
583 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
584 orderByComparator);
585
586 if (list.isEmpty()) {
587 StringBundler msg = new StringBundler(6);
588
589 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
590
591 msg.append("companyId=");
592 msg.append(companyId);
593
594 msg.append(", classNameId=");
595 msg.append(classNameId);
596
597 msg.append(StringPool.CLOSE_CURLY_BRACE);
598
599 throw new NoSuchTableException(msg.toString());
600 }
601 else {
602 return list.get(0);
603 }
604 }
605
606
620 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
621 OrderByComparator orderByComparator)
622 throws NoSuchTableException, SystemException {
623 int count = countByC_C(companyId, classNameId);
624
625 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
626 count, orderByComparator);
627
628 if (list.isEmpty()) {
629 StringBundler msg = new StringBundler(6);
630
631 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
632
633 msg.append("companyId=");
634 msg.append(companyId);
635
636 msg.append(", classNameId=");
637 msg.append(classNameId);
638
639 msg.append(StringPool.CLOSE_CURLY_BRACE);
640
641 throw new NoSuchTableException(msg.toString());
642 }
643 else {
644 return list.get(0);
645 }
646 }
647
648
663 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
664 long classNameId, OrderByComparator orderByComparator)
665 throws NoSuchTableException, SystemException {
666 ExpandoTable expandoTable = findByPrimaryKey(tableId);
667
668 Session session = null;
669
670 try {
671 session = openSession();
672
673 ExpandoTable[] array = new ExpandoTableImpl[3];
674
675 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
676 classNameId, orderByComparator, true);
677
678 array[1] = expandoTable;
679
680 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
681 classNameId, orderByComparator, false);
682
683 return array;
684 }
685 catch (Exception e) {
686 throw processException(e);
687 }
688 finally {
689 closeSession(session);
690 }
691 }
692
693 protected ExpandoTable getByC_C_PrevAndNext(Session session,
694 ExpandoTable expandoTable, long companyId, long classNameId,
695 OrderByComparator orderByComparator, boolean previous) {
696 StringBundler query = null;
697
698 if (orderByComparator != null) {
699 query = new StringBundler(6 +
700 (orderByComparator.getOrderByFields().length * 6));
701 }
702 else {
703 query = new StringBundler(3);
704 }
705
706 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
707
708 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
709
710 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
711
712 if (orderByComparator != null) {
713 String[] orderByFields = orderByComparator.getOrderByFields();
714
715 if (orderByFields.length > 0) {
716 query.append(WHERE_AND);
717 }
718
719 for (int i = 0; i < orderByFields.length; i++) {
720 query.append(_ORDER_BY_ENTITY_ALIAS);
721 query.append(orderByFields[i]);
722
723 if ((i + 1) < orderByFields.length) {
724 if (orderByComparator.isAscending() ^ previous) {
725 query.append(WHERE_GREATER_THAN_HAS_NEXT);
726 }
727 else {
728 query.append(WHERE_LESSER_THAN_HAS_NEXT);
729 }
730 }
731 else {
732 if (orderByComparator.isAscending() ^ previous) {
733 query.append(WHERE_GREATER_THAN);
734 }
735 else {
736 query.append(WHERE_LESSER_THAN);
737 }
738 }
739 }
740
741 query.append(ORDER_BY_CLAUSE);
742
743 for (int i = 0; i < orderByFields.length; i++) {
744 query.append(_ORDER_BY_ENTITY_ALIAS);
745 query.append(orderByFields[i]);
746
747 if ((i + 1) < orderByFields.length) {
748 if (orderByComparator.isAscending() ^ previous) {
749 query.append(ORDER_BY_ASC_HAS_NEXT);
750 }
751 else {
752 query.append(ORDER_BY_DESC_HAS_NEXT);
753 }
754 }
755 else {
756 if (orderByComparator.isAscending() ^ previous) {
757 query.append(ORDER_BY_ASC);
758 }
759 else {
760 query.append(ORDER_BY_DESC);
761 }
762 }
763 }
764 }
765
766 String sql = query.toString();
767
768 Query q = session.createQuery(sql);
769
770 q.setFirstResult(0);
771 q.setMaxResults(2);
772
773 QueryPos qPos = QueryPos.getInstance(q);
774
775 qPos.add(companyId);
776
777 qPos.add(classNameId);
778
779 if (orderByComparator != null) {
780 Object[] values = orderByComparator.getOrderByValues(expandoTable);
781
782 for (Object value : values) {
783 qPos.add(value);
784 }
785 }
786
787 List<ExpandoTable> list = q.list();
788
789 if (list.size() == 2) {
790 return list.get(1);
791 }
792 else {
793 return null;
794 }
795 }
796
797
807 public ExpandoTable findByC_C_N(long companyId, long classNameId,
808 String name) throws NoSuchTableException, SystemException {
809 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
810
811 if (expandoTable == null) {
812 StringBundler msg = new StringBundler(8);
813
814 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
815
816 msg.append("companyId=");
817 msg.append(companyId);
818
819 msg.append(", classNameId=");
820 msg.append(classNameId);
821
822 msg.append(", name=");
823 msg.append(name);
824
825 msg.append(StringPool.CLOSE_CURLY_BRACE);
826
827 if (_log.isWarnEnabled()) {
828 _log.warn(msg.toString());
829 }
830
831 throw new NoSuchTableException(msg.toString());
832 }
833
834 return expandoTable;
835 }
836
837
846 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
847 String name) throws SystemException {
848 return fetchByC_C_N(companyId, classNameId, name, true);
849 }
850
851
860 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
861 String name, boolean retrieveFromCache) throws SystemException {
862 Object[] finderArgs = new Object[] { companyId, classNameId, name };
863
864 Object result = null;
865
866 if (retrieveFromCache) {
867 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
868 finderArgs, this);
869 }
870
871 if (result == null) {
872 Session session = null;
873
874 try {
875 session = openSession();
876
877 StringBundler query = new StringBundler(4);
878
879 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
880
881 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
882
883 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
884
885 if (name == null) {
886 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
887 }
888 else {
889 if (name.equals(StringPool.BLANK)) {
890 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
891 }
892 else {
893 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
894 }
895 }
896
897 String sql = query.toString();
898
899 Query q = session.createQuery(sql);
900
901 QueryPos qPos = QueryPos.getInstance(q);
902
903 qPos.add(companyId);
904
905 qPos.add(classNameId);
906
907 if (name != null) {
908 qPos.add(name);
909 }
910
911 List<ExpandoTable> list = q.list();
912
913 result = list;
914
915 ExpandoTable expandoTable = null;
916
917 if (list.isEmpty()) {
918 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
919 finderArgs, list);
920 }
921 else {
922 expandoTable = list.get(0);
923
924 cacheResult(expandoTable);
925
926 if ((expandoTable.getCompanyId() != companyId) ||
927 (expandoTable.getClassNameId() != classNameId) ||
928 (expandoTable.getName() == null) ||
929 !expandoTable.getName().equals(name)) {
930 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
931 finderArgs, expandoTable);
932 }
933 }
934
935 return expandoTable;
936 }
937 catch (Exception e) {
938 throw processException(e);
939 }
940 finally {
941 if (result == null) {
942 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
943 finderArgs, new ArrayList<ExpandoTable>());
944 }
945
946 closeSession(session);
947 }
948 }
949 else {
950 if (result instanceof List<?>) {
951 return null;
952 }
953 else {
954 return (ExpandoTable)result;
955 }
956 }
957 }
958
959
965 public List<ExpandoTable> findAll() throws SystemException {
966 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
967 }
968
969
981 public List<ExpandoTable> findAll(int start, int end)
982 throws SystemException {
983 return findAll(start, end, null);
984 }
985
986
999 public List<ExpandoTable> findAll(int start, int end,
1000 OrderByComparator orderByComparator) throws SystemException {
1001 Object[] finderArgs = new Object[] {
1002 String.valueOf(start), String.valueOf(end),
1003 String.valueOf(orderByComparator)
1004 };
1005
1006 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1007 finderArgs, this);
1008
1009 if (list == null) {
1010 Session session = null;
1011
1012 try {
1013 session = openSession();
1014
1015 StringBundler query = null;
1016 String sql = null;
1017
1018 if (orderByComparator != null) {
1019 query = new StringBundler(2 +
1020 (orderByComparator.getOrderByFields().length * 3));
1021
1022 query.append(_SQL_SELECT_EXPANDOTABLE);
1023
1024 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1025 orderByComparator);
1026
1027 sql = query.toString();
1028 }
1029 else {
1030 sql = _SQL_SELECT_EXPANDOTABLE;
1031 }
1032
1033 Query q = session.createQuery(sql);
1034
1035 if (orderByComparator == null) {
1036 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1037 start, end, false);
1038
1039 Collections.sort(list);
1040 }
1041 else {
1042 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1043 start, end);
1044 }
1045 }
1046 catch (Exception e) {
1047 throw processException(e);
1048 }
1049 finally {
1050 if (list == null) {
1051 list = new ArrayList<ExpandoTable>();
1052 }
1053
1054 cacheResult(list);
1055
1056 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1057
1058 closeSession(session);
1059 }
1060 }
1061
1062 return list;
1063 }
1064
1065
1072 public void removeByC_C(long companyId, long classNameId)
1073 throws SystemException {
1074 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId)) {
1075 remove(expandoTable);
1076 }
1077 }
1078
1079
1087 public void removeByC_C_N(long companyId, long classNameId, String name)
1088 throws NoSuchTableException, SystemException {
1089 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
1090
1091 remove(expandoTable);
1092 }
1093
1094
1099 public void removeAll() throws SystemException {
1100 for (ExpandoTable expandoTable : findAll()) {
1101 remove(expandoTable);
1102 }
1103 }
1104
1105
1113 public int countByC_C(long companyId, long classNameId)
1114 throws SystemException {
1115 Object[] finderArgs = new Object[] { companyId, classNameId };
1116
1117 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1118 finderArgs, this);
1119
1120 if (count == null) {
1121 Session session = null;
1122
1123 try {
1124 session = openSession();
1125
1126 StringBundler query = new StringBundler(3);
1127
1128 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1129
1130 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1131
1132 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1133
1134 String sql = query.toString();
1135
1136 Query q = session.createQuery(sql);
1137
1138 QueryPos qPos = QueryPos.getInstance(q);
1139
1140 qPos.add(companyId);
1141
1142 qPos.add(classNameId);
1143
1144 count = (Long)q.uniqueResult();
1145 }
1146 catch (Exception e) {
1147 throw processException(e);
1148 }
1149 finally {
1150 if (count == null) {
1151 count = Long.valueOf(0);
1152 }
1153
1154 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1155 count);
1156
1157 closeSession(session);
1158 }
1159 }
1160
1161 return count.intValue();
1162 }
1163
1164
1173 public int countByC_C_N(long companyId, long classNameId, String name)
1174 throws SystemException {
1175 Object[] finderArgs = new Object[] { companyId, classNameId, name };
1176
1177 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_N,
1178 finderArgs, this);
1179
1180 if (count == null) {
1181 Session session = null;
1182
1183 try {
1184 session = openSession();
1185
1186 StringBundler query = new StringBundler(4);
1187
1188 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1189
1190 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1191
1192 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1193
1194 if (name == null) {
1195 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1196 }
1197 else {
1198 if (name.equals(StringPool.BLANK)) {
1199 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1200 }
1201 else {
1202 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1203 }
1204 }
1205
1206 String sql = query.toString();
1207
1208 Query q = session.createQuery(sql);
1209
1210 QueryPos qPos = QueryPos.getInstance(q);
1211
1212 qPos.add(companyId);
1213
1214 qPos.add(classNameId);
1215
1216 if (name != null) {
1217 qPos.add(name);
1218 }
1219
1220 count = (Long)q.uniqueResult();
1221 }
1222 catch (Exception e) {
1223 throw processException(e);
1224 }
1225 finally {
1226 if (count == null) {
1227 count = Long.valueOf(0);
1228 }
1229
1230 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N,
1231 finderArgs, count);
1232
1233 closeSession(session);
1234 }
1235 }
1236
1237 return count.intValue();
1238 }
1239
1240
1246 public int countAll() throws SystemException {
1247 Object[] finderArgs = new Object[0];
1248
1249 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1250 finderArgs, this);
1251
1252 if (count == null) {
1253 Session session = null;
1254
1255 try {
1256 session = openSession();
1257
1258 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1259
1260 count = (Long)q.uniqueResult();
1261 }
1262 catch (Exception e) {
1263 throw processException(e);
1264 }
1265 finally {
1266 if (count == null) {
1267 count = Long.valueOf(0);
1268 }
1269
1270 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1271 count);
1272
1273 closeSession(session);
1274 }
1275 }
1276
1277 return count.intValue();
1278 }
1279
1280
1283 public void afterPropertiesSet() {
1284 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1285 com.liferay.portal.util.PropsUtil.get(
1286 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1287
1288 if (listenerClassNames.length > 0) {
1289 try {
1290 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1291
1292 for (String listenerClassName : listenerClassNames) {
1293 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1294 listenerClassName));
1295 }
1296
1297 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1298 }
1299 catch (Exception e) {
1300 _log.error(e);
1301 }
1302 }
1303 }
1304
1305 public void destroy() {
1306 EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1307 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1308 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1309 }
1310
1311 @BeanReference(type = ExpandoColumnPersistence.class)
1312 protected ExpandoColumnPersistence expandoColumnPersistence;
1313 @BeanReference(type = ExpandoRowPersistence.class)
1314 protected ExpandoRowPersistence expandoRowPersistence;
1315 @BeanReference(type = ExpandoTablePersistence.class)
1316 protected ExpandoTablePersistence expandoTablePersistence;
1317 @BeanReference(type = ExpandoValuePersistence.class)
1318 protected ExpandoValuePersistence expandoValuePersistence;
1319 @BeanReference(type = ResourcePersistence.class)
1320 protected ResourcePersistence resourcePersistence;
1321 @BeanReference(type = UserPersistence.class)
1322 protected UserPersistence userPersistence;
1323 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1324 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1325 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1326 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1327 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1328 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
1329 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1330 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
1331 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
1332 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
1333 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = ?)";
1334 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1335 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1336 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1337 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1338 }