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 if (expandoTable.isCachedModel() || BatchSessionUtil.isEnabled()) {
255 Object staleObject = session.get(ExpandoTableImpl.class,
256 expandoTable.getPrimaryKeyObj());
257
258 if (staleObject != null) {
259 session.evict(staleObject);
260 }
261 }
262
263 session.delete(expandoTable);
264
265 session.flush();
266 }
267 catch (Exception e) {
268 throw processException(e);
269 }
270 finally {
271 closeSession(session);
272 }
273
274 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
275
276 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
277
278 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
279 new Object[] {
280 new Long(expandoTableModelImpl.getOriginalCompanyId()),
281 new Long(expandoTableModelImpl.getOriginalClassNameId()),
282
283 expandoTableModelImpl.getOriginalName()
284 });
285
286 EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
287 ExpandoTableImpl.class, expandoTable.getPrimaryKey());
288
289 return expandoTable;
290 }
291
292 public ExpandoTable updateImpl(
293 com.liferay.portlet.expando.model.ExpandoTable expandoTable,
294 boolean merge) throws SystemException {
295 expandoTable = toUnwrappedModel(expandoTable);
296
297 boolean isNew = expandoTable.isNew();
298
299 ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
300
301 Session session = null;
302
303 try {
304 session = openSession();
305
306 BatchSessionUtil.update(session, expandoTable, merge);
307
308 expandoTable.setNew(false);
309 }
310 catch (Exception e) {
311 throw processException(e);
312 }
313 finally {
314 closeSession(session);
315 }
316
317 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
318
319 EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
320 ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
321
322 if (!isNew &&
323 ((expandoTable.getCompanyId() != expandoTableModelImpl.getOriginalCompanyId()) ||
324 (expandoTable.getClassNameId() != expandoTableModelImpl.getOriginalClassNameId()) ||
325 !Validator.equals(expandoTable.getName(),
326 expandoTableModelImpl.getOriginalName()))) {
327 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
328 new Object[] {
329 new Long(expandoTableModelImpl.getOriginalCompanyId()),
330 new Long(expandoTableModelImpl.getOriginalClassNameId()),
331
332 expandoTableModelImpl.getOriginalName()
333 });
334 }
335
336 if (isNew ||
337 ((expandoTable.getCompanyId() != expandoTableModelImpl.getOriginalCompanyId()) ||
338 (expandoTable.getClassNameId() != expandoTableModelImpl.getOriginalClassNameId()) ||
339 !Validator.equals(expandoTable.getName(),
340 expandoTableModelImpl.getOriginalName()))) {
341 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
342 new Object[] {
343 new Long(expandoTable.getCompanyId()),
344 new Long(expandoTable.getClassNameId()),
345
346 expandoTable.getName()
347 }, expandoTable);
348 }
349
350 return expandoTable;
351 }
352
353 protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
354 if (expandoTable instanceof ExpandoTableImpl) {
355 return expandoTable;
356 }
357
358 ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
359
360 expandoTableImpl.setNew(expandoTable.isNew());
361 expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
362
363 expandoTableImpl.setTableId(expandoTable.getTableId());
364 expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
365 expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
366 expandoTableImpl.setName(expandoTable.getName());
367
368 return expandoTableImpl;
369 }
370
371
379 public ExpandoTable findByPrimaryKey(Serializable primaryKey)
380 throws NoSuchModelException, SystemException {
381 return findByPrimaryKey(((Long)primaryKey).longValue());
382 }
383
384
392 public ExpandoTable findByPrimaryKey(long tableId)
393 throws NoSuchTableException, SystemException {
394 ExpandoTable expandoTable = fetchByPrimaryKey(tableId);
395
396 if (expandoTable == null) {
397 if (_log.isWarnEnabled()) {
398 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
399 }
400
401 throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
402 tableId);
403 }
404
405 return expandoTable;
406 }
407
408
415 public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
416 throws SystemException {
417 return fetchByPrimaryKey(((Long)primaryKey).longValue());
418 }
419
420
427 public ExpandoTable fetchByPrimaryKey(long tableId)
428 throws SystemException {
429 ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
430 ExpandoTableImpl.class, tableId, this);
431
432 if (expandoTable == null) {
433 Session session = null;
434
435 try {
436 session = openSession();
437
438 expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
439 new Long(tableId));
440 }
441 catch (Exception e) {
442 throw processException(e);
443 }
444 finally {
445 if (expandoTable != null) {
446 cacheResult(expandoTable);
447 }
448
449 closeSession(session);
450 }
451 }
452
453 return expandoTable;
454 }
455
456
464 public List<ExpandoTable> findByC_C(long companyId, long classNameId)
465 throws SystemException {
466 return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
467 QueryUtil.ALL_POS, null);
468 }
469
470
484 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
485 int start, int end) throws SystemException {
486 return findByC_C(companyId, classNameId, start, end, null);
487 }
488
489
504 public List<ExpandoTable> findByC_C(long companyId, long classNameId,
505 int start, int end, OrderByComparator orderByComparator)
506 throws SystemException {
507 Object[] finderArgs = new Object[] {
508 companyId, classNameId,
509
510 String.valueOf(start), String.valueOf(end),
511 String.valueOf(orderByComparator)
512 };
513
514 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
515 finderArgs, this);
516
517 if (list == null) {
518 Session session = null;
519
520 try {
521 session = openSession();
522
523 StringBundler query = null;
524
525 if (orderByComparator != null) {
526 query = new StringBundler(4 +
527 (orderByComparator.getOrderByFields().length * 3));
528 }
529 else {
530 query = new StringBundler(3);
531 }
532
533 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
534
535 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
536
537 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
538
539 if (orderByComparator != null) {
540 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
541 orderByComparator);
542 }
543
544 String sql = query.toString();
545
546 Query q = session.createQuery(sql);
547
548 QueryPos qPos = QueryPos.getInstance(q);
549
550 qPos.add(companyId);
551
552 qPos.add(classNameId);
553
554 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
555 start, end);
556 }
557 catch (Exception e) {
558 throw processException(e);
559 }
560 finally {
561 if (list == null) {
562 list = new ArrayList<ExpandoTable>();
563 }
564
565 cacheResult(list);
566
567 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
568 list);
569
570 closeSession(session);
571 }
572 }
573
574 return list;
575 }
576
577
591 public ExpandoTable findByC_C_First(long companyId, long classNameId,
592 OrderByComparator orderByComparator)
593 throws NoSuchTableException, SystemException {
594 List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
595 orderByComparator);
596
597 if (list.isEmpty()) {
598 StringBundler msg = new StringBundler(6);
599
600 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
601
602 msg.append("companyId=");
603 msg.append(companyId);
604
605 msg.append(", classNameId=");
606 msg.append(classNameId);
607
608 msg.append(StringPool.CLOSE_CURLY_BRACE);
609
610 throw new NoSuchTableException(msg.toString());
611 }
612 else {
613 return list.get(0);
614 }
615 }
616
617
631 public ExpandoTable findByC_C_Last(long companyId, long classNameId,
632 OrderByComparator orderByComparator)
633 throws NoSuchTableException, SystemException {
634 int count = countByC_C(companyId, classNameId);
635
636 List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
637 count, orderByComparator);
638
639 if (list.isEmpty()) {
640 StringBundler msg = new StringBundler(6);
641
642 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
643
644 msg.append("companyId=");
645 msg.append(companyId);
646
647 msg.append(", classNameId=");
648 msg.append(classNameId);
649
650 msg.append(StringPool.CLOSE_CURLY_BRACE);
651
652 throw new NoSuchTableException(msg.toString());
653 }
654 else {
655 return list.get(0);
656 }
657 }
658
659
674 public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
675 long classNameId, OrderByComparator orderByComparator)
676 throws NoSuchTableException, SystemException {
677 ExpandoTable expandoTable = findByPrimaryKey(tableId);
678
679 Session session = null;
680
681 try {
682 session = openSession();
683
684 ExpandoTable[] array = new ExpandoTableImpl[3];
685
686 array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
687 classNameId, orderByComparator, true);
688
689 array[1] = expandoTable;
690
691 array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
692 classNameId, orderByComparator, false);
693
694 return array;
695 }
696 catch (Exception e) {
697 throw processException(e);
698 }
699 finally {
700 closeSession(session);
701 }
702 }
703
704 protected ExpandoTable getByC_C_PrevAndNext(Session session,
705 ExpandoTable expandoTable, long companyId, long classNameId,
706 OrderByComparator orderByComparator, boolean previous) {
707 StringBundler query = null;
708
709 if (orderByComparator != null) {
710 query = new StringBundler(6 +
711 (orderByComparator.getOrderByFields().length * 6));
712 }
713 else {
714 query = new StringBundler(3);
715 }
716
717 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
718
719 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
720
721 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
722
723 if (orderByComparator != null) {
724 String[] orderByFields = orderByComparator.getOrderByFields();
725
726 if (orderByFields.length > 0) {
727 query.append(WHERE_AND);
728 }
729
730 for (int i = 0; i < orderByFields.length; i++) {
731 query.append(_ORDER_BY_ENTITY_ALIAS);
732 query.append(orderByFields[i]);
733
734 if ((i + 1) < orderByFields.length) {
735 if (orderByComparator.isAscending() ^ previous) {
736 query.append(WHERE_GREATER_THAN_HAS_NEXT);
737 }
738 else {
739 query.append(WHERE_LESSER_THAN_HAS_NEXT);
740 }
741 }
742 else {
743 if (orderByComparator.isAscending() ^ previous) {
744 query.append(WHERE_GREATER_THAN);
745 }
746 else {
747 query.append(WHERE_LESSER_THAN);
748 }
749 }
750 }
751
752 query.append(ORDER_BY_CLAUSE);
753
754 for (int i = 0; i < orderByFields.length; i++) {
755 query.append(_ORDER_BY_ENTITY_ALIAS);
756 query.append(orderByFields[i]);
757
758 if ((i + 1) < orderByFields.length) {
759 if (orderByComparator.isAscending() ^ previous) {
760 query.append(ORDER_BY_ASC_HAS_NEXT);
761 }
762 else {
763 query.append(ORDER_BY_DESC_HAS_NEXT);
764 }
765 }
766 else {
767 if (orderByComparator.isAscending() ^ previous) {
768 query.append(ORDER_BY_ASC);
769 }
770 else {
771 query.append(ORDER_BY_DESC);
772 }
773 }
774 }
775 }
776
777 String sql = query.toString();
778
779 Query q = session.createQuery(sql);
780
781 q.setFirstResult(0);
782 q.setMaxResults(2);
783
784 QueryPos qPos = QueryPos.getInstance(q);
785
786 qPos.add(companyId);
787
788 qPos.add(classNameId);
789
790 if (orderByComparator != null) {
791 Object[] values = orderByComparator.getOrderByValues(expandoTable);
792
793 for (Object value : values) {
794 qPos.add(value);
795 }
796 }
797
798 List<ExpandoTable> list = q.list();
799
800 if (list.size() == 2) {
801 return list.get(1);
802 }
803 else {
804 return null;
805 }
806 }
807
808
818 public ExpandoTable findByC_C_N(long companyId, long classNameId,
819 String name) throws NoSuchTableException, SystemException {
820 ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
821
822 if (expandoTable == null) {
823 StringBundler msg = new StringBundler(8);
824
825 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
826
827 msg.append("companyId=");
828 msg.append(companyId);
829
830 msg.append(", classNameId=");
831 msg.append(classNameId);
832
833 msg.append(", name=");
834 msg.append(name);
835
836 msg.append(StringPool.CLOSE_CURLY_BRACE);
837
838 if (_log.isWarnEnabled()) {
839 _log.warn(msg.toString());
840 }
841
842 throw new NoSuchTableException(msg.toString());
843 }
844
845 return expandoTable;
846 }
847
848
857 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
858 String name) throws SystemException {
859 return fetchByC_C_N(companyId, classNameId, name, true);
860 }
861
862
871 public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
872 String name, boolean retrieveFromCache) throws SystemException {
873 Object[] finderArgs = new Object[] { companyId, classNameId, name };
874
875 Object result = null;
876
877 if (retrieveFromCache) {
878 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
879 finderArgs, this);
880 }
881
882 if (result == null) {
883 Session session = null;
884
885 try {
886 session = openSession();
887
888 StringBundler query = new StringBundler(4);
889
890 query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
891
892 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
893
894 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
895
896 if (name == null) {
897 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
898 }
899 else {
900 if (name.equals(StringPool.BLANK)) {
901 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
902 }
903 else {
904 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
905 }
906 }
907
908 String sql = query.toString();
909
910 Query q = session.createQuery(sql);
911
912 QueryPos qPos = QueryPos.getInstance(q);
913
914 qPos.add(companyId);
915
916 qPos.add(classNameId);
917
918 if (name != null) {
919 qPos.add(name);
920 }
921
922 List<ExpandoTable> list = q.list();
923
924 result = list;
925
926 ExpandoTable expandoTable = null;
927
928 if (list.isEmpty()) {
929 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
930 finderArgs, list);
931 }
932 else {
933 expandoTable = list.get(0);
934
935 cacheResult(expandoTable);
936
937 if ((expandoTable.getCompanyId() != companyId) ||
938 (expandoTable.getClassNameId() != classNameId) ||
939 (expandoTable.getName() == null) ||
940 !expandoTable.getName().equals(name)) {
941 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
942 finderArgs, expandoTable);
943 }
944 }
945
946 return expandoTable;
947 }
948 catch (Exception e) {
949 throw processException(e);
950 }
951 finally {
952 if (result == null) {
953 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
954 finderArgs, new ArrayList<ExpandoTable>());
955 }
956
957 closeSession(session);
958 }
959 }
960 else {
961 if (result instanceof List<?>) {
962 return null;
963 }
964 else {
965 return (ExpandoTable)result;
966 }
967 }
968 }
969
970
976 public List<ExpandoTable> findAll() throws SystemException {
977 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
978 }
979
980
992 public List<ExpandoTable> findAll(int start, int end)
993 throws SystemException {
994 return findAll(start, end, null);
995 }
996
997
1010 public List<ExpandoTable> findAll(int start, int end,
1011 OrderByComparator orderByComparator) throws SystemException {
1012 Object[] finderArgs = new Object[] {
1013 String.valueOf(start), String.valueOf(end),
1014 String.valueOf(orderByComparator)
1015 };
1016
1017 List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1018 finderArgs, this);
1019
1020 if (list == null) {
1021 Session session = null;
1022
1023 try {
1024 session = openSession();
1025
1026 StringBundler query = null;
1027 String sql = null;
1028
1029 if (orderByComparator != null) {
1030 query = new StringBundler(2 +
1031 (orderByComparator.getOrderByFields().length * 3));
1032
1033 query.append(_SQL_SELECT_EXPANDOTABLE);
1034
1035 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1036 orderByComparator);
1037
1038 sql = query.toString();
1039 }
1040 else {
1041 sql = _SQL_SELECT_EXPANDOTABLE;
1042 }
1043
1044 Query q = session.createQuery(sql);
1045
1046 if (orderByComparator == null) {
1047 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1048 start, end, false);
1049
1050 Collections.sort(list);
1051 }
1052 else {
1053 list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1054 start, end);
1055 }
1056 }
1057 catch (Exception e) {
1058 throw processException(e);
1059 }
1060 finally {
1061 if (list == null) {
1062 list = new ArrayList<ExpandoTable>();
1063 }
1064
1065 cacheResult(list);
1066
1067 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1068
1069 closeSession(session);
1070 }
1071 }
1072
1073 return list;
1074 }
1075
1076
1083 public void removeByC_C(long companyId, long classNameId)
1084 throws SystemException {
1085 for (ExpandoTable expandoTable : findByC_C(companyId, classNameId)) {
1086 remove(expandoTable);
1087 }
1088 }
1089
1090
1098 public void removeByC_C_N(long companyId, long classNameId, String name)
1099 throws NoSuchTableException, SystemException {
1100 ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
1101
1102 remove(expandoTable);
1103 }
1104
1105
1110 public void removeAll() throws SystemException {
1111 for (ExpandoTable expandoTable : findAll()) {
1112 remove(expandoTable);
1113 }
1114 }
1115
1116
1124 public int countByC_C(long companyId, long classNameId)
1125 throws SystemException {
1126 Object[] finderArgs = new Object[] { companyId, classNameId };
1127
1128 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1129 finderArgs, this);
1130
1131 if (count == null) {
1132 Session session = null;
1133
1134 try {
1135 session = openSession();
1136
1137 StringBundler query = new StringBundler(3);
1138
1139 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1140
1141 query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1142
1143 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1144
1145 String sql = query.toString();
1146
1147 Query q = session.createQuery(sql);
1148
1149 QueryPos qPos = QueryPos.getInstance(q);
1150
1151 qPos.add(companyId);
1152
1153 qPos.add(classNameId);
1154
1155 count = (Long)q.uniqueResult();
1156 }
1157 catch (Exception e) {
1158 throw processException(e);
1159 }
1160 finally {
1161 if (count == null) {
1162 count = Long.valueOf(0);
1163 }
1164
1165 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1166 count);
1167
1168 closeSession(session);
1169 }
1170 }
1171
1172 return count.intValue();
1173 }
1174
1175
1184 public int countByC_C_N(long companyId, long classNameId, String name)
1185 throws SystemException {
1186 Object[] finderArgs = new Object[] { companyId, classNameId, name };
1187
1188 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_N,
1189 finderArgs, this);
1190
1191 if (count == null) {
1192 Session session = null;
1193
1194 try {
1195 session = openSession();
1196
1197 StringBundler query = new StringBundler(4);
1198
1199 query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1200
1201 query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1202
1203 query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1204
1205 if (name == null) {
1206 query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1207 }
1208 else {
1209 if (name.equals(StringPool.BLANK)) {
1210 query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1211 }
1212 else {
1213 query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1214 }
1215 }
1216
1217 String sql = query.toString();
1218
1219 Query q = session.createQuery(sql);
1220
1221 QueryPos qPos = QueryPos.getInstance(q);
1222
1223 qPos.add(companyId);
1224
1225 qPos.add(classNameId);
1226
1227 if (name != null) {
1228 qPos.add(name);
1229 }
1230
1231 count = (Long)q.uniqueResult();
1232 }
1233 catch (Exception e) {
1234 throw processException(e);
1235 }
1236 finally {
1237 if (count == null) {
1238 count = Long.valueOf(0);
1239 }
1240
1241 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N,
1242 finderArgs, count);
1243
1244 closeSession(session);
1245 }
1246 }
1247
1248 return count.intValue();
1249 }
1250
1251
1257 public int countAll() throws SystemException {
1258 Object[] finderArgs = new Object[0];
1259
1260 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1261 finderArgs, this);
1262
1263 if (count == null) {
1264 Session session = null;
1265
1266 try {
1267 session = openSession();
1268
1269 Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1270
1271 count = (Long)q.uniqueResult();
1272 }
1273 catch (Exception e) {
1274 throw processException(e);
1275 }
1276 finally {
1277 if (count == null) {
1278 count = Long.valueOf(0);
1279 }
1280
1281 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1282 count);
1283
1284 closeSession(session);
1285 }
1286 }
1287
1288 return count.intValue();
1289 }
1290
1291
1294 public void afterPropertiesSet() {
1295 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1296 com.liferay.portal.util.PropsUtil.get(
1297 "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1298
1299 if (listenerClassNames.length > 0) {
1300 try {
1301 List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1302
1303 for (String listenerClassName : listenerClassNames) {
1304 listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1305 listenerClassName));
1306 }
1307
1308 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1309 }
1310 catch (Exception e) {
1311 _log.error(e);
1312 }
1313 }
1314 }
1315
1316 @BeanReference(type = ExpandoColumnPersistence.class)
1317 protected ExpandoColumnPersistence expandoColumnPersistence;
1318 @BeanReference(type = ExpandoRowPersistence.class)
1319 protected ExpandoRowPersistence expandoRowPersistence;
1320 @BeanReference(type = ExpandoTablePersistence.class)
1321 protected ExpandoTablePersistence expandoTablePersistence;
1322 @BeanReference(type = ExpandoValuePersistence.class)
1323 protected ExpandoValuePersistence expandoValuePersistence;
1324 @BeanReference(type = ResourcePersistence.class)
1325 protected ResourcePersistence resourcePersistence;
1326 @BeanReference(type = UserPersistence.class)
1327 protected UserPersistence userPersistence;
1328 private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1329 private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1330 private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1331 private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1332 private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1333 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
1334 private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1335 private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
1336 private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
1337 private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
1338 private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = ?)";
1339 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1340 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1341 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1342 private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1343 }