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 else {
342 if ((expandoColumnModelImpl.getColumnBitmask() &
343 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
344 Object[] args = new Object[] {
345 Long.valueOf(expandoColumnModelImpl.getOriginalTableId())
346 };
347
348 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
349 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
350 args);
351
352 args = new Object[] {
353 Long.valueOf(expandoColumnModelImpl.getTableId())
354 };
355
356 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
357 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
358 args);
359 }
360
361 if ((expandoColumnModelImpl.getColumnBitmask() &
362 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N.getColumnBitmask()) != 0) {
363 Object[] args = new Object[] {
364 Long.valueOf(expandoColumnModelImpl.getOriginalTableId()),
365
366 expandoColumnModelImpl.getOriginalName()
367 };
368
369 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
370 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
371 args);
372
373 args = new Object[] {
374 Long.valueOf(expandoColumnModelImpl.getTableId()),
375
376 expandoColumnModelImpl.getName()
377 };
378
379 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
380 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
381 args);
382 }
383 }
384
385 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
386 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
387 expandoColumn);
388
389 return expandoColumn;
390 }
391
392 protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
393 if (expandoColumn instanceof ExpandoColumnImpl) {
394 return expandoColumn;
395 }
396
397 ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
398
399 expandoColumnImpl.setNew(expandoColumn.isNew());
400 expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
401
402 expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
403 expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
404 expandoColumnImpl.setTableId(expandoColumn.getTableId());
405 expandoColumnImpl.setName(expandoColumn.getName());
406 expandoColumnImpl.setType(expandoColumn.getType());
407 expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
408 expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
409
410 return expandoColumnImpl;
411 }
412
413
421 @Override
422 public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
423 throws NoSuchModelException, SystemException {
424 return findByPrimaryKey(((Long)primaryKey).longValue());
425 }
426
427
435 public ExpandoColumn findByPrimaryKey(long columnId)
436 throws NoSuchColumnException, SystemException {
437 ExpandoColumn expandoColumn = fetchByPrimaryKey(columnId);
438
439 if (expandoColumn == null) {
440 if (_log.isWarnEnabled()) {
441 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
442 }
443
444 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
445 columnId);
446 }
447
448 return expandoColumn;
449 }
450
451
458 @Override
459 public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey)
460 throws SystemException {
461 return fetchByPrimaryKey(((Long)primaryKey).longValue());
462 }
463
464
471 public ExpandoColumn fetchByPrimaryKey(long columnId)
472 throws SystemException {
473 ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
474 ExpandoColumnImpl.class, columnId);
475
476 if (expandoColumn == _nullExpandoColumn) {
477 return null;
478 }
479
480 if (expandoColumn == null) {
481 Session session = null;
482
483 boolean hasException = false;
484
485 try {
486 session = openSession();
487
488 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
489 Long.valueOf(columnId));
490 }
491 catch (Exception e) {
492 hasException = true;
493
494 throw processException(e);
495 }
496 finally {
497 if (expandoColumn != null) {
498 cacheResult(expandoColumn);
499 }
500 else if (!hasException) {
501 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
502 ExpandoColumnImpl.class, columnId, _nullExpandoColumn);
503 }
504
505 closeSession(session);
506 }
507 }
508
509 return expandoColumn;
510 }
511
512
519 public List<ExpandoColumn> findByTableId(long tableId)
520 throws SystemException {
521 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
522 }
523
524
537 public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
538 throws SystemException {
539 return findByTableId(tableId, start, end, null);
540 }
541
542
556 public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
557 OrderByComparator orderByComparator) throws SystemException {
558 FinderPath finderPath = null;
559 Object[] finderArgs = null;
560
561 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
562 (orderByComparator == null)) {
563 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
564 finderArgs = new Object[] { tableId };
565 }
566 else {
567 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
568 finderArgs = new Object[] { tableId, start, end, orderByComparator };
569 }
570
571 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
572 finderArgs, this);
573
574 if ((list != null) && !list.isEmpty()) {
575 for (ExpandoColumn expandoColumn : list) {
576 if ((tableId != expandoColumn.getTableId())) {
577 list = null;
578
579 break;
580 }
581 }
582 }
583
584 if (list == null) {
585 StringBundler query = null;
586
587 if (orderByComparator != null) {
588 query = new StringBundler(3 +
589 (orderByComparator.getOrderByFields().length * 3));
590 }
591 else {
592 query = new StringBundler(3);
593 }
594
595 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
596
597 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
598
599 if (orderByComparator != null) {
600 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
601 orderByComparator);
602 }
603
604 else {
605 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
606 }
607
608 String sql = query.toString();
609
610 Session session = null;
611
612 try {
613 session = openSession();
614
615 Query q = session.createQuery(sql);
616
617 QueryPos qPos = QueryPos.getInstance(q);
618
619 qPos.add(tableId);
620
621 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
622 start, end);
623 }
624 catch (Exception e) {
625 throw processException(e);
626 }
627 finally {
628 if (list == null) {
629 FinderCacheUtil.removeResult(finderPath, finderArgs);
630 }
631 else {
632 cacheResult(list);
633
634 FinderCacheUtil.putResult(finderPath, finderArgs, list);
635 }
636
637 closeSession(session);
638 }
639 }
640
641 return list;
642 }
643
644
657 public ExpandoColumn findByTableId_First(long tableId,
658 OrderByComparator orderByComparator)
659 throws NoSuchColumnException, SystemException {
660 List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
661 orderByComparator);
662
663 if (list.isEmpty()) {
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 else {
676 return list.get(0);
677 }
678 }
679
680
693 public ExpandoColumn findByTableId_Last(long tableId,
694 OrderByComparator orderByComparator)
695 throws NoSuchColumnException, SystemException {
696 int count = countByTableId(tableId);
697
698 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
699 orderByComparator);
700
701 if (list.isEmpty()) {
702 StringBundler msg = new StringBundler(4);
703
704 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
705
706 msg.append("tableId=");
707 msg.append(tableId);
708
709 msg.append(StringPool.CLOSE_CURLY_BRACE);
710
711 throw new NoSuchColumnException(msg.toString());
712 }
713 else {
714 return list.get(0);
715 }
716 }
717
718
732 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
733 long tableId, OrderByComparator orderByComparator)
734 throws NoSuchColumnException, SystemException {
735 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
736
737 Session session = null;
738
739 try {
740 session = openSession();
741
742 ExpandoColumn[] array = new ExpandoColumnImpl[3];
743
744 array[0] = getByTableId_PrevAndNext(session, expandoColumn,
745 tableId, orderByComparator, true);
746
747 array[1] = expandoColumn;
748
749 array[2] = getByTableId_PrevAndNext(session, expandoColumn,
750 tableId, orderByComparator, false);
751
752 return array;
753 }
754 catch (Exception e) {
755 throw processException(e);
756 }
757 finally {
758 closeSession(session);
759 }
760 }
761
762 protected ExpandoColumn getByTableId_PrevAndNext(Session session,
763 ExpandoColumn expandoColumn, long tableId,
764 OrderByComparator orderByComparator, boolean previous) {
765 StringBundler query = null;
766
767 if (orderByComparator != null) {
768 query = new StringBundler(6 +
769 (orderByComparator.getOrderByFields().length * 6));
770 }
771 else {
772 query = new StringBundler(3);
773 }
774
775 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
776
777 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
778
779 if (orderByComparator != null) {
780 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
781
782 if (orderByConditionFields.length > 0) {
783 query.append(WHERE_AND);
784 }
785
786 for (int i = 0; i < orderByConditionFields.length; i++) {
787 query.append(_ORDER_BY_ENTITY_ALIAS);
788 query.append(orderByConditionFields[i]);
789
790 if ((i + 1) < orderByConditionFields.length) {
791 if (orderByComparator.isAscending() ^ previous) {
792 query.append(WHERE_GREATER_THAN_HAS_NEXT);
793 }
794 else {
795 query.append(WHERE_LESSER_THAN_HAS_NEXT);
796 }
797 }
798 else {
799 if (orderByComparator.isAscending() ^ previous) {
800 query.append(WHERE_GREATER_THAN);
801 }
802 else {
803 query.append(WHERE_LESSER_THAN);
804 }
805 }
806 }
807
808 query.append(ORDER_BY_CLAUSE);
809
810 String[] orderByFields = orderByComparator.getOrderByFields();
811
812 for (int i = 0; i < orderByFields.length; i++) {
813 query.append(_ORDER_BY_ENTITY_ALIAS);
814 query.append(orderByFields[i]);
815
816 if ((i + 1) < orderByFields.length) {
817 if (orderByComparator.isAscending() ^ previous) {
818 query.append(ORDER_BY_ASC_HAS_NEXT);
819 }
820 else {
821 query.append(ORDER_BY_DESC_HAS_NEXT);
822 }
823 }
824 else {
825 if (orderByComparator.isAscending() ^ previous) {
826 query.append(ORDER_BY_ASC);
827 }
828 else {
829 query.append(ORDER_BY_DESC);
830 }
831 }
832 }
833 }
834
835 else {
836 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
837 }
838
839 String sql = query.toString();
840
841 Query q = session.createQuery(sql);
842
843 q.setFirstResult(0);
844 q.setMaxResults(2);
845
846 QueryPos qPos = QueryPos.getInstance(q);
847
848 qPos.add(tableId);
849
850 if (orderByComparator != null) {
851 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
852
853 for (Object value : values) {
854 qPos.add(value);
855 }
856 }
857
858 List<ExpandoColumn> list = q.list();
859
860 if (list.size() == 2) {
861 return list.get(1);
862 }
863 else {
864 return null;
865 }
866 }
867
868
875 public List<ExpandoColumn> filterFindByTableId(long tableId)
876 throws SystemException {
877 return filterFindByTableId(tableId, QueryUtil.ALL_POS,
878 QueryUtil.ALL_POS, null);
879 }
880
881
894 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
895 int end) throws SystemException {
896 return filterFindByTableId(tableId, start, end, null);
897 }
898
899
913 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
914 int end, OrderByComparator orderByComparator) throws SystemException {
915 if (!InlineSQLHelperUtil.isEnabled()) {
916 return findByTableId(tableId, start, end, orderByComparator);
917 }
918
919 StringBundler query = null;
920
921 if (orderByComparator != null) {
922 query = new StringBundler(3 +
923 (orderByComparator.getOrderByFields().length * 3));
924 }
925 else {
926 query = new StringBundler(3);
927 }
928
929 if (getDB().isSupportsInlineDistinct()) {
930 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
931 }
932 else {
933 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
934 }
935
936 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
937
938 if (!getDB().isSupportsInlineDistinct()) {
939 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
940 }
941
942 if (orderByComparator != null) {
943 if (getDB().isSupportsInlineDistinct()) {
944 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
945 orderByComparator);
946 }
947 else {
948 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
949 orderByComparator);
950 }
951 }
952
953 else {
954 if (getDB().isSupportsInlineDistinct()) {
955 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
956 }
957 else {
958 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
959 }
960 }
961
962 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
963 ExpandoColumn.class.getName(),
964 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
965
966 Session session = null;
967
968 try {
969 session = openSession();
970
971 SQLQuery q = session.createSQLQuery(sql);
972
973 if (getDB().isSupportsInlineDistinct()) {
974 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
975 }
976 else {
977 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
978 }
979
980 QueryPos qPos = QueryPos.getInstance(q);
981
982 qPos.add(tableId);
983
984 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
985 end);
986 }
987 catch (Exception e) {
988 throw processException(e);
989 }
990 finally {
991 closeSession(session);
992 }
993 }
994
995
1005 public ExpandoColumn[] filterFindByTableId_PrevAndNext(long columnId,
1006 long tableId, OrderByComparator orderByComparator)
1007 throws NoSuchColumnException, SystemException {
1008 if (!InlineSQLHelperUtil.isEnabled()) {
1009 return findByTableId_PrevAndNext(columnId, tableId,
1010 orderByComparator);
1011 }
1012
1013 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1014
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1021
1022 array[0] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1023 tableId, orderByComparator, true);
1024
1025 array[1] = expandoColumn;
1026
1027 array[2] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1028 tableId, orderByComparator, false);
1029
1030 return array;
1031 }
1032 catch (Exception e) {
1033 throw processException(e);
1034 }
1035 finally {
1036 closeSession(session);
1037 }
1038 }
1039
1040 protected ExpandoColumn filterGetByTableId_PrevAndNext(Session session,
1041 ExpandoColumn expandoColumn, long tableId,
1042 OrderByComparator orderByComparator, boolean previous) {
1043 StringBundler query = null;
1044
1045 if (orderByComparator != null) {
1046 query = new StringBundler(6 +
1047 (orderByComparator.getOrderByFields().length * 6));
1048 }
1049 else {
1050 query = new StringBundler(3);
1051 }
1052
1053 if (getDB().isSupportsInlineDistinct()) {
1054 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1055 }
1056 else {
1057 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1058 }
1059
1060 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1061
1062 if (!getDB().isSupportsInlineDistinct()) {
1063 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1064 }
1065
1066 if (orderByComparator != null) {
1067 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1068
1069 if (orderByConditionFields.length > 0) {
1070 query.append(WHERE_AND);
1071 }
1072
1073 for (int i = 0; i < orderByConditionFields.length; i++) {
1074 if (getDB().isSupportsInlineDistinct()) {
1075 query.append(_ORDER_BY_ENTITY_ALIAS);
1076 }
1077 else {
1078 query.append(_ORDER_BY_ENTITY_TABLE);
1079 }
1080
1081 query.append(orderByConditionFields[i]);
1082
1083 if ((i + 1) < orderByConditionFields.length) {
1084 if (orderByComparator.isAscending() ^ previous) {
1085 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1086 }
1087 else {
1088 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1089 }
1090 }
1091 else {
1092 if (orderByComparator.isAscending() ^ previous) {
1093 query.append(WHERE_GREATER_THAN);
1094 }
1095 else {
1096 query.append(WHERE_LESSER_THAN);
1097 }
1098 }
1099 }
1100
1101 query.append(ORDER_BY_CLAUSE);
1102
1103 String[] orderByFields = orderByComparator.getOrderByFields();
1104
1105 for (int i = 0; i < orderByFields.length; i++) {
1106 if (getDB().isSupportsInlineDistinct()) {
1107 query.append(_ORDER_BY_ENTITY_ALIAS);
1108 }
1109 else {
1110 query.append(_ORDER_BY_ENTITY_TABLE);
1111 }
1112
1113 query.append(orderByFields[i]);
1114
1115 if ((i + 1) < orderByFields.length) {
1116 if (orderByComparator.isAscending() ^ previous) {
1117 query.append(ORDER_BY_ASC_HAS_NEXT);
1118 }
1119 else {
1120 query.append(ORDER_BY_DESC_HAS_NEXT);
1121 }
1122 }
1123 else {
1124 if (orderByComparator.isAscending() ^ previous) {
1125 query.append(ORDER_BY_ASC);
1126 }
1127 else {
1128 query.append(ORDER_BY_DESC);
1129 }
1130 }
1131 }
1132 }
1133
1134 else {
1135 if (getDB().isSupportsInlineDistinct()) {
1136 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1137 }
1138 else {
1139 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1140 }
1141 }
1142
1143 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1144 ExpandoColumn.class.getName(),
1145 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1146
1147 SQLQuery q = session.createSQLQuery(sql);
1148
1149 q.setFirstResult(0);
1150 q.setMaxResults(2);
1151
1152 if (getDB().isSupportsInlineDistinct()) {
1153 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1154 }
1155 else {
1156 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1157 }
1158
1159 QueryPos qPos = QueryPos.getInstance(q);
1160
1161 qPos.add(tableId);
1162
1163 if (orderByComparator != null) {
1164 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1165
1166 for (Object value : values) {
1167 qPos.add(value);
1168 }
1169 }
1170
1171 List<ExpandoColumn> list = q.list();
1172
1173 if (list.size() == 2) {
1174 return list.get(1);
1175 }
1176 else {
1177 return null;
1178 }
1179 }
1180
1181
1189 public List<ExpandoColumn> findByT_N(long tableId, String name)
1190 throws SystemException {
1191 return findByT_N(tableId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1192 null);
1193 }
1194
1195
1209 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1210 int end) throws SystemException {
1211 return findByT_N(tableId, name, start, end, null);
1212 }
1213
1214
1229 public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1230 int end, OrderByComparator orderByComparator) throws SystemException {
1231 FinderPath finderPath = null;
1232 Object[] finderArgs = null;
1233
1234 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1235 (orderByComparator == null)) {
1236 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N;
1237 finderArgs = new Object[] { tableId, name };
1238 }
1239 else {
1240 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1241 finderArgs = new Object[] {
1242 tableId, name,
1243
1244 start, end, orderByComparator
1245 };
1246 }
1247
1248 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1249 finderArgs, this);
1250
1251 if ((list != null) && !list.isEmpty()) {
1252 for (ExpandoColumn expandoColumn : list) {
1253 if ((tableId != expandoColumn.getTableId()) ||
1254 !Validator.equals(name, expandoColumn.getName())) {
1255 list = null;
1256
1257 break;
1258 }
1259 }
1260 }
1261
1262 if (list == null) {
1263 StringBundler query = null;
1264
1265 if (orderByComparator != null) {
1266 query = new StringBundler(4 +
1267 (orderByComparator.getOrderByFields().length * 3));
1268 }
1269 else {
1270 query = new StringBundler(4);
1271 }
1272
1273 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1274
1275 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1276
1277 if (name == null) {
1278 query.append(_FINDER_COLUMN_T_N_NAME_1);
1279 }
1280 else {
1281 if (name.equals(StringPool.BLANK)) {
1282 query.append(_FINDER_COLUMN_T_N_NAME_3);
1283 }
1284 else {
1285 query.append(_FINDER_COLUMN_T_N_NAME_2);
1286 }
1287 }
1288
1289 if (orderByComparator != null) {
1290 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1291 orderByComparator);
1292 }
1293
1294 else {
1295 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1296 }
1297
1298 String sql = query.toString();
1299
1300 Session session = null;
1301
1302 try {
1303 session = openSession();
1304
1305 Query q = session.createQuery(sql);
1306
1307 QueryPos qPos = QueryPos.getInstance(q);
1308
1309 qPos.add(tableId);
1310
1311 if (name != null) {
1312 qPos.add(name);
1313 }
1314
1315 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1316 start, end);
1317 }
1318 catch (Exception e) {
1319 throw processException(e);
1320 }
1321 finally {
1322 if (list == null) {
1323 FinderCacheUtil.removeResult(finderPath, finderArgs);
1324 }
1325 else {
1326 cacheResult(list);
1327
1328 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1329 }
1330
1331 closeSession(session);
1332 }
1333 }
1334
1335 return list;
1336 }
1337
1338
1352 public ExpandoColumn findByT_N_First(long tableId, String name,
1353 OrderByComparator orderByComparator)
1354 throws NoSuchColumnException, SystemException {
1355 List<ExpandoColumn> list = findByT_N(tableId, name, 0, 1,
1356 orderByComparator);
1357
1358 if (list.isEmpty()) {
1359 StringBundler msg = new StringBundler(6);
1360
1361 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1362
1363 msg.append("tableId=");
1364 msg.append(tableId);
1365
1366 msg.append(", name=");
1367 msg.append(name);
1368
1369 msg.append(StringPool.CLOSE_CURLY_BRACE);
1370
1371 throw new NoSuchColumnException(msg.toString());
1372 }
1373 else {
1374 return list.get(0);
1375 }
1376 }
1377
1378
1392 public ExpandoColumn findByT_N_Last(long tableId, String name,
1393 OrderByComparator orderByComparator)
1394 throws NoSuchColumnException, SystemException {
1395 int count = countByT_N(tableId, name);
1396
1397 List<ExpandoColumn> list = findByT_N(tableId, name, count - 1, count,
1398 orderByComparator);
1399
1400 if (list.isEmpty()) {
1401 StringBundler msg = new StringBundler(6);
1402
1403 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1404
1405 msg.append("tableId=");
1406 msg.append(tableId);
1407
1408 msg.append(", name=");
1409 msg.append(name);
1410
1411 msg.append(StringPool.CLOSE_CURLY_BRACE);
1412
1413 throw new NoSuchColumnException(msg.toString());
1414 }
1415 else {
1416 return list.get(0);
1417 }
1418 }
1419
1420
1435 public ExpandoColumn[] findByT_N_PrevAndNext(long columnId, long tableId,
1436 String name, OrderByComparator orderByComparator)
1437 throws NoSuchColumnException, SystemException {
1438 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1439
1440 Session session = null;
1441
1442 try {
1443 session = openSession();
1444
1445 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1446
1447 array[0] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1448 name, orderByComparator, true);
1449
1450 array[1] = expandoColumn;
1451
1452 array[2] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1453 name, orderByComparator, false);
1454
1455 return array;
1456 }
1457 catch (Exception e) {
1458 throw processException(e);
1459 }
1460 finally {
1461 closeSession(session);
1462 }
1463 }
1464
1465 protected ExpandoColumn getByT_N_PrevAndNext(Session session,
1466 ExpandoColumn expandoColumn, long tableId, String name,
1467 OrderByComparator orderByComparator, boolean previous) {
1468 StringBundler query = null;
1469
1470 if (orderByComparator != null) {
1471 query = new StringBundler(6 +
1472 (orderByComparator.getOrderByFields().length * 6));
1473 }
1474 else {
1475 query = new StringBundler(3);
1476 }
1477
1478 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1479
1480 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1481
1482 if (name == null) {
1483 query.append(_FINDER_COLUMN_T_N_NAME_1);
1484 }
1485 else {
1486 if (name.equals(StringPool.BLANK)) {
1487 query.append(_FINDER_COLUMN_T_N_NAME_3);
1488 }
1489 else {
1490 query.append(_FINDER_COLUMN_T_N_NAME_2);
1491 }
1492 }
1493
1494 if (orderByComparator != null) {
1495 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1496
1497 if (orderByConditionFields.length > 0) {
1498 query.append(WHERE_AND);
1499 }
1500
1501 for (int i = 0; i < orderByConditionFields.length; i++) {
1502 query.append(_ORDER_BY_ENTITY_ALIAS);
1503 query.append(orderByConditionFields[i]);
1504
1505 if ((i + 1) < orderByConditionFields.length) {
1506 if (orderByComparator.isAscending() ^ previous) {
1507 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1508 }
1509 else {
1510 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1511 }
1512 }
1513 else {
1514 if (orderByComparator.isAscending() ^ previous) {
1515 query.append(WHERE_GREATER_THAN);
1516 }
1517 else {
1518 query.append(WHERE_LESSER_THAN);
1519 }
1520 }
1521 }
1522
1523 query.append(ORDER_BY_CLAUSE);
1524
1525 String[] orderByFields = orderByComparator.getOrderByFields();
1526
1527 for (int i = 0; i < orderByFields.length; i++) {
1528 query.append(_ORDER_BY_ENTITY_ALIAS);
1529 query.append(orderByFields[i]);
1530
1531 if ((i + 1) < orderByFields.length) {
1532 if (orderByComparator.isAscending() ^ previous) {
1533 query.append(ORDER_BY_ASC_HAS_NEXT);
1534 }
1535 else {
1536 query.append(ORDER_BY_DESC_HAS_NEXT);
1537 }
1538 }
1539 else {
1540 if (orderByComparator.isAscending() ^ previous) {
1541 query.append(ORDER_BY_ASC);
1542 }
1543 else {
1544 query.append(ORDER_BY_DESC);
1545 }
1546 }
1547 }
1548 }
1549
1550 else {
1551 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1552 }
1553
1554 String sql = query.toString();
1555
1556 Query q = session.createQuery(sql);
1557
1558 q.setFirstResult(0);
1559 q.setMaxResults(2);
1560
1561 QueryPos qPos = QueryPos.getInstance(q);
1562
1563 qPos.add(tableId);
1564
1565 if (name != null) {
1566 qPos.add(name);
1567 }
1568
1569 if (orderByComparator != null) {
1570 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1571
1572 for (Object value : values) {
1573 qPos.add(value);
1574 }
1575 }
1576
1577 List<ExpandoColumn> list = q.list();
1578
1579 if (list.size() == 2) {
1580 return list.get(1);
1581 }
1582 else {
1583 return null;
1584 }
1585 }
1586
1587
1599 public List<ExpandoColumn> findByT_N(long tableId, String[] names)
1600 throws SystemException {
1601 return findByT_N(tableId, names, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1602 null);
1603 }
1604
1605
1619 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1620 int start, int end) throws SystemException {
1621 return findByT_N(tableId, names, start, end, null);
1622 }
1623
1624
1639 public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1640 int start, int end, OrderByComparator orderByComparator)
1641 throws SystemException {
1642 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1643 Object[] finderArgs = null;
1644
1645 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1646 (orderByComparator == null)) {
1647 finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1648 }
1649 else {
1650 finderArgs = new Object[] {
1651 tableId, StringUtil.merge(names),
1652
1653 start, end, orderByComparator
1654 };
1655 }
1656
1657 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1658 finderArgs, this);
1659
1660 if ((list != null) && !list.isEmpty()) {
1661 for (ExpandoColumn expandoColumn : list) {
1662 if ((tableId != expandoColumn.getTableId()) ||
1663 !ArrayUtil.contains(names, expandoColumn.getName())) {
1664 list = null;
1665
1666 break;
1667 }
1668 }
1669 }
1670
1671 if (list == null) {
1672 StringBundler query = new StringBundler();
1673
1674 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1675
1676 boolean conjunctionable = false;
1677
1678 if (conjunctionable) {
1679 query.append(WHERE_AND);
1680 }
1681
1682 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1683
1684 conjunctionable = true;
1685
1686 if ((names == null) || (names.length > 0)) {
1687 if (conjunctionable) {
1688 query.append(WHERE_AND);
1689 }
1690
1691 query.append(StringPool.OPEN_PARENTHESIS);
1692
1693 for (int i = 0; i < names.length; i++) {
1694 String name = names[i];
1695
1696 if (name == null) {
1697 query.append(_FINDER_COLUMN_T_N_NAME_4);
1698 }
1699 else {
1700 if (name.equals(StringPool.BLANK)) {
1701 query.append(_FINDER_COLUMN_T_N_NAME_6);
1702 }
1703 else {
1704 query.append(_FINDER_COLUMN_T_N_NAME_5);
1705 }
1706 }
1707
1708 if ((i + 1) < names.length) {
1709 query.append(WHERE_OR);
1710 }
1711 }
1712
1713 query.append(StringPool.CLOSE_PARENTHESIS);
1714
1715 conjunctionable = true;
1716 }
1717
1718 if (orderByComparator != null) {
1719 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1720 orderByComparator);
1721 }
1722
1723 else {
1724 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1725 }
1726
1727 String sql = query.toString();
1728
1729 Session session = null;
1730
1731 try {
1732 session = openSession();
1733
1734 Query q = session.createQuery(sql);
1735
1736 QueryPos qPos = QueryPos.getInstance(q);
1737
1738 qPos.add(tableId);
1739
1740 if (names != null) {
1741 qPos.add(names);
1742 }
1743
1744 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1745 start, end);
1746 }
1747 catch (Exception e) {
1748 throw processException(e);
1749 }
1750 finally {
1751 if (list == null) {
1752 FinderCacheUtil.removeResult(finderPath, finderArgs);
1753 }
1754 else {
1755 cacheResult(list);
1756
1757 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1758 }
1759
1760 closeSession(session);
1761 }
1762 }
1763
1764 return list;
1765 }
1766
1767
1775 public List<ExpandoColumn> filterFindByT_N(long tableId, String name)
1776 throws SystemException {
1777 return filterFindByT_N(tableId, name, QueryUtil.ALL_POS,
1778 QueryUtil.ALL_POS, null);
1779 }
1780
1781
1795 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1796 int start, int end) throws SystemException {
1797 return filterFindByT_N(tableId, name, start, end, null);
1798 }
1799
1800
1815 public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1816 int start, int end, OrderByComparator orderByComparator)
1817 throws SystemException {
1818 if (!InlineSQLHelperUtil.isEnabled()) {
1819 return findByT_N(tableId, name, start, end, orderByComparator);
1820 }
1821
1822 StringBundler query = null;
1823
1824 if (orderByComparator != null) {
1825 query = new StringBundler(4 +
1826 (orderByComparator.getOrderByFields().length * 3));
1827 }
1828 else {
1829 query = new StringBundler(4);
1830 }
1831
1832 if (getDB().isSupportsInlineDistinct()) {
1833 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1834 }
1835 else {
1836 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1837 }
1838
1839 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1840
1841 if (name == null) {
1842 query.append(_FINDER_COLUMN_T_N_NAME_1);
1843 }
1844 else {
1845 if (name.equals(StringPool.BLANK)) {
1846 query.append(_FINDER_COLUMN_T_N_NAME_3);
1847 }
1848 else {
1849 query.append(_FINDER_COLUMN_T_N_NAME_2);
1850 }
1851 }
1852
1853 if (!getDB().isSupportsInlineDistinct()) {
1854 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1855 }
1856
1857 if (orderByComparator != null) {
1858 if (getDB().isSupportsInlineDistinct()) {
1859 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1860 orderByComparator);
1861 }
1862 else {
1863 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1864 orderByComparator);
1865 }
1866 }
1867
1868 else {
1869 if (getDB().isSupportsInlineDistinct()) {
1870 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1871 }
1872 else {
1873 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1874 }
1875 }
1876
1877 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1878 ExpandoColumn.class.getName(),
1879 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1880
1881 Session session = null;
1882
1883 try {
1884 session = openSession();
1885
1886 SQLQuery q = session.createSQLQuery(sql);
1887
1888 if (getDB().isSupportsInlineDistinct()) {
1889 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1890 }
1891 else {
1892 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1893 }
1894
1895 QueryPos qPos = QueryPos.getInstance(q);
1896
1897 qPos.add(tableId);
1898
1899 if (name != null) {
1900 qPos.add(name);
1901 }
1902
1903 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
1904 end);
1905 }
1906 catch (Exception e) {
1907 throw processException(e);
1908 }
1909 finally {
1910 closeSession(session);
1911 }
1912 }
1913
1914
1925 public ExpandoColumn[] filterFindByT_N_PrevAndNext(long columnId,
1926 long tableId, String name, OrderByComparator orderByComparator)
1927 throws NoSuchColumnException, SystemException {
1928 if (!InlineSQLHelperUtil.isEnabled()) {
1929 return findByT_N_PrevAndNext(columnId, tableId, name,
1930 orderByComparator);
1931 }
1932
1933 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1934
1935 Session session = null;
1936
1937 try {
1938 session = openSession();
1939
1940 ExpandoColumn[] array = new ExpandoColumnImpl[3];
1941
1942 array[0] = filterGetByT_N_PrevAndNext(session, expandoColumn,
1943 tableId, name, orderByComparator, true);
1944
1945 array[1] = expandoColumn;
1946
1947 array[2] = filterGetByT_N_PrevAndNext(session, expandoColumn,
1948 tableId, name, orderByComparator, false);
1949
1950 return array;
1951 }
1952 catch (Exception e) {
1953 throw processException(e);
1954 }
1955 finally {
1956 closeSession(session);
1957 }
1958 }
1959
1960 protected ExpandoColumn filterGetByT_N_PrevAndNext(Session session,
1961 ExpandoColumn expandoColumn, long tableId, String name,
1962 OrderByComparator orderByComparator, boolean previous) {
1963 StringBundler query = null;
1964
1965 if (orderByComparator != null) {
1966 query = new StringBundler(6 +
1967 (orderByComparator.getOrderByFields().length * 6));
1968 }
1969 else {
1970 query = new StringBundler(3);
1971 }
1972
1973 if (getDB().isSupportsInlineDistinct()) {
1974 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1975 }
1976 else {
1977 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1978 }
1979
1980 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1981
1982 if (name == null) {
1983 query.append(_FINDER_COLUMN_T_N_NAME_1);
1984 }
1985 else {
1986 if (name.equals(StringPool.BLANK)) {
1987 query.append(_FINDER_COLUMN_T_N_NAME_3);
1988 }
1989 else {
1990 query.append(_FINDER_COLUMN_T_N_NAME_2);
1991 }
1992 }
1993
1994 if (!getDB().isSupportsInlineDistinct()) {
1995 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1996 }
1997
1998 if (orderByComparator != null) {
1999 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2000
2001 if (orderByConditionFields.length > 0) {
2002 query.append(WHERE_AND);
2003 }
2004
2005 for (int i = 0; i < orderByConditionFields.length; i++) {
2006 if (getDB().isSupportsInlineDistinct()) {
2007 query.append(_ORDER_BY_ENTITY_ALIAS);
2008 }
2009 else {
2010 query.append(_ORDER_BY_ENTITY_TABLE);
2011 }
2012
2013 query.append(orderByConditionFields[i]);
2014
2015 if ((i + 1) < orderByConditionFields.length) {
2016 if (orderByComparator.isAscending() ^ previous) {
2017 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2018 }
2019 else {
2020 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2021 }
2022 }
2023 else {
2024 if (orderByComparator.isAscending() ^ previous) {
2025 query.append(WHERE_GREATER_THAN);
2026 }
2027 else {
2028 query.append(WHERE_LESSER_THAN);
2029 }
2030 }
2031 }
2032
2033 query.append(ORDER_BY_CLAUSE);
2034
2035 String[] orderByFields = orderByComparator.getOrderByFields();
2036
2037 for (int i = 0; i < orderByFields.length; i++) {
2038 if (getDB().isSupportsInlineDistinct()) {
2039 query.append(_ORDER_BY_ENTITY_ALIAS);
2040 }
2041 else {
2042 query.append(_ORDER_BY_ENTITY_TABLE);
2043 }
2044
2045 query.append(orderByFields[i]);
2046
2047 if ((i + 1) < orderByFields.length) {
2048 if (orderByComparator.isAscending() ^ previous) {
2049 query.append(ORDER_BY_ASC_HAS_NEXT);
2050 }
2051 else {
2052 query.append(ORDER_BY_DESC_HAS_NEXT);
2053 }
2054 }
2055 else {
2056 if (orderByComparator.isAscending() ^ previous) {
2057 query.append(ORDER_BY_ASC);
2058 }
2059 else {
2060 query.append(ORDER_BY_DESC);
2061 }
2062 }
2063 }
2064 }
2065
2066 else {
2067 if (getDB().isSupportsInlineDistinct()) {
2068 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2069 }
2070 else {
2071 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2072 }
2073 }
2074
2075 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2076 ExpandoColumn.class.getName(),
2077 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2078
2079 SQLQuery q = session.createSQLQuery(sql);
2080
2081 q.setFirstResult(0);
2082 q.setMaxResults(2);
2083
2084 if (getDB().isSupportsInlineDistinct()) {
2085 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2086 }
2087 else {
2088 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2089 }
2090
2091 QueryPos qPos = QueryPos.getInstance(q);
2092
2093 qPos.add(tableId);
2094
2095 if (name != null) {
2096 qPos.add(name);
2097 }
2098
2099 if (orderByComparator != null) {
2100 Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
2101
2102 for (Object value : values) {
2103 qPos.add(value);
2104 }
2105 }
2106
2107 List<ExpandoColumn> list = q.list();
2108
2109 if (list.size() == 2) {
2110 return list.get(1);
2111 }
2112 else {
2113 return null;
2114 }
2115 }
2116
2117
2125 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names)
2126 throws SystemException {
2127 return filterFindByT_N(tableId, names, QueryUtil.ALL_POS,
2128 QueryUtil.ALL_POS, null);
2129 }
2130
2131
2145 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2146 int start, int end) throws SystemException {
2147 return filterFindByT_N(tableId, names, start, end, null);
2148 }
2149
2150
2165 public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2166 int start, int end, OrderByComparator orderByComparator)
2167 throws SystemException {
2168 if (!InlineSQLHelperUtil.isEnabled()) {
2169 return findByT_N(tableId, names, start, end, orderByComparator);
2170 }
2171
2172 StringBundler query = new StringBundler();
2173
2174 if (getDB().isSupportsInlineDistinct()) {
2175 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
2176 }
2177 else {
2178 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
2179 }
2180
2181 boolean conjunctionable = false;
2182
2183 if (conjunctionable) {
2184 query.append(WHERE_AND);
2185 }
2186
2187 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2188
2189 conjunctionable = true;
2190
2191 if ((names == null) || (names.length > 0)) {
2192 if (conjunctionable) {
2193 query.append(WHERE_AND);
2194 }
2195
2196 query.append(StringPool.OPEN_PARENTHESIS);
2197
2198 for (int i = 0; i < names.length; i++) {
2199 String name = names[i];
2200
2201 if (name == null) {
2202 query.append(_FINDER_COLUMN_T_N_NAME_4);
2203 }
2204 else {
2205 if (name.equals(StringPool.BLANK)) {
2206 query.append(_FINDER_COLUMN_T_N_NAME_6);
2207 }
2208 else {
2209 query.append(_FINDER_COLUMN_T_N_NAME_5);
2210 }
2211 }
2212
2213 if ((i + 1) < names.length) {
2214 query.append(WHERE_OR);
2215 }
2216 }
2217
2218 query.append(StringPool.CLOSE_PARENTHESIS);
2219
2220 conjunctionable = true;
2221 }
2222
2223 if (!getDB().isSupportsInlineDistinct()) {
2224 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
2225 }
2226
2227 if (orderByComparator != null) {
2228 if (getDB().isSupportsInlineDistinct()) {
2229 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2230 orderByComparator);
2231 }
2232 else {
2233 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2234 orderByComparator);
2235 }
2236 }
2237
2238 else {
2239 if (getDB().isSupportsInlineDistinct()) {
2240 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2241 }
2242 else {
2243 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2244 }
2245 }
2246
2247 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2248 ExpandoColumn.class.getName(),
2249 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2250
2251 Session session = null;
2252
2253 try {
2254 session = openSession();
2255
2256 SQLQuery q = session.createSQLQuery(sql);
2257
2258 if (getDB().isSupportsInlineDistinct()) {
2259 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2260 }
2261 else {
2262 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2263 }
2264
2265 QueryPos qPos = QueryPos.getInstance(q);
2266
2267 qPos.add(tableId);
2268
2269 if (names != null) {
2270 qPos.add(names);
2271 }
2272
2273 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
2274 end);
2275 }
2276 catch (Exception e) {
2277 throw processException(e);
2278 }
2279 finally {
2280 closeSession(session);
2281 }
2282 }
2283
2284
2290 public List<ExpandoColumn> findAll() throws SystemException {
2291 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2292 }
2293
2294
2306 public List<ExpandoColumn> findAll(int start, int end)
2307 throws SystemException {
2308 return findAll(start, end, null);
2309 }
2310
2311
2324 public List<ExpandoColumn> findAll(int start, int end,
2325 OrderByComparator orderByComparator) throws SystemException {
2326 FinderPath finderPath = null;
2327 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2328
2329 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2330 (orderByComparator == null)) {
2331 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2332 finderArgs = FINDER_ARGS_EMPTY;
2333 }
2334 else {
2335 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2336 finderArgs = new Object[] { start, end, orderByComparator };
2337 }
2338
2339 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
2340 finderArgs, this);
2341
2342 if (list == null) {
2343 StringBundler query = null;
2344 String sql = null;
2345
2346 if (orderByComparator != null) {
2347 query = new StringBundler(2 +
2348 (orderByComparator.getOrderByFields().length * 3));
2349
2350 query.append(_SQL_SELECT_EXPANDOCOLUMN);
2351
2352 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2353 orderByComparator);
2354
2355 sql = query.toString();
2356 }
2357 else {
2358 sql = _SQL_SELECT_EXPANDOCOLUMN.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2359 }
2360
2361 Session session = null;
2362
2363 try {
2364 session = openSession();
2365
2366 Query q = session.createQuery(sql);
2367
2368 if (orderByComparator == null) {
2369 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2370 start, end, false);
2371
2372 Collections.sort(list);
2373 }
2374 else {
2375 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2376 start, end);
2377 }
2378 }
2379 catch (Exception e) {
2380 throw processException(e);
2381 }
2382 finally {
2383 if (list == null) {
2384 FinderCacheUtil.removeResult(finderPath, finderArgs);
2385 }
2386 else {
2387 cacheResult(list);
2388
2389 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2390 }
2391
2392 closeSession(session);
2393 }
2394 }
2395
2396 return list;
2397 }
2398
2399
2405 public void removeByTableId(long tableId) throws SystemException {
2406 for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
2407 remove(expandoColumn);
2408 }
2409 }
2410
2411
2418 public void removeByT_N(long tableId, String name)
2419 throws SystemException {
2420 for (ExpandoColumn expandoColumn : findByT_N(tableId, name)) {
2421 remove(expandoColumn);
2422 }
2423 }
2424
2425
2430 public void removeAll() throws SystemException {
2431 for (ExpandoColumn expandoColumn : findAll()) {
2432 remove(expandoColumn);
2433 }
2434 }
2435
2436
2443 public int countByTableId(long tableId) throws SystemException {
2444 Object[] finderArgs = new Object[] { tableId };
2445
2446 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
2447 finderArgs, this);
2448
2449 if (count == null) {
2450 StringBundler query = new StringBundler(2);
2451
2452 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2453
2454 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2455
2456 String sql = query.toString();
2457
2458 Session session = null;
2459
2460 try {
2461 session = openSession();
2462
2463 Query q = session.createQuery(sql);
2464
2465 QueryPos qPos = QueryPos.getInstance(q);
2466
2467 qPos.add(tableId);
2468
2469 count = (Long)q.uniqueResult();
2470 }
2471 catch (Exception e) {
2472 throw processException(e);
2473 }
2474 finally {
2475 if (count == null) {
2476 count = Long.valueOf(0);
2477 }
2478
2479 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
2480 finderArgs, count);
2481
2482 closeSession(session);
2483 }
2484 }
2485
2486 return count.intValue();
2487 }
2488
2489
2496 public int filterCountByTableId(long tableId) throws SystemException {
2497 if (!InlineSQLHelperUtil.isEnabled()) {
2498 return countByTableId(tableId);
2499 }
2500
2501 StringBundler query = new StringBundler(2);
2502
2503 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2504
2505 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2506
2507 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2508 ExpandoColumn.class.getName(),
2509 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2510
2511 Session session = null;
2512
2513 try {
2514 session = openSession();
2515
2516 SQLQuery q = session.createSQLQuery(sql);
2517
2518 q.addScalar(COUNT_COLUMN_NAME,
2519 com.liferay.portal.kernel.dao.orm.Type.LONG);
2520
2521 QueryPos qPos = QueryPos.getInstance(q);
2522
2523 qPos.add(tableId);
2524
2525 Long count = (Long)q.uniqueResult();
2526
2527 return count.intValue();
2528 }
2529 catch (Exception e) {
2530 throw processException(e);
2531 }
2532 finally {
2533 closeSession(session);
2534 }
2535 }
2536
2537
2545 public int countByT_N(long tableId, String name) throws SystemException {
2546 Object[] finderArgs = new Object[] { tableId, name };
2547
2548 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
2549 finderArgs, this);
2550
2551 if (count == null) {
2552 StringBundler query = new StringBundler(3);
2553
2554 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2555
2556 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2557
2558 if (name == null) {
2559 query.append(_FINDER_COLUMN_T_N_NAME_1);
2560 }
2561 else {
2562 if (name.equals(StringPool.BLANK)) {
2563 query.append(_FINDER_COLUMN_T_N_NAME_3);
2564 }
2565 else {
2566 query.append(_FINDER_COLUMN_T_N_NAME_2);
2567 }
2568 }
2569
2570 String sql = query.toString();
2571
2572 Session session = null;
2573
2574 try {
2575 session = openSession();
2576
2577 Query q = session.createQuery(sql);
2578
2579 QueryPos qPos = QueryPos.getInstance(q);
2580
2581 qPos.add(tableId);
2582
2583 if (name != null) {
2584 qPos.add(name);
2585 }
2586
2587 count = (Long)q.uniqueResult();
2588 }
2589 catch (Exception e) {
2590 throw processException(e);
2591 }
2592 finally {
2593 if (count == null) {
2594 count = Long.valueOf(0);
2595 }
2596
2597 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
2598 count);
2599
2600 closeSession(session);
2601 }
2602 }
2603
2604 return count.intValue();
2605 }
2606
2607
2615 public int countByT_N(long tableId, String[] names)
2616 throws SystemException {
2617 Object[] finderArgs = new Object[] { tableId, StringUtil.merge(names) };
2618
2619 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
2620 finderArgs, this);
2621
2622 if (count == null) {
2623 StringBundler query = new StringBundler();
2624
2625 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2626
2627 boolean conjunctionable = false;
2628
2629 if (conjunctionable) {
2630 query.append(WHERE_AND);
2631 }
2632
2633 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2634
2635 conjunctionable = true;
2636
2637 if ((names == null) || (names.length > 0)) {
2638 if (conjunctionable) {
2639 query.append(WHERE_AND);
2640 }
2641
2642 query.append(StringPool.OPEN_PARENTHESIS);
2643
2644 for (int i = 0; i < names.length; i++) {
2645 String name = names[i];
2646
2647 if (name == null) {
2648 query.append(_FINDER_COLUMN_T_N_NAME_4);
2649 }
2650 else {
2651 if (name.equals(StringPool.BLANK)) {
2652 query.append(_FINDER_COLUMN_T_N_NAME_6);
2653 }
2654 else {
2655 query.append(_FINDER_COLUMN_T_N_NAME_5);
2656 }
2657 }
2658
2659 if ((i + 1) < names.length) {
2660 query.append(WHERE_OR);
2661 }
2662 }
2663
2664 query.append(StringPool.CLOSE_PARENTHESIS);
2665
2666 conjunctionable = true;
2667 }
2668
2669 String sql = query.toString();
2670
2671 Session session = null;
2672
2673 try {
2674 session = openSession();
2675
2676 Query q = session.createQuery(sql);
2677
2678 QueryPos qPos = QueryPos.getInstance(q);
2679
2680 qPos.add(tableId);
2681
2682 if (names != null) {
2683 qPos.add(names);
2684 }
2685
2686 count = (Long)q.uniqueResult();
2687 }
2688 catch (Exception e) {
2689 throw processException(e);
2690 }
2691 finally {
2692 if (count == null) {
2693 count = Long.valueOf(0);
2694 }
2695
2696 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
2697 finderArgs, count);
2698
2699 closeSession(session);
2700 }
2701 }
2702
2703 return count.intValue();
2704 }
2705
2706
2714 public int filterCountByT_N(long tableId, String name)
2715 throws SystemException {
2716 if (!InlineSQLHelperUtil.isEnabled()) {
2717 return countByT_N(tableId, name);
2718 }
2719
2720 StringBundler query = new StringBundler(3);
2721
2722 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2723
2724 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2725
2726 if (name == null) {
2727 query.append(_FINDER_COLUMN_T_N_NAME_1);
2728 }
2729 else {
2730 if (name.equals(StringPool.BLANK)) {
2731 query.append(_FINDER_COLUMN_T_N_NAME_3);
2732 }
2733 else {
2734 query.append(_FINDER_COLUMN_T_N_NAME_2);
2735 }
2736 }
2737
2738 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2739 ExpandoColumn.class.getName(),
2740 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2741
2742 Session session = null;
2743
2744 try {
2745 session = openSession();
2746
2747 SQLQuery q = session.createSQLQuery(sql);
2748
2749 q.addScalar(COUNT_COLUMN_NAME,
2750 com.liferay.portal.kernel.dao.orm.Type.LONG);
2751
2752 QueryPos qPos = QueryPos.getInstance(q);
2753
2754 qPos.add(tableId);
2755
2756 if (name != null) {
2757 qPos.add(name);
2758 }
2759
2760 Long count = (Long)q.uniqueResult();
2761
2762 return count.intValue();
2763 }
2764 catch (Exception e) {
2765 throw processException(e);
2766 }
2767 finally {
2768 closeSession(session);
2769 }
2770 }
2771
2772
2780 public int filterCountByT_N(long tableId, String[] names)
2781 throws SystemException {
2782 if (!InlineSQLHelperUtil.isEnabled()) {
2783 return countByT_N(tableId, names);
2784 }
2785
2786 StringBundler query = new StringBundler();
2787
2788 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2789
2790 boolean conjunctionable = false;
2791
2792 if (conjunctionable) {
2793 query.append(WHERE_AND);
2794 }
2795
2796 query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2797
2798 conjunctionable = true;
2799
2800 if ((names == null) || (names.length > 0)) {
2801 if (conjunctionable) {
2802 query.append(WHERE_AND);
2803 }
2804
2805 query.append(StringPool.OPEN_PARENTHESIS);
2806
2807 for (int i = 0; i < names.length; i++) {
2808 String name = names[i];
2809
2810 if (name == null) {
2811 query.append(_FINDER_COLUMN_T_N_NAME_4);
2812 }
2813 else {
2814 if (name.equals(StringPool.BLANK)) {
2815 query.append(_FINDER_COLUMN_T_N_NAME_6);
2816 }
2817 else {
2818 query.append(_FINDER_COLUMN_T_N_NAME_5);
2819 }
2820 }
2821
2822 if ((i + 1) < names.length) {
2823 query.append(WHERE_OR);
2824 }
2825 }
2826
2827 query.append(StringPool.CLOSE_PARENTHESIS);
2828
2829 conjunctionable = true;
2830 }
2831
2832 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2833 ExpandoColumn.class.getName(),
2834 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2835
2836 Session session = null;
2837
2838 try {
2839 session = openSession();
2840
2841 SQLQuery q = session.createSQLQuery(sql);
2842
2843 q.addScalar(COUNT_COLUMN_NAME,
2844 com.liferay.portal.kernel.dao.orm.Type.LONG);
2845
2846 QueryPos qPos = QueryPos.getInstance(q);
2847
2848 qPos.add(tableId);
2849
2850 if (names != null) {
2851 qPos.add(names);
2852 }
2853
2854 Long count = (Long)q.uniqueResult();
2855
2856 return count.intValue();
2857 }
2858 catch (Exception e) {
2859 throw processException(e);
2860 }
2861 finally {
2862 closeSession(session);
2863 }
2864 }
2865
2866
2872 public int countAll() throws SystemException {
2873 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2874 FINDER_ARGS_EMPTY, this);
2875
2876 if (count == null) {
2877 Session session = null;
2878
2879 try {
2880 session = openSession();
2881
2882 Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
2883
2884 count = (Long)q.uniqueResult();
2885 }
2886 catch (Exception e) {
2887 throw processException(e);
2888 }
2889 finally {
2890 if (count == null) {
2891 count = Long.valueOf(0);
2892 }
2893
2894 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2895 FINDER_ARGS_EMPTY, count);
2896
2897 closeSession(session);
2898 }
2899 }
2900
2901 return count.intValue();
2902 }
2903
2904
2907 public void afterPropertiesSet() {
2908 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2909 com.liferay.portal.util.PropsUtil.get(
2910 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
2911
2912 if (listenerClassNames.length > 0) {
2913 try {
2914 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
2915
2916 for (String listenerClassName : listenerClassNames) {
2917 listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
2918 listenerClassName));
2919 }
2920
2921 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2922 }
2923 catch (Exception e) {
2924 _log.error(e);
2925 }
2926 }
2927 }
2928
2929 public void destroy() {
2930 EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
2931 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2932 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2933 }
2934
2935 @BeanReference(type = ExpandoColumnPersistence.class)
2936 protected ExpandoColumnPersistence expandoColumnPersistence;
2937 @BeanReference(type = ExpandoRowPersistence.class)
2938 protected ExpandoRowPersistence expandoRowPersistence;
2939 @BeanReference(type = ExpandoTablePersistence.class)
2940 protected ExpandoTablePersistence expandoTablePersistence;
2941 @BeanReference(type = ExpandoValuePersistence.class)
2942 protected ExpandoValuePersistence expandoValuePersistence;
2943 @BeanReference(type = ResourcePersistence.class)
2944 protected ResourcePersistence resourcePersistence;
2945 @BeanReference(type = UserPersistence.class)
2946 protected UserPersistence userPersistence;
2947 private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
2948 private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
2949 private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
2950 private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
2951 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
2952 private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
2953 private static final String _FINDER_COLUMN_T_N_TABLEID_5 = "(" +
2954 _removeConjunction(_FINDER_COLUMN_T_N_TABLEID_2) + ")";
2955 private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
2956 private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
2957 private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = ?)";
2958 private static final String _FINDER_COLUMN_T_N_NAME_4 = "(" +
2959 _removeConjunction(_FINDER_COLUMN_T_N_NAME_1) + ")";
2960 private static final String _FINDER_COLUMN_T_N_NAME_5 = "(" +
2961 _removeConjunction(_FINDER_COLUMN_T_N_NAME_2) + ")";
2962 private static final String _FINDER_COLUMN_T_N_NAME_6 = "(" +
2963 _removeConjunction(_FINDER_COLUMN_T_N_NAME_3) + ")";
2964
2965 private static String _removeConjunction(String sql) {
2966 int pos = sql.indexOf(" AND ");
2967
2968 if (pos != -1) {
2969 sql = sql.substring(0, pos);
2970 }
2971
2972 return sql;
2973 }
2974
2975 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "expandoColumn.columnId";
2976 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
2977 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
2978 "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
2979 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
2980 ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
2981 private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
2982 private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
2983 private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
2984 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
2985 private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
2986 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
2987 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
2988 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2989 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
2990 private static ExpandoColumn _nullExpandoColumn = new ExpandoColumnImpl() {
2991 @Override
2992 public Object clone() {
2993 return this;
2994 }
2995
2996 @Override
2997 public CacheModel<ExpandoColumn> toCacheModel() {
2998 return _nullExpandoColumnCacheModel;
2999 }
3000 };
3001
3002 private static CacheModel<ExpandoColumn> _nullExpandoColumnCacheModel = new CacheModel<ExpandoColumn>() {
3003 public ExpandoColumn toEntityModel() {
3004 return _nullExpandoColumn;
3005 }
3006 };
3007 }