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.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_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
122 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
123 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByT_N",
124 new String[] { Long.class.getName(), String.class.getName() });
125 public static final FinderPath FINDER_PATH_WITH_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_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
130 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
131 ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
132 "findAll", new String[0]);
133 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
134 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
135 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
136
137
142 public void cacheResult(ExpandoColumn expandoColumn) {
143 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
144 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
145 expandoColumn);
146
147 expandoColumn.resetOriginalValues();
148 }
149
150
155 public void cacheResult(List<ExpandoColumn> expandoColumns) {
156 for (ExpandoColumn expandoColumn : expandoColumns) {
157 if (EntityCacheUtil.getResult(
158 ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
159 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey()) == null) {
160 cacheResult(expandoColumn);
161 }
162 else {
163 expandoColumn.resetOriginalValues();
164 }
165 }
166 }
167
168
175 @Override
176 public void clearCache() {
177 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
178 CacheRegistryUtil.clear(ExpandoColumnImpl.class.getName());
179 }
180
181 EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
182
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
186 }
187
188
195 @Override
196 public void clearCache(ExpandoColumn expandoColumn) {
197 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
198 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
199
200 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
201 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
202 }
203
204 @Override
205 public void clearCache(List<ExpandoColumn> expandoColumns) {
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
208
209 for (ExpandoColumn expandoColumn : expandoColumns) {
210 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
211 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
212 }
213 }
214
215
221 public ExpandoColumn create(long columnId) {
222 ExpandoColumn expandoColumn = new ExpandoColumnImpl();
223
224 expandoColumn.setNew(true);
225 expandoColumn.setPrimaryKey(columnId);
226
227 return expandoColumn;
228 }
229
230
238 public ExpandoColumn remove(long columnId)
239 throws NoSuchColumnException, SystemException {
240 return remove(Long.valueOf(columnId));
241 }
242
243
251 @Override
252 public ExpandoColumn remove(Serializable primaryKey)
253 throws NoSuchColumnException, SystemException {
254 Session session = null;
255
256 try {
257 session = openSession();
258
259 ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
260 primaryKey);
261
262 if (expandoColumn == null) {
263 if (_log.isWarnEnabled()) {
264 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
265 }
266
267 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
268 primaryKey);
269 }
270
271 return remove(expandoColumn);
272 }
273 catch (NoSuchColumnException nsee) {
274 throw nsee;
275 }
276 catch (Exception e) {
277 throw processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282 }
283
284 @Override
285 protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
286 throws SystemException {
287 expandoColumn = toUnwrappedModel(expandoColumn);
288
289 Session session = null;
290
291 try {
292 session = openSession();
293
294 if (expandoColumn.isCachedModel()) {
295 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
296 expandoColumn.getPrimaryKeyObj());
297 }
298
299 session.delete(expandoColumn);
300 }
301 catch (Exception e) {
302 throw processException(e);
303 }
304 finally {
305 closeSession(session);
306 }
307
308 clearCache(expandoColumn);
309
310 return expandoColumn;
311 }
312
313 @Override
314 public ExpandoColumn updateImpl(
315 com.liferay.portlet.expando.model.ExpandoColumn expandoColumn)
316 throws SystemException {
317 expandoColumn = toUnwrappedModel(expandoColumn);
318
319 boolean isNew = expandoColumn.isNew();
320
321 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
322
323 Session session = null;
324
325 try {
326 session = openSession();
327
328 if (expandoColumn.isNew()) {
329 session.save(expandoColumn);
330
331 expandoColumn.setNew(false);
332 }
333 else {
334 session.merge(expandoColumn);
335 }
336 }
337 catch (Exception e) {
338 throw processException(e);
339 }
340 finally {
341 closeSession(session);
342 }
343
344 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
345
346 if (isNew || !ExpandoColumnModelImpl.COLUMN_BITMASK_ENABLED) {
347 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
348 }
349
350 else {
351 if ((expandoColumnModelImpl.getColumnBitmask() &
352 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
353 Object[] args = new Object[] {
354 Long.valueOf(expandoColumnModelImpl.getOriginalTableId())
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 args = new Object[] {
362 Long.valueOf(expandoColumnModelImpl.getTableId())
363 };
364
365 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
366 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
367 args);
368 }
369
370 if ((expandoColumnModelImpl.getColumnBitmask() &
371 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N.getColumnBitmask()) != 0) {
372 Object[] args = new Object[] {
373 Long.valueOf(expandoColumnModelImpl.getOriginalTableId()),
374
375 expandoColumnModelImpl.getOriginalName()
376 };
377
378 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
379 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
380 args);
381
382 args = new Object[] {
383 Long.valueOf(expandoColumnModelImpl.getTableId()),
384
385 expandoColumnModelImpl.getName()
386 };
387
388 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
389 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
390 args);
391 }
392 }
393
394 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
395 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
396 expandoColumn);
397
398 return expandoColumn;
399 }
400
401 protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
402 if (expandoColumn instanceof ExpandoColumnImpl) {
403 return expandoColumn;
404 }
405
406 ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
407
408 expandoColumnImpl.setNew(expandoColumn.isNew());
409 expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
410
411 expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
412 expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
413 expandoColumnImpl.setTableId(expandoColumn.getTableId());
414 expandoColumnImpl.setName(expandoColumn.getName());
415 expandoColumnImpl.setType(expandoColumn.getType());
416 expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
417 expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
418
419 return expandoColumnImpl;
420 }
421
422
430 @Override
431 public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
432 throws NoSuchModelException, SystemException {
433 return findByPrimaryKey(((Long)primaryKey).longValue());
434 }
435
436
444 public ExpandoColumn findByPrimaryKey(long columnId)
445 throws NoSuchColumnException, SystemException {
446 ExpandoColumn expandoColumn = fetchByPrimaryKey(columnId);
447
448 if (expandoColumn == null) {
449 if (_log.isWarnEnabled()) {
450 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
451 }
452
453 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
454 columnId);
455 }
456
457 return expandoColumn;
458 }
459
460
467 @Override
468 public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey)
469 throws SystemException {
470 return fetchByPrimaryKey(((Long)primaryKey).longValue());
471 }
472
473
480 public ExpandoColumn fetchByPrimaryKey(long columnId)
481 throws SystemException {
482 ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
483 ExpandoColumnImpl.class, columnId);
484
485 if (expandoColumn == _nullExpandoColumn) {
486 return null;
487 }
488
489 if (expandoColumn == null) {
490 Session session = null;
491
492 boolean hasException = false;
493
494 try {
495 session = openSession();
496
497 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
498 Long.valueOf(columnId));
499 }
500 catch (Exception e) {
501 hasException = true;
502
503 throw processException(e);
504 }
505 finally {
506 if (expandoColumn != null) {
507 cacheResult(expandoColumn);
508 }
509 else if (!hasException) {
510 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
511 ExpandoColumnImpl.class, columnId, _nullExpandoColumn);
512 }
513
514 closeSession(session);
515 }
516 }
517
518 return expandoColumn;
519 }
520
521
528 public List<ExpandoColumn> findByTableId(long tableId)
529 throws SystemException {
530 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
531 }
532
533
546 public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
547 throws SystemException {
548 return findByTableId(tableId, start, end, null);
549 }
550
551
565 public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
566 OrderByComparator orderByComparator) throws SystemException {
567 FinderPath finderPath = null;
568 Object[] finderArgs = null;
569
570 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
571 (orderByComparator == null)) {
572 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
573 finderArgs = new Object[] { tableId };
574 }
575 else {
576 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
577 finderArgs = new Object[] { tableId, start, end, orderByComparator };
578 }
579
580 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
581 finderArgs, this);
582
583 if ((list != null) && !list.isEmpty()) {
584 for (ExpandoColumn expandoColumn : list) {
585 if ((tableId != expandoColumn.getTableId())) {
586 list = null;
587
588 break;
589 }
590 }
591 }
592
593 if (list == null) {
594 StringBundler query = null;
595
596 if (orderByComparator != null) {
597 query = new StringBundler(3 +
598 (orderByComparator.getOrderByFields().length * 3));
599 }
600 else {
601 query = new StringBundler(3);
602 }
603
604 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
605
606 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
607
608 if (orderByComparator != null) {
609 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
610 orderByComparator);
611 }
612
613 else {
614 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
615 }
616
617 String sql = query.toString();
618
619 Session session = null;
620
621 try {
622 session = openSession();
623
624 Query q = session.createQuery(sql);
625
626 QueryPos qPos = QueryPos.getInstance(q);
627
628 qPos.add(tableId);
629
630 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
631 start, end);
632 }
633 catch (Exception e) {
634 throw processException(e);
635 }
636 finally {
637 if (list == null) {
638 FinderCacheUtil.removeResult(finderPath, finderArgs);
639 }
640 else {
641 cacheResult(list);
642
643 FinderCacheUtil.putResult(finderPath, finderArgs, list);
644 }
645
646 closeSession(session);
647 }
648 }
649
650 return list;
651 }
652
653
662 public ExpandoColumn findByTableId_First(long tableId,
663 OrderByComparator orderByComparator)
664 throws NoSuchColumnException, SystemException {
665 ExpandoColumn expandoColumn = fetchByTableId_First(tableId,
666 orderByComparator);
667
668 if (expandoColumn != null) {
669 return expandoColumn;
670 }
671
672 StringBundler msg = new StringBundler(4);
673
674 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
675
676 msg.append("tableId=");
677 msg.append(tableId);
678
679 msg.append(StringPool.CLOSE_CURLY_BRACE);
680
681 throw new NoSuchColumnException(msg.toString());
682 }
683
684
692 public ExpandoColumn fetchByTableId_First(long tableId,
693 OrderByComparator orderByComparator) throws SystemException {
694 List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
695 orderByComparator);
696
697 if (!list.isEmpty()) {
698 return list.get(0);
699 }
700
701 return null;
702 }
703
704
713 public ExpandoColumn findByTableId_Last(long tableId,
714 OrderByComparator orderByComparator)
715 throws NoSuchColumnException, SystemException {
716 ExpandoColumn expandoColumn = fetchByTableId_Last(tableId,
717 orderByComparator);
718
719 if (expandoColumn != null) {
720 return expandoColumn;
721 }
722
723 StringBundler msg = new StringBundler(4);
724
725 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
726
727 msg.append("tableId=");
728 msg.append(tableId);
729
730 msg.append(StringPool.CLOSE_CURLY_BRACE);
731
732 throw new NoSuchColumnException(msg.toString());
733 }
734
735
743 public ExpandoColumn fetchByTableId_Last(long tableId,
744 OrderByComparator orderByComparator) throws SystemException {
745 int count = countByTableId(tableId);
746
747 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
748 orderByComparator);
749
750 if (!list.isEmpty()) {
751 return list.get(0);
752 }
753
754 return null;
755 }
756
757
767 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
768 long tableId, OrderByComparator orderByComparator)
769 throws NoSuchColumnException, SystemException {
770 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
771
772 Session session = null;
773
774 try {
775 session = openSession();
776
777 ExpandoColumn[] array = new ExpandoColumnImpl[3];
778
779 array[0] = getByTableId_PrevAndNext(session, expandoColumn,
780 tableId, orderByComparator, true);
781
782 array[1] = expandoColumn;
783
784 array[2] = getByTableId_PrevAndNext(session, expandoColumn,
785 tableId, orderByComparator, false);
786
787 return array;
788 }
789 catch (Exception e) {
790 throw processException(e);
791 }
792 finally {
793 closeSession(session);
794 }
795 }
796
797 protected ExpandoColumn getByTableId_PrevAndNext(Session session,
798 ExpandoColumn expandoColumn, long tableId,
799 OrderByComparator orderByComparator, boolean previous) {
800 StringBundler query = null;
801
802 if (orderByComparator != null) {
803 query = new StringBundler(6 +
804 (orderByComparator.getOrderByFields().length * 6));
805 }
806 else {
807 query = new StringBundler(3);
808 }
809
810 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
811
812 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
813
814 if (orderByComparator != null) {
815 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
816
817 if (orderByConditionFields.length > 0) {
818 query.append(WHERE_AND);
819 }
820
821 for (int i = 0; i < orderByConditionFields.length; i++) {
822 query.append(_ORDER_BY_ENTITY_ALIAS);
823 query.append(orderByConditionFields[i]);
824
825 if ((i + 1) < orderByConditionFields.length) {
826 if (orderByComparator.isAscending() ^ previous) {
827 query.append(WHERE_GREATER_THAN_HAS_NEXT);
828 }
829 else {
830 query.append(WHERE_LESSER_THAN_HAS_NEXT);
831 }
832 }
833 else {
834 if (orderByComparator.isAscending() ^ previous) {
835 query.append(WHERE_GREATER_THAN);
836 }
837 else {
838 query.append(WHERE_LESSER_THAN);
839 }
840 }
841 }
842
843 query.append(ORDER_BY_CLAUSE);
844
845 String[] orderByFields = orderByComparator.getOrderByFields();
846
847 for (int i = 0; i < orderByFields.length; i++) {
848 query.append(_ORDER_BY_ENTITY_ALIAS);
849 query.append(orderByFields[i]);
850
851 if ((i + 1) < orderByFields.length) {
852 if (orderByComparator.isAscending() ^ previous) {
853 query.append(ORDER_BY_ASC_HAS_NEXT);
854 }
855 else {
856 query.append(ORDER_BY_DESC_HAS_NEXT);
857 }
858 }
859 else {
860 if (orderByComparator.isAscending() ^ previous) {
861 query.append(ORDER_BY_ASC);
862 }
863 else {
864 query.append(ORDER_BY_DESC);
865 }
866 }
867 }
868 }
869
870 else {
871 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
872 }
873
874 String sql = query.toString();
875
876 Query q = session.createQuery(sql);
877
878 q.setFirstResult(0);
879 q.setMaxResults(2);
880
881 QueryPos qPos = QueryPos.getInstance(q);
882
883 qPos.add(tableId);
884
885 if (orderByComparator != null) {
886 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
887
888 for (Object value : values) {
889 qPos.add(value);
890 }
891 }
892
893 List<ExpandoColumn> list = q.list();
894
895 if (list.size() == 2) {
896 return list.get(1);
897 }
898 else {
899 return null;
900 }
901 }
902
903
910 public List<ExpandoColumn> filterFindByTableId(long tableId)
911 throws SystemException {
912 return filterFindByTableId(tableId, QueryUtil.ALL_POS,
913 QueryUtil.ALL_POS, null);
914 }
915
916
929 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
930 int end) throws SystemException {
931 return filterFindByTableId(tableId, start, end, null);
932 }
933
934
948 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
949 int end, OrderByComparator orderByComparator) throws SystemException {
950 if (!InlineSQLHelperUtil.isEnabled()) {
951 return findByTableId(tableId, start, end, orderByComparator);
952 }
953
954 StringBundler query = null;
955
956 if (orderByComparator != null) {
957 query = new StringBundler(3 +
958 (orderByComparator.getOrderByFields().length * 3));
959 }
960 else {
961 query = new StringBundler(3);
962 }
963
964 if (getDB().isSupportsInlineDistinct()) {
965 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
966 }
967 else {
968 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
969 }
970
971 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
972
973 if (!getDB().isSupportsInlineDistinct()) {
974 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
975 }
976
977 if (orderByComparator != null) {
978 if (getDB().isSupportsInlineDistinct()) {
979 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
980 orderByComparator);
981 }
982 else {
983 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
984 orderByComparator);
985 }
986 }
987
988 else {
989 if (getDB().isSupportsInlineDistinct()) {
990 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
991 }
992 else {
993 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
994 }
995 }
996
997 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
998 ExpandoColumn.class.getName(),
999 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1000
1001 Session session = null;
1002
1003 try {
1004 session = openSession();
1005
1006 SQLQuery q = session.createSQLQuery(sql);
1007
1008 if (getDB().isSupportsInlineDistinct()) {
1009 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1010 }
1011 else {
1012 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1013 }
1014
1015 QueryPos qPos = QueryPos.getInstance(q);
1016
1017 qPos.add(tableId);
1018
1019 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
1020 end);
1021 }
1022 catch (Exception e) {
1023 throw processException(e);
1024 }
1025 finally {
1026 closeSession(session);
1027 }
1028 }
1029
1030
1040 public ExpandoColumn[] filterFindByTableId_PrevAndNext(long columnId,
1041 long tableId, OrderByComparator orderByComparator)
1042 throws NoSuchColumnException, SystemException {
1043 if (!InlineSQLHelperUtil.isEnabled()) {
1044 return findByTableId_PrevAndNext(columnId, tableId,
1045 orderByComparator);
1046 }
1047
1048 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1049
1050 Session session = null;
1051
1052 try {
1053 session = openSession();
1054
1055 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1056
1057 array[0] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1058 tableId, orderByComparator, true);
1059
1060 array[1] = expandoColumn;
1061
1062 array[2] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1063 tableId, orderByComparator, false);
1064
1065 return array;
1066 }
1067 catch (Exception e) {
1068 throw processException(e);
1069 }
1070 finally {
1071 closeSession(session);
1072 }
1073 }
1074
1075 protected ExpandoColumn filterGetByTableId_PrevAndNext(Session session,
1076 ExpandoColumn expandoColumn, long tableId,
1077 OrderByComparator orderByComparator, boolean previous) {
1078 StringBundler query = null;
1079
1080 if (orderByComparator != null) {
1081 query = new StringBundler(6 +
1082 (orderByComparator.getOrderByFields().length * 6));
1083 }
1084 else {
1085 query = new StringBundler(3);
1086 }
1087
1088 if (getDB().isSupportsInlineDistinct()) {
1089 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1090 }
1091 else {
1092 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1093 }
1094
1095 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1096
1097 if (!getDB().isSupportsInlineDistinct()) {
1098 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1099 }
1100
1101 if (orderByComparator != null) {
1102 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1103
1104 if (orderByConditionFields.length > 0) {
1105 query.append(WHERE_AND);
1106 }
1107
1108 for (int i = 0; i < orderByConditionFields.length; i++) {
1109 if (getDB().isSupportsInlineDistinct()) {
1110 query.append(_ORDER_BY_ENTITY_ALIAS);
1111 }
1112 else {
1113 query.append(_ORDER_BY_ENTITY_TABLE);
1114 }
1115
1116 query.append(orderByConditionFields[i]);
1117
1118 if ((i + 1) < orderByConditionFields.length) {
1119 if (orderByComparator.isAscending() ^ previous) {
1120 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1121 }
1122 else {
1123 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1124 }
1125 }
1126 else {
1127 if (orderByComparator.isAscending() ^ previous) {
1128 query.append(WHERE_GREATER_THAN);
1129 }
1130 else {
1131 query.append(WHERE_LESSER_THAN);
1132 }
1133 }
1134 }
1135
1136 query.append(ORDER_BY_CLAUSE);
1137
1138 String[] orderByFields = orderByComparator.getOrderByFields();
1139
1140 for (int i = 0; i < orderByFields.length; i++) {
1141 if (getDB().isSupportsInlineDistinct()) {
1142 query.append(_ORDER_BY_ENTITY_ALIAS);
1143 }
1144 else {
1145 query.append(_ORDER_BY_ENTITY_TABLE);
1146 }
1147
1148 query.append(orderByFields[i]);
1149
1150 if ((i + 1) < orderByFields.length) {
1151 if (orderByComparator.isAscending() ^ previous) {
1152 query.append(ORDER_BY_ASC_HAS_NEXT);
1153 }
1154 else {
1155 query.append(ORDER_BY_DESC_HAS_NEXT);
1156 }
1157 }
1158 else {
1159 if (orderByComparator.isAscending() ^ previous) {
1160 query.append(ORDER_BY_ASC);
1161 }
1162 else {
1163 query.append(ORDER_BY_DESC);
1164 }
1165 }
1166 }
1167 }
1168
1169 else {
1170 if (getDB().isSupportsInlineDistinct()) {
1171 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1172 }
1173 else {
1174 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1175 }
1176 }
1177
1178 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1179 ExpandoColumn.class.getName(),
1180 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1181
1182 SQLQuery q = session.createSQLQuery(sql);
1183
1184 q.setFirstResult(0);
1185 q.setMaxResults(2);
1186
1187 if (getDB().isSupportsInlineDistinct()) {
1188 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1189 }
1190 else {
1191 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1192 }
1193
1194 QueryPos qPos = QueryPos.getInstance(q);
1195
1196 qPos.add(tableId);
1197
1198 if (orderByComparator != null) {
1199 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1200
1201 for (Object value : values) {
1202 qPos.add(value);
1203 }
1204 }
1205
1206 List<ExpandoColumn> list = q.list();
1207
1208 if (list.size() == 2) {
1209 return list.get(1);
1210 }
1211 else {
1212 return null;
1213 }
1214 }
1215
1216
1224 public List<ExpandoColumn> findByT_N(long tableId, String name)
1225 throws SystemException {
1226 return findByT_N(tableId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1227 null);
1228 }
1229
1230
1244 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1245 int end) throws SystemException {
1246 return findByT_N(tableId, name, start, end, null);
1247 }
1248
1249
1264 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1265 int end, OrderByComparator orderByComparator) throws SystemException {
1266 FinderPath finderPath = null;
1267 Object[] finderArgs = null;
1268
1269 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1270 (orderByComparator == null)) {
1271 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N;
1272 finderArgs = new Object[] { tableId, name };
1273 }
1274 else {
1275 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1276 finderArgs = new Object[] {
1277 tableId, name,
1278
1279 start, end, orderByComparator
1280 };
1281 }
1282
1283 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1284 finderArgs, this);
1285
1286 if ((list != null) && !list.isEmpty()) {
1287 for (ExpandoColumn expandoColumn : list) {
1288 if ((tableId != expandoColumn.getTableId()) ||
1289 !Validator.equals(name, expandoColumn.getName())) {
1290 list = null;
1291
1292 break;
1293 }
1294 }
1295 }
1296
1297 if (list == null) {
1298 StringBundler query = null;
1299
1300 if (orderByComparator != null) {
1301 query = new StringBundler(4 +
1302 (orderByComparator.getOrderByFields().length * 3));
1303 }
1304 else {
1305 query = new StringBundler(4);
1306 }
1307
1308 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1309
1310 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1311
1312 if (name == null) {
1313 query.append(_FINDER_COLUMN_T_N_NAME_1);
1314 }
1315 else {
1316 if (name.equals(StringPool.BLANK)) {
1317 query.append(_FINDER_COLUMN_T_N_NAME_3);
1318 }
1319 else {
1320 query.append(_FINDER_COLUMN_T_N_NAME_2);
1321 }
1322 }
1323
1324 if (orderByComparator != null) {
1325 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1326 orderByComparator);
1327 }
1328
1329 else {
1330 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1331 }
1332
1333 String sql = query.toString();
1334
1335 Session session = null;
1336
1337 try {
1338 session = openSession();
1339
1340 Query q = session.createQuery(sql);
1341
1342 QueryPos qPos = QueryPos.getInstance(q);
1343
1344 qPos.add(tableId);
1345
1346 if (name != null) {
1347 qPos.add(name);
1348 }
1349
1350 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1351 start, end);
1352 }
1353 catch (Exception e) {
1354 throw processException(e);
1355 }
1356 finally {
1357 if (list == null) {
1358 FinderCacheUtil.removeResult(finderPath, finderArgs);
1359 }
1360 else {
1361 cacheResult(list);
1362
1363 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1364 }
1365
1366 closeSession(session);
1367 }
1368 }
1369
1370 return list;
1371 }
1372
1373
1383 public ExpandoColumn findByT_N_First(long tableId, String name,
1384 OrderByComparator orderByComparator)
1385 throws NoSuchColumnException, SystemException {
1386 ExpandoColumn expandoColumn = fetchByT_N_First(tableId, name,
1387 orderByComparator);
1388
1389 if (expandoColumn != null) {
1390 return expandoColumn;
1391 }
1392
1393 StringBundler msg = new StringBundler(6);
1394
1395 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1396
1397 msg.append("tableId=");
1398 msg.append(tableId);
1399
1400 msg.append(", name=");
1401 msg.append(name);
1402
1403 msg.append(StringPool.CLOSE_CURLY_BRACE);
1404
1405 throw new NoSuchColumnException(msg.toString());
1406 }
1407
1408
1417 public ExpandoColumn fetchByT_N_First(long tableId, String name,
1418 OrderByComparator orderByComparator) throws SystemException {
1419 List<ExpandoColumn> list = findByT_N(tableId, name, 0, 1,
1420 orderByComparator);
1421
1422 if (!list.isEmpty()) {
1423 return list.get(0);
1424 }
1425
1426 return null;
1427 }
1428
1429
1439 public ExpandoColumn findByT_N_Last(long tableId, String name,
1440 OrderByComparator orderByComparator)
1441 throws NoSuchColumnException, SystemException {
1442 ExpandoColumn expandoColumn = fetchByT_N_Last(tableId, name,
1443 orderByComparator);
1444
1445 if (expandoColumn != null) {
1446 return expandoColumn;
1447 }
1448
1449 StringBundler msg = new StringBundler(6);
1450
1451 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1452
1453 msg.append("tableId=");
1454 msg.append(tableId);
1455
1456 msg.append(", name=");
1457 msg.append(name);
1458
1459 msg.append(StringPool.CLOSE_CURLY_BRACE);
1460
1461 throw new NoSuchColumnException(msg.toString());
1462 }
1463
1464
1473 public ExpandoColumn fetchByT_N_Last(long tableId, String name,
1474 OrderByComparator orderByComparator) throws SystemException {
1475 int count = countByT_N(tableId, name);
1476
1477 List<ExpandoColumn> list = findByT_N(tableId, name, count - 1, count,
1478 orderByComparator);
1479
1480 if (!list.isEmpty()) {
1481 return list.get(0);
1482 }
1483
1484 return null;
1485 }
1486
1487
1498 public ExpandoColumn[] findByT_N_PrevAndNext(long columnId, long tableId,
1499 String name, OrderByComparator orderByComparator)
1500 throws NoSuchColumnException, SystemException {
1501 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1502
1503 Session session = null;
1504
1505 try {
1506 session = openSession();
1507
1508 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1509
1510 array[0] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1511 name, orderByComparator, true);
1512
1513 array[1] = expandoColumn;
1514
1515 array[2] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1516 name, orderByComparator, false);
1517
1518 return array;
1519 }
1520 catch (Exception e) {
1521 throw processException(e);
1522 }
1523 finally {
1524 closeSession(session);
1525 }
1526 }
1527
1528 protected ExpandoColumn getByT_N_PrevAndNext(Session session,
1529 ExpandoColumn expandoColumn, long tableId, String name,
1530 OrderByComparator orderByComparator, boolean previous) {
1531 StringBundler query = null;
1532
1533 if (orderByComparator != null) {
1534 query = new StringBundler(6 +
1535 (orderByComparator.getOrderByFields().length * 6));
1536 }
1537 else {
1538 query = new StringBundler(3);
1539 }
1540
1541 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1542
1543 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1544
1545 if (name == null) {
1546 query.append(_FINDER_COLUMN_T_N_NAME_1);
1547 }
1548 else {
1549 if (name.equals(StringPool.BLANK)) {
1550 query.append(_FINDER_COLUMN_T_N_NAME_3);
1551 }
1552 else {
1553 query.append(_FINDER_COLUMN_T_N_NAME_2);
1554 }
1555 }
1556
1557 if (orderByComparator != null) {
1558 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1559
1560 if (orderByConditionFields.length > 0) {
1561 query.append(WHERE_AND);
1562 }
1563
1564 for (int i = 0; i < orderByConditionFields.length; i++) {
1565 query.append(_ORDER_BY_ENTITY_ALIAS);
1566 query.append(orderByConditionFields[i]);
1567
1568 if ((i + 1) < orderByConditionFields.length) {
1569 if (orderByComparator.isAscending() ^ previous) {
1570 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1571 }
1572 else {
1573 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1574 }
1575 }
1576 else {
1577 if (orderByComparator.isAscending() ^ previous) {
1578 query.append(WHERE_GREATER_THAN);
1579 }
1580 else {
1581 query.append(WHERE_LESSER_THAN);
1582 }
1583 }
1584 }
1585
1586 query.append(ORDER_BY_CLAUSE);
1587
1588 String[] orderByFields = orderByComparator.getOrderByFields();
1589
1590 for (int i = 0; i < orderByFields.length; i++) {
1591 query.append(_ORDER_BY_ENTITY_ALIAS);
1592 query.append(orderByFields[i]);
1593
1594 if ((i + 1) < orderByFields.length) {
1595 if (orderByComparator.isAscending() ^ previous) {
1596 query.append(ORDER_BY_ASC_HAS_NEXT);
1597 }
1598 else {
1599 query.append(ORDER_BY_DESC_HAS_NEXT);
1600 }
1601 }
1602 else {
1603 if (orderByComparator.isAscending() ^ previous) {
1604 query.append(ORDER_BY_ASC);
1605 }
1606 else {
1607 query.append(ORDER_BY_DESC);
1608 }
1609 }
1610 }
1611 }
1612
1613 else {
1614 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1615 }
1616
1617 String sql = query.toString();
1618
1619 Query q = session.createQuery(sql);
1620
1621 q.setFirstResult(0);
1622 q.setMaxResults(2);
1623
1624 QueryPos qPos = QueryPos.getInstance(q);
1625
1626 qPos.add(tableId);
1627
1628 if (name != null) {
1629 qPos.add(name);
1630 }
1631
1632 if (orderByComparator != null) {
1633 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1634
1635 for (Object value : values) {
1636 qPos.add(value);
1637 }
1638 }
1639
1640 List<ExpandoColumn> list = q.list();
1641
1642 if (list.size() == 2) {
1643 return list.get(1);
1644 }
1645 else {
1646 return null;
1647 }
1648 }
1649
1650
1662 public List<ExpandoColumn> findByT_N(long tableId, String[] names)
1663 throws SystemException {
1664 return findByT_N(tableId, names, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1665 null);
1666 }
1667
1668
1682 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1683 int start, int end) throws SystemException {
1684 return findByT_N(tableId, names, start, end, null);
1685 }
1686
1687
1702 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1703 int start, int end, OrderByComparator orderByComparator)
1704 throws SystemException {
1705 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1706 Object[] finderArgs = null;
1707
1708 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1709 (orderByComparator == null)) {
1710 finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1711 }
1712 else {
1713 finderArgs = new Object[] {
1714 tableId, StringUtil.merge(names),
1715
1716 start, end, orderByComparator
1717 };
1718 }
1719
1720 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1721 finderArgs, this);
1722
1723 if ((list != null) && !list.isEmpty()) {
1724 for (ExpandoColumn expandoColumn : list) {
1725 if ((tableId != expandoColumn.getTableId()) ||
1726 !ArrayUtil.contains(names, expandoColumn.getName())) {
1727 list = null;
1728
1729 break;
1730 }
1731 }
1732 }
1733
1734 if (list == null) {
1735 StringBundler query = new StringBundler();
1736
1737 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1738
1739 boolean conjunctionable = false;
1740
1741 if (conjunctionable) {
1742 query.append(WHERE_AND);
1743 }
1744
1745 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1746
1747 conjunctionable = true;
1748
1749 if ((names == null) || (names.length > 0)) {
1750 if (conjunctionable) {
1751 query.append(WHERE_AND);
1752 }
1753
1754 query.append(StringPool.OPEN_PARENTHESIS);
1755
1756 for (int i = 0; i < names.length; i++) {
1757 String name = names[i];
1758
1759 if (name == null) {
1760 query.append(_FINDER_COLUMN_T_N_NAME_4);
1761 }
1762 else {
1763 if (name.equals(StringPool.BLANK)) {
1764 query.append(_FINDER_COLUMN_T_N_NAME_6);
1765 }
1766 else {
1767 query.append(_FINDER_COLUMN_T_N_NAME_5);
1768 }
1769 }
1770
1771 if ((i + 1) < names.length) {
1772 query.append(WHERE_OR);
1773 }
1774 }
1775
1776 query.append(StringPool.CLOSE_PARENTHESIS);
1777
1778 conjunctionable = true;
1779 }
1780
1781 if (orderByComparator != null) {
1782 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1783 orderByComparator);
1784 }
1785
1786 else {
1787 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1788 }
1789
1790 String sql = query.toString();
1791
1792 Session session = null;
1793
1794 try {
1795 session = openSession();
1796
1797 Query q = session.createQuery(sql);
1798
1799 QueryPos qPos = QueryPos.getInstance(q);
1800
1801 qPos.add(tableId);
1802
1803 if (names != null) {
1804 qPos.add(names);
1805 }
1806
1807 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1808 start, end);
1809 }
1810 catch (Exception e) {
1811 throw processException(e);
1812 }
1813 finally {
1814 if (list == null) {
1815 FinderCacheUtil.removeResult(finderPath, finderArgs);
1816 }
1817 else {
1818 cacheResult(list);
1819
1820 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1821 }
1822
1823 closeSession(session);
1824 }
1825 }
1826
1827 return list;
1828 }
1829
1830
1838 public List<ExpandoColumn> filterFindByT_N(long tableId, String name)
1839 throws SystemException {
1840 return filterFindByT_N(tableId, name, QueryUtil.ALL_POS,
1841 QueryUtil.ALL_POS, null);
1842 }
1843
1844
1858 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1859 int start, int end) throws SystemException {
1860 return filterFindByT_N(tableId, name, start, end, null);
1861 }
1862
1863
1878 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1879 int start, int end, OrderByComparator orderByComparator)
1880 throws SystemException {
1881 if (!InlineSQLHelperUtil.isEnabled()) {
1882 return findByT_N(tableId, name, start, end, orderByComparator);
1883 }
1884
1885 StringBundler query = null;
1886
1887 if (orderByComparator != null) {
1888 query = new StringBundler(4 +
1889 (orderByComparator.getOrderByFields().length * 3));
1890 }
1891 else {
1892 query = new StringBundler(4);
1893 }
1894
1895 if (getDB().isSupportsInlineDistinct()) {
1896 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1897 }
1898 else {
1899 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1900 }
1901
1902 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1903
1904 if (name == null) {
1905 query.append(_FINDER_COLUMN_T_N_NAME_1);
1906 }
1907 else {
1908 if (name.equals(StringPool.BLANK)) {
1909 query.append(_FINDER_COLUMN_T_N_NAME_3);
1910 }
1911 else {
1912 query.append(_FINDER_COLUMN_T_N_NAME_2);
1913 }
1914 }
1915
1916 if (!getDB().isSupportsInlineDistinct()) {
1917 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1918 }
1919
1920 if (orderByComparator != null) {
1921 if (getDB().isSupportsInlineDistinct()) {
1922 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1923 orderByComparator);
1924 }
1925 else {
1926 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1927 orderByComparator);
1928 }
1929 }
1930
1931 else {
1932 if (getDB().isSupportsInlineDistinct()) {
1933 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1934 }
1935 else {
1936 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1937 }
1938 }
1939
1940 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1941 ExpandoColumn.class.getName(),
1942 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1943
1944 Session session = null;
1945
1946 try {
1947 session = openSession();
1948
1949 SQLQuery q = session.createSQLQuery(sql);
1950
1951 if (getDB().isSupportsInlineDistinct()) {
1952 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1953 }
1954 else {
1955 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1956 }
1957
1958 QueryPos qPos = QueryPos.getInstance(q);
1959
1960 qPos.add(tableId);
1961
1962 if (name != null) {
1963 qPos.add(name);
1964 }
1965
1966 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
1967 end);
1968 }
1969 catch (Exception e) {
1970 throw processException(e);
1971 }
1972 finally {
1973 closeSession(session);
1974 }
1975 }
1976
1977
1988 public ExpandoColumn[] filterFindByT_N_PrevAndNext(long columnId,
1989 long tableId, String name, OrderByComparator orderByComparator)
1990 throws NoSuchColumnException, SystemException {
1991 if (!InlineSQLHelperUtil.isEnabled()) {
1992 return findByT_N_PrevAndNext(columnId, tableId, name,
1993 orderByComparator);
1994 }
1995
1996 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1997
1998 Session session = null;
1999
2000 try {
2001 session = openSession();
2002
2003 ExpandoColumn[] array = new ExpandoColumnImpl[3];
2004
2005 array[0] = filterGetByT_N_PrevAndNext(session, expandoColumn,
2006 tableId, name, orderByComparator, true);
2007
2008 array[1] = expandoColumn;
2009
2010 array[2] = filterGetByT_N_PrevAndNext(session, expandoColumn,
2011 tableId, name, orderByComparator, false);
2012
2013 return array;
2014 }
2015 catch (Exception e) {
2016 throw processException(e);
2017 }
2018 finally {
2019 closeSession(session);
2020 }
2021 }
2022
2023 protected ExpandoColumn filterGetByT_N_PrevAndNext(Session session,
2024 ExpandoColumn expandoColumn, long tableId, String name,
2025 OrderByComparator orderByComparator, boolean previous) {
2026 StringBundler query = null;
2027
2028 if (orderByComparator != null) {
2029 query = new StringBundler(6 +
2030 (orderByComparator.getOrderByFields().length * 6));
2031 }
2032 else {
2033 query = new StringBundler(3);
2034 }
2035
2036 if (getDB().isSupportsInlineDistinct()) {
2037 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
2038 }
2039 else {
2040 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
2041 }
2042
2043 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2044
2045 if (name == null) {
2046 query.append(_FINDER_COLUMN_T_N_NAME_1);
2047 }
2048 else {
2049 if (name.equals(StringPool.BLANK)) {
2050 query.append(_FINDER_COLUMN_T_N_NAME_3);
2051 }
2052 else {
2053 query.append(_FINDER_COLUMN_T_N_NAME_2);
2054 }
2055 }
2056
2057 if (!getDB().isSupportsInlineDistinct()) {
2058 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
2059 }
2060
2061 if (orderByComparator != null) {
2062 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2063
2064 if (orderByConditionFields.length > 0) {
2065 query.append(WHERE_AND);
2066 }
2067
2068 for (int i = 0; i < orderByConditionFields.length; i++) {
2069 if (getDB().isSupportsInlineDistinct()) {
2070 query.append(_ORDER_BY_ENTITY_ALIAS);
2071 }
2072 else {
2073 query.append(_ORDER_BY_ENTITY_TABLE);
2074 }
2075
2076 query.append(orderByConditionFields[i]);
2077
2078 if ((i + 1) < orderByConditionFields.length) {
2079 if (orderByComparator.isAscending() ^ previous) {
2080 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2081 }
2082 else {
2083 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2084 }
2085 }
2086 else {
2087 if (orderByComparator.isAscending() ^ previous) {
2088 query.append(WHERE_GREATER_THAN);
2089 }
2090 else {
2091 query.append(WHERE_LESSER_THAN);
2092 }
2093 }
2094 }
2095
2096 query.append(ORDER_BY_CLAUSE);
2097
2098 String[] orderByFields = orderByComparator.getOrderByFields();
2099
2100 for (int i = 0; i < orderByFields.length; i++) {
2101 if (getDB().isSupportsInlineDistinct()) {
2102 query.append(_ORDER_BY_ENTITY_ALIAS);
2103 }
2104 else {
2105 query.append(_ORDER_BY_ENTITY_TABLE);
2106 }
2107
2108 query.append(orderByFields[i]);
2109
2110 if ((i + 1) < orderByFields.length) {
2111 if (orderByComparator.isAscending() ^ previous) {
2112 query.append(ORDER_BY_ASC_HAS_NEXT);
2113 }
2114 else {
2115 query.append(ORDER_BY_DESC_HAS_NEXT);
2116 }
2117 }
2118 else {
2119 if (orderByComparator.isAscending() ^ previous) {
2120 query.append(ORDER_BY_ASC);
2121 }
2122 else {
2123 query.append(ORDER_BY_DESC);
2124 }
2125 }
2126 }
2127 }
2128
2129 else {
2130 if (getDB().isSupportsInlineDistinct()) {
2131 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2132 }
2133 else {
2134 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2135 }
2136 }
2137
2138 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2139 ExpandoColumn.class.getName(),
2140 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2141
2142 SQLQuery q = session.createSQLQuery(sql);
2143
2144 q.setFirstResult(0);
2145 q.setMaxResults(2);
2146
2147 if (getDB().isSupportsInlineDistinct()) {
2148 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2149 }
2150 else {
2151 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2152 }
2153
2154 QueryPos qPos = QueryPos.getInstance(q);
2155
2156 qPos.add(tableId);
2157
2158 if (name != null) {
2159 qPos.add(name);
2160 }
2161
2162 if (orderByComparator != null) {
2163 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
2164
2165 for (Object value : values) {
2166 qPos.add(value);
2167 }
2168 }
2169
2170 List<ExpandoColumn> list = q.list();
2171
2172 if (list.size() == 2) {
2173 return list.get(1);
2174 }
2175 else {
2176 return null;
2177 }
2178 }
2179
2180
2188 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names)
2189 throws SystemException {
2190 return filterFindByT_N(tableId, names, QueryUtil.ALL_POS,
2191 QueryUtil.ALL_POS, null);
2192 }
2193
2194
2208 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2209 int start, int end) throws SystemException {
2210 return filterFindByT_N(tableId, names, start, end, null);
2211 }
2212
2213
2228 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2229 int start, int end, OrderByComparator orderByComparator)
2230 throws SystemException {
2231 if (!InlineSQLHelperUtil.isEnabled()) {
2232 return findByT_N(tableId, names, start, end, orderByComparator);
2233 }
2234
2235 StringBundler query = new StringBundler();
2236
2237 if (getDB().isSupportsInlineDistinct()) {
2238 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
2239 }
2240 else {
2241 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
2242 }
2243
2244 boolean conjunctionable = false;
2245
2246 if (conjunctionable) {
2247 query.append(WHERE_AND);
2248 }
2249
2250 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2251
2252 conjunctionable = true;
2253
2254 if ((names == null) || (names.length > 0)) {
2255 if (conjunctionable) {
2256 query.append(WHERE_AND);
2257 }
2258
2259 query.append(StringPool.OPEN_PARENTHESIS);
2260
2261 for (int i = 0; i < names.length; i++) {
2262 String name = names[i];
2263
2264 if (name == null) {
2265 query.append(_FINDER_COLUMN_T_N_NAME_4);
2266 }
2267 else {
2268 if (name.equals(StringPool.BLANK)) {
2269 query.append(_FINDER_COLUMN_T_N_NAME_6);
2270 }
2271 else {
2272 query.append(_FINDER_COLUMN_T_N_NAME_5);
2273 }
2274 }
2275
2276 if ((i + 1) < names.length) {
2277 query.append(WHERE_OR);
2278 }
2279 }
2280
2281 query.append(StringPool.CLOSE_PARENTHESIS);
2282
2283 conjunctionable = true;
2284 }
2285
2286 if (!getDB().isSupportsInlineDistinct()) {
2287 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
2288 }
2289
2290 if (orderByComparator != null) {
2291 if (getDB().isSupportsInlineDistinct()) {
2292 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2293 orderByComparator);
2294 }
2295 else {
2296 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2297 orderByComparator);
2298 }
2299 }
2300
2301 else {
2302 if (getDB().isSupportsInlineDistinct()) {
2303 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2304 }
2305 else {
2306 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2307 }
2308 }
2309
2310 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2311 ExpandoColumn.class.getName(),
2312 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2313
2314 Session session = null;
2315
2316 try {
2317 session = openSession();
2318
2319 SQLQuery q = session.createSQLQuery(sql);
2320
2321 if (getDB().isSupportsInlineDistinct()) {
2322 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2323 }
2324 else {
2325 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2326 }
2327
2328 QueryPos qPos = QueryPos.getInstance(q);
2329
2330 qPos.add(tableId);
2331
2332 if (names != null) {
2333 qPos.add(names);
2334 }
2335
2336 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
2337 end);
2338 }
2339 catch (Exception e) {
2340 throw processException(e);
2341 }
2342 finally {
2343 closeSession(session);
2344 }
2345 }
2346
2347
2353 public List<ExpandoColumn> findAll() throws SystemException {
2354 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2355 }
2356
2357
2369 public List<ExpandoColumn> findAll(int start, int end)
2370 throws SystemException {
2371 return findAll(start, end, null);
2372 }
2373
2374
2387 public List<ExpandoColumn> findAll(int start, int end,
2388 OrderByComparator orderByComparator) throws SystemException {
2389 FinderPath finderPath = null;
2390 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2391
2392 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2393 (orderByComparator == null)) {
2394 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2395 finderArgs = FINDER_ARGS_EMPTY;
2396 }
2397 else {
2398 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2399 finderArgs = new Object[] { start, end, orderByComparator };
2400 }
2401
2402 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
2403 finderArgs, this);
2404
2405 if (list == null) {
2406 StringBundler query = null;
2407 String sql = null;
2408
2409 if (orderByComparator != null) {
2410 query = new StringBundler(2 +
2411 (orderByComparator.getOrderByFields().length * 3));
2412
2413 query.append(_SQL_SELECT_EXPANDOCOLUMN);
2414
2415 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2416 orderByComparator);
2417
2418 sql = query.toString();
2419 }
2420 else {
2421 sql = _SQL_SELECT_EXPANDOCOLUMN.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2422 }
2423
2424 Session session = null;
2425
2426 try {
2427 session = openSession();
2428
2429 Query q = session.createQuery(sql);
2430
2431 if (orderByComparator == null) {
2432 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2433 start, end, false);
2434
2435 Collections.sort(list);
2436 }
2437 else {
2438 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2439 start, end);
2440 }
2441 }
2442 catch (Exception e) {
2443 throw processException(e);
2444 }
2445 finally {
2446 if (list == null) {
2447 FinderCacheUtil.removeResult(finderPath, finderArgs);
2448 }
2449 else {
2450 cacheResult(list);
2451
2452 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2453 }
2454
2455 closeSession(session);
2456 }
2457 }
2458
2459 return list;
2460 }
2461
2462
2468 public void removeByTableId(long tableId) throws SystemException {
2469 for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
2470 remove(expandoColumn);
2471 }
2472 }
2473
2474
2481 public void removeByT_N(long tableId, String name)
2482 throws SystemException {
2483 for (ExpandoColumn expandoColumn : findByT_N(tableId, name)) {
2484 remove(expandoColumn);
2485 }
2486 }
2487
2488
2493 public void removeAll() throws SystemException {
2494 for (ExpandoColumn expandoColumn : findAll()) {
2495 remove(expandoColumn);
2496 }
2497 }
2498
2499
2506 public int countByTableId(long tableId) throws SystemException {
2507 Object[] finderArgs = new Object[] { tableId };
2508
2509 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
2510 finderArgs, this);
2511
2512 if (count == null) {
2513 StringBundler query = new StringBundler(2);
2514
2515 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2516
2517 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2518
2519 String sql = query.toString();
2520
2521 Session session = null;
2522
2523 try {
2524 session = openSession();
2525
2526 Query q = session.createQuery(sql);
2527
2528 QueryPos qPos = QueryPos.getInstance(q);
2529
2530 qPos.add(tableId);
2531
2532 count = (Long)q.uniqueResult();
2533 }
2534 catch (Exception e) {
2535 throw processException(e);
2536 }
2537 finally {
2538 if (count == null) {
2539 count = Long.valueOf(0);
2540 }
2541
2542 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
2543 finderArgs, count);
2544
2545 closeSession(session);
2546 }
2547 }
2548
2549 return count.intValue();
2550 }
2551
2552
2559 public int filterCountByTableId(long tableId) throws SystemException {
2560 if (!InlineSQLHelperUtil.isEnabled()) {
2561 return countByTableId(tableId);
2562 }
2563
2564 StringBundler query = new StringBundler(2);
2565
2566 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2567
2568 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2569
2570 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2571 ExpandoColumn.class.getName(),
2572 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2573
2574 Session session = null;
2575
2576 try {
2577 session = openSession();
2578
2579 SQLQuery q = session.createSQLQuery(sql);
2580
2581 q.addScalar(COUNT_COLUMN_NAME,
2582 com.liferay.portal.kernel.dao.orm.Type.LONG);
2583
2584 QueryPos qPos = QueryPos.getInstance(q);
2585
2586 qPos.add(tableId);
2587
2588 Long count = (Long)q.uniqueResult();
2589
2590 return count.intValue();
2591 }
2592 catch (Exception e) {
2593 throw processException(e);
2594 }
2595 finally {
2596 closeSession(session);
2597 }
2598 }
2599
2600
2608 public int countByT_N(long tableId, String name) throws SystemException {
2609 Object[] finderArgs = new Object[] { tableId, name };
2610
2611 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
2612 finderArgs, this);
2613
2614 if (count == null) {
2615 StringBundler query = new StringBundler(3);
2616
2617 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2618
2619 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2620
2621 if (name == null) {
2622 query.append(_FINDER_COLUMN_T_N_NAME_1);
2623 }
2624 else {
2625 if (name.equals(StringPool.BLANK)) {
2626 query.append(_FINDER_COLUMN_T_N_NAME_3);
2627 }
2628 else {
2629 query.append(_FINDER_COLUMN_T_N_NAME_2);
2630 }
2631 }
2632
2633 String sql = query.toString();
2634
2635 Session session = null;
2636
2637 try {
2638 session = openSession();
2639
2640 Query q = session.createQuery(sql);
2641
2642 QueryPos qPos = QueryPos.getInstance(q);
2643
2644 qPos.add(tableId);
2645
2646 if (name != null) {
2647 qPos.add(name);
2648 }
2649
2650 count = (Long)q.uniqueResult();
2651 }
2652 catch (Exception e) {
2653 throw processException(e);
2654 }
2655 finally {
2656 if (count == null) {
2657 count = Long.valueOf(0);
2658 }
2659
2660 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
2661 count);
2662
2663 closeSession(session);
2664 }
2665 }
2666
2667 return count.intValue();
2668 }
2669
2670
2678 public int countByT_N(long tableId, String[] names)
2679 throws SystemException {
2680 Object[] finderArgs = new Object[] { tableId, StringUtil.merge(names) };
2681
2682 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
2683 finderArgs, this);
2684
2685 if (count == null) {
2686 StringBundler query = new StringBundler();
2687
2688 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2689
2690 boolean conjunctionable = false;
2691
2692 if (conjunctionable) {
2693 query.append(WHERE_AND);
2694 }
2695
2696 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2697
2698 conjunctionable = true;
2699
2700 if ((names == null) || (names.length > 0)) {
2701 if (conjunctionable) {
2702 query.append(WHERE_AND);
2703 }
2704
2705 query.append(StringPool.OPEN_PARENTHESIS);
2706
2707 for (int i = 0; i < names.length; i++) {
2708 String name = names[i];
2709
2710 if (name == null) {
2711 query.append(_FINDER_COLUMN_T_N_NAME_4);
2712 }
2713 else {
2714 if (name.equals(StringPool.BLANK)) {
2715 query.append(_FINDER_COLUMN_T_N_NAME_6);
2716 }
2717 else {
2718 query.append(_FINDER_COLUMN_T_N_NAME_5);
2719 }
2720 }
2721
2722 if ((i + 1) < names.length) {
2723 query.append(WHERE_OR);
2724 }
2725 }
2726
2727 query.append(StringPool.CLOSE_PARENTHESIS);
2728
2729 conjunctionable = true;
2730 }
2731
2732 String sql = query.toString();
2733
2734 Session session = null;
2735
2736 try {
2737 session = openSession();
2738
2739 Query q = session.createQuery(sql);
2740
2741 QueryPos qPos = QueryPos.getInstance(q);
2742
2743 qPos.add(tableId);
2744
2745 if (names != null) {
2746 qPos.add(names);
2747 }
2748
2749 count = (Long)q.uniqueResult();
2750 }
2751 catch (Exception e) {
2752 throw processException(e);
2753 }
2754 finally {
2755 if (count == null) {
2756 count = Long.valueOf(0);
2757 }
2758
2759 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
2760 finderArgs, count);
2761
2762 closeSession(session);
2763 }
2764 }
2765
2766 return count.intValue();
2767 }
2768
2769
2777 public int filterCountByT_N(long tableId, String name)
2778 throws SystemException {
2779 if (!InlineSQLHelperUtil.isEnabled()) {
2780 return countByT_N(tableId, name);
2781 }
2782
2783 StringBundler query = new StringBundler(3);
2784
2785 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2786
2787 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2788
2789 if (name == null) {
2790 query.append(_FINDER_COLUMN_T_N_NAME_1);
2791 }
2792 else {
2793 if (name.equals(StringPool.BLANK)) {
2794 query.append(_FINDER_COLUMN_T_N_NAME_3);
2795 }
2796 else {
2797 query.append(_FINDER_COLUMN_T_N_NAME_2);
2798 }
2799 }
2800
2801 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2802 ExpandoColumn.class.getName(),
2803 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2804
2805 Session session = null;
2806
2807 try {
2808 session = openSession();
2809
2810 SQLQuery q = session.createSQLQuery(sql);
2811
2812 q.addScalar(COUNT_COLUMN_NAME,
2813 com.liferay.portal.kernel.dao.orm.Type.LONG);
2814
2815 QueryPos qPos = QueryPos.getInstance(q);
2816
2817 qPos.add(tableId);
2818
2819 if (name != null) {
2820 qPos.add(name);
2821 }
2822
2823 Long count = (Long)q.uniqueResult();
2824
2825 return count.intValue();
2826 }
2827 catch (Exception e) {
2828 throw processException(e);
2829 }
2830 finally {
2831 closeSession(session);
2832 }
2833 }
2834
2835
2843 public int filterCountByT_N(long tableId, String[] names)
2844 throws SystemException {
2845 if (!InlineSQLHelperUtil.isEnabled()) {
2846 return countByT_N(tableId, names);
2847 }
2848
2849 StringBundler query = new StringBundler();
2850
2851 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2852
2853 boolean conjunctionable = false;
2854
2855 if (conjunctionable) {
2856 query.append(WHERE_AND);
2857 }
2858
2859 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2860
2861 conjunctionable = true;
2862
2863 if ((names == null) || (names.length > 0)) {
2864 if (conjunctionable) {
2865 query.append(WHERE_AND);
2866 }
2867
2868 query.append(StringPool.OPEN_PARENTHESIS);
2869
2870 for (int i = 0; i < names.length; i++) {
2871 String name = names[i];
2872
2873 if (name == null) {
2874 query.append(_FINDER_COLUMN_T_N_NAME_4);
2875 }
2876 else {
2877 if (name.equals(StringPool.BLANK)) {
2878 query.append(_FINDER_COLUMN_T_N_NAME_6);
2879 }
2880 else {
2881 query.append(_FINDER_COLUMN_T_N_NAME_5);
2882 }
2883 }
2884
2885 if ((i + 1) < names.length) {
2886 query.append(WHERE_OR);
2887 }
2888 }
2889
2890 query.append(StringPool.CLOSE_PARENTHESIS);
2891
2892 conjunctionable = true;
2893 }
2894
2895 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2896 ExpandoColumn.class.getName(),
2897 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2898
2899 Session session = null;
2900
2901 try {
2902 session = openSession();
2903
2904 SQLQuery q = session.createSQLQuery(sql);
2905
2906 q.addScalar(COUNT_COLUMN_NAME,
2907 com.liferay.portal.kernel.dao.orm.Type.LONG);
2908
2909 QueryPos qPos = QueryPos.getInstance(q);
2910
2911 qPos.add(tableId);
2912
2913 if (names != null) {
2914 qPos.add(names);
2915 }
2916
2917 Long count = (Long)q.uniqueResult();
2918
2919 return count.intValue();
2920 }
2921 catch (Exception e) {
2922 throw processException(e);
2923 }
2924 finally {
2925 closeSession(session);
2926 }
2927 }
2928
2929
2935 public int countAll() throws SystemException {
2936 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2937 FINDER_ARGS_EMPTY, this);
2938
2939 if (count == null) {
2940 Session session = null;
2941
2942 try {
2943 session = openSession();
2944
2945 Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
2946
2947 count = (Long)q.uniqueResult();
2948 }
2949 catch (Exception e) {
2950 throw processException(e);
2951 }
2952 finally {
2953 if (count == null) {
2954 count = Long.valueOf(0);
2955 }
2956
2957 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2958 FINDER_ARGS_EMPTY, count);
2959
2960 closeSession(session);
2961 }
2962 }
2963
2964 return count.intValue();
2965 }
2966
2967
2970 public void afterPropertiesSet() {
2971 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2972 com.liferay.portal.util.PropsUtil.get(
2973 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
2974
2975 if (listenerClassNames.length > 0) {
2976 try {
2977 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
2978
2979 for (String listenerClassName : listenerClassNames) {
2980 listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
2981 listenerClassName));
2982 }
2983
2984 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2985 }
2986 catch (Exception e) {
2987 _log.error(e);
2988 }
2989 }
2990 }
2991
2992 public void destroy() {
2993 EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
2994 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2995 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2996 }
2997
2998 @BeanReference(type = ExpandoColumnPersistence.class)
2999 protected ExpandoColumnPersistence expandoColumnPersistence;
3000 @BeanReference(type = ExpandoRowPersistence.class)
3001 protected ExpandoRowPersistence expandoRowPersistence;
3002 @BeanReference(type = ExpandoTablePersistence.class)
3003 protected ExpandoTablePersistence expandoTablePersistence;
3004 @BeanReference(type = ExpandoValuePersistence.class)
3005 protected ExpandoValuePersistence expandoValuePersistence;
3006 @BeanReference(type = UserPersistence.class)
3007 protected UserPersistence userPersistence;
3008 private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
3009 private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
3010 private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
3011 private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
3012 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
3013 private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
3014 private static final String _FINDER_COLUMN_T_N_TABLEID_5 = "(" +
3015 _removeConjunction(_FINDER_COLUMN_T_N_TABLEID_2) + ")";
3016 private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
3017 private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
3018 private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = ?)";
3019 private static final String _FINDER_COLUMN_T_N_NAME_4 = "(" +
3020 _removeConjunction(_FINDER_COLUMN_T_N_NAME_1) + ")";
3021 private static final String _FINDER_COLUMN_T_N_NAME_5 = "(" +
3022 _removeConjunction(_FINDER_COLUMN_T_N_NAME_2) + ")";
3023 private static final String _FINDER_COLUMN_T_N_NAME_6 = "(" +
3024 _removeConjunction(_FINDER_COLUMN_T_N_NAME_3) + ")";
3025
3026 private static String _removeConjunction(String sql) {
3027 int pos = sql.indexOf(" AND ");
3028
3029 if (pos != -1) {
3030 sql = sql.substring(0, pos);
3031 }
3032
3033 return sql;
3034 }
3035
3036 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "expandoColumn.columnId";
3037 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
3038 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
3039 "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
3040 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
3041 ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
3042 private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
3043 private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
3044 private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
3045 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
3046 private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
3047 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
3048 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
3049 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3050 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
3051 private static ExpandoColumn _nullExpandoColumn = new ExpandoColumnImpl() {
3052 @Override
3053 public Object clone() {
3054 return this;
3055 }
3056
3057 @Override
3058 public CacheModel<ExpandoColumn> toCacheModel() {
3059 return _nullExpandoColumnCacheModel;
3060 }
3061 };
3062
3063 private static CacheModel<ExpandoColumn> _nullExpandoColumnCacheModel = new CacheModel<ExpandoColumn>() {
3064 public ExpandoColumn toEntityModel() {
3065 return _nullExpandoColumn;
3066 }
3067 };
3068 }