001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.SQLQuery;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.ArrayUtil;
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.SetUtil;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.UnmodifiableList;
038 import com.liferay.portal.kernel.util.Validator;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.expando.NoSuchColumnException;
045 import com.liferay.portlet.expando.model.ExpandoColumn;
046 import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
047 import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054 import java.util.Set;
055
056
068 public class ExpandoColumnPersistenceImpl extends BasePersistenceImpl<ExpandoColumn>
069 implements ExpandoColumnPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoColumnImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
081 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
082 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
085 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
086 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
087 "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
089 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
092 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
093 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
094 "findByTableId",
095 new String[] {
096 Long.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
102 new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
103 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
104 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
105 "findByTableId", new String[] { Long.class.getName() },
106 ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
107 ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
109 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
111 new String[] { Long.class.getName() });
112
113
120 public List<ExpandoColumn> findByTableId(long tableId)
121 throws SystemException {
122 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
138 public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
139 throws SystemException {
140 return findByTableId(tableId, start, end, null);
141 }
142
143
157 public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
158 OrderByComparator orderByComparator) throws SystemException {
159 boolean pagination = true;
160 FinderPath finderPath = null;
161 Object[] finderArgs = null;
162
163 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164 (orderByComparator == null)) {
165 pagination = false;
166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
167 finderArgs = new Object[] { tableId };
168 }
169 else {
170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
171 finderArgs = new Object[] { tableId, start, end, orderByComparator };
172 }
173
174 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
175 finderArgs, this);
176
177 if ((list != null) && !list.isEmpty()) {
178 for (ExpandoColumn expandoColumn : list) {
179 if ((tableId != expandoColumn.getTableId())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(3 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(3);
196 }
197
198 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
199
200 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
201
202 if (orderByComparator != null) {
203 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
204 orderByComparator);
205 }
206 else
207 if (pagination) {
208 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
209 }
210
211 String sql = query.toString();
212
213 Session session = null;
214
215 try {
216 session = openSession();
217
218 Query q = session.createQuery(sql);
219
220 QueryPos qPos = QueryPos.getInstance(q);
221
222 qPos.add(tableId);
223
224 if (!pagination) {
225 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
226 start, end, false);
227
228 Collections.sort(list);
229
230 list = new UnmodifiableList<ExpandoColumn>(list);
231 }
232 else {
233 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
234 start, end);
235 }
236
237 cacheResult(list);
238
239 FinderCacheUtil.putResult(finderPath, finderArgs, list);
240 }
241 catch (Exception e) {
242 FinderCacheUtil.removeResult(finderPath, finderArgs);
243
244 throw processException(e);
245 }
246 finally {
247 closeSession(session);
248 }
249 }
250
251 return list;
252 }
253
254
263 public ExpandoColumn findByTableId_First(long tableId,
264 OrderByComparator orderByComparator)
265 throws NoSuchColumnException, SystemException {
266 ExpandoColumn expandoColumn = fetchByTableId_First(tableId,
267 orderByComparator);
268
269 if (expandoColumn != null) {
270 return expandoColumn;
271 }
272
273 StringBundler msg = new StringBundler(4);
274
275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
276
277 msg.append("tableId=");
278 msg.append(tableId);
279
280 msg.append(StringPool.CLOSE_CURLY_BRACE);
281
282 throw new NoSuchColumnException(msg.toString());
283 }
284
285
293 public ExpandoColumn fetchByTableId_First(long tableId,
294 OrderByComparator orderByComparator) throws SystemException {
295 List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
296 orderByComparator);
297
298 if (!list.isEmpty()) {
299 return list.get(0);
300 }
301
302 return null;
303 }
304
305
314 public ExpandoColumn findByTableId_Last(long tableId,
315 OrderByComparator orderByComparator)
316 throws NoSuchColumnException, SystemException {
317 ExpandoColumn expandoColumn = fetchByTableId_Last(tableId,
318 orderByComparator);
319
320 if (expandoColumn != null) {
321 return expandoColumn;
322 }
323
324 StringBundler msg = new StringBundler(4);
325
326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327
328 msg.append("tableId=");
329 msg.append(tableId);
330
331 msg.append(StringPool.CLOSE_CURLY_BRACE);
332
333 throw new NoSuchColumnException(msg.toString());
334 }
335
336
344 public ExpandoColumn fetchByTableId_Last(long tableId,
345 OrderByComparator orderByComparator) throws SystemException {
346 int count = countByTableId(tableId);
347
348 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
349 orderByComparator);
350
351 if (!list.isEmpty()) {
352 return list.get(0);
353 }
354
355 return null;
356 }
357
358
368 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
369 long tableId, OrderByComparator orderByComparator)
370 throws NoSuchColumnException, SystemException {
371 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 ExpandoColumn[] array = new ExpandoColumnImpl[3];
379
380 array[0] = getByTableId_PrevAndNext(session, expandoColumn,
381 tableId, orderByComparator, true);
382
383 array[1] = expandoColumn;
384
385 array[2] = getByTableId_PrevAndNext(session, expandoColumn,
386 tableId, orderByComparator, false);
387
388 return array;
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396 }
397
398 protected ExpandoColumn getByTableId_PrevAndNext(Session session,
399 ExpandoColumn expandoColumn, long tableId,
400 OrderByComparator orderByComparator, boolean previous) {
401 StringBundler query = null;
402
403 if (orderByComparator != null) {
404 query = new StringBundler(6 +
405 (orderByComparator.getOrderByFields().length * 6));
406 }
407 else {
408 query = new StringBundler(3);
409 }
410
411 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
412
413 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
414
415 if (orderByComparator != null) {
416 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
417
418 if (orderByConditionFields.length > 0) {
419 query.append(WHERE_AND);
420 }
421
422 for (int i = 0; i < orderByConditionFields.length; i++) {
423 query.append(_ORDER_BY_ENTITY_ALIAS);
424 query.append(orderByConditionFields[i]);
425
426 if ((i + 1) < orderByConditionFields.length) {
427 if (orderByComparator.isAscending() ^ previous) {
428 query.append(WHERE_GREATER_THAN_HAS_NEXT);
429 }
430 else {
431 query.append(WHERE_LESSER_THAN_HAS_NEXT);
432 }
433 }
434 else {
435 if (orderByComparator.isAscending() ^ previous) {
436 query.append(WHERE_GREATER_THAN);
437 }
438 else {
439 query.append(WHERE_LESSER_THAN);
440 }
441 }
442 }
443
444 query.append(ORDER_BY_CLAUSE);
445
446 String[] orderByFields = orderByComparator.getOrderByFields();
447
448 for (int i = 0; i < orderByFields.length; i++) {
449 query.append(_ORDER_BY_ENTITY_ALIAS);
450 query.append(orderByFields[i]);
451
452 if ((i + 1) < orderByFields.length) {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(ORDER_BY_ASC_HAS_NEXT);
455 }
456 else {
457 query.append(ORDER_BY_DESC_HAS_NEXT);
458 }
459 }
460 else {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(ORDER_BY_ASC);
463 }
464 else {
465 query.append(ORDER_BY_DESC);
466 }
467 }
468 }
469 }
470 else {
471 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
472 }
473
474 String sql = query.toString();
475
476 Query q = session.createQuery(sql);
477
478 q.setFirstResult(0);
479 q.setMaxResults(2);
480
481 QueryPos qPos = QueryPos.getInstance(q);
482
483 qPos.add(tableId);
484
485 if (orderByComparator != null) {
486 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
487
488 for (Object value : values) {
489 qPos.add(value);
490 }
491 }
492
493 List<ExpandoColumn> list = q.list();
494
495 if (list.size() == 2) {
496 return list.get(1);
497 }
498 else {
499 return null;
500 }
501 }
502
503
510 public List<ExpandoColumn> filterFindByTableId(long tableId)
511 throws SystemException {
512 return filterFindByTableId(tableId, QueryUtil.ALL_POS,
513 QueryUtil.ALL_POS, null);
514 }
515
516
529 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
530 int end) throws SystemException {
531 return filterFindByTableId(tableId, start, end, null);
532 }
533
534
548 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
549 int end, OrderByComparator orderByComparator) throws SystemException {
550 if (!InlineSQLHelperUtil.isEnabled()) {
551 return findByTableId(tableId, start, end, orderByComparator);
552 }
553
554 StringBundler query = null;
555
556 if (orderByComparator != null) {
557 query = new StringBundler(3 +
558 (orderByComparator.getOrderByFields().length * 3));
559 }
560 else {
561 query = new StringBundler(3);
562 }
563
564 if (getDB().isSupportsInlineDistinct()) {
565 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
566 }
567 else {
568 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
569 }
570
571 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
572
573 if (!getDB().isSupportsInlineDistinct()) {
574 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
575 }
576
577 if (orderByComparator != null) {
578 if (getDB().isSupportsInlineDistinct()) {
579 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
580 orderByComparator, true);
581 }
582 else {
583 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
584 orderByComparator, true);
585 }
586 }
587 else {
588 if (getDB().isSupportsInlineDistinct()) {
589 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
590 }
591 else {
592 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
593 }
594 }
595
596 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
597 ExpandoColumn.class.getName(),
598 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
599
600 Session session = null;
601
602 try {
603 session = openSession();
604
605 SQLQuery q = session.createSQLQuery(sql);
606
607 if (getDB().isSupportsInlineDistinct()) {
608 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
609 }
610 else {
611 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
612 }
613
614 QueryPos qPos = QueryPos.getInstance(q);
615
616 qPos.add(tableId);
617
618 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
619 end);
620 }
621 catch (Exception e) {
622 throw processException(e);
623 }
624 finally {
625 closeSession(session);
626 }
627 }
628
629
639 public ExpandoColumn[] filterFindByTableId_PrevAndNext(long columnId,
640 long tableId, OrderByComparator orderByComparator)
641 throws NoSuchColumnException, SystemException {
642 if (!InlineSQLHelperUtil.isEnabled()) {
643 return findByTableId_PrevAndNext(columnId, tableId,
644 orderByComparator);
645 }
646
647 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
648
649 Session session = null;
650
651 try {
652 session = openSession();
653
654 ExpandoColumn[] array = new ExpandoColumnImpl[3];
655
656 array[0] = filterGetByTableId_PrevAndNext(session, expandoColumn,
657 tableId, orderByComparator, true);
658
659 array[1] = expandoColumn;
660
661 array[2] = filterGetByTableId_PrevAndNext(session, expandoColumn,
662 tableId, orderByComparator, false);
663
664 return array;
665 }
666 catch (Exception e) {
667 throw processException(e);
668 }
669 finally {
670 closeSession(session);
671 }
672 }
673
674 protected ExpandoColumn filterGetByTableId_PrevAndNext(Session session,
675 ExpandoColumn expandoColumn, long tableId,
676 OrderByComparator orderByComparator, boolean previous) {
677 StringBundler query = null;
678
679 if (orderByComparator != null) {
680 query = new StringBundler(6 +
681 (orderByComparator.getOrderByFields().length * 6));
682 }
683 else {
684 query = new StringBundler(3);
685 }
686
687 if (getDB().isSupportsInlineDistinct()) {
688 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
689 }
690 else {
691 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
692 }
693
694 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
695
696 if (!getDB().isSupportsInlineDistinct()) {
697 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
698 }
699
700 if (orderByComparator != null) {
701 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
702
703 if (orderByConditionFields.length > 0) {
704 query.append(WHERE_AND);
705 }
706
707 for (int i = 0; i < orderByConditionFields.length; i++) {
708 if (getDB().isSupportsInlineDistinct()) {
709 query.append(_ORDER_BY_ENTITY_ALIAS);
710 }
711 else {
712 query.append(_ORDER_BY_ENTITY_TABLE);
713 }
714
715 query.append(orderByConditionFields[i]);
716
717 if ((i + 1) < orderByConditionFields.length) {
718 if (orderByComparator.isAscending() ^ previous) {
719 query.append(WHERE_GREATER_THAN_HAS_NEXT);
720 }
721 else {
722 query.append(WHERE_LESSER_THAN_HAS_NEXT);
723 }
724 }
725 else {
726 if (orderByComparator.isAscending() ^ previous) {
727 query.append(WHERE_GREATER_THAN);
728 }
729 else {
730 query.append(WHERE_LESSER_THAN);
731 }
732 }
733 }
734
735 query.append(ORDER_BY_CLAUSE);
736
737 String[] orderByFields = orderByComparator.getOrderByFields();
738
739 for (int i = 0; i < orderByFields.length; i++) {
740 if (getDB().isSupportsInlineDistinct()) {
741 query.append(_ORDER_BY_ENTITY_ALIAS);
742 }
743 else {
744 query.append(_ORDER_BY_ENTITY_TABLE);
745 }
746
747 query.append(orderByFields[i]);
748
749 if ((i + 1) < orderByFields.length) {
750 if (orderByComparator.isAscending() ^ previous) {
751 query.append(ORDER_BY_ASC_HAS_NEXT);
752 }
753 else {
754 query.append(ORDER_BY_DESC_HAS_NEXT);
755 }
756 }
757 else {
758 if (orderByComparator.isAscending() ^ previous) {
759 query.append(ORDER_BY_ASC);
760 }
761 else {
762 query.append(ORDER_BY_DESC);
763 }
764 }
765 }
766 }
767 else {
768 if (getDB().isSupportsInlineDistinct()) {
769 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
770 }
771 else {
772 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
773 }
774 }
775
776 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
777 ExpandoColumn.class.getName(),
778 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
779
780 SQLQuery q = session.createSQLQuery(sql);
781
782 q.setFirstResult(0);
783 q.setMaxResults(2);
784
785 if (getDB().isSupportsInlineDistinct()) {
786 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
787 }
788 else {
789 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
790 }
791
792 QueryPos qPos = QueryPos.getInstance(q);
793
794 qPos.add(tableId);
795
796 if (orderByComparator != null) {
797 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
798
799 for (Object value : values) {
800 qPos.add(value);
801 }
802 }
803
804 List<ExpandoColumn> list = q.list();
805
806 if (list.size() == 2) {
807 return list.get(1);
808 }
809 else {
810 return null;
811 }
812 }
813
814
820 public void removeByTableId(long tableId) throws SystemException {
821 for (ExpandoColumn expandoColumn : findByTableId(tableId,
822 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
823 remove(expandoColumn);
824 }
825 }
826
827
834 public int countByTableId(long tableId) throws SystemException {
835 FinderPath finderPath = FINDER_PATH_COUNT_BY_TABLEID;
836
837 Object[] finderArgs = new Object[] { tableId };
838
839 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
840 this);
841
842 if (count == null) {
843 StringBundler query = new StringBundler(2);
844
845 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
846
847 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
848
849 String sql = query.toString();
850
851 Session session = null;
852
853 try {
854 session = openSession();
855
856 Query q = session.createQuery(sql);
857
858 QueryPos qPos = QueryPos.getInstance(q);
859
860 qPos.add(tableId);
861
862 count = (Long)q.uniqueResult();
863
864 FinderCacheUtil.putResult(finderPath, finderArgs, count);
865 }
866 catch (Exception e) {
867 FinderCacheUtil.removeResult(finderPath, finderArgs);
868
869 throw processException(e);
870 }
871 finally {
872 closeSession(session);
873 }
874 }
875
876 return count.intValue();
877 }
878
879
886 public int filterCountByTableId(long tableId) throws SystemException {
887 if (!InlineSQLHelperUtil.isEnabled()) {
888 return countByTableId(tableId);
889 }
890
891 StringBundler query = new StringBundler(2);
892
893 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
894
895 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
896
897 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
898 ExpandoColumn.class.getName(),
899 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
900
901 Session session = null;
902
903 try {
904 session = openSession();
905
906 SQLQuery q = session.createSQLQuery(sql);
907
908 q.addScalar(COUNT_COLUMN_NAME,
909 com.liferay.portal.kernel.dao.orm.Type.LONG);
910
911 QueryPos qPos = QueryPos.getInstance(q);
912
913 qPos.add(tableId);
914
915 Long count = (Long)q.uniqueResult();
916
917 return count.intValue();
918 }
919 catch (Exception e) {
920 throw processException(e);
921 }
922 finally {
923 closeSession(session);
924 }
925 }
926
927 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
928 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
929 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
930 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
931 "findByT_N",
932 new String[] {
933 Long.class.getName(), String.class.getName(),
934
935 Integer.class.getName(), Integer.class.getName(),
936 OrderByComparator.class.getName()
937 });
938 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
939 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
940 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
941 "findByT_N",
942 new String[] { Long.class.getName(), String.class.getName() },
943 ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
944 ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
945 public static final FinderPath FINDER_PATH_FETCH_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
946 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
947 ExpandoColumnImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByT_N",
948 new String[] { Long.class.getName(), String.class.getName() },
949 ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
950 ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
951 public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
952 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
953 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_N",
954 new String[] { Long.class.getName(), String.class.getName() });
955 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
956 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
957 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByT_N",
958 new String[] { Long.class.getName(), String.class.getName() });
959
960
972 public List<ExpandoColumn> findByT_N(long tableId, String[] names)
973 throws SystemException {
974 return findByT_N(tableId, names, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
975 null);
976 }
977
978
992 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
993 int start, int end) throws SystemException {
994 return findByT_N(tableId, names, start, end, null);
995 }
996
997
1012 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1013 int start, int end, OrderByComparator orderByComparator)
1014 throws SystemException {
1015 if ((names != null) && (names.length == 1)) {
1016 ExpandoColumn expandoColumn = fetchByT_N(tableId, names[0]);
1017
1018 if (expandoColumn == null) {
1019 return Collections.emptyList();
1020 }
1021 else {
1022 List<ExpandoColumn> list = new ArrayList<ExpandoColumn>(1);
1023
1024 list.add(expandoColumn);
1025
1026 return list;
1027 }
1028 }
1029
1030 boolean pagination = true;
1031 Object[] finderArgs = null;
1032
1033 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1034 (orderByComparator == null)) {
1035 pagination = false;
1036 finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1037 }
1038 else {
1039 finderArgs = new Object[] {
1040 tableId, StringUtil.merge(names),
1041
1042 start, end, orderByComparator
1043 };
1044 }
1045
1046 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N,
1047 finderArgs, this);
1048
1049 if ((list != null) && !list.isEmpty()) {
1050 for (ExpandoColumn expandoColumn : list) {
1051 if ((tableId != expandoColumn.getTableId()) ||
1052 !ArrayUtil.contains(names, expandoColumn.getName())) {
1053 list = null;
1054
1055 break;
1056 }
1057 }
1058 }
1059
1060 if (list == null) {
1061 StringBundler query = new StringBundler();
1062
1063 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1064
1065 boolean conjunctionable = false;
1066
1067 if (conjunctionable) {
1068 query.append(WHERE_AND);
1069 }
1070
1071 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1072
1073 conjunctionable = true;
1074
1075 if ((names == null) || (names.length > 0)) {
1076 if (conjunctionable) {
1077 query.append(WHERE_AND);
1078 }
1079
1080 query.append(StringPool.OPEN_PARENTHESIS);
1081
1082 for (int i = 0; i < names.length; i++) {
1083 String name = names[i];
1084
1085 if (name == null) {
1086 query.append(_FINDER_COLUMN_T_N_NAME_4);
1087 }
1088 else if (name.equals(StringPool.BLANK)) {
1089 query.append(_FINDER_COLUMN_T_N_NAME_6);
1090 }
1091 else {
1092 query.append(_FINDER_COLUMN_T_N_NAME_5);
1093 }
1094
1095 if ((i + 1) < names.length) {
1096 query.append(WHERE_OR);
1097 }
1098 }
1099
1100 query.append(StringPool.CLOSE_PARENTHESIS);
1101
1102 conjunctionable = true;
1103 }
1104
1105 if (orderByComparator != null) {
1106 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1107 orderByComparator);
1108 }
1109 else
1110 if (pagination) {
1111 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1112 }
1113
1114 String sql = query.toString();
1115
1116 Session session = null;
1117
1118 try {
1119 session = openSession();
1120
1121 Query q = session.createQuery(sql);
1122
1123 QueryPos qPos = QueryPos.getInstance(q);
1124
1125 qPos.add(tableId);
1126
1127 if (names != null) {
1128 qPos.add(names);
1129 }
1130
1131 if (!pagination) {
1132 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1133 start, end, false);
1134
1135 Collections.sort(list);
1136
1137 list = new UnmodifiableList<ExpandoColumn>(list);
1138 }
1139 else {
1140 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1141 start, end);
1142 }
1143
1144 cacheResult(list);
1145
1146 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N,
1147 finderArgs, list);
1148 }
1149 catch (Exception e) {
1150 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N,
1151 finderArgs);
1152
1153 throw processException(e);
1154 }
1155 finally {
1156 closeSession(session);
1157 }
1158 }
1159
1160 return list;
1161 }
1162
1163
1172 public ExpandoColumn findByT_N(long tableId, String name)
1173 throws NoSuchColumnException, SystemException {
1174 ExpandoColumn expandoColumn = fetchByT_N(tableId, name);
1175
1176 if (expandoColumn == null) {
1177 StringBundler msg = new StringBundler(6);
1178
1179 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1180
1181 msg.append("tableId=");
1182 msg.append(tableId);
1183
1184 msg.append(", name=");
1185 msg.append(name);
1186
1187 msg.append(StringPool.CLOSE_CURLY_BRACE);
1188
1189 if (_log.isWarnEnabled()) {
1190 _log.warn(msg.toString());
1191 }
1192
1193 throw new NoSuchColumnException(msg.toString());
1194 }
1195
1196 return expandoColumn;
1197 }
1198
1199
1207 public ExpandoColumn fetchByT_N(long tableId, String name)
1208 throws SystemException {
1209 return fetchByT_N(tableId, name, true);
1210 }
1211
1212
1221 public ExpandoColumn fetchByT_N(long tableId, String name,
1222 boolean retrieveFromCache) throws SystemException {
1223 Object[] finderArgs = new Object[] { tableId, name };
1224
1225 Object result = null;
1226
1227 if (retrieveFromCache) {
1228 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_N,
1229 finderArgs, this);
1230 }
1231
1232 if (result instanceof ExpandoColumn) {
1233 ExpandoColumn expandoColumn = (ExpandoColumn)result;
1234
1235 if ((tableId != expandoColumn.getTableId()) ||
1236 !Validator.equals(name, expandoColumn.getName())) {
1237 result = null;
1238 }
1239 }
1240
1241 if (result == null) {
1242 StringBundler query = new StringBundler(4);
1243
1244 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1245
1246 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1247
1248 boolean bindName = false;
1249
1250 if (name == null) {
1251 query.append(_FINDER_COLUMN_T_N_NAME_1);
1252 }
1253 else if (name.equals(StringPool.BLANK)) {
1254 query.append(_FINDER_COLUMN_T_N_NAME_3);
1255 }
1256 else {
1257 bindName = true;
1258
1259 query.append(_FINDER_COLUMN_T_N_NAME_2);
1260 }
1261
1262 String sql = query.toString();
1263
1264 Session session = null;
1265
1266 try {
1267 session = openSession();
1268
1269 Query q = session.createQuery(sql);
1270
1271 QueryPos qPos = QueryPos.getInstance(q);
1272
1273 qPos.add(tableId);
1274
1275 if (bindName) {
1276 qPos.add(name);
1277 }
1278
1279 List<ExpandoColumn> list = q.list();
1280
1281 if (list.isEmpty()) {
1282 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
1283 finderArgs, list);
1284 }
1285 else {
1286 ExpandoColumn expandoColumn = list.get(0);
1287
1288 result = expandoColumn;
1289
1290 cacheResult(expandoColumn);
1291
1292 if ((expandoColumn.getTableId() != tableId) ||
1293 (expandoColumn.getName() == null) ||
1294 !expandoColumn.getName().equals(name)) {
1295 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
1296 finderArgs, expandoColumn);
1297 }
1298 }
1299 }
1300 catch (Exception e) {
1301 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
1302 finderArgs);
1303
1304 throw processException(e);
1305 }
1306 finally {
1307 closeSession(session);
1308 }
1309 }
1310
1311 if (result instanceof List<?>) {
1312 return null;
1313 }
1314 else {
1315 return (ExpandoColumn)result;
1316 }
1317 }
1318
1319
1327 public ExpandoColumn removeByT_N(long tableId, String name)
1328 throws NoSuchColumnException, SystemException {
1329 ExpandoColumn expandoColumn = findByT_N(tableId, name);
1330
1331 return remove(expandoColumn);
1332 }
1333
1334
1342 public int countByT_N(long tableId, String name) throws SystemException {
1343 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_N;
1344
1345 Object[] finderArgs = new Object[] { tableId, name };
1346
1347 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1348 this);
1349
1350 if (count == null) {
1351 StringBundler query = new StringBundler(3);
1352
1353 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1354
1355 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1356
1357 boolean bindName = false;
1358
1359 if (name == null) {
1360 query.append(_FINDER_COLUMN_T_N_NAME_1);
1361 }
1362 else if (name.equals(StringPool.BLANK)) {
1363 query.append(_FINDER_COLUMN_T_N_NAME_3);
1364 }
1365 else {
1366 bindName = true;
1367
1368 query.append(_FINDER_COLUMN_T_N_NAME_2);
1369 }
1370
1371 String sql = query.toString();
1372
1373 Session session = null;
1374
1375 try {
1376 session = openSession();
1377
1378 Query q = session.createQuery(sql);
1379
1380 QueryPos qPos = QueryPos.getInstance(q);
1381
1382 qPos.add(tableId);
1383
1384 if (bindName) {
1385 qPos.add(name);
1386 }
1387
1388 count = (Long)q.uniqueResult();
1389
1390 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1391 }
1392 catch (Exception e) {
1393 FinderCacheUtil.removeResult(finderPath, finderArgs);
1394
1395 throw processException(e);
1396 }
1397 finally {
1398 closeSession(session);
1399 }
1400 }
1401
1402 return count.intValue();
1403 }
1404
1405
1413 public int countByT_N(long tableId, String[] names)
1414 throws SystemException {
1415 Object[] finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1416
1417 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
1418 finderArgs, this);
1419
1420 if (count == null) {
1421 StringBundler query = new StringBundler();
1422
1423 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1424
1425 boolean conjunctionable = false;
1426
1427 if (conjunctionable) {
1428 query.append(WHERE_AND);
1429 }
1430
1431 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1432
1433 conjunctionable = true;
1434
1435 if ((names == null) || (names.length > 0)) {
1436 if (conjunctionable) {
1437 query.append(WHERE_AND);
1438 }
1439
1440 query.append(StringPool.OPEN_PARENTHESIS);
1441
1442 for (int i = 0; i < names.length; i++) {
1443 String name = names[i];
1444
1445 if (name == null) {
1446 query.append(_FINDER_COLUMN_T_N_NAME_4);
1447 }
1448 else if (name.equals(StringPool.BLANK)) {
1449 query.append(_FINDER_COLUMN_T_N_NAME_6);
1450 }
1451 else {
1452 query.append(_FINDER_COLUMN_T_N_NAME_5);
1453 }
1454
1455 if ((i + 1) < names.length) {
1456 query.append(WHERE_OR);
1457 }
1458 }
1459
1460 query.append(StringPool.CLOSE_PARENTHESIS);
1461
1462 conjunctionable = true;
1463 }
1464
1465 String sql = query.toString();
1466
1467 Session session = null;
1468
1469 try {
1470 session = openSession();
1471
1472 Query q = session.createQuery(sql);
1473
1474 QueryPos qPos = QueryPos.getInstance(q);
1475
1476 qPos.add(tableId);
1477
1478 if (names != null) {
1479 qPos.add(names);
1480 }
1481
1482 count = (Long)q.uniqueResult();
1483
1484 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
1485 finderArgs, count);
1486 }
1487 catch (Exception e) {
1488 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
1489 finderArgs);
1490
1491 throw processException(e);
1492 }
1493 finally {
1494 closeSession(session);
1495 }
1496 }
1497
1498 return count.intValue();
1499 }
1500
1501
1509 public int filterCountByT_N(long tableId, String name)
1510 throws SystemException {
1511 if (!InlineSQLHelperUtil.isEnabled()) {
1512 return countByT_N(tableId, name);
1513 }
1514
1515 StringBundler query = new StringBundler(3);
1516
1517 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1518
1519 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1520
1521 boolean bindName = false;
1522
1523 if (name == null) {
1524 query.append(_FINDER_COLUMN_T_N_NAME_1);
1525 }
1526 else if (name.equals(StringPool.BLANK)) {
1527 query.append(_FINDER_COLUMN_T_N_NAME_3);
1528 }
1529 else {
1530 bindName = true;
1531
1532 query.append(_FINDER_COLUMN_T_N_NAME_2);
1533 }
1534
1535 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1536 ExpandoColumn.class.getName(),
1537 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1538
1539 Session session = null;
1540
1541 try {
1542 session = openSession();
1543
1544 SQLQuery q = session.createSQLQuery(sql);
1545
1546 q.addScalar(COUNT_COLUMN_NAME,
1547 com.liferay.portal.kernel.dao.orm.Type.LONG);
1548
1549 QueryPos qPos = QueryPos.getInstance(q);
1550
1551 qPos.add(tableId);
1552
1553 if (bindName) {
1554 qPos.add(name);
1555 }
1556
1557 Long count = (Long)q.uniqueResult();
1558
1559 return count.intValue();
1560 }
1561 catch (Exception e) {
1562 throw processException(e);
1563 }
1564 finally {
1565 closeSession(session);
1566 }
1567 }
1568
1569
1577 public int filterCountByT_N(long tableId, String[] names)
1578 throws SystemException {
1579 if (!InlineSQLHelperUtil.isEnabled()) {
1580 return countByT_N(tableId, names);
1581 }
1582
1583 StringBundler query = new StringBundler();
1584
1585 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1586
1587 boolean conjunctionable = false;
1588
1589 if (conjunctionable) {
1590 query.append(WHERE_AND);
1591 }
1592
1593 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1594
1595 conjunctionable = true;
1596
1597 if ((names == null) || (names.length > 0)) {
1598 if (conjunctionable) {
1599 query.append(WHERE_AND);
1600 }
1601
1602 query.append(StringPool.OPEN_PARENTHESIS);
1603
1604 for (int i = 0; i < names.length; i++) {
1605 String name = names[i];
1606
1607 if (name == null) {
1608 query.append(_FINDER_COLUMN_T_N_NAME_4);
1609 }
1610 else if (name.equals(StringPool.BLANK)) {
1611 query.append(_FINDER_COLUMN_T_N_NAME_6);
1612 }
1613 else {
1614 query.append(_FINDER_COLUMN_T_N_NAME_5);
1615 }
1616
1617 if ((i + 1) < names.length) {
1618 query.append(WHERE_OR);
1619 }
1620 }
1621
1622 query.append(StringPool.CLOSE_PARENTHESIS);
1623
1624 conjunctionable = true;
1625 }
1626
1627 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1628 ExpandoColumn.class.getName(),
1629 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1630
1631 Session session = null;
1632
1633 try {
1634 session = openSession();
1635
1636 SQLQuery q = session.createSQLQuery(sql);
1637
1638 q.addScalar(COUNT_COLUMN_NAME,
1639 com.liferay.portal.kernel.dao.orm.Type.LONG);
1640
1641 QueryPos qPos = QueryPos.getInstance(q);
1642
1643 qPos.add(tableId);
1644
1645 if (names != null) {
1646 qPos.add(names);
1647 }
1648
1649 Long count = (Long)q.uniqueResult();
1650
1651 return count.intValue();
1652 }
1653 catch (Exception e) {
1654 throw processException(e);
1655 }
1656 finally {
1657 closeSession(session);
1658 }
1659 }
1660
1661 private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
1662 private static final String _FINDER_COLUMN_T_N_TABLEID_5 = "(" +
1663 removeConjunction(_FINDER_COLUMN_T_N_TABLEID_2) + ")";
1664 private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
1665 private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
1666 private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = '')";
1667 private static final String _FINDER_COLUMN_T_N_NAME_4 = "(" +
1668 removeConjunction(_FINDER_COLUMN_T_N_NAME_1) + ")";
1669 private static final String _FINDER_COLUMN_T_N_NAME_5 = "(" +
1670 removeConjunction(_FINDER_COLUMN_T_N_NAME_2) + ")";
1671 private static final String _FINDER_COLUMN_T_N_NAME_6 = "(" +
1672 removeConjunction(_FINDER_COLUMN_T_N_NAME_3) + ")";
1673
1674
1679 public void cacheResult(ExpandoColumn expandoColumn) {
1680 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1681 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
1682 expandoColumn);
1683
1684 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
1685 new Object[] { expandoColumn.getTableId(), expandoColumn.getName() },
1686 expandoColumn);
1687
1688 expandoColumn.resetOriginalValues();
1689 }
1690
1691
1696 public void cacheResult(List<ExpandoColumn> expandoColumns) {
1697 for (ExpandoColumn expandoColumn : expandoColumns) {
1698 if (EntityCacheUtil.getResult(
1699 ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1700 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey()) == null) {
1701 cacheResult(expandoColumn);
1702 }
1703 else {
1704 expandoColumn.resetOriginalValues();
1705 }
1706 }
1707 }
1708
1709
1716 @Override
1717 public void clearCache() {
1718 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1719 CacheRegistryUtil.clear(ExpandoColumnImpl.class.getName());
1720 }
1721
1722 EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
1723
1724 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1725 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1726 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1727 }
1728
1729
1736 @Override
1737 public void clearCache(ExpandoColumn expandoColumn) {
1738 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1739 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
1740
1741 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1742 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1743
1744 clearUniqueFindersCache(expandoColumn);
1745 }
1746
1747 @Override
1748 public void clearCache(List<ExpandoColumn> expandoColumns) {
1749 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1750 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1751
1752 for (ExpandoColumn expandoColumn : expandoColumns) {
1753 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1754 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
1755
1756 clearUniqueFindersCache(expandoColumn);
1757 }
1758 }
1759
1760 protected void cacheUniqueFindersCache(ExpandoColumn expandoColumn) {
1761 if (expandoColumn.isNew()) {
1762 Object[] args = new Object[] {
1763 expandoColumn.getTableId(), expandoColumn.getName()
1764 };
1765
1766 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, args,
1767 Long.valueOf(1));
1768 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N, args,
1769 expandoColumn);
1770 }
1771 else {
1772 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
1773
1774 if ((expandoColumnModelImpl.getColumnBitmask() &
1775 FINDER_PATH_FETCH_BY_T_N.getColumnBitmask()) != 0) {
1776 Object[] args = new Object[] {
1777 expandoColumn.getTableId(), expandoColumn.getName()
1778 };
1779
1780 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, args,
1781 Long.valueOf(1));
1782 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N, args,
1783 expandoColumn);
1784 }
1785 }
1786 }
1787
1788 protected void clearUniqueFindersCache(ExpandoColumn expandoColumn) {
1789 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
1790
1791 Object[] args = new Object[] {
1792 expandoColumn.getTableId(), expandoColumn.getName()
1793 };
1794
1795 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
1796 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N, args);
1797
1798 if ((expandoColumnModelImpl.getColumnBitmask() &
1799 FINDER_PATH_FETCH_BY_T_N.getColumnBitmask()) != 0) {
1800 args = new Object[] {
1801 expandoColumnModelImpl.getOriginalTableId(),
1802 expandoColumnModelImpl.getOriginalName()
1803 };
1804
1805 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
1806 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N, args);
1807 }
1808 }
1809
1810
1816 public ExpandoColumn create(long columnId) {
1817 ExpandoColumn expandoColumn = new ExpandoColumnImpl();
1818
1819 expandoColumn.setNew(true);
1820 expandoColumn.setPrimaryKey(columnId);
1821
1822 return expandoColumn;
1823 }
1824
1825
1833 public ExpandoColumn remove(long columnId)
1834 throws NoSuchColumnException, SystemException {
1835 return remove((Serializable)columnId);
1836 }
1837
1838
1846 @Override
1847 public ExpandoColumn remove(Serializable primaryKey)
1848 throws NoSuchColumnException, SystemException {
1849 Session session = null;
1850
1851 try {
1852 session = openSession();
1853
1854 ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
1855 primaryKey);
1856
1857 if (expandoColumn == null) {
1858 if (_log.isWarnEnabled()) {
1859 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1860 }
1861
1862 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1863 primaryKey);
1864 }
1865
1866 return remove(expandoColumn);
1867 }
1868 catch (NoSuchColumnException nsee) {
1869 throw nsee;
1870 }
1871 catch (Exception e) {
1872 throw processException(e);
1873 }
1874 finally {
1875 closeSession(session);
1876 }
1877 }
1878
1879 @Override
1880 protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
1881 throws SystemException {
1882 expandoColumn = toUnwrappedModel(expandoColumn);
1883
1884 Session session = null;
1885
1886 try {
1887 session = openSession();
1888
1889 if (!session.contains(expandoColumn)) {
1890 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
1891 expandoColumn.getPrimaryKeyObj());
1892 }
1893
1894 if (expandoColumn != null) {
1895 session.delete(expandoColumn);
1896 }
1897 }
1898 catch (Exception e) {
1899 throw processException(e);
1900 }
1901 finally {
1902 closeSession(session);
1903 }
1904
1905 if (expandoColumn != null) {
1906 clearCache(expandoColumn);
1907 }
1908
1909 return expandoColumn;
1910 }
1911
1912 @Override
1913 public ExpandoColumn updateImpl(
1914 com.liferay.portlet.expando.model.ExpandoColumn expandoColumn)
1915 throws SystemException {
1916 expandoColumn = toUnwrappedModel(expandoColumn);
1917
1918 boolean isNew = expandoColumn.isNew();
1919
1920 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
1921
1922 Session session = null;
1923
1924 try {
1925 session = openSession();
1926
1927 if (expandoColumn.isNew()) {
1928 session.save(expandoColumn);
1929
1930 expandoColumn.setNew(false);
1931 }
1932 else {
1933 session.merge(expandoColumn);
1934 }
1935 }
1936 catch (Exception e) {
1937 throw processException(e);
1938 }
1939 finally {
1940 closeSession(session);
1941 }
1942
1943 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1944
1945 if (isNew || !ExpandoColumnModelImpl.COLUMN_BITMASK_ENABLED) {
1946 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1947 }
1948
1949 else {
1950 if ((expandoColumnModelImpl.getColumnBitmask() &
1951 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
1952 Object[] args = new Object[] {
1953 expandoColumnModelImpl.getOriginalTableId()
1954 };
1955
1956 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1957 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1958 args);
1959
1960 args = new Object[] { expandoColumnModelImpl.getTableId() };
1961
1962 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1963 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1964 args);
1965 }
1966
1967 if ((expandoColumnModelImpl.getColumnBitmask() &
1968 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N.getColumnBitmask()) != 0) {
1969 Object[] args = new Object[] {
1970 expandoColumnModelImpl.getOriginalTableId(),
1971 expandoColumnModelImpl.getOriginalName()
1972 };
1973
1974 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
1975 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
1976 args);
1977
1978 args = new Object[] {
1979 expandoColumnModelImpl.getTableId(),
1980 expandoColumnModelImpl.getName()
1981 };
1982
1983 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
1984 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
1985 args);
1986 }
1987 }
1988
1989 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1990 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
1991 expandoColumn);
1992
1993 clearUniqueFindersCache(expandoColumn);
1994 cacheUniqueFindersCache(expandoColumn);
1995
1996 return expandoColumn;
1997 }
1998
1999 protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
2000 if (expandoColumn instanceof ExpandoColumnImpl) {
2001 return expandoColumn;
2002 }
2003
2004 ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
2005
2006 expandoColumnImpl.setNew(expandoColumn.isNew());
2007 expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
2008
2009 expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
2010 expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
2011 expandoColumnImpl.setTableId(expandoColumn.getTableId());
2012 expandoColumnImpl.setName(expandoColumn.getName());
2013 expandoColumnImpl.setType(expandoColumn.getType());
2014 expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
2015 expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
2016
2017 return expandoColumnImpl;
2018 }
2019
2020
2028 @Override
2029 public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
2030 throws NoSuchColumnException, SystemException {
2031 ExpandoColumn expandoColumn = fetchByPrimaryKey(primaryKey);
2032
2033 if (expandoColumn == null) {
2034 if (_log.isWarnEnabled()) {
2035 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2036 }
2037
2038 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2039 primaryKey);
2040 }
2041
2042 return expandoColumn;
2043 }
2044
2045
2053 public ExpandoColumn findByPrimaryKey(long columnId)
2054 throws NoSuchColumnException, SystemException {
2055 return findByPrimaryKey((Serializable)columnId);
2056 }
2057
2058
2065 @Override
2066 public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey)
2067 throws SystemException {
2068 ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2069 ExpandoColumnImpl.class, primaryKey);
2070
2071 if (expandoColumn == _nullExpandoColumn) {
2072 return null;
2073 }
2074
2075 if (expandoColumn == null) {
2076 Session session = null;
2077
2078 try {
2079 session = openSession();
2080
2081 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
2082 primaryKey);
2083
2084 if (expandoColumn != null) {
2085 cacheResult(expandoColumn);
2086 }
2087 else {
2088 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2089 ExpandoColumnImpl.class, primaryKey, _nullExpandoColumn);
2090 }
2091 }
2092 catch (Exception e) {
2093 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2094 ExpandoColumnImpl.class, primaryKey);
2095
2096 throw processException(e);
2097 }
2098 finally {
2099 closeSession(session);
2100 }
2101 }
2102
2103 return expandoColumn;
2104 }
2105
2106
2113 public ExpandoColumn fetchByPrimaryKey(long columnId)
2114 throws SystemException {
2115 return fetchByPrimaryKey((Serializable)columnId);
2116 }
2117
2118
2124 public List<ExpandoColumn> findAll() throws SystemException {
2125 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2126 }
2127
2128
2140 public List<ExpandoColumn> findAll(int start, int end)
2141 throws SystemException {
2142 return findAll(start, end, null);
2143 }
2144
2145
2158 public List<ExpandoColumn> findAll(int start, int end,
2159 OrderByComparator orderByComparator) throws SystemException {
2160 boolean pagination = true;
2161 FinderPath finderPath = null;
2162 Object[] finderArgs = null;
2163
2164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2165 (orderByComparator == null)) {
2166 pagination = false;
2167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2168 finderArgs = FINDER_ARGS_EMPTY;
2169 }
2170 else {
2171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2172 finderArgs = new Object[] { start, end, orderByComparator };
2173 }
2174
2175 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
2176 finderArgs, this);
2177
2178 if (list == null) {
2179 StringBundler query = null;
2180 String sql = null;
2181
2182 if (orderByComparator != null) {
2183 query = new StringBundler(2 +
2184 (orderByComparator.getOrderByFields().length * 3));
2185
2186 query.append(_SQL_SELECT_EXPANDOCOLUMN);
2187
2188 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2189 orderByComparator);
2190
2191 sql = query.toString();
2192 }
2193 else {
2194 sql = _SQL_SELECT_EXPANDOCOLUMN;
2195
2196 if (pagination) {
2197 sql = sql.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2198 }
2199 }
2200
2201 Session session = null;
2202
2203 try {
2204 session = openSession();
2205
2206 Query q = session.createQuery(sql);
2207
2208 if (!pagination) {
2209 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2210 start, end, false);
2211
2212 Collections.sort(list);
2213
2214 list = new UnmodifiableList<ExpandoColumn>(list);
2215 }
2216 else {
2217 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2218 start, end);
2219 }
2220
2221 cacheResult(list);
2222
2223 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2224 }
2225 catch (Exception e) {
2226 FinderCacheUtil.removeResult(finderPath, finderArgs);
2227
2228 throw processException(e);
2229 }
2230 finally {
2231 closeSession(session);
2232 }
2233 }
2234
2235 return list;
2236 }
2237
2238
2243 public void removeAll() throws SystemException {
2244 for (ExpandoColumn expandoColumn : findAll()) {
2245 remove(expandoColumn);
2246 }
2247 }
2248
2249
2255 public int countAll() throws SystemException {
2256 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2257 FINDER_ARGS_EMPTY, this);
2258
2259 if (count == null) {
2260 Session session = null;
2261
2262 try {
2263 session = openSession();
2264
2265 Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
2266
2267 count = (Long)q.uniqueResult();
2268
2269 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2270 FINDER_ARGS_EMPTY, count);
2271 }
2272 catch (Exception e) {
2273 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2274 FINDER_ARGS_EMPTY);
2275
2276 throw processException(e);
2277 }
2278 finally {
2279 closeSession(session);
2280 }
2281 }
2282
2283 return count.intValue();
2284 }
2285
2286 @Override
2287 protected Set<String> getBadColumnNames() {
2288 return _badColumnNames;
2289 }
2290
2291
2294 public void afterPropertiesSet() {
2295 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2296 com.liferay.portal.util.PropsUtil.get(
2297 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
2298
2299 if (listenerClassNames.length > 0) {
2300 try {
2301 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
2302
2303 for (String listenerClassName : listenerClassNames) {
2304 listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
2305 getClassLoader(), listenerClassName));
2306 }
2307
2308 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2309 }
2310 catch (Exception e) {
2311 _log.error(e);
2312 }
2313 }
2314 }
2315
2316 public void destroy() {
2317 EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
2318 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2319 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2320 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2321 }
2322
2323 private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
2324 private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
2325 private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
2326 private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
2327 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "expandoColumn.columnId";
2328 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
2329 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
2330 "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
2331 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
2332 ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
2333 private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
2334 private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
2335 private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
2336 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
2337 private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
2338 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
2339 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
2340 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2341 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
2342 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2343 "type"
2344 });
2345 private static ExpandoColumn _nullExpandoColumn = new ExpandoColumnImpl() {
2346 @Override
2347 public Object clone() {
2348 return this;
2349 }
2350
2351 @Override
2352 public CacheModel<ExpandoColumn> toCacheModel() {
2353 return _nullExpandoColumnCacheModel;
2354 }
2355 };
2356
2357 private static CacheModel<ExpandoColumn> _nullExpandoColumnCacheModel = new CacheModel<ExpandoColumn>() {
2358 public ExpandoColumn toEntityModel() {
2359 return _nullExpandoColumn;
2360 }
2361 };
2362 }