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.ArrayUtil;
032 import com.liferay.portal.kernel.util.GetterUtil;
033 import com.liferay.portal.kernel.util.InstanceFactory;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.StringBundler;
036 import com.liferay.portal.kernel.util.StringPool;
037 import com.liferay.portal.kernel.util.StringUtil;
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.BatchSessionUtil;
043 import com.liferay.portal.service.persistence.ResourcePersistence;
044 import com.liferay.portal.service.persistence.UserPersistence;
045 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046
047 import com.liferay.portlet.expando.NoSuchColumnException;
048 import com.liferay.portlet.expando.model.ExpandoColumn;
049 import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
050 import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
051
052 import java.io.Serializable;
053
054 import java.util.ArrayList;
055 import java.util.Collections;
056 import java.util.List;
057
058
070 public class ExpandoColumnPersistenceImpl extends BasePersistenceImpl<ExpandoColumn>
071 implements ExpandoColumnPersistence {
072
077 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoColumnImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List1";
080 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List2";
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
083 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
084 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
085 "findByTableId",
086 new String[] {
087 Long.class.getName(),
088
089 "java.lang.Integer", "java.lang.Integer",
090 "com.liferay.portal.kernel.util.OrderByComparator"
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
093 new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
094 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
095 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
096 "findByTableId", new String[] { Long.class.getName() },
097 ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK);
098 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
099 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
101 new String[] { Long.class.getName() });
102 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
103 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
104 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
105 "findByT_N",
106 new String[] {
107 Long.class.getName(), String.class.getName(),
108
109 "java.lang.Integer", "java.lang.Integer",
110 "com.liferay.portal.kernel.util.OrderByComparator"
111 });
112 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
113 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
114 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
115 "findByT_N",
116 new String[] { Long.class.getName(), String.class.getName() },
117 ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
118 ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
119 public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
120 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
121 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_N",
122 new String[] { Long.class.getName(), String.class.getName() });
123 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
124 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
125 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByT_N",
126 new String[] { Long.class.getName(), String.class.getName() });
127 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
128 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
129 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
130 "findAll", new String[0]);
131 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
132 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
133 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
134 "findAll", new String[0]);
135 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
136 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
137 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
138
139
144 public void cacheResult(ExpandoColumn expandoColumn) {
145 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
146 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
147 expandoColumn);
148
149 expandoColumn.resetOriginalValues();
150 }
151
152
157 public void cacheResult(List<ExpandoColumn> expandoColumns) {
158 for (ExpandoColumn expandoColumn : expandoColumns) {
159 if (EntityCacheUtil.getResult(
160 ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
161 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey()) == null) {
162 cacheResult(expandoColumn);
163 }
164 else {
165 expandoColumn.resetOriginalValues();
166 }
167 }
168 }
169
170
177 @Override
178 public void clearCache() {
179 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
180 CacheRegistryUtil.clear(ExpandoColumnImpl.class.getName());
181 }
182
183 EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
184
185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
188 }
189
190
197 @Override
198 public void clearCache(ExpandoColumn expandoColumn) {
199 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
200 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
201
202 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
203 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
204 }
205
206 @Override
207 public void clearCache(List<ExpandoColumn> expandoColumns) {
208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
209 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
210
211 for (ExpandoColumn expandoColumn : expandoColumns) {
212 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
213 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
214 }
215 }
216
217
223 public ExpandoColumn create(long columnId) {
224 ExpandoColumn expandoColumn = new ExpandoColumnImpl();
225
226 expandoColumn.setNew(true);
227 expandoColumn.setPrimaryKey(columnId);
228
229 return expandoColumn;
230 }
231
232
240 public ExpandoColumn remove(long columnId)
241 throws NoSuchColumnException, SystemException {
242 return remove(Long.valueOf(columnId));
243 }
244
245
253 @Override
254 public ExpandoColumn remove(Serializable primaryKey)
255 throws NoSuchColumnException, SystemException {
256 Session session = null;
257
258 try {
259 session = openSession();
260
261 ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
262 primaryKey);
263
264 if (expandoColumn == null) {
265 if (_log.isWarnEnabled()) {
266 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
267 }
268
269 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
270 primaryKey);
271 }
272
273 return remove(expandoColumn);
274 }
275 catch (NoSuchColumnException nsee) {
276 throw nsee;
277 }
278 catch (Exception e) {
279 throw processException(e);
280 }
281 finally {
282 closeSession(session);
283 }
284 }
285
286 @Override
287 protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
288 throws SystemException {
289 expandoColumn = toUnwrappedModel(expandoColumn);
290
291 Session session = null;
292
293 try {
294 session = openSession();
295
296 BatchSessionUtil.delete(session, expandoColumn);
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304
305 clearCache(expandoColumn);
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) && !list.isEmpty()) {
576 for (ExpandoColumn expandoColumn : list) {
577 if ((tableId != expandoColumn.getTableId())) {
578 list = null;
579
580 break;
581 }
582 }
583 }
584
585 if (list == null) {
586 StringBundler query = null;
587
588 if (orderByComparator != null) {
589 query = new StringBundler(3 +
590 (orderByComparator.getOrderByFields().length * 3));
591 }
592 else {
593 query = new StringBundler(3);
594 }
595
596 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
597
598 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
599
600 if (orderByComparator != null) {
601 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
602 orderByComparator);
603 }
604
605 else {
606 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
607 }
608
609 String sql = query.toString();
610
611 Session session = null;
612
613 try {
614 session = openSession();
615
616 Query q = session.createQuery(sql);
617
618 QueryPos qPos = QueryPos.getInstance(q);
619
620 qPos.add(tableId);
621
622 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
623 start, end);
624 }
625 catch (Exception e) {
626 throw processException(e);
627 }
628 finally {
629 if (list == null) {
630 FinderCacheUtil.removeResult(finderPath, finderArgs);
631 }
632 else {
633 cacheResult(list);
634
635 FinderCacheUtil.putResult(finderPath, finderArgs, list);
636 }
637
638 closeSession(session);
639 }
640 }
641
642 return list;
643 }
644
645
654 public ExpandoColumn findByTableId_First(long tableId,
655 OrderByComparator orderByComparator)
656 throws NoSuchColumnException, SystemException {
657 ExpandoColumn expandoColumn = fetchByTableId_First(tableId,
658 orderByComparator);
659
660 if (expandoColumn != null) {
661 return expandoColumn;
662 }
663
664 StringBundler msg = new StringBundler(4);
665
666 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
667
668 msg.append("tableId=");
669 msg.append(tableId);
670
671 msg.append(StringPool.CLOSE_CURLY_BRACE);
672
673 throw new NoSuchColumnException(msg.toString());
674 }
675
676
684 public ExpandoColumn fetchByTableId_First(long tableId,
685 OrderByComparator orderByComparator) throws SystemException {
686 List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
687 orderByComparator);
688
689 if (!list.isEmpty()) {
690 return list.get(0);
691 }
692
693 return null;
694 }
695
696
705 public ExpandoColumn findByTableId_Last(long tableId,
706 OrderByComparator orderByComparator)
707 throws NoSuchColumnException, SystemException {
708 ExpandoColumn expandoColumn = fetchByTableId_Last(tableId,
709 orderByComparator);
710
711 if (expandoColumn != null) {
712 return expandoColumn;
713 }
714
715 StringBundler msg = new StringBundler(4);
716
717 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
718
719 msg.append("tableId=");
720 msg.append(tableId);
721
722 msg.append(StringPool.CLOSE_CURLY_BRACE);
723
724 throw new NoSuchColumnException(msg.toString());
725 }
726
727
735 public ExpandoColumn fetchByTableId_Last(long tableId,
736 OrderByComparator orderByComparator) throws SystemException {
737 int count = countByTableId(tableId);
738
739 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
740 orderByComparator);
741
742 if (!list.isEmpty()) {
743 return list.get(0);
744 }
745
746 return null;
747 }
748
749
759 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
760 long tableId, OrderByComparator orderByComparator)
761 throws NoSuchColumnException, SystemException {
762 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
763
764 Session session = null;
765
766 try {
767 session = openSession();
768
769 ExpandoColumn[] array = new ExpandoColumnImpl[3];
770
771 array[0] = getByTableId_PrevAndNext(session, expandoColumn,
772 tableId, orderByComparator, true);
773
774 array[1] = expandoColumn;
775
776 array[2] = getByTableId_PrevAndNext(session, expandoColumn,
777 tableId, orderByComparator, false);
778
779 return array;
780 }
781 catch (Exception e) {
782 throw processException(e);
783 }
784 finally {
785 closeSession(session);
786 }
787 }
788
789 protected ExpandoColumn getByTableId_PrevAndNext(Session session,
790 ExpandoColumn expandoColumn, long tableId,
791 OrderByComparator orderByComparator, boolean previous) {
792 StringBundler query = null;
793
794 if (orderByComparator != null) {
795 query = new StringBundler(6 +
796 (orderByComparator.getOrderByFields().length * 6));
797 }
798 else {
799 query = new StringBundler(3);
800 }
801
802 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
803
804 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
805
806 if (orderByComparator != null) {
807 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
808
809 if (orderByConditionFields.length > 0) {
810 query.append(WHERE_AND);
811 }
812
813 for (int i = 0; i < orderByConditionFields.length; i++) {
814 query.append(_ORDER_BY_ENTITY_ALIAS);
815 query.append(orderByConditionFields[i]);
816
817 if ((i + 1) < orderByConditionFields.length) {
818 if (orderByComparator.isAscending() ^ previous) {
819 query.append(WHERE_GREATER_THAN_HAS_NEXT);
820 }
821 else {
822 query.append(WHERE_LESSER_THAN_HAS_NEXT);
823 }
824 }
825 else {
826 if (orderByComparator.isAscending() ^ previous) {
827 query.append(WHERE_GREATER_THAN);
828 }
829 else {
830 query.append(WHERE_LESSER_THAN);
831 }
832 }
833 }
834
835 query.append(ORDER_BY_CLAUSE);
836
837 String[] orderByFields = orderByComparator.getOrderByFields();
838
839 for (int i = 0; i < orderByFields.length; i++) {
840 query.append(_ORDER_BY_ENTITY_ALIAS);
841 query.append(orderByFields[i]);
842
843 if ((i + 1) < orderByFields.length) {
844 if (orderByComparator.isAscending() ^ previous) {
845 query.append(ORDER_BY_ASC_HAS_NEXT);
846 }
847 else {
848 query.append(ORDER_BY_DESC_HAS_NEXT);
849 }
850 }
851 else {
852 if (orderByComparator.isAscending() ^ previous) {
853 query.append(ORDER_BY_ASC);
854 }
855 else {
856 query.append(ORDER_BY_DESC);
857 }
858 }
859 }
860 }
861
862 else {
863 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
864 }
865
866 String sql = query.toString();
867
868 Query q = session.createQuery(sql);
869
870 q.setFirstResult(0);
871 q.setMaxResults(2);
872
873 QueryPos qPos = QueryPos.getInstance(q);
874
875 qPos.add(tableId);
876
877 if (orderByComparator != null) {
878 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
879
880 for (Object value : values) {
881 qPos.add(value);
882 }
883 }
884
885 List<ExpandoColumn> list = q.list();
886
887 if (list.size() == 2) {
888 return list.get(1);
889 }
890 else {
891 return null;
892 }
893 }
894
895
902 public List<ExpandoColumn> filterFindByTableId(long tableId)
903 throws SystemException {
904 return filterFindByTableId(tableId, QueryUtil.ALL_POS,
905 QueryUtil.ALL_POS, null);
906 }
907
908
921 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
922 int end) throws SystemException {
923 return filterFindByTableId(tableId, start, end, null);
924 }
925
926
940 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
941 int end, OrderByComparator orderByComparator) throws SystemException {
942 if (!InlineSQLHelperUtil.isEnabled()) {
943 return findByTableId(tableId, start, end, orderByComparator);
944 }
945
946 StringBundler query = null;
947
948 if (orderByComparator != null) {
949 query = new StringBundler(3 +
950 (orderByComparator.getOrderByFields().length * 3));
951 }
952 else {
953 query = new StringBundler(3);
954 }
955
956 if (getDB().isSupportsInlineDistinct()) {
957 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
958 }
959 else {
960 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
961 }
962
963 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
964
965 if (!getDB().isSupportsInlineDistinct()) {
966 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
967 }
968
969 if (orderByComparator != null) {
970 if (getDB().isSupportsInlineDistinct()) {
971 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
972 orderByComparator);
973 }
974 else {
975 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
976 orderByComparator);
977 }
978 }
979
980 else {
981 if (getDB().isSupportsInlineDistinct()) {
982 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
983 }
984 else {
985 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
986 }
987 }
988
989 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
990 ExpandoColumn.class.getName(),
991 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
992
993 Session session = null;
994
995 try {
996 session = openSession();
997
998 SQLQuery q = session.createSQLQuery(sql);
999
1000 if (getDB().isSupportsInlineDistinct()) {
1001 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1002 }
1003 else {
1004 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1005 }
1006
1007 QueryPos qPos = QueryPos.getInstance(q);
1008
1009 qPos.add(tableId);
1010
1011 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
1012 end);
1013 }
1014 catch (Exception e) {
1015 throw processException(e);
1016 }
1017 finally {
1018 closeSession(session);
1019 }
1020 }
1021
1022
1032 public ExpandoColumn[] filterFindByTableId_PrevAndNext(long columnId,
1033 long tableId, OrderByComparator orderByComparator)
1034 throws NoSuchColumnException, SystemException {
1035 if (!InlineSQLHelperUtil.isEnabled()) {
1036 return findByTableId_PrevAndNext(columnId, tableId,
1037 orderByComparator);
1038 }
1039
1040 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1041
1042 Session session = null;
1043
1044 try {
1045 session = openSession();
1046
1047 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1048
1049 array[0] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1050 tableId, orderByComparator, true);
1051
1052 array[1] = expandoColumn;
1053
1054 array[2] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1055 tableId, orderByComparator, false);
1056
1057 return array;
1058 }
1059 catch (Exception e) {
1060 throw processException(e);
1061 }
1062 finally {
1063 closeSession(session);
1064 }
1065 }
1066
1067 protected ExpandoColumn filterGetByTableId_PrevAndNext(Session session,
1068 ExpandoColumn expandoColumn, long tableId,
1069 OrderByComparator orderByComparator, boolean previous) {
1070 StringBundler query = null;
1071
1072 if (orderByComparator != null) {
1073 query = new StringBundler(6 +
1074 (orderByComparator.getOrderByFields().length * 6));
1075 }
1076 else {
1077 query = new StringBundler(3);
1078 }
1079
1080 if (getDB().isSupportsInlineDistinct()) {
1081 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1082 }
1083 else {
1084 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1085 }
1086
1087 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1088
1089 if (!getDB().isSupportsInlineDistinct()) {
1090 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1091 }
1092
1093 if (orderByComparator != null) {
1094 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1095
1096 if (orderByConditionFields.length > 0) {
1097 query.append(WHERE_AND);
1098 }
1099
1100 for (int i = 0; i < orderByConditionFields.length; i++) {
1101 if (getDB().isSupportsInlineDistinct()) {
1102 query.append(_ORDER_BY_ENTITY_ALIAS);
1103 }
1104 else {
1105 query.append(_ORDER_BY_ENTITY_TABLE);
1106 }
1107
1108 query.append(orderByConditionFields[i]);
1109
1110 if ((i + 1) < orderByConditionFields.length) {
1111 if (orderByComparator.isAscending() ^ previous) {
1112 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1113 }
1114 else {
1115 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1116 }
1117 }
1118 else {
1119 if (orderByComparator.isAscending() ^ previous) {
1120 query.append(WHERE_GREATER_THAN);
1121 }
1122 else {
1123 query.append(WHERE_LESSER_THAN);
1124 }
1125 }
1126 }
1127
1128 query.append(ORDER_BY_CLAUSE);
1129
1130 String[] orderByFields = orderByComparator.getOrderByFields();
1131
1132 for (int i = 0; i < orderByFields.length; i++) {
1133 if (getDB().isSupportsInlineDistinct()) {
1134 query.append(_ORDER_BY_ENTITY_ALIAS);
1135 }
1136 else {
1137 query.append(_ORDER_BY_ENTITY_TABLE);
1138 }
1139
1140 query.append(orderByFields[i]);
1141
1142 if ((i + 1) < orderByFields.length) {
1143 if (orderByComparator.isAscending() ^ previous) {
1144 query.append(ORDER_BY_ASC_HAS_NEXT);
1145 }
1146 else {
1147 query.append(ORDER_BY_DESC_HAS_NEXT);
1148 }
1149 }
1150 else {
1151 if (orderByComparator.isAscending() ^ previous) {
1152 query.append(ORDER_BY_ASC);
1153 }
1154 else {
1155 query.append(ORDER_BY_DESC);
1156 }
1157 }
1158 }
1159 }
1160
1161 else {
1162 if (getDB().isSupportsInlineDistinct()) {
1163 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1164 }
1165 else {
1166 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1167 }
1168 }
1169
1170 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1171 ExpandoColumn.class.getName(),
1172 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1173
1174 SQLQuery q = session.createSQLQuery(sql);
1175
1176 q.setFirstResult(0);
1177 q.setMaxResults(2);
1178
1179 if (getDB().isSupportsInlineDistinct()) {
1180 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1181 }
1182 else {
1183 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1184 }
1185
1186 QueryPos qPos = QueryPos.getInstance(q);
1187
1188 qPos.add(tableId);
1189
1190 if (orderByComparator != null) {
1191 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1192
1193 for (Object value : values) {
1194 qPos.add(value);
1195 }
1196 }
1197
1198 List<ExpandoColumn> list = q.list();
1199
1200 if (list.size() == 2) {
1201 return list.get(1);
1202 }
1203 else {
1204 return null;
1205 }
1206 }
1207
1208
1216 public List<ExpandoColumn> findByT_N(long tableId, String name)
1217 throws SystemException {
1218 return findByT_N(tableId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1219 null);
1220 }
1221
1222
1236 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1237 int end) throws SystemException {
1238 return findByT_N(tableId, name, start, end, null);
1239 }
1240
1241
1256 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1257 int end, OrderByComparator orderByComparator) throws SystemException {
1258 FinderPath finderPath = null;
1259 Object[] finderArgs = null;
1260
1261 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1262 (orderByComparator == null)) {
1263 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N;
1264 finderArgs = new Object[] { tableId, name };
1265 }
1266 else {
1267 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1268 finderArgs = new Object[] {
1269 tableId, name,
1270
1271 start, end, orderByComparator
1272 };
1273 }
1274
1275 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1276 finderArgs, this);
1277
1278 if ((list != null) && !list.isEmpty()) {
1279 for (ExpandoColumn expandoColumn : list) {
1280 if ((tableId != expandoColumn.getTableId()) ||
1281 !Validator.equals(name, expandoColumn.getName())) {
1282 list = null;
1283
1284 break;
1285 }
1286 }
1287 }
1288
1289 if (list == null) {
1290 StringBundler query = null;
1291
1292 if (orderByComparator != null) {
1293 query = new StringBundler(4 +
1294 (orderByComparator.getOrderByFields().length * 3));
1295 }
1296 else {
1297 query = new StringBundler(4);
1298 }
1299
1300 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1301
1302 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1303
1304 if (name == null) {
1305 query.append(_FINDER_COLUMN_T_N_NAME_1);
1306 }
1307 else {
1308 if (name.equals(StringPool.BLANK)) {
1309 query.append(_FINDER_COLUMN_T_N_NAME_3);
1310 }
1311 else {
1312 query.append(_FINDER_COLUMN_T_N_NAME_2);
1313 }
1314 }
1315
1316 if (orderByComparator != null) {
1317 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1318 orderByComparator);
1319 }
1320
1321 else {
1322 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1323 }
1324
1325 String sql = query.toString();
1326
1327 Session session = null;
1328
1329 try {
1330 session = openSession();
1331
1332 Query q = session.createQuery(sql);
1333
1334 QueryPos qPos = QueryPos.getInstance(q);
1335
1336 qPos.add(tableId);
1337
1338 if (name != null) {
1339 qPos.add(name);
1340 }
1341
1342 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1343 start, end);
1344 }
1345 catch (Exception e) {
1346 throw processException(e);
1347 }
1348 finally {
1349 if (list == null) {
1350 FinderCacheUtil.removeResult(finderPath, finderArgs);
1351 }
1352 else {
1353 cacheResult(list);
1354
1355 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1356 }
1357
1358 closeSession(session);
1359 }
1360 }
1361
1362 return list;
1363 }
1364
1365
1375 public ExpandoColumn findByT_N_First(long tableId, String name,
1376 OrderByComparator orderByComparator)
1377 throws NoSuchColumnException, SystemException {
1378 ExpandoColumn expandoColumn = fetchByT_N_First(tableId, name,
1379 orderByComparator);
1380
1381 if (expandoColumn != null) {
1382 return expandoColumn;
1383 }
1384
1385 StringBundler msg = new StringBundler(6);
1386
1387 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1388
1389 msg.append("tableId=");
1390 msg.append(tableId);
1391
1392 msg.append(", name=");
1393 msg.append(name);
1394
1395 msg.append(StringPool.CLOSE_CURLY_BRACE);
1396
1397 throw new NoSuchColumnException(msg.toString());
1398 }
1399
1400
1409 public ExpandoColumn fetchByT_N_First(long tableId, String name,
1410 OrderByComparator orderByComparator) throws SystemException {
1411 List<ExpandoColumn> list = findByT_N(tableId, name, 0, 1,
1412 orderByComparator);
1413
1414 if (!list.isEmpty()) {
1415 return list.get(0);
1416 }
1417
1418 return null;
1419 }
1420
1421
1431 public ExpandoColumn findByT_N_Last(long tableId, String name,
1432 OrderByComparator orderByComparator)
1433 throws NoSuchColumnException, SystemException {
1434 ExpandoColumn expandoColumn = fetchByT_N_Last(tableId, name,
1435 orderByComparator);
1436
1437 if (expandoColumn != null) {
1438 return expandoColumn;
1439 }
1440
1441 StringBundler msg = new StringBundler(6);
1442
1443 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1444
1445 msg.append("tableId=");
1446 msg.append(tableId);
1447
1448 msg.append(", name=");
1449 msg.append(name);
1450
1451 msg.append(StringPool.CLOSE_CURLY_BRACE);
1452
1453 throw new NoSuchColumnException(msg.toString());
1454 }
1455
1456
1465 public ExpandoColumn fetchByT_N_Last(long tableId, String name,
1466 OrderByComparator orderByComparator) throws SystemException {
1467 int count = countByT_N(tableId, name);
1468
1469 List<ExpandoColumn> list = findByT_N(tableId, name, count - 1, count,
1470 orderByComparator);
1471
1472 if (!list.isEmpty()) {
1473 return list.get(0);
1474 }
1475
1476 return null;
1477 }
1478
1479
1490 public ExpandoColumn[] findByT_N_PrevAndNext(long columnId, long tableId,
1491 String name, OrderByComparator orderByComparator)
1492 throws NoSuchColumnException, SystemException {
1493 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1494
1495 Session session = null;
1496
1497 try {
1498 session = openSession();
1499
1500 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1501
1502 array[0] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1503 name, orderByComparator, true);
1504
1505 array[1] = expandoColumn;
1506
1507 array[2] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1508 name, orderByComparator, false);
1509
1510 return array;
1511 }
1512 catch (Exception e) {
1513 throw processException(e);
1514 }
1515 finally {
1516 closeSession(session);
1517 }
1518 }
1519
1520 protected ExpandoColumn getByT_N_PrevAndNext(Session session,
1521 ExpandoColumn expandoColumn, long tableId, String name,
1522 OrderByComparator orderByComparator, boolean previous) {
1523 StringBundler query = null;
1524
1525 if (orderByComparator != null) {
1526 query = new StringBundler(6 +
1527 (orderByComparator.getOrderByFields().length * 6));
1528 }
1529 else {
1530 query = new StringBundler(3);
1531 }
1532
1533 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1534
1535 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1536
1537 if (name == null) {
1538 query.append(_FINDER_COLUMN_T_N_NAME_1);
1539 }
1540 else {
1541 if (name.equals(StringPool.BLANK)) {
1542 query.append(_FINDER_COLUMN_T_N_NAME_3);
1543 }
1544 else {
1545 query.append(_FINDER_COLUMN_T_N_NAME_2);
1546 }
1547 }
1548
1549 if (orderByComparator != null) {
1550 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1551
1552 if (orderByConditionFields.length > 0) {
1553 query.append(WHERE_AND);
1554 }
1555
1556 for (int i = 0; i < orderByConditionFields.length; i++) {
1557 query.append(_ORDER_BY_ENTITY_ALIAS);
1558 query.append(orderByConditionFields[i]);
1559
1560 if ((i + 1) < orderByConditionFields.length) {
1561 if (orderByComparator.isAscending() ^ previous) {
1562 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1563 }
1564 else {
1565 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1566 }
1567 }
1568 else {
1569 if (orderByComparator.isAscending() ^ previous) {
1570 query.append(WHERE_GREATER_THAN);
1571 }
1572 else {
1573 query.append(WHERE_LESSER_THAN);
1574 }
1575 }
1576 }
1577
1578 query.append(ORDER_BY_CLAUSE);
1579
1580 String[] orderByFields = orderByComparator.getOrderByFields();
1581
1582 for (int i = 0; i < orderByFields.length; i++) {
1583 query.append(_ORDER_BY_ENTITY_ALIAS);
1584 query.append(orderByFields[i]);
1585
1586 if ((i + 1) < orderByFields.length) {
1587 if (orderByComparator.isAscending() ^ previous) {
1588 query.append(ORDER_BY_ASC_HAS_NEXT);
1589 }
1590 else {
1591 query.append(ORDER_BY_DESC_HAS_NEXT);
1592 }
1593 }
1594 else {
1595 if (orderByComparator.isAscending() ^ previous) {
1596 query.append(ORDER_BY_ASC);
1597 }
1598 else {
1599 query.append(ORDER_BY_DESC);
1600 }
1601 }
1602 }
1603 }
1604
1605 else {
1606 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1607 }
1608
1609 String sql = query.toString();
1610
1611 Query q = session.createQuery(sql);
1612
1613 q.setFirstResult(0);
1614 q.setMaxResults(2);
1615
1616 QueryPos qPos = QueryPos.getInstance(q);
1617
1618 qPos.add(tableId);
1619
1620 if (name != null) {
1621 qPos.add(name);
1622 }
1623
1624 if (orderByComparator != null) {
1625 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1626
1627 for (Object value : values) {
1628 qPos.add(value);
1629 }
1630 }
1631
1632 List<ExpandoColumn> list = q.list();
1633
1634 if (list.size() == 2) {
1635 return list.get(1);
1636 }
1637 else {
1638 return null;
1639 }
1640 }
1641
1642
1654 public List<ExpandoColumn> findByT_N(long tableId, String[] names)
1655 throws SystemException {
1656 return findByT_N(tableId, names, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1657 null);
1658 }
1659
1660
1674 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1675 int start, int end) throws SystemException {
1676 return findByT_N(tableId, names, start, end, null);
1677 }
1678
1679
1694 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1695 int start, int end, OrderByComparator orderByComparator)
1696 throws SystemException {
1697 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1698 Object[] finderArgs = null;
1699
1700 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1701 (orderByComparator == null)) {
1702 finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1703 }
1704 else {
1705 finderArgs = new Object[] {
1706 tableId, StringUtil.merge(names),
1707
1708 start, end, orderByComparator
1709 };
1710 }
1711
1712 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1713 finderArgs, this);
1714
1715 if ((list != null) && !list.isEmpty()) {
1716 for (ExpandoColumn expandoColumn : list) {
1717 if ((tableId != expandoColumn.getTableId()) ||
1718 !ArrayUtil.contains(names, expandoColumn.getName())) {
1719 list = null;
1720
1721 break;
1722 }
1723 }
1724 }
1725
1726 if (list == null) {
1727 StringBundler query = new StringBundler();
1728
1729 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1730
1731 boolean conjunctionable = false;
1732
1733 if (conjunctionable) {
1734 query.append(WHERE_AND);
1735 }
1736
1737 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1738
1739 conjunctionable = true;
1740
1741 if ((names == null) || (names.length > 0)) {
1742 if (conjunctionable) {
1743 query.append(WHERE_AND);
1744 }
1745
1746 query.append(StringPool.OPEN_PARENTHESIS);
1747
1748 for (int i = 0; i < names.length; i++) {
1749 String name = names[i];
1750
1751 if (name == null) {
1752 query.append(_FINDER_COLUMN_T_N_NAME_4);
1753 }
1754 else {
1755 if (name.equals(StringPool.BLANK)) {
1756 query.append(_FINDER_COLUMN_T_N_NAME_6);
1757 }
1758 else {
1759 query.append(_FINDER_COLUMN_T_N_NAME_5);
1760 }
1761 }
1762
1763 if ((i + 1) < names.length) {
1764 query.append(WHERE_OR);
1765 }
1766 }
1767
1768 query.append(StringPool.CLOSE_PARENTHESIS);
1769
1770 conjunctionable = true;
1771 }
1772
1773 if (orderByComparator != null) {
1774 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1775 orderByComparator);
1776 }
1777
1778 else {
1779 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1780 }
1781
1782 String sql = query.toString();
1783
1784 Session session = null;
1785
1786 try {
1787 session = openSession();
1788
1789 Query q = session.createQuery(sql);
1790
1791 QueryPos qPos = QueryPos.getInstance(q);
1792
1793 qPos.add(tableId);
1794
1795 if (names != null) {
1796 qPos.add(names);
1797 }
1798
1799 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1800 start, end);
1801 }
1802 catch (Exception e) {
1803 throw processException(e);
1804 }
1805 finally {
1806 if (list == null) {
1807 FinderCacheUtil.removeResult(finderPath, finderArgs);
1808 }
1809 else {
1810 cacheResult(list);
1811
1812 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1813 }
1814
1815 closeSession(session);
1816 }
1817 }
1818
1819 return list;
1820 }
1821
1822
1830 public List<ExpandoColumn> filterFindByT_N(long tableId, String name)
1831 throws SystemException {
1832 return filterFindByT_N(tableId, name, QueryUtil.ALL_POS,
1833 QueryUtil.ALL_POS, null);
1834 }
1835
1836
1850 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1851 int start, int end) throws SystemException {
1852 return filterFindByT_N(tableId, name, start, end, null);
1853 }
1854
1855
1870 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1871 int start, int end, OrderByComparator orderByComparator)
1872 throws SystemException {
1873 if (!InlineSQLHelperUtil.isEnabled()) {
1874 return findByT_N(tableId, name, start, end, orderByComparator);
1875 }
1876
1877 StringBundler query = null;
1878
1879 if (orderByComparator != null) {
1880 query = new StringBundler(4 +
1881 (orderByComparator.getOrderByFields().length * 3));
1882 }
1883 else {
1884 query = new StringBundler(4);
1885 }
1886
1887 if (getDB().isSupportsInlineDistinct()) {
1888 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1889 }
1890 else {
1891 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1892 }
1893
1894 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1895
1896 if (name == null) {
1897 query.append(_FINDER_COLUMN_T_N_NAME_1);
1898 }
1899 else {
1900 if (name.equals(StringPool.BLANK)) {
1901 query.append(_FINDER_COLUMN_T_N_NAME_3);
1902 }
1903 else {
1904 query.append(_FINDER_COLUMN_T_N_NAME_2);
1905 }
1906 }
1907
1908 if (!getDB().isSupportsInlineDistinct()) {
1909 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1910 }
1911
1912 if (orderByComparator != null) {
1913 if (getDB().isSupportsInlineDistinct()) {
1914 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1915 orderByComparator);
1916 }
1917 else {
1918 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1919 orderByComparator);
1920 }
1921 }
1922
1923 else {
1924 if (getDB().isSupportsInlineDistinct()) {
1925 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1926 }
1927 else {
1928 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1929 }
1930 }
1931
1932 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1933 ExpandoColumn.class.getName(),
1934 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1935
1936 Session session = null;
1937
1938 try {
1939 session = openSession();
1940
1941 SQLQuery q = session.createSQLQuery(sql);
1942
1943 if (getDB().isSupportsInlineDistinct()) {
1944 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1945 }
1946 else {
1947 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1948 }
1949
1950 QueryPos qPos = QueryPos.getInstance(q);
1951
1952 qPos.add(tableId);
1953
1954 if (name != null) {
1955 qPos.add(name);
1956 }
1957
1958 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
1959 end);
1960 }
1961 catch (Exception e) {
1962 throw processException(e);
1963 }
1964 finally {
1965 closeSession(session);
1966 }
1967 }
1968
1969
1980 public ExpandoColumn[] filterFindByT_N_PrevAndNext(long columnId,
1981 long tableId, String name, OrderByComparator orderByComparator)
1982 throws NoSuchColumnException, SystemException {
1983 if (!InlineSQLHelperUtil.isEnabled()) {
1984 return findByT_N_PrevAndNext(columnId, tableId, name,
1985 orderByComparator);
1986 }
1987
1988 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1989
1990 Session session = null;
1991
1992 try {
1993 session = openSession();
1994
1995 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1996
1997 array[0] = filterGetByT_N_PrevAndNext(session, expandoColumn,
1998 tableId, name, orderByComparator, true);
1999
2000 array[1] = expandoColumn;
2001
2002 array[2] = filterGetByT_N_PrevAndNext(session, expandoColumn,
2003 tableId, name, orderByComparator, false);
2004
2005 return array;
2006 }
2007 catch (Exception e) {
2008 throw processException(e);
2009 }
2010 finally {
2011 closeSession(session);
2012 }
2013 }
2014
2015 protected ExpandoColumn filterGetByT_N_PrevAndNext(Session session,
2016 ExpandoColumn expandoColumn, long tableId, String name,
2017 OrderByComparator orderByComparator, boolean previous) {
2018 StringBundler query = null;
2019
2020 if (orderByComparator != null) {
2021 query = new StringBundler(6 +
2022 (orderByComparator.getOrderByFields().length * 6));
2023 }
2024 else {
2025 query = new StringBundler(3);
2026 }
2027
2028 if (getDB().isSupportsInlineDistinct()) {
2029 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
2030 }
2031 else {
2032 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
2033 }
2034
2035 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2036
2037 if (name == null) {
2038 query.append(_FINDER_COLUMN_T_N_NAME_1);
2039 }
2040 else {
2041 if (name.equals(StringPool.BLANK)) {
2042 query.append(_FINDER_COLUMN_T_N_NAME_3);
2043 }
2044 else {
2045 query.append(_FINDER_COLUMN_T_N_NAME_2);
2046 }
2047 }
2048
2049 if (!getDB().isSupportsInlineDistinct()) {
2050 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
2051 }
2052
2053 if (orderByComparator != null) {
2054 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2055
2056 if (orderByConditionFields.length > 0) {
2057 query.append(WHERE_AND);
2058 }
2059
2060 for (int i = 0; i < orderByConditionFields.length; i++) {
2061 if (getDB().isSupportsInlineDistinct()) {
2062 query.append(_ORDER_BY_ENTITY_ALIAS);
2063 }
2064 else {
2065 query.append(_ORDER_BY_ENTITY_TABLE);
2066 }
2067
2068 query.append(orderByConditionFields[i]);
2069
2070 if ((i + 1) < orderByConditionFields.length) {
2071 if (orderByComparator.isAscending() ^ previous) {
2072 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2073 }
2074 else {
2075 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2076 }
2077 }
2078 else {
2079 if (orderByComparator.isAscending() ^ previous) {
2080 query.append(WHERE_GREATER_THAN);
2081 }
2082 else {
2083 query.append(WHERE_LESSER_THAN);
2084 }
2085 }
2086 }
2087
2088 query.append(ORDER_BY_CLAUSE);
2089
2090 String[] orderByFields = orderByComparator.getOrderByFields();
2091
2092 for (int i = 0; i < orderByFields.length; i++) {
2093 if (getDB().isSupportsInlineDistinct()) {
2094 query.append(_ORDER_BY_ENTITY_ALIAS);
2095 }
2096 else {
2097 query.append(_ORDER_BY_ENTITY_TABLE);
2098 }
2099
2100 query.append(orderByFields[i]);
2101
2102 if ((i + 1) < orderByFields.length) {
2103 if (orderByComparator.isAscending() ^ previous) {
2104 query.append(ORDER_BY_ASC_HAS_NEXT);
2105 }
2106 else {
2107 query.append(ORDER_BY_DESC_HAS_NEXT);
2108 }
2109 }
2110 else {
2111 if (orderByComparator.isAscending() ^ previous) {
2112 query.append(ORDER_BY_ASC);
2113 }
2114 else {
2115 query.append(ORDER_BY_DESC);
2116 }
2117 }
2118 }
2119 }
2120
2121 else {
2122 if (getDB().isSupportsInlineDistinct()) {
2123 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2124 }
2125 else {
2126 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2127 }
2128 }
2129
2130 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2131 ExpandoColumn.class.getName(),
2132 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2133
2134 SQLQuery q = session.createSQLQuery(sql);
2135
2136 q.setFirstResult(0);
2137 q.setMaxResults(2);
2138
2139 if (getDB().isSupportsInlineDistinct()) {
2140 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2141 }
2142 else {
2143 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2144 }
2145
2146 QueryPos qPos = QueryPos.getInstance(q);
2147
2148 qPos.add(tableId);
2149
2150 if (name != null) {
2151 qPos.add(name);
2152 }
2153
2154 if (orderByComparator != null) {
2155 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
2156
2157 for (Object value : values) {
2158 qPos.add(value);
2159 }
2160 }
2161
2162 List<ExpandoColumn> list = q.list();
2163
2164 if (list.size() == 2) {
2165 return list.get(1);
2166 }
2167 else {
2168 return null;
2169 }
2170 }
2171
2172
2180 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names)
2181 throws SystemException {
2182 return filterFindByT_N(tableId, names, QueryUtil.ALL_POS,
2183 QueryUtil.ALL_POS, null);
2184 }
2185
2186
2200 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2201 int start, int end) throws SystemException {
2202 return filterFindByT_N(tableId, names, start, end, null);
2203 }
2204
2205
2220 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2221 int start, int end, OrderByComparator orderByComparator)
2222 throws SystemException {
2223 if (!InlineSQLHelperUtil.isEnabled()) {
2224 return findByT_N(tableId, names, start, end, orderByComparator);
2225 }
2226
2227 StringBundler query = new StringBundler();
2228
2229 if (getDB().isSupportsInlineDistinct()) {
2230 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
2231 }
2232 else {
2233 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
2234 }
2235
2236 boolean conjunctionable = false;
2237
2238 if (conjunctionable) {
2239 query.append(WHERE_AND);
2240 }
2241
2242 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2243
2244 conjunctionable = true;
2245
2246 if ((names == null) || (names.length > 0)) {
2247 if (conjunctionable) {
2248 query.append(WHERE_AND);
2249 }
2250
2251 query.append(StringPool.OPEN_PARENTHESIS);
2252
2253 for (int i = 0; i < names.length; i++) {
2254 String name = names[i];
2255
2256 if (name == null) {
2257 query.append(_FINDER_COLUMN_T_N_NAME_4);
2258 }
2259 else {
2260 if (name.equals(StringPool.BLANK)) {
2261 query.append(_FINDER_COLUMN_T_N_NAME_6);
2262 }
2263 else {
2264 query.append(_FINDER_COLUMN_T_N_NAME_5);
2265 }
2266 }
2267
2268 if ((i + 1) < names.length) {
2269 query.append(WHERE_OR);
2270 }
2271 }
2272
2273 query.append(StringPool.CLOSE_PARENTHESIS);
2274
2275 conjunctionable = true;
2276 }
2277
2278 if (!getDB().isSupportsInlineDistinct()) {
2279 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
2280 }
2281
2282 if (orderByComparator != null) {
2283 if (getDB().isSupportsInlineDistinct()) {
2284 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2285 orderByComparator);
2286 }
2287 else {
2288 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2289 orderByComparator);
2290 }
2291 }
2292
2293 else {
2294 if (getDB().isSupportsInlineDistinct()) {
2295 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2296 }
2297 else {
2298 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2299 }
2300 }
2301
2302 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2303 ExpandoColumn.class.getName(),
2304 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2305
2306 Session session = null;
2307
2308 try {
2309 session = openSession();
2310
2311 SQLQuery q = session.createSQLQuery(sql);
2312
2313 if (getDB().isSupportsInlineDistinct()) {
2314 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2315 }
2316 else {
2317 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2318 }
2319
2320 QueryPos qPos = QueryPos.getInstance(q);
2321
2322 qPos.add(tableId);
2323
2324 if (names != null) {
2325 qPos.add(names);
2326 }
2327
2328 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
2329 end);
2330 }
2331 catch (Exception e) {
2332 throw processException(e);
2333 }
2334 finally {
2335 closeSession(session);
2336 }
2337 }
2338
2339
2345 public List<ExpandoColumn> findAll() throws SystemException {
2346 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2347 }
2348
2349
2361 public List<ExpandoColumn> findAll(int start, int end)
2362 throws SystemException {
2363 return findAll(start, end, null);
2364 }
2365
2366
2379 public List<ExpandoColumn> findAll(int start, int end,
2380 OrderByComparator orderByComparator) throws SystemException {
2381 FinderPath finderPath = null;
2382 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2383
2384 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2385 (orderByComparator == null)) {
2386 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2387 finderArgs = FINDER_ARGS_EMPTY;
2388 }
2389 else {
2390 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2391 finderArgs = new Object[] { start, end, orderByComparator };
2392 }
2393
2394 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
2395 finderArgs, this);
2396
2397 if (list == null) {
2398 StringBundler query = null;
2399 String sql = null;
2400
2401 if (orderByComparator != null) {
2402 query = new StringBundler(2 +
2403 (orderByComparator.getOrderByFields().length * 3));
2404
2405 query.append(_SQL_SELECT_EXPANDOCOLUMN);
2406
2407 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2408 orderByComparator);
2409
2410 sql = query.toString();
2411 }
2412 else {
2413 sql = _SQL_SELECT_EXPANDOCOLUMN.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2414 }
2415
2416 Session session = null;
2417
2418 try {
2419 session = openSession();
2420
2421 Query q = session.createQuery(sql);
2422
2423 if (orderByComparator == null) {
2424 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2425 start, end, false);
2426
2427 Collections.sort(list);
2428 }
2429 else {
2430 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2431 start, end);
2432 }
2433 }
2434 catch (Exception e) {
2435 throw processException(e);
2436 }
2437 finally {
2438 if (list == null) {
2439 FinderCacheUtil.removeResult(finderPath, finderArgs);
2440 }
2441 else {
2442 cacheResult(list);
2443
2444 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2445 }
2446
2447 closeSession(session);
2448 }
2449 }
2450
2451 return list;
2452 }
2453
2454
2460 public void removeByTableId(long tableId) throws SystemException {
2461 for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
2462 remove(expandoColumn);
2463 }
2464 }
2465
2466
2473 public void removeByT_N(long tableId, String name)
2474 throws SystemException {
2475 for (ExpandoColumn expandoColumn : findByT_N(tableId, name)) {
2476 remove(expandoColumn);
2477 }
2478 }
2479
2480
2485 public void removeAll() throws SystemException {
2486 for (ExpandoColumn expandoColumn : findAll()) {
2487 remove(expandoColumn);
2488 }
2489 }
2490
2491
2498 public int countByTableId(long tableId) throws SystemException {
2499 Object[] finderArgs = new Object[] { tableId };
2500
2501 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
2502 finderArgs, this);
2503
2504 if (count == null) {
2505 StringBundler query = new StringBundler(2);
2506
2507 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2508
2509 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2510
2511 String sql = query.toString();
2512
2513 Session session = null;
2514
2515 try {
2516 session = openSession();
2517
2518 Query q = session.createQuery(sql);
2519
2520 QueryPos qPos = QueryPos.getInstance(q);
2521
2522 qPos.add(tableId);
2523
2524 count = (Long)q.uniqueResult();
2525 }
2526 catch (Exception e) {
2527 throw processException(e);
2528 }
2529 finally {
2530 if (count == null) {
2531 count = Long.valueOf(0);
2532 }
2533
2534 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
2535 finderArgs, count);
2536
2537 closeSession(session);
2538 }
2539 }
2540
2541 return count.intValue();
2542 }
2543
2544
2551 public int filterCountByTableId(long tableId) throws SystemException {
2552 if (!InlineSQLHelperUtil.isEnabled()) {
2553 return countByTableId(tableId);
2554 }
2555
2556 StringBundler query = new StringBundler(2);
2557
2558 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2559
2560 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2561
2562 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2563 ExpandoColumn.class.getName(),
2564 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2565
2566 Session session = null;
2567
2568 try {
2569 session = openSession();
2570
2571 SQLQuery q = session.createSQLQuery(sql);
2572
2573 q.addScalar(COUNT_COLUMN_NAME,
2574 com.liferay.portal.kernel.dao.orm.Type.LONG);
2575
2576 QueryPos qPos = QueryPos.getInstance(q);
2577
2578 qPos.add(tableId);
2579
2580 Long count = (Long)q.uniqueResult();
2581
2582 return count.intValue();
2583 }
2584 catch (Exception e) {
2585 throw processException(e);
2586 }
2587 finally {
2588 closeSession(session);
2589 }
2590 }
2591
2592
2600 public int countByT_N(long tableId, String name) throws SystemException {
2601 Object[] finderArgs = new Object[] { tableId, name };
2602
2603 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
2604 finderArgs, this);
2605
2606 if (count == null) {
2607 StringBundler query = new StringBundler(3);
2608
2609 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2610
2611 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2612
2613 if (name == null) {
2614 query.append(_FINDER_COLUMN_T_N_NAME_1);
2615 }
2616 else {
2617 if (name.equals(StringPool.BLANK)) {
2618 query.append(_FINDER_COLUMN_T_N_NAME_3);
2619 }
2620 else {
2621 query.append(_FINDER_COLUMN_T_N_NAME_2);
2622 }
2623 }
2624
2625 String sql = query.toString();
2626
2627 Session session = null;
2628
2629 try {
2630 session = openSession();
2631
2632 Query q = session.createQuery(sql);
2633
2634 QueryPos qPos = QueryPos.getInstance(q);
2635
2636 qPos.add(tableId);
2637
2638 if (name != null) {
2639 qPos.add(name);
2640 }
2641
2642 count = (Long)q.uniqueResult();
2643 }
2644 catch (Exception e) {
2645 throw processException(e);
2646 }
2647 finally {
2648 if (count == null) {
2649 count = Long.valueOf(0);
2650 }
2651
2652 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
2653 count);
2654
2655 closeSession(session);
2656 }
2657 }
2658
2659 return count.intValue();
2660 }
2661
2662
2670 public int countByT_N(long tableId, String[] names)
2671 throws SystemException {
2672 Object[] finderArgs = new Object[] { tableId, StringUtil.merge(names) };
2673
2674 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
2675 finderArgs, this);
2676
2677 if (count == null) {
2678 StringBundler query = new StringBundler();
2679
2680 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2681
2682 boolean conjunctionable = false;
2683
2684 if (conjunctionable) {
2685 query.append(WHERE_AND);
2686 }
2687
2688 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2689
2690 conjunctionable = true;
2691
2692 if ((names == null) || (names.length > 0)) {
2693 if (conjunctionable) {
2694 query.append(WHERE_AND);
2695 }
2696
2697 query.append(StringPool.OPEN_PARENTHESIS);
2698
2699 for (int i = 0; i < names.length; i++) {
2700 String name = names[i];
2701
2702 if (name == null) {
2703 query.append(_FINDER_COLUMN_T_N_NAME_4);
2704 }
2705 else {
2706 if (name.equals(StringPool.BLANK)) {
2707 query.append(_FINDER_COLUMN_T_N_NAME_6);
2708 }
2709 else {
2710 query.append(_FINDER_COLUMN_T_N_NAME_5);
2711 }
2712 }
2713
2714 if ((i + 1) < names.length) {
2715 query.append(WHERE_OR);
2716 }
2717 }
2718
2719 query.append(StringPool.CLOSE_PARENTHESIS);
2720
2721 conjunctionable = true;
2722 }
2723
2724 String sql = query.toString();
2725
2726 Session session = null;
2727
2728 try {
2729 session = openSession();
2730
2731 Query q = session.createQuery(sql);
2732
2733 QueryPos qPos = QueryPos.getInstance(q);
2734
2735 qPos.add(tableId);
2736
2737 if (names != null) {
2738 qPos.add(names);
2739 }
2740
2741 count = (Long)q.uniqueResult();
2742 }
2743 catch (Exception e) {
2744 throw processException(e);
2745 }
2746 finally {
2747 if (count == null) {
2748 count = Long.valueOf(0);
2749 }
2750
2751 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
2752 finderArgs, count);
2753
2754 closeSession(session);
2755 }
2756 }
2757
2758 return count.intValue();
2759 }
2760
2761
2769 public int filterCountByT_N(long tableId, String name)
2770 throws SystemException {
2771 if (!InlineSQLHelperUtil.isEnabled()) {
2772 return countByT_N(tableId, name);
2773 }
2774
2775 StringBundler query = new StringBundler(3);
2776
2777 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2778
2779 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2780
2781 if (name == null) {
2782 query.append(_FINDER_COLUMN_T_N_NAME_1);
2783 }
2784 else {
2785 if (name.equals(StringPool.BLANK)) {
2786 query.append(_FINDER_COLUMN_T_N_NAME_3);
2787 }
2788 else {
2789 query.append(_FINDER_COLUMN_T_N_NAME_2);
2790 }
2791 }
2792
2793 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2794 ExpandoColumn.class.getName(),
2795 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2796
2797 Session session = null;
2798
2799 try {
2800 session = openSession();
2801
2802 SQLQuery q = session.createSQLQuery(sql);
2803
2804 q.addScalar(COUNT_COLUMN_NAME,
2805 com.liferay.portal.kernel.dao.orm.Type.LONG);
2806
2807 QueryPos qPos = QueryPos.getInstance(q);
2808
2809 qPos.add(tableId);
2810
2811 if (name != null) {
2812 qPos.add(name);
2813 }
2814
2815 Long count = (Long)q.uniqueResult();
2816
2817 return count.intValue();
2818 }
2819 catch (Exception e) {
2820 throw processException(e);
2821 }
2822 finally {
2823 closeSession(session);
2824 }
2825 }
2826
2827
2835 public int filterCountByT_N(long tableId, String[] names)
2836 throws SystemException {
2837 if (!InlineSQLHelperUtil.isEnabled()) {
2838 return countByT_N(tableId, names);
2839 }
2840
2841 StringBundler query = new StringBundler();
2842
2843 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2844
2845 boolean conjunctionable = false;
2846
2847 if (conjunctionable) {
2848 query.append(WHERE_AND);
2849 }
2850
2851 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2852
2853 conjunctionable = true;
2854
2855 if ((names == null) || (names.length > 0)) {
2856 if (conjunctionable) {
2857 query.append(WHERE_AND);
2858 }
2859
2860 query.append(StringPool.OPEN_PARENTHESIS);
2861
2862 for (int i = 0; i < names.length; i++) {
2863 String name = names[i];
2864
2865 if (name == null) {
2866 query.append(_FINDER_COLUMN_T_N_NAME_4);
2867 }
2868 else {
2869 if (name.equals(StringPool.BLANK)) {
2870 query.append(_FINDER_COLUMN_T_N_NAME_6);
2871 }
2872 else {
2873 query.append(_FINDER_COLUMN_T_N_NAME_5);
2874 }
2875 }
2876
2877 if ((i + 1) < names.length) {
2878 query.append(WHERE_OR);
2879 }
2880 }
2881
2882 query.append(StringPool.CLOSE_PARENTHESIS);
2883
2884 conjunctionable = true;
2885 }
2886
2887 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2888 ExpandoColumn.class.getName(),
2889 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2890
2891 Session session = null;
2892
2893 try {
2894 session = openSession();
2895
2896 SQLQuery q = session.createSQLQuery(sql);
2897
2898 q.addScalar(COUNT_COLUMN_NAME,
2899 com.liferay.portal.kernel.dao.orm.Type.LONG);
2900
2901 QueryPos qPos = QueryPos.getInstance(q);
2902
2903 qPos.add(tableId);
2904
2905 if (names != null) {
2906 qPos.add(names);
2907 }
2908
2909 Long count = (Long)q.uniqueResult();
2910
2911 return count.intValue();
2912 }
2913 catch (Exception e) {
2914 throw processException(e);
2915 }
2916 finally {
2917 closeSession(session);
2918 }
2919 }
2920
2921
2927 public int countAll() throws SystemException {
2928 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2929 FINDER_ARGS_EMPTY, this);
2930
2931 if (count == null) {
2932 Session session = null;
2933
2934 try {
2935 session = openSession();
2936
2937 Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
2938
2939 count = (Long)q.uniqueResult();
2940 }
2941 catch (Exception e) {
2942 throw processException(e);
2943 }
2944 finally {
2945 if (count == null) {
2946 count = Long.valueOf(0);
2947 }
2948
2949 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2950 FINDER_ARGS_EMPTY, count);
2951
2952 closeSession(session);
2953 }
2954 }
2955
2956 return count.intValue();
2957 }
2958
2959
2962 public void afterPropertiesSet() {
2963 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2964 com.liferay.portal.util.PropsUtil.get(
2965 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
2966
2967 if (listenerClassNames.length > 0) {
2968 try {
2969 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
2970
2971 for (String listenerClassName : listenerClassNames) {
2972 Class<?> clazz = getClass();
2973
2974 listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
2975 clazz.getClassLoader(), listenerClassName));
2976 }
2977
2978 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2979 }
2980 catch (Exception e) {
2981 _log.error(e);
2982 }
2983 }
2984 }
2985
2986 public void destroy() {
2987 EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
2988 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2989 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2990 }
2991
2992 @BeanReference(type = ExpandoColumnPersistence.class)
2993 protected ExpandoColumnPersistence expandoColumnPersistence;
2994 @BeanReference(type = ExpandoRowPersistence.class)
2995 protected ExpandoRowPersistence expandoRowPersistence;
2996 @BeanReference(type = ExpandoTablePersistence.class)
2997 protected ExpandoTablePersistence expandoTablePersistence;
2998 @BeanReference(type = ExpandoValuePersistence.class)
2999 protected ExpandoValuePersistence expandoValuePersistence;
3000 @BeanReference(type = ResourcePersistence.class)
3001 protected ResourcePersistence resourcePersistence;
3002 @BeanReference(type = UserPersistence.class)
3003 protected UserPersistence userPersistence;
3004 private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
3005 private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
3006 private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
3007 private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
3008 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
3009 private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
3010 private static final String _FINDER_COLUMN_T_N_TABLEID_5 = "(" +
3011 _removeConjunction(_FINDER_COLUMN_T_N_TABLEID_2) + ")";
3012 private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
3013 private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
3014 private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = ?)";
3015 private static final String _FINDER_COLUMN_T_N_NAME_4 = "(" +
3016 _removeConjunction(_FINDER_COLUMN_T_N_NAME_1) + ")";
3017 private static final String _FINDER_COLUMN_T_N_NAME_5 = "(" +
3018 _removeConjunction(_FINDER_COLUMN_T_N_NAME_2) + ")";
3019 private static final String _FINDER_COLUMN_T_N_NAME_6 = "(" +
3020 _removeConjunction(_FINDER_COLUMN_T_N_NAME_3) + ")";
3021
3022 private static String _removeConjunction(String sql) {
3023 int pos = sql.indexOf(" AND ");
3024
3025 if (pos != -1) {
3026 sql = sql.substring(0, pos);
3027 }
3028
3029 return sql;
3030 }
3031
3032 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "expandoColumn.columnId";
3033 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
3034 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
3035 "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
3036 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
3037 ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
3038 private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
3039 private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
3040 private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
3041 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
3042 private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
3043 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
3044 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
3045 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3046 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
3047 private static ExpandoColumn _nullExpandoColumn = new ExpandoColumnImpl() {
3048 @Override
3049 public Object clone() {
3050 return this;
3051 }
3052
3053 @Override
3054 public CacheModel<ExpandoColumn> toCacheModel() {
3055 return _nullExpandoColumnCacheModel;
3056 }
3057 };
3058
3059 private static CacheModel<ExpandoColumn> _nullExpandoColumnCacheModel = new CacheModel<ExpandoColumn>() {
3060 public ExpandoColumn toEntityModel() {
3061 return _nullExpandoColumn;
3062 }
3063 };
3064 }