001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
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.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.expando.NoSuchColumnException;
046 import com.liferay.portlet.expando.model.ExpandoColumn;
047 import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
048 import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
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_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
081 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
082 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findByTableId",
084 new String[] {
085 Long.class.getName(),
086
087 "java.lang.Integer", "java.lang.Integer",
088 "com.liferay.portal.kernel.util.OrderByComparator"
089 });
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
091 new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
092 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
093 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
094 "findByTableId", new String[] { Long.class.getName() },
095 ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK);
096 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
097 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
099 new String[] { Long.class.getName() });
100 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
101 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
102 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
103 "findByT_N",
104 new String[] {
105 Long.class.getName(), String.class.getName(),
106
107 "java.lang.Integer", "java.lang.Integer",
108 "com.liferay.portal.kernel.util.OrderByComparator"
109 });
110 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
111 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
112 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
113 "findByT_N",
114 new String[] { Long.class.getName(), String.class.getName() },
115 ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
116 ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
117 public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
118 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
119 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_N",
120 new String[] { Long.class.getName(), String.class.getName() });
121 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
122 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
123 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
124 "findAll", new String[0]);
125 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
126 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
127 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
128 "findAll", new String[0]);
129 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
130 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
131 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
132
133
138 public void cacheResult(ExpandoColumn expandoColumn) {
139 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
140 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
141 expandoColumn);
142
143 expandoColumn.resetOriginalValues();
144 }
145
146
151 public void cacheResult(List<ExpandoColumn> expandoColumns) {
152 for (ExpandoColumn expandoColumn : expandoColumns) {
153 if (EntityCacheUtil.getResult(
154 ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
155 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey()) == null) {
156 cacheResult(expandoColumn);
157 }
158 else {
159 expandoColumn.resetOriginalValues();
160 }
161 }
162 }
163
164
171 @Override
172 public void clearCache() {
173 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
174 CacheRegistryUtil.clear(ExpandoColumnImpl.class.getName());
175 }
176
177 EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
178
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
181 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
182 }
183
184
191 @Override
192 public void clearCache(ExpandoColumn expandoColumn) {
193 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
194 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
195
196 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
197 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
198 }
199
200
206 public ExpandoColumn create(long columnId) {
207 ExpandoColumn expandoColumn = new ExpandoColumnImpl();
208
209 expandoColumn.setNew(true);
210 expandoColumn.setPrimaryKey(columnId);
211
212 return expandoColumn;
213 }
214
215
223 @Override
224 public ExpandoColumn remove(Serializable primaryKey)
225 throws NoSuchModelException, SystemException {
226 return remove(((Long)primaryKey).longValue());
227 }
228
229
237 public ExpandoColumn remove(long columnId)
238 throws NoSuchColumnException, SystemException {
239 Session session = null;
240
241 try {
242 session = openSession();
243
244 ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
245 Long.valueOf(columnId));
246
247 if (expandoColumn == null) {
248 if (_log.isWarnEnabled()) {
249 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
250 }
251
252 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
253 columnId);
254 }
255
256 return expandoColumnPersistence.remove(expandoColumn);
257 }
258 catch (NoSuchColumnException nsee) {
259 throw nsee;
260 }
261 catch (Exception e) {
262 throw processException(e);
263 }
264 finally {
265 closeSession(session);
266 }
267 }
268
269
276 @Override
277 public ExpandoColumn remove(ExpandoColumn expandoColumn)
278 throws SystemException {
279 return super.remove(expandoColumn);
280 }
281
282 @Override
283 protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
284 throws SystemException {
285 expandoColumn = toUnwrappedModel(expandoColumn);
286
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 BatchSessionUtil.delete(session, expandoColumn);
293 }
294 catch (Exception e) {
295 throw processException(e);
296 }
297 finally {
298 closeSession(session);
299 }
300
301 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
302 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
303
304 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
305 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
306
307 return expandoColumn;
308 }
309
310 @Override
311 public ExpandoColumn updateImpl(
312 com.liferay.portlet.expando.model.ExpandoColumn expandoColumn,
313 boolean merge) throws SystemException {
314 expandoColumn = toUnwrappedModel(expandoColumn);
315
316 boolean isNew = expandoColumn.isNew();
317
318 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
319
320 Session session = null;
321
322 try {
323 session = openSession();
324
325 BatchSessionUtil.update(session, expandoColumn, merge);
326
327 expandoColumn.setNew(false);
328 }
329 catch (Exception e) {
330 throw processException(e);
331 }
332 finally {
333 closeSession(session);
334 }
335
336 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
337
338 if (isNew || !ExpandoColumnModelImpl.COLUMN_BITMASK_ENABLED) {
339 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
340 }
341
342 else {
343 if ((expandoColumnModelImpl.getColumnBitmask() &
344 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
345 Object[] args = new Object[] {
346 Long.valueOf(expandoColumnModelImpl.getOriginalTableId())
347 };
348
349 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
350 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
351 args);
352
353 args = new Object[] {
354 Long.valueOf(expandoColumnModelImpl.getTableId())
355 };
356
357 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
358 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
359 args);
360 }
361
362 if ((expandoColumnModelImpl.getColumnBitmask() &
363 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N.getColumnBitmask()) != 0) {
364 Object[] args = new Object[] {
365 Long.valueOf(expandoColumnModelImpl.getOriginalTableId()),
366
367 expandoColumnModelImpl.getOriginalName()
368 };
369
370 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
371 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
372 args);
373
374 args = new Object[] {
375 Long.valueOf(expandoColumnModelImpl.getTableId()),
376
377 expandoColumnModelImpl.getName()
378 };
379
380 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
381 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
382 args);
383 }
384 }
385
386 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
387 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
388 expandoColumn);
389
390 return expandoColumn;
391 }
392
393 protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
394 if (expandoColumn instanceof ExpandoColumnImpl) {
395 return expandoColumn;
396 }
397
398 ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
399
400 expandoColumnImpl.setNew(expandoColumn.isNew());
401 expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
402
403 expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
404 expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
405 expandoColumnImpl.setTableId(expandoColumn.getTableId());
406 expandoColumnImpl.setName(expandoColumn.getName());
407 expandoColumnImpl.setType(expandoColumn.getType());
408 expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
409 expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
410
411 return expandoColumnImpl;
412 }
413
414
422 @Override
423 public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
424 throws NoSuchModelException, SystemException {
425 return findByPrimaryKey(((Long)primaryKey).longValue());
426 }
427
428
436 public ExpandoColumn findByPrimaryKey(long columnId)
437 throws NoSuchColumnException, SystemException {
438 ExpandoColumn expandoColumn = fetchByPrimaryKey(columnId);
439
440 if (expandoColumn == null) {
441 if (_log.isWarnEnabled()) {
442 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
443 }
444
445 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
446 columnId);
447 }
448
449 return expandoColumn;
450 }
451
452
459 @Override
460 public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey)
461 throws SystemException {
462 return fetchByPrimaryKey(((Long)primaryKey).longValue());
463 }
464
465
472 public ExpandoColumn fetchByPrimaryKey(long columnId)
473 throws SystemException {
474 ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
475 ExpandoColumnImpl.class, columnId);
476
477 if (expandoColumn == _nullExpandoColumn) {
478 return null;
479 }
480
481 if (expandoColumn == null) {
482 Session session = null;
483
484 boolean hasException = false;
485
486 try {
487 session = openSession();
488
489 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
490 Long.valueOf(columnId));
491 }
492 catch (Exception e) {
493 hasException = true;
494
495 throw processException(e);
496 }
497 finally {
498 if (expandoColumn != null) {
499 cacheResult(expandoColumn);
500 }
501 else if (!hasException) {
502 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
503 ExpandoColumnImpl.class, columnId, _nullExpandoColumn);
504 }
505
506 closeSession(session);
507 }
508 }
509
510 return expandoColumn;
511 }
512
513
520 public List<ExpandoColumn> findByTableId(long tableId)
521 throws SystemException {
522 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
523 }
524
525
538 public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
539 throws SystemException {
540 return findByTableId(tableId, start, end, null);
541 }
542
543
557 public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
558 OrderByComparator orderByComparator) throws SystemException {
559 FinderPath finderPath = null;
560 Object[] finderArgs = null;
561
562 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
563 (orderByComparator == null)) {
564 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
565 finderArgs = new Object[] { tableId };
566 }
567 else {
568 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
569 finderArgs = new Object[] { tableId, start, end, orderByComparator };
570 }
571
572 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
573 finderArgs, this);
574
575 if (list == null) {
576 StringBundler query = null;
577
578 if (orderByComparator != null) {
579 query = new StringBundler(3 +
580 (orderByComparator.getOrderByFields().length * 3));
581 }
582 else {
583 query = new StringBundler(3);
584 }
585
586 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
587
588 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
589
590 if (orderByComparator != null) {
591 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
592 orderByComparator);
593 }
594
595 else {
596 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
597 }
598
599 String sql = query.toString();
600
601 Session session = null;
602
603 try {
604 session = openSession();
605
606 Query q = session.createQuery(sql);
607
608 QueryPos qPos = QueryPos.getInstance(q);
609
610 qPos.add(tableId);
611
612 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
613 start, end);
614 }
615 catch (Exception e) {
616 throw processException(e);
617 }
618 finally {
619 if (list == null) {
620 FinderCacheUtil.removeResult(finderPath, finderArgs);
621 }
622 else {
623 cacheResult(list);
624
625 FinderCacheUtil.putResult(finderPath, finderArgs, list);
626 }
627
628 closeSession(session);
629 }
630 }
631
632 return list;
633 }
634
635
648 public ExpandoColumn findByTableId_First(long tableId,
649 OrderByComparator orderByComparator)
650 throws NoSuchColumnException, SystemException {
651 List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
652 orderByComparator);
653
654 if (list.isEmpty()) {
655 StringBundler msg = new StringBundler(4);
656
657 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
658
659 msg.append("tableId=");
660 msg.append(tableId);
661
662 msg.append(StringPool.CLOSE_CURLY_BRACE);
663
664 throw new NoSuchColumnException(msg.toString());
665 }
666 else {
667 return list.get(0);
668 }
669 }
670
671
684 public ExpandoColumn findByTableId_Last(long tableId,
685 OrderByComparator orderByComparator)
686 throws NoSuchColumnException, SystemException {
687 int count = countByTableId(tableId);
688
689 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
690 orderByComparator);
691
692 if (list.isEmpty()) {
693 StringBundler msg = new StringBundler(4);
694
695 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
696
697 msg.append("tableId=");
698 msg.append(tableId);
699
700 msg.append(StringPool.CLOSE_CURLY_BRACE);
701
702 throw new NoSuchColumnException(msg.toString());
703 }
704 else {
705 return list.get(0);
706 }
707 }
708
709
723 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
724 long tableId, OrderByComparator orderByComparator)
725 throws NoSuchColumnException, SystemException {
726 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
727
728 Session session = null;
729
730 try {
731 session = openSession();
732
733 ExpandoColumn[] array = new ExpandoColumnImpl[3];
734
735 array[0] = getByTableId_PrevAndNext(session, expandoColumn,
736 tableId, orderByComparator, true);
737
738 array[1] = expandoColumn;
739
740 array[2] = getByTableId_PrevAndNext(session, expandoColumn,
741 tableId, orderByComparator, false);
742
743 return array;
744 }
745 catch (Exception e) {
746 throw processException(e);
747 }
748 finally {
749 closeSession(session);
750 }
751 }
752
753 protected ExpandoColumn getByTableId_PrevAndNext(Session session,
754 ExpandoColumn expandoColumn, long tableId,
755 OrderByComparator orderByComparator, boolean previous) {
756 StringBundler query = null;
757
758 if (orderByComparator != null) {
759 query = new StringBundler(6 +
760 (orderByComparator.getOrderByFields().length * 6));
761 }
762 else {
763 query = new StringBundler(3);
764 }
765
766 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
767
768 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
769
770 if (orderByComparator != null) {
771 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
772
773 if (orderByConditionFields.length > 0) {
774 query.append(WHERE_AND);
775 }
776
777 for (int i = 0; i < orderByConditionFields.length; i++) {
778 query.append(_ORDER_BY_ENTITY_ALIAS);
779 query.append(orderByConditionFields[i]);
780
781 if ((i + 1) < orderByConditionFields.length) {
782 if (orderByComparator.isAscending() ^ previous) {
783 query.append(WHERE_GREATER_THAN_HAS_NEXT);
784 }
785 else {
786 query.append(WHERE_LESSER_THAN_HAS_NEXT);
787 }
788 }
789 else {
790 if (orderByComparator.isAscending() ^ previous) {
791 query.append(WHERE_GREATER_THAN);
792 }
793 else {
794 query.append(WHERE_LESSER_THAN);
795 }
796 }
797 }
798
799 query.append(ORDER_BY_CLAUSE);
800
801 String[] orderByFields = orderByComparator.getOrderByFields();
802
803 for (int i = 0; i < orderByFields.length; i++) {
804 query.append(_ORDER_BY_ENTITY_ALIAS);
805 query.append(orderByFields[i]);
806
807 if ((i + 1) < orderByFields.length) {
808 if (orderByComparator.isAscending() ^ previous) {
809 query.append(ORDER_BY_ASC_HAS_NEXT);
810 }
811 else {
812 query.append(ORDER_BY_DESC_HAS_NEXT);
813 }
814 }
815 else {
816 if (orderByComparator.isAscending() ^ previous) {
817 query.append(ORDER_BY_ASC);
818 }
819 else {
820 query.append(ORDER_BY_DESC);
821 }
822 }
823 }
824 }
825
826 else {
827 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
828 }
829
830 String sql = query.toString();
831
832 Query q = session.createQuery(sql);
833
834 q.setFirstResult(0);
835 q.setMaxResults(2);
836
837 QueryPos qPos = QueryPos.getInstance(q);
838
839 qPos.add(tableId);
840
841 if (orderByComparator != null) {
842 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
843
844 for (Object value : values) {
845 qPos.add(value);
846 }
847 }
848
849 List<ExpandoColumn> list = q.list();
850
851 if (list.size() == 2) {
852 return list.get(1);
853 }
854 else {
855 return null;
856 }
857 }
858
859
866 public List<ExpandoColumn> filterFindByTableId(long tableId)
867 throws SystemException {
868 return filterFindByTableId(tableId, QueryUtil.ALL_POS,
869 QueryUtil.ALL_POS, null);
870 }
871
872
885 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
886 int end) throws SystemException {
887 return filterFindByTableId(tableId, start, end, null);
888 }
889
890
904 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
905 int end, OrderByComparator orderByComparator) throws SystemException {
906 if (!InlineSQLHelperUtil.isEnabled()) {
907 return findByTableId(tableId, start, end, orderByComparator);
908 }
909
910 StringBundler query = null;
911
912 if (orderByComparator != null) {
913 query = new StringBundler(3 +
914 (orderByComparator.getOrderByFields().length * 3));
915 }
916 else {
917 query = new StringBundler(3);
918 }
919
920 if (getDB().isSupportsInlineDistinct()) {
921 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
922 }
923 else {
924 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
925 }
926
927 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
928
929 if (!getDB().isSupportsInlineDistinct()) {
930 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
931 }
932
933 if (orderByComparator != null) {
934 if (getDB().isSupportsInlineDistinct()) {
935 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
936 orderByComparator);
937 }
938 else {
939 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
940 orderByComparator);
941 }
942 }
943
944 else {
945 if (getDB().isSupportsInlineDistinct()) {
946 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
947 }
948 else {
949 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
950 }
951 }
952
953 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
954 ExpandoColumn.class.getName(),
955 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
956
957 Session session = null;
958
959 try {
960 session = openSession();
961
962 SQLQuery q = session.createSQLQuery(sql);
963
964 if (getDB().isSupportsInlineDistinct()) {
965 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
966 }
967 else {
968 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
969 }
970
971 QueryPos qPos = QueryPos.getInstance(q);
972
973 qPos.add(tableId);
974
975 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
976 end);
977 }
978 catch (Exception e) {
979 throw processException(e);
980 }
981 finally {
982 closeSession(session);
983 }
984 }
985
986
996 public ExpandoColumn[] filterFindByTableId_PrevAndNext(long columnId,
997 long tableId, OrderByComparator orderByComparator)
998 throws NoSuchColumnException, SystemException {
999 if (!InlineSQLHelperUtil.isEnabled()) {
1000 return findByTableId_PrevAndNext(columnId, tableId,
1001 orderByComparator);
1002 }
1003
1004 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1005
1006 Session session = null;
1007
1008 try {
1009 session = openSession();
1010
1011 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1012
1013 array[0] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1014 tableId, orderByComparator, true);
1015
1016 array[1] = expandoColumn;
1017
1018 array[2] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1019 tableId, orderByComparator, false);
1020
1021 return array;
1022 }
1023 catch (Exception e) {
1024 throw processException(e);
1025 }
1026 finally {
1027 closeSession(session);
1028 }
1029 }
1030
1031 protected ExpandoColumn filterGetByTableId_PrevAndNext(Session session,
1032 ExpandoColumn expandoColumn, long tableId,
1033 OrderByComparator orderByComparator, boolean previous) {
1034 StringBundler query = null;
1035
1036 if (orderByComparator != null) {
1037 query = new StringBundler(6 +
1038 (orderByComparator.getOrderByFields().length * 6));
1039 }
1040 else {
1041 query = new StringBundler(3);
1042 }
1043
1044 if (getDB().isSupportsInlineDistinct()) {
1045 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1046 }
1047 else {
1048 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1049 }
1050
1051 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1052
1053 if (!getDB().isSupportsInlineDistinct()) {
1054 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1055 }
1056
1057 if (orderByComparator != null) {
1058 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1059
1060 if (orderByConditionFields.length > 0) {
1061 query.append(WHERE_AND);
1062 }
1063
1064 for (int i = 0; i < orderByConditionFields.length; i++) {
1065 if (getDB().isSupportsInlineDistinct()) {
1066 query.append(_ORDER_BY_ENTITY_ALIAS);
1067 }
1068 else {
1069 query.append(_ORDER_BY_ENTITY_TABLE);
1070 }
1071
1072 query.append(orderByConditionFields[i]);
1073
1074 if ((i + 1) < orderByConditionFields.length) {
1075 if (orderByComparator.isAscending() ^ previous) {
1076 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1077 }
1078 else {
1079 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1080 }
1081 }
1082 else {
1083 if (orderByComparator.isAscending() ^ previous) {
1084 query.append(WHERE_GREATER_THAN);
1085 }
1086 else {
1087 query.append(WHERE_LESSER_THAN);
1088 }
1089 }
1090 }
1091
1092 query.append(ORDER_BY_CLAUSE);
1093
1094 String[] orderByFields = orderByComparator.getOrderByFields();
1095
1096 for (int i = 0; i < orderByFields.length; i++) {
1097 if (getDB().isSupportsInlineDistinct()) {
1098 query.append(_ORDER_BY_ENTITY_ALIAS);
1099 }
1100 else {
1101 query.append(_ORDER_BY_ENTITY_TABLE);
1102 }
1103
1104 query.append(orderByFields[i]);
1105
1106 if ((i + 1) < orderByFields.length) {
1107 if (orderByComparator.isAscending() ^ previous) {
1108 query.append(ORDER_BY_ASC_HAS_NEXT);
1109 }
1110 else {
1111 query.append(ORDER_BY_DESC_HAS_NEXT);
1112 }
1113 }
1114 else {
1115 if (orderByComparator.isAscending() ^ previous) {
1116 query.append(ORDER_BY_ASC);
1117 }
1118 else {
1119 query.append(ORDER_BY_DESC);
1120 }
1121 }
1122 }
1123 }
1124
1125 else {
1126 if (getDB().isSupportsInlineDistinct()) {
1127 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1128 }
1129 else {
1130 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1131 }
1132 }
1133
1134 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1135 ExpandoColumn.class.getName(),
1136 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1137
1138 SQLQuery q = session.createSQLQuery(sql);
1139
1140 q.setFirstResult(0);
1141 q.setMaxResults(2);
1142
1143 if (getDB().isSupportsInlineDistinct()) {
1144 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1145 }
1146 else {
1147 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1148 }
1149
1150 QueryPos qPos = QueryPos.getInstance(q);
1151
1152 qPos.add(tableId);
1153
1154 if (orderByComparator != null) {
1155 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1156
1157 for (Object value : values) {
1158 qPos.add(value);
1159 }
1160 }
1161
1162 List<ExpandoColumn> list = q.list();
1163
1164 if (list.size() == 2) {
1165 return list.get(1);
1166 }
1167 else {
1168 return null;
1169 }
1170 }
1171
1172
1180 public List<ExpandoColumn> findByT_N(long tableId, String name)
1181 throws SystemException {
1182 return findByT_N(tableId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1183 null);
1184 }
1185
1186
1200 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1201 int end) throws SystemException {
1202 return findByT_N(tableId, name, start, end, null);
1203 }
1204
1205
1220 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1221 int end, OrderByComparator orderByComparator) throws SystemException {
1222 FinderPath finderPath = null;
1223 Object[] finderArgs = null;
1224
1225 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1226 (orderByComparator == null)) {
1227 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N;
1228 finderArgs = new Object[] { tableId, name };
1229 }
1230 else {
1231 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1232 finderArgs = new Object[] {
1233 tableId, name,
1234
1235 start, end, orderByComparator
1236 };
1237 }
1238
1239 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1240 finderArgs, this);
1241
1242 if (list == null) {
1243 StringBundler query = null;
1244
1245 if (orderByComparator != null) {
1246 query = new StringBundler(4 +
1247 (orderByComparator.getOrderByFields().length * 3));
1248 }
1249 else {
1250 query = new StringBundler(4);
1251 }
1252
1253 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1254
1255 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1256
1257 if (name == null) {
1258 query.append(_FINDER_COLUMN_T_N_NAME_1);
1259 }
1260 else {
1261 if (name.equals(StringPool.BLANK)) {
1262 query.append(_FINDER_COLUMN_T_N_NAME_3);
1263 }
1264 else {
1265 query.append(_FINDER_COLUMN_T_N_NAME_2);
1266 }
1267 }
1268
1269 if (orderByComparator != null) {
1270 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1271 orderByComparator);
1272 }
1273
1274 else {
1275 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1276 }
1277
1278 String sql = query.toString();
1279
1280 Session session = null;
1281
1282 try {
1283 session = openSession();
1284
1285 Query q = session.createQuery(sql);
1286
1287 QueryPos qPos = QueryPos.getInstance(q);
1288
1289 qPos.add(tableId);
1290
1291 if (name != null) {
1292 qPos.add(name);
1293 }
1294
1295 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1296 start, end);
1297 }
1298 catch (Exception e) {
1299 throw processException(e);
1300 }
1301 finally {
1302 if (list == null) {
1303 FinderCacheUtil.removeResult(finderPath, finderArgs);
1304 }
1305 else {
1306 cacheResult(list);
1307
1308 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1309 }
1310
1311 closeSession(session);
1312 }
1313 }
1314
1315 return list;
1316 }
1317
1318
1332 public ExpandoColumn findByT_N_First(long tableId, String name,
1333 OrderByComparator orderByComparator)
1334 throws NoSuchColumnException, SystemException {
1335 List<ExpandoColumn> list = findByT_N(tableId, name, 0, 1,
1336 orderByComparator);
1337
1338 if (list.isEmpty()) {
1339 StringBundler msg = new StringBundler(6);
1340
1341 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1342
1343 msg.append("tableId=");
1344 msg.append(tableId);
1345
1346 msg.append(", name=");
1347 msg.append(name);
1348
1349 msg.append(StringPool.CLOSE_CURLY_BRACE);
1350
1351 throw new NoSuchColumnException(msg.toString());
1352 }
1353 else {
1354 return list.get(0);
1355 }
1356 }
1357
1358
1372 public ExpandoColumn findByT_N_Last(long tableId, String name,
1373 OrderByComparator orderByComparator)
1374 throws NoSuchColumnException, SystemException {
1375 int count = countByT_N(tableId, name);
1376
1377 List<ExpandoColumn> list = findByT_N(tableId, name, count - 1, count,
1378 orderByComparator);
1379
1380 if (list.isEmpty()) {
1381 StringBundler msg = new StringBundler(6);
1382
1383 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1384
1385 msg.append("tableId=");
1386 msg.append(tableId);
1387
1388 msg.append(", name=");
1389 msg.append(name);
1390
1391 msg.append(StringPool.CLOSE_CURLY_BRACE);
1392
1393 throw new NoSuchColumnException(msg.toString());
1394 }
1395 else {
1396 return list.get(0);
1397 }
1398 }
1399
1400
1415 public ExpandoColumn[] findByT_N_PrevAndNext(long columnId, long tableId,
1416 String name, OrderByComparator orderByComparator)
1417 throws NoSuchColumnException, SystemException {
1418 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1419
1420 Session session = null;
1421
1422 try {
1423 session = openSession();
1424
1425 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1426
1427 array[0] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1428 name, orderByComparator, true);
1429
1430 array[1] = expandoColumn;
1431
1432 array[2] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1433 name, orderByComparator, false);
1434
1435 return array;
1436 }
1437 catch (Exception e) {
1438 throw processException(e);
1439 }
1440 finally {
1441 closeSession(session);
1442 }
1443 }
1444
1445 protected ExpandoColumn getByT_N_PrevAndNext(Session session,
1446 ExpandoColumn expandoColumn, long tableId, String name,
1447 OrderByComparator orderByComparator, boolean previous) {
1448 StringBundler query = null;
1449
1450 if (orderByComparator != null) {
1451 query = new StringBundler(6 +
1452 (orderByComparator.getOrderByFields().length * 6));
1453 }
1454 else {
1455 query = new StringBundler(3);
1456 }
1457
1458 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1459
1460 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1461
1462 if (name == null) {
1463 query.append(_FINDER_COLUMN_T_N_NAME_1);
1464 }
1465 else {
1466 if (name.equals(StringPool.BLANK)) {
1467 query.append(_FINDER_COLUMN_T_N_NAME_3);
1468 }
1469 else {
1470 query.append(_FINDER_COLUMN_T_N_NAME_2);
1471 }
1472 }
1473
1474 if (orderByComparator != null) {
1475 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1476
1477 if (orderByConditionFields.length > 0) {
1478 query.append(WHERE_AND);
1479 }
1480
1481 for (int i = 0; i < orderByConditionFields.length; i++) {
1482 query.append(_ORDER_BY_ENTITY_ALIAS);
1483 query.append(orderByConditionFields[i]);
1484
1485 if ((i + 1) < orderByConditionFields.length) {
1486 if (orderByComparator.isAscending() ^ previous) {
1487 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1488 }
1489 else {
1490 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1491 }
1492 }
1493 else {
1494 if (orderByComparator.isAscending() ^ previous) {
1495 query.append(WHERE_GREATER_THAN);
1496 }
1497 else {
1498 query.append(WHERE_LESSER_THAN);
1499 }
1500 }
1501 }
1502
1503 query.append(ORDER_BY_CLAUSE);
1504
1505 String[] orderByFields = orderByComparator.getOrderByFields();
1506
1507 for (int i = 0; i < orderByFields.length; i++) {
1508 query.append(_ORDER_BY_ENTITY_ALIAS);
1509 query.append(orderByFields[i]);
1510
1511 if ((i + 1) < orderByFields.length) {
1512 if (orderByComparator.isAscending() ^ previous) {
1513 query.append(ORDER_BY_ASC_HAS_NEXT);
1514 }
1515 else {
1516 query.append(ORDER_BY_DESC_HAS_NEXT);
1517 }
1518 }
1519 else {
1520 if (orderByComparator.isAscending() ^ previous) {
1521 query.append(ORDER_BY_ASC);
1522 }
1523 else {
1524 query.append(ORDER_BY_DESC);
1525 }
1526 }
1527 }
1528 }
1529
1530 else {
1531 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1532 }
1533
1534 String sql = query.toString();
1535
1536 Query q = session.createQuery(sql);
1537
1538 q.setFirstResult(0);
1539 q.setMaxResults(2);
1540
1541 QueryPos qPos = QueryPos.getInstance(q);
1542
1543 qPos.add(tableId);
1544
1545 if (name != null) {
1546 qPos.add(name);
1547 }
1548
1549 if (orderByComparator != null) {
1550 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1551
1552 for (Object value : values) {
1553 qPos.add(value);
1554 }
1555 }
1556
1557 List<ExpandoColumn> list = q.list();
1558
1559 if (list.size() == 2) {
1560 return list.get(1);
1561 }
1562 else {
1563 return null;
1564 }
1565 }
1566
1567
1579 public List<ExpandoColumn> findByT_N(long tableId, String[] names)
1580 throws SystemException {
1581 return findByT_N(tableId, names, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1582 null);
1583 }
1584
1585
1599 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1600 int start, int end) throws SystemException {
1601 return findByT_N(tableId, names, start, end, null);
1602 }
1603
1604
1619 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1620 int start, int end, OrderByComparator orderByComparator)
1621 throws SystemException {
1622 FinderPath finderPath = null;
1623 Object[] finderArgs = null;
1624
1625 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1626 (orderByComparator == null)) {
1627 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N;
1628 finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1629 }
1630 else {
1631 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1632 finderArgs = new Object[] {
1633 tableId, StringUtil.merge(names),
1634
1635 start, end, orderByComparator
1636 };
1637 }
1638
1639 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1640 finderArgs, this);
1641
1642 if (list == null) {
1643 StringBundler query = new StringBundler();
1644
1645 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1646
1647 boolean conjunctionable = false;
1648
1649 if (conjunctionable) {
1650 query.append(WHERE_AND);
1651 }
1652
1653 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1654
1655 conjunctionable = true;
1656
1657 if ((names == null) || (names.length > 0)) {
1658 if (conjunctionable) {
1659 query.append(WHERE_AND);
1660 }
1661
1662 query.append(StringPool.OPEN_PARENTHESIS);
1663
1664 for (int i = 0; i < names.length; i++) {
1665 String name = names[i];
1666
1667 if (name == null) {
1668 query.append(_FINDER_COLUMN_T_N_NAME_4);
1669 }
1670 else {
1671 if (name.equals(StringPool.BLANK)) {
1672 query.append(_FINDER_COLUMN_T_N_NAME_6);
1673 }
1674 else {
1675 query.append(_FINDER_COLUMN_T_N_NAME_5);
1676 }
1677 }
1678
1679 if ((i + 1) < names.length) {
1680 query.append(WHERE_OR);
1681 }
1682 }
1683
1684 query.append(StringPool.CLOSE_PARENTHESIS);
1685
1686 conjunctionable = true;
1687 }
1688
1689 if (orderByComparator != null) {
1690 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1691 orderByComparator);
1692 }
1693
1694 else {
1695 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1696 }
1697
1698 String sql = query.toString();
1699
1700 Session session = null;
1701
1702 try {
1703 session = openSession();
1704
1705 Query q = session.createQuery(sql);
1706
1707 QueryPos qPos = QueryPos.getInstance(q);
1708
1709 qPos.add(tableId);
1710
1711 if (names != null) {
1712 qPos.add(names);
1713 }
1714
1715 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1716 start, end);
1717 }
1718 catch (Exception e) {
1719 throw processException(e);
1720 }
1721 finally {
1722 if (list == null) {
1723 FinderCacheUtil.removeResult(finderPath, finderArgs);
1724 }
1725 else {
1726 cacheResult(list);
1727
1728 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1729 }
1730
1731 closeSession(session);
1732 }
1733 }
1734
1735 return list;
1736 }
1737
1738
1746 public List<ExpandoColumn> filterFindByT_N(long tableId, String name)
1747 throws SystemException {
1748 return filterFindByT_N(tableId, name, QueryUtil.ALL_POS,
1749 QueryUtil.ALL_POS, null);
1750 }
1751
1752
1766 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1767 int start, int end) throws SystemException {
1768 return filterFindByT_N(tableId, name, start, end, null);
1769 }
1770
1771
1786 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1787 int start, int end, OrderByComparator orderByComparator)
1788 throws SystemException {
1789 if (!InlineSQLHelperUtil.isEnabled()) {
1790 return findByT_N(tableId, name, start, end, orderByComparator);
1791 }
1792
1793 StringBundler query = null;
1794
1795 if (orderByComparator != null) {
1796 query = new StringBundler(4 +
1797 (orderByComparator.getOrderByFields().length * 3));
1798 }
1799 else {
1800 query = new StringBundler(4);
1801 }
1802
1803 if (getDB().isSupportsInlineDistinct()) {
1804 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1805 }
1806 else {
1807 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1808 }
1809
1810 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1811
1812 if (name == null) {
1813 query.append(_FINDER_COLUMN_T_N_NAME_1);
1814 }
1815 else {
1816 if (name.equals(StringPool.BLANK)) {
1817 query.append(_FINDER_COLUMN_T_N_NAME_3);
1818 }
1819 else {
1820 query.append(_FINDER_COLUMN_T_N_NAME_2);
1821 }
1822 }
1823
1824 if (!getDB().isSupportsInlineDistinct()) {
1825 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1826 }
1827
1828 if (orderByComparator != null) {
1829 if (getDB().isSupportsInlineDistinct()) {
1830 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1831 orderByComparator);
1832 }
1833 else {
1834 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1835 orderByComparator);
1836 }
1837 }
1838
1839 else {
1840 if (getDB().isSupportsInlineDistinct()) {
1841 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1842 }
1843 else {
1844 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1845 }
1846 }
1847
1848 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1849 ExpandoColumn.class.getName(),
1850 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1851
1852 Session session = null;
1853
1854 try {
1855 session = openSession();
1856
1857 SQLQuery q = session.createSQLQuery(sql);
1858
1859 if (getDB().isSupportsInlineDistinct()) {
1860 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1861 }
1862 else {
1863 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1864 }
1865
1866 QueryPos qPos = QueryPos.getInstance(q);
1867
1868 qPos.add(tableId);
1869
1870 if (name != null) {
1871 qPos.add(name);
1872 }
1873
1874 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
1875 end);
1876 }
1877 catch (Exception e) {
1878 throw processException(e);
1879 }
1880 finally {
1881 closeSession(session);
1882 }
1883 }
1884
1885
1896 public ExpandoColumn[] filterFindByT_N_PrevAndNext(long columnId,
1897 long tableId, String name, OrderByComparator orderByComparator)
1898 throws NoSuchColumnException, SystemException {
1899 if (!InlineSQLHelperUtil.isEnabled()) {
1900 return findByT_N_PrevAndNext(columnId, tableId, name,
1901 orderByComparator);
1902 }
1903
1904 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1905
1906 Session session = null;
1907
1908 try {
1909 session = openSession();
1910
1911 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1912
1913 array[0] = filterGetByT_N_PrevAndNext(session, expandoColumn,
1914 tableId, name, orderByComparator, true);
1915
1916 array[1] = expandoColumn;
1917
1918 array[2] = filterGetByT_N_PrevAndNext(session, expandoColumn,
1919 tableId, name, orderByComparator, false);
1920
1921 return array;
1922 }
1923 catch (Exception e) {
1924 throw processException(e);
1925 }
1926 finally {
1927 closeSession(session);
1928 }
1929 }
1930
1931 protected ExpandoColumn filterGetByT_N_PrevAndNext(Session session,
1932 ExpandoColumn expandoColumn, long tableId, String name,
1933 OrderByComparator orderByComparator, boolean previous) {
1934 StringBundler query = null;
1935
1936 if (orderByComparator != null) {
1937 query = new StringBundler(6 +
1938 (orderByComparator.getOrderByFields().length * 6));
1939 }
1940 else {
1941 query = new StringBundler(3);
1942 }
1943
1944 if (getDB().isSupportsInlineDistinct()) {
1945 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1946 }
1947 else {
1948 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1949 }
1950
1951 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1952
1953 if (name == null) {
1954 query.append(_FINDER_COLUMN_T_N_NAME_1);
1955 }
1956 else {
1957 if (name.equals(StringPool.BLANK)) {
1958 query.append(_FINDER_COLUMN_T_N_NAME_3);
1959 }
1960 else {
1961 query.append(_FINDER_COLUMN_T_N_NAME_2);
1962 }
1963 }
1964
1965 if (!getDB().isSupportsInlineDistinct()) {
1966 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1967 }
1968
1969 if (orderByComparator != null) {
1970 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1971
1972 if (orderByConditionFields.length > 0) {
1973 query.append(WHERE_AND);
1974 }
1975
1976 for (int i = 0; i < orderByConditionFields.length; i++) {
1977 if (getDB().isSupportsInlineDistinct()) {
1978 query.append(_ORDER_BY_ENTITY_ALIAS);
1979 }
1980 else {
1981 query.append(_ORDER_BY_ENTITY_TABLE);
1982 }
1983
1984 query.append(orderByConditionFields[i]);
1985
1986 if ((i + 1) < orderByConditionFields.length) {
1987 if (orderByComparator.isAscending() ^ previous) {
1988 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1989 }
1990 else {
1991 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1992 }
1993 }
1994 else {
1995 if (orderByComparator.isAscending() ^ previous) {
1996 query.append(WHERE_GREATER_THAN);
1997 }
1998 else {
1999 query.append(WHERE_LESSER_THAN);
2000 }
2001 }
2002 }
2003
2004 query.append(ORDER_BY_CLAUSE);
2005
2006 String[] orderByFields = orderByComparator.getOrderByFields();
2007
2008 for (int i = 0; i < orderByFields.length; i++) {
2009 if (getDB().isSupportsInlineDistinct()) {
2010 query.append(_ORDER_BY_ENTITY_ALIAS);
2011 }
2012 else {
2013 query.append(_ORDER_BY_ENTITY_TABLE);
2014 }
2015
2016 query.append(orderByFields[i]);
2017
2018 if ((i + 1) < orderByFields.length) {
2019 if (orderByComparator.isAscending() ^ previous) {
2020 query.append(ORDER_BY_ASC_HAS_NEXT);
2021 }
2022 else {
2023 query.append(ORDER_BY_DESC_HAS_NEXT);
2024 }
2025 }
2026 else {
2027 if (orderByComparator.isAscending() ^ previous) {
2028 query.append(ORDER_BY_ASC);
2029 }
2030 else {
2031 query.append(ORDER_BY_DESC);
2032 }
2033 }
2034 }
2035 }
2036
2037 else {
2038 if (getDB().isSupportsInlineDistinct()) {
2039 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2040 }
2041 else {
2042 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2043 }
2044 }
2045
2046 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2047 ExpandoColumn.class.getName(),
2048 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2049
2050 SQLQuery q = session.createSQLQuery(sql);
2051
2052 q.setFirstResult(0);
2053 q.setMaxResults(2);
2054
2055 if (getDB().isSupportsInlineDistinct()) {
2056 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2057 }
2058 else {
2059 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2060 }
2061
2062 QueryPos qPos = QueryPos.getInstance(q);
2063
2064 qPos.add(tableId);
2065
2066 if (name != null) {
2067 qPos.add(name);
2068 }
2069
2070 if (orderByComparator != null) {
2071 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
2072
2073 for (Object value : values) {
2074 qPos.add(value);
2075 }
2076 }
2077
2078 List<ExpandoColumn> list = q.list();
2079
2080 if (list.size() == 2) {
2081 return list.get(1);
2082 }
2083 else {
2084 return null;
2085 }
2086 }
2087
2088
2096 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names)
2097 throws SystemException {
2098 return filterFindByT_N(tableId, names, QueryUtil.ALL_POS,
2099 QueryUtil.ALL_POS, null);
2100 }
2101
2102
2116 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2117 int start, int end) throws SystemException {
2118 return filterFindByT_N(tableId, names, start, end, null);
2119 }
2120
2121
2136 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2137 int start, int end, OrderByComparator orderByComparator)
2138 throws SystemException {
2139 if (!InlineSQLHelperUtil.isEnabled()) {
2140 return findByT_N(tableId, names, start, end, orderByComparator);
2141 }
2142
2143 StringBundler query = new StringBundler();
2144
2145 if (getDB().isSupportsInlineDistinct()) {
2146 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
2147 }
2148 else {
2149 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
2150 }
2151
2152 boolean conjunctionable = false;
2153
2154 if (conjunctionable) {
2155 query.append(WHERE_AND);
2156 }
2157
2158 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2159
2160 conjunctionable = true;
2161
2162 if ((names == null) || (names.length > 0)) {
2163 if (conjunctionable) {
2164 query.append(WHERE_AND);
2165 }
2166
2167 query.append(StringPool.OPEN_PARENTHESIS);
2168
2169 for (int i = 0; i < names.length; i++) {
2170 String name = names[i];
2171
2172 if (name == null) {
2173 query.append(_FINDER_COLUMN_T_N_NAME_4);
2174 }
2175 else {
2176 if (name.equals(StringPool.BLANK)) {
2177 query.append(_FINDER_COLUMN_T_N_NAME_6);
2178 }
2179 else {
2180 query.append(_FINDER_COLUMN_T_N_NAME_5);
2181 }
2182 }
2183
2184 if ((i + 1) < names.length) {
2185 query.append(WHERE_OR);
2186 }
2187 }
2188
2189 query.append(StringPool.CLOSE_PARENTHESIS);
2190
2191 conjunctionable = true;
2192 }
2193
2194 if (!getDB().isSupportsInlineDistinct()) {
2195 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
2196 }
2197
2198 if (orderByComparator != null) {
2199 if (getDB().isSupportsInlineDistinct()) {
2200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2201 orderByComparator);
2202 }
2203 else {
2204 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2205 orderByComparator);
2206 }
2207 }
2208
2209 else {
2210 if (getDB().isSupportsInlineDistinct()) {
2211 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2212 }
2213 else {
2214 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2215 }
2216 }
2217
2218 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2219 ExpandoColumn.class.getName(),
2220 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2221
2222 Session session = null;
2223
2224 try {
2225 session = openSession();
2226
2227 SQLQuery q = session.createSQLQuery(sql);
2228
2229 if (getDB().isSupportsInlineDistinct()) {
2230 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2231 }
2232 else {
2233 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2234 }
2235
2236 QueryPos qPos = QueryPos.getInstance(q);
2237
2238 qPos.add(tableId);
2239
2240 if (names != null) {
2241 qPos.add(names);
2242 }
2243
2244 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
2245 end);
2246 }
2247 catch (Exception e) {
2248 throw processException(e);
2249 }
2250 finally {
2251 closeSession(session);
2252 }
2253 }
2254
2255
2261 public List<ExpandoColumn> findAll() throws SystemException {
2262 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2263 }
2264
2265
2277 public List<ExpandoColumn> findAll(int start, int end)
2278 throws SystemException {
2279 return findAll(start, end, null);
2280 }
2281
2282
2295 public List<ExpandoColumn> findAll(int start, int end,
2296 OrderByComparator orderByComparator) throws SystemException {
2297 FinderPath finderPath = null;
2298 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2299
2300 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2301 (orderByComparator == null)) {
2302 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2303 finderArgs = FINDER_ARGS_EMPTY;
2304 }
2305 else {
2306 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2307 finderArgs = new Object[] { start, end, orderByComparator };
2308 }
2309
2310 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
2311 finderArgs, this);
2312
2313 if (list == null) {
2314 StringBundler query = null;
2315 String sql = null;
2316
2317 if (orderByComparator != null) {
2318 query = new StringBundler(2 +
2319 (orderByComparator.getOrderByFields().length * 3));
2320
2321 query.append(_SQL_SELECT_EXPANDOCOLUMN);
2322
2323 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2324 orderByComparator);
2325
2326 sql = query.toString();
2327 }
2328 else {
2329 sql = _SQL_SELECT_EXPANDOCOLUMN.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2330 }
2331
2332 Session session = null;
2333
2334 try {
2335 session = openSession();
2336
2337 Query q = session.createQuery(sql);
2338
2339 if (orderByComparator == null) {
2340 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2341 start, end, false);
2342
2343 Collections.sort(list);
2344 }
2345 else {
2346 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2347 start, end);
2348 }
2349 }
2350 catch (Exception e) {
2351 throw processException(e);
2352 }
2353 finally {
2354 if (list == null) {
2355 FinderCacheUtil.removeResult(finderPath, finderArgs);
2356 }
2357 else {
2358 cacheResult(list);
2359
2360 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2361 }
2362
2363 closeSession(session);
2364 }
2365 }
2366
2367 return list;
2368 }
2369
2370
2376 public void removeByTableId(long tableId) throws SystemException {
2377 for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
2378 expandoColumnPersistence.remove(expandoColumn);
2379 }
2380 }
2381
2382
2389 public void removeByT_N(long tableId, String name)
2390 throws SystemException {
2391 for (ExpandoColumn expandoColumn : findByT_N(tableId, name)) {
2392 expandoColumnPersistence.remove(expandoColumn);
2393 }
2394 }
2395
2396
2401 public void removeAll() throws SystemException {
2402 for (ExpandoColumn expandoColumn : findAll()) {
2403 expandoColumnPersistence.remove(expandoColumn);
2404 }
2405 }
2406
2407
2414 public int countByTableId(long tableId) throws SystemException {
2415 Object[] finderArgs = new Object[] { tableId };
2416
2417 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
2418 finderArgs, this);
2419
2420 if (count == null) {
2421 StringBundler query = new StringBundler(2);
2422
2423 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2424
2425 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2426
2427 String sql = query.toString();
2428
2429 Session session = null;
2430
2431 try {
2432 session = openSession();
2433
2434 Query q = session.createQuery(sql);
2435
2436 QueryPos qPos = QueryPos.getInstance(q);
2437
2438 qPos.add(tableId);
2439
2440 count = (Long)q.uniqueResult();
2441 }
2442 catch (Exception e) {
2443 throw processException(e);
2444 }
2445 finally {
2446 if (count == null) {
2447 count = Long.valueOf(0);
2448 }
2449
2450 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
2451 finderArgs, count);
2452
2453 closeSession(session);
2454 }
2455 }
2456
2457 return count.intValue();
2458 }
2459
2460
2467 public int filterCountByTableId(long tableId) throws SystemException {
2468 if (!InlineSQLHelperUtil.isEnabled()) {
2469 return countByTableId(tableId);
2470 }
2471
2472 StringBundler query = new StringBundler(2);
2473
2474 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2475
2476 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2477
2478 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2479 ExpandoColumn.class.getName(),
2480 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2481
2482 Session session = null;
2483
2484 try {
2485 session = openSession();
2486
2487 SQLQuery q = session.createSQLQuery(sql);
2488
2489 q.addScalar(COUNT_COLUMN_NAME,
2490 com.liferay.portal.kernel.dao.orm.Type.LONG);
2491
2492 QueryPos qPos = QueryPos.getInstance(q);
2493
2494 qPos.add(tableId);
2495
2496 Long count = (Long)q.uniqueResult();
2497
2498 return count.intValue();
2499 }
2500 catch (Exception e) {
2501 throw processException(e);
2502 }
2503 finally {
2504 closeSession(session);
2505 }
2506 }
2507
2508
2516 public int countByT_N(long tableId, String name) throws SystemException {
2517 Object[] finderArgs = new Object[] { tableId, name };
2518
2519 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
2520 finderArgs, this);
2521
2522 if (count == null) {
2523 StringBundler query = new StringBundler(3);
2524
2525 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2526
2527 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2528
2529 if (name == null) {
2530 query.append(_FINDER_COLUMN_T_N_NAME_1);
2531 }
2532 else {
2533 if (name.equals(StringPool.BLANK)) {
2534 query.append(_FINDER_COLUMN_T_N_NAME_3);
2535 }
2536 else {
2537 query.append(_FINDER_COLUMN_T_N_NAME_2);
2538 }
2539 }
2540
2541 String sql = query.toString();
2542
2543 Session session = null;
2544
2545 try {
2546 session = openSession();
2547
2548 Query q = session.createQuery(sql);
2549
2550 QueryPos qPos = QueryPos.getInstance(q);
2551
2552 qPos.add(tableId);
2553
2554 if (name != null) {
2555 qPos.add(name);
2556 }
2557
2558 count = (Long)q.uniqueResult();
2559 }
2560 catch (Exception e) {
2561 throw processException(e);
2562 }
2563 finally {
2564 if (count == null) {
2565 count = Long.valueOf(0);
2566 }
2567
2568 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
2569 count);
2570
2571 closeSession(session);
2572 }
2573 }
2574
2575 return count.intValue();
2576 }
2577
2578
2586 public int countByT_N(long tableId, String[] names)
2587 throws SystemException {
2588 Object[] finderArgs = new Object[] { tableId, StringUtil.merge(names) };
2589
2590 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
2591 finderArgs, this);
2592
2593 if (count == null) {
2594 StringBundler query = new StringBundler();
2595
2596 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2597
2598 boolean conjunctionable = false;
2599
2600 if (conjunctionable) {
2601 query.append(WHERE_AND);
2602 }
2603
2604 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2605
2606 conjunctionable = true;
2607
2608 if ((names == null) || (names.length > 0)) {
2609 if (conjunctionable) {
2610 query.append(WHERE_AND);
2611 }
2612
2613 query.append(StringPool.OPEN_PARENTHESIS);
2614
2615 for (int i = 0; i < names.length; i++) {
2616 String name = names[i];
2617
2618 if (name == null) {
2619 query.append(_FINDER_COLUMN_T_N_NAME_4);
2620 }
2621 else {
2622 if (name.equals(StringPool.BLANK)) {
2623 query.append(_FINDER_COLUMN_T_N_NAME_6);
2624 }
2625 else {
2626 query.append(_FINDER_COLUMN_T_N_NAME_5);
2627 }
2628 }
2629
2630 if ((i + 1) < names.length) {
2631 query.append(WHERE_OR);
2632 }
2633 }
2634
2635 query.append(StringPool.CLOSE_PARENTHESIS);
2636
2637 conjunctionable = true;
2638 }
2639
2640 String sql = query.toString();
2641
2642 Session session = null;
2643
2644 try {
2645 session = openSession();
2646
2647 Query q = session.createQuery(sql);
2648
2649 QueryPos qPos = QueryPos.getInstance(q);
2650
2651 qPos.add(tableId);
2652
2653 if (names != null) {
2654 qPos.add(names);
2655 }
2656
2657 count = (Long)q.uniqueResult();
2658 }
2659 catch (Exception e) {
2660 throw processException(e);
2661 }
2662 finally {
2663 if (count == null) {
2664 count = Long.valueOf(0);
2665 }
2666
2667 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
2668 count);
2669
2670 closeSession(session);
2671 }
2672 }
2673
2674 return count.intValue();
2675 }
2676
2677
2685 public int filterCountByT_N(long tableId, String name)
2686 throws SystemException {
2687 if (!InlineSQLHelperUtil.isEnabled()) {
2688 return countByT_N(tableId, name);
2689 }
2690
2691 StringBundler query = new StringBundler(3);
2692
2693 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2694
2695 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2696
2697 if (name == null) {
2698 query.append(_FINDER_COLUMN_T_N_NAME_1);
2699 }
2700 else {
2701 if (name.equals(StringPool.BLANK)) {
2702 query.append(_FINDER_COLUMN_T_N_NAME_3);
2703 }
2704 else {
2705 query.append(_FINDER_COLUMN_T_N_NAME_2);
2706 }
2707 }
2708
2709 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2710 ExpandoColumn.class.getName(),
2711 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2712
2713 Session session = null;
2714
2715 try {
2716 session = openSession();
2717
2718 SQLQuery q = session.createSQLQuery(sql);
2719
2720 q.addScalar(COUNT_COLUMN_NAME,
2721 com.liferay.portal.kernel.dao.orm.Type.LONG);
2722
2723 QueryPos qPos = QueryPos.getInstance(q);
2724
2725 qPos.add(tableId);
2726
2727 if (name != null) {
2728 qPos.add(name);
2729 }
2730
2731 Long count = (Long)q.uniqueResult();
2732
2733 return count.intValue();
2734 }
2735 catch (Exception e) {
2736 throw processException(e);
2737 }
2738 finally {
2739 closeSession(session);
2740 }
2741 }
2742
2743
2751 public int filterCountByT_N(long tableId, String[] names)
2752 throws SystemException {
2753 if (!InlineSQLHelperUtil.isEnabled()) {
2754 return countByT_N(tableId, names);
2755 }
2756
2757 StringBundler query = new StringBundler();
2758
2759 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2760
2761 boolean conjunctionable = false;
2762
2763 if (conjunctionable) {
2764 query.append(WHERE_AND);
2765 }
2766
2767 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2768
2769 conjunctionable = true;
2770
2771 if ((names == null) || (names.length > 0)) {
2772 if (conjunctionable) {
2773 query.append(WHERE_AND);
2774 }
2775
2776 query.append(StringPool.OPEN_PARENTHESIS);
2777
2778 for (int i = 0; i < names.length; i++) {
2779 String name = names[i];
2780
2781 if (name == null) {
2782 query.append(_FINDER_COLUMN_T_N_NAME_4);
2783 }
2784 else {
2785 if (name.equals(StringPool.BLANK)) {
2786 query.append(_FINDER_COLUMN_T_N_NAME_6);
2787 }
2788 else {
2789 query.append(_FINDER_COLUMN_T_N_NAME_5);
2790 }
2791 }
2792
2793 if ((i + 1) < names.length) {
2794 query.append(WHERE_OR);
2795 }
2796 }
2797
2798 query.append(StringPool.CLOSE_PARENTHESIS);
2799
2800 conjunctionable = true;
2801 }
2802
2803 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2804 ExpandoColumn.class.getName(),
2805 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2806
2807 Session session = null;
2808
2809 try {
2810 session = openSession();
2811
2812 SQLQuery q = session.createSQLQuery(sql);
2813
2814 q.addScalar(COUNT_COLUMN_NAME,
2815 com.liferay.portal.kernel.dao.orm.Type.LONG);
2816
2817 QueryPos qPos = QueryPos.getInstance(q);
2818
2819 qPos.add(tableId);
2820
2821 if (names != null) {
2822 qPos.add(names);
2823 }
2824
2825 Long count = (Long)q.uniqueResult();
2826
2827 return count.intValue();
2828 }
2829 catch (Exception e) {
2830 throw processException(e);
2831 }
2832 finally {
2833 closeSession(session);
2834 }
2835 }
2836
2837
2843 public int countAll() throws SystemException {
2844 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2845 FINDER_ARGS_EMPTY, this);
2846
2847 if (count == null) {
2848 Session session = null;
2849
2850 try {
2851 session = openSession();
2852
2853 Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
2854
2855 count = (Long)q.uniqueResult();
2856 }
2857 catch (Exception e) {
2858 throw processException(e);
2859 }
2860 finally {
2861 if (count == null) {
2862 count = Long.valueOf(0);
2863 }
2864
2865 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2866 FINDER_ARGS_EMPTY, count);
2867
2868 closeSession(session);
2869 }
2870 }
2871
2872 return count.intValue();
2873 }
2874
2875
2878 public void afterPropertiesSet() {
2879 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2880 com.liferay.portal.util.PropsUtil.get(
2881 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
2882
2883 if (listenerClassNames.length > 0) {
2884 try {
2885 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
2886
2887 for (String listenerClassName : listenerClassNames) {
2888 listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
2889 listenerClassName));
2890 }
2891
2892 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2893 }
2894 catch (Exception e) {
2895 _log.error(e);
2896 }
2897 }
2898 }
2899
2900 public void destroy() {
2901 EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
2902 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2903 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2904 }
2905
2906 @BeanReference(type = ExpandoColumnPersistence.class)
2907 protected ExpandoColumnPersistence expandoColumnPersistence;
2908 @BeanReference(type = ExpandoRowPersistence.class)
2909 protected ExpandoRowPersistence expandoRowPersistence;
2910 @BeanReference(type = ExpandoTablePersistence.class)
2911 protected ExpandoTablePersistence expandoTablePersistence;
2912 @BeanReference(type = ExpandoValuePersistence.class)
2913 protected ExpandoValuePersistence expandoValuePersistence;
2914 @BeanReference(type = ResourcePersistence.class)
2915 protected ResourcePersistence resourcePersistence;
2916 @BeanReference(type = UserPersistence.class)
2917 protected UserPersistence userPersistence;
2918 private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
2919 private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
2920 private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
2921 private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
2922 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
2923 private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
2924 private static final String _FINDER_COLUMN_T_N_TABLEID_5 = "(" +
2925 _removeConjunction(_FINDER_COLUMN_T_N_TABLEID_2) + ")";
2926 private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
2927 private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
2928 private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = ?)";
2929 private static final String _FINDER_COLUMN_T_N_NAME_4 = "(" +
2930 _removeConjunction(_FINDER_COLUMN_T_N_NAME_1) + ")";
2931 private static final String _FINDER_COLUMN_T_N_NAME_5 = "(" +
2932 _removeConjunction(_FINDER_COLUMN_T_N_NAME_2) + ")";
2933 private static final String _FINDER_COLUMN_T_N_NAME_6 = "(" +
2934 _removeConjunction(_FINDER_COLUMN_T_N_NAME_3) + ")";
2935
2936 private static String _removeConjunction(String sql) {
2937 int pos = sql.indexOf(" AND ");
2938
2939 if (pos != -1) {
2940 sql = sql.substring(0, pos);
2941 }
2942
2943 return sql;
2944 }
2945
2946 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "expandoColumn.columnId";
2947 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
2948 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
2949 "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
2950 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
2951 ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
2952 private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
2953 private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
2954 private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
2955 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
2956 private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
2957 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
2958 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
2959 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2960 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
2961 private static ExpandoColumn _nullExpandoColumn = new ExpandoColumnImpl() {
2962 @Override
2963 public Object clone() {
2964 return this;
2965 }
2966
2967 @Override
2968 public CacheModel<ExpandoColumn> toCacheModel() {
2969 return _nullExpandoColumnCacheModel;
2970 }
2971 };
2972
2973 private static CacheModel<ExpandoColumn> _nullExpandoColumnCacheModel = new CacheModel<ExpandoColumn>() {
2974 public ExpandoColumn toEntityModel() {
2975 return _nullExpandoColumn;
2976 }
2977 };
2978 }