001
014
015 package com.liferay.portlet.expando.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.expando.NoSuchColumnException;
046 import com.liferay.portlet.expando.model.ExpandoColumn;
047 import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
048 import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
072 public class ExpandoColumnPersistenceImpl extends BasePersistenceImpl<ExpandoColumn>
073 implements ExpandoColumnPersistence {
074 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoColumnImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
076 ".List";
077 public static final FinderPath FINDER_PATH_FIND_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
078 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
079 FINDER_CLASS_NAME_LIST, "findByTableId",
080 new String[] {
081 Long.class.getName(),
082
083 "java.lang.Integer", "java.lang.Integer",
084 "com.liferay.portal.kernel.util.OrderByComparator"
085 });
086 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
087 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
088 FINDER_CLASS_NAME_LIST, "countByTableId",
089 new String[] { Long.class.getName() });
090 public static final FinderPath FINDER_PATH_FETCH_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
091 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
092 FINDER_CLASS_NAME_ENTITY, "fetchByT_N",
093 new String[] { Long.class.getName(), String.class.getName() });
094 public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
095 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
096 FINDER_CLASS_NAME_LIST, "countByT_N",
097 new String[] { Long.class.getName(), String.class.getName() });
098 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
099 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
100 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
101 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
102 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
104
105
110 public void cacheResult(ExpandoColumn expandoColumn) {
111 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
112 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
113 expandoColumn);
114
115 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
116 new Object[] {
117 new Long(expandoColumn.getTableId()),
118
119 expandoColumn.getName()
120 }, expandoColumn);
121 }
122
123
128 public void cacheResult(List<ExpandoColumn> expandoColumns) {
129 for (ExpandoColumn expandoColumn : expandoColumns) {
130 if (EntityCacheUtil.getResult(
131 ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
132 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
133 this) == null) {
134 cacheResult(expandoColumn);
135 }
136 }
137 }
138
139
146 public void clearCache() {
147 CacheRegistryUtil.clear(ExpandoColumnImpl.class.getName());
148 EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
151 }
152
153
160 public void clearCache(ExpandoColumn expandoColumn) {
161 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
162 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
163
164 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
165 new Object[] {
166 new Long(expandoColumn.getTableId()),
167
168 expandoColumn.getName()
169 });
170 }
171
172
178 public ExpandoColumn create(long columnId) {
179 ExpandoColumn expandoColumn = new ExpandoColumnImpl();
180
181 expandoColumn.setNew(true);
182 expandoColumn.setPrimaryKey(columnId);
183
184 return expandoColumn;
185 }
186
187
195 public ExpandoColumn remove(Serializable primaryKey)
196 throws NoSuchModelException, SystemException {
197 return remove(((Long)primaryKey).longValue());
198 }
199
200
208 public ExpandoColumn remove(long columnId)
209 throws NoSuchColumnException, SystemException {
210 Session session = null;
211
212 try {
213 session = openSession();
214
215 ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
216 new Long(columnId));
217
218 if (expandoColumn == null) {
219 if (_log.isWarnEnabled()) {
220 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
221 }
222
223 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
224 columnId);
225 }
226
227 return remove(expandoColumn);
228 }
229 catch (NoSuchColumnException nsee) {
230 throw nsee;
231 }
232 catch (Exception e) {
233 throw processException(e);
234 }
235 finally {
236 closeSession(session);
237 }
238 }
239
240 protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
241 throws SystemException {
242 expandoColumn = toUnwrappedModel(expandoColumn);
243
244 Session session = null;
245
246 try {
247 session = openSession();
248
249 BatchSessionUtil.delete(session, expandoColumn);
250 }
251 catch (Exception e) {
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257
258 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
259
260 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
261
262 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
263 new Object[] {
264 new Long(expandoColumnModelImpl.getTableId()),
265
266 expandoColumnModelImpl.getName()
267 });
268
269 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
270 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
271
272 return expandoColumn;
273 }
274
275 public ExpandoColumn updateImpl(
276 com.liferay.portlet.expando.model.ExpandoColumn expandoColumn,
277 boolean merge) throws SystemException {
278 expandoColumn = toUnwrappedModel(expandoColumn);
279
280 boolean isNew = expandoColumn.isNew();
281
282 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
283
284 Session session = null;
285
286 try {
287 session = openSession();
288
289 BatchSessionUtil.update(session, expandoColumn, merge);
290
291 expandoColumn.setNew(false);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
301
302 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
303 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
304 expandoColumn);
305
306 if (!isNew &&
307 ((expandoColumn.getTableId() != expandoColumnModelImpl.getOriginalTableId()) ||
308 !Validator.equals(expandoColumn.getName(),
309 expandoColumnModelImpl.getOriginalName()))) {
310 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
311 new Object[] {
312 new Long(expandoColumnModelImpl.getOriginalTableId()),
313
314 expandoColumnModelImpl.getOriginalName()
315 });
316 }
317
318 if (isNew ||
319 ((expandoColumn.getTableId() != expandoColumnModelImpl.getOriginalTableId()) ||
320 !Validator.equals(expandoColumn.getName(),
321 expandoColumnModelImpl.getOriginalName()))) {
322 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
323 new Object[] {
324 new Long(expandoColumn.getTableId()),
325
326 expandoColumn.getName()
327 }, expandoColumn);
328 }
329
330 return expandoColumn;
331 }
332
333 protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
334 if (expandoColumn instanceof ExpandoColumnImpl) {
335 return expandoColumn;
336 }
337
338 ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
339
340 expandoColumnImpl.setNew(expandoColumn.isNew());
341 expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
342
343 expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
344 expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
345 expandoColumnImpl.setTableId(expandoColumn.getTableId());
346 expandoColumnImpl.setName(expandoColumn.getName());
347 expandoColumnImpl.setType(expandoColumn.getType());
348 expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
349 expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
350
351 return expandoColumnImpl;
352 }
353
354
362 public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
363 throws NoSuchModelException, SystemException {
364 return findByPrimaryKey(((Long)primaryKey).longValue());
365 }
366
367
375 public ExpandoColumn findByPrimaryKey(long columnId)
376 throws NoSuchColumnException, SystemException {
377 ExpandoColumn expandoColumn = fetchByPrimaryKey(columnId);
378
379 if (expandoColumn == null) {
380 if (_log.isWarnEnabled()) {
381 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
382 }
383
384 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
385 columnId);
386 }
387
388 return expandoColumn;
389 }
390
391
398 public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey)
399 throws SystemException {
400 return fetchByPrimaryKey(((Long)primaryKey).longValue());
401 }
402
403
410 public ExpandoColumn fetchByPrimaryKey(long columnId)
411 throws SystemException {
412 ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
413 ExpandoColumnImpl.class, columnId, this);
414
415 if (expandoColumn == null) {
416 Session session = null;
417
418 try {
419 session = openSession();
420
421 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
422 new Long(columnId));
423 }
424 catch (Exception e) {
425 throw processException(e);
426 }
427 finally {
428 if (expandoColumn != null) {
429 cacheResult(expandoColumn);
430 }
431
432 closeSession(session);
433 }
434 }
435
436 return expandoColumn;
437 }
438
439
446 public List<ExpandoColumn> findByTableId(long tableId)
447 throws SystemException {
448 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
449 }
450
451
464 public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
465 throws SystemException {
466 return findByTableId(tableId, start, end, null);
467 }
468
469
483 public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
484 OrderByComparator orderByComparator) throws SystemException {
485 Object[] finderArgs = new Object[] {
486 tableId,
487
488 String.valueOf(start), String.valueOf(end),
489 String.valueOf(orderByComparator)
490 };
491
492 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TABLEID,
493 finderArgs, this);
494
495 if (list == null) {
496 StringBundler query = null;
497
498 if (orderByComparator != null) {
499 query = new StringBundler(3 +
500 (orderByComparator.getOrderByFields().length * 3));
501 }
502 else {
503 query = new StringBundler(3);
504 }
505
506 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
507
508 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
509
510 if (orderByComparator != null) {
511 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
512 orderByComparator);
513 }
514
515 else {
516 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
517 }
518
519 String sql = query.toString();
520
521 Session session = null;
522
523 try {
524 session = openSession();
525
526 Query q = session.createQuery(sql);
527
528 QueryPos qPos = QueryPos.getInstance(q);
529
530 qPos.add(tableId);
531
532 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
533 start, end);
534 }
535 catch (Exception e) {
536 throw processException(e);
537 }
538 finally {
539 if (list == null) {
540 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_TABLEID,
541 finderArgs);
542 }
543 else {
544 cacheResult(list);
545
546 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TABLEID,
547 finderArgs, list);
548 }
549
550 closeSession(session);
551 }
552 }
553
554 return list;
555 }
556
557
570 public ExpandoColumn findByTableId_First(long tableId,
571 OrderByComparator orderByComparator)
572 throws NoSuchColumnException, SystemException {
573 List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
574 orderByComparator);
575
576 if (list.isEmpty()) {
577 StringBundler msg = new StringBundler(4);
578
579 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
580
581 msg.append("tableId=");
582 msg.append(tableId);
583
584 msg.append(StringPool.CLOSE_CURLY_BRACE);
585
586 throw new NoSuchColumnException(msg.toString());
587 }
588 else {
589 return list.get(0);
590 }
591 }
592
593
606 public ExpandoColumn findByTableId_Last(long tableId,
607 OrderByComparator orderByComparator)
608 throws NoSuchColumnException, SystemException {
609 int count = countByTableId(tableId);
610
611 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
612 orderByComparator);
613
614 if (list.isEmpty()) {
615 StringBundler msg = new StringBundler(4);
616
617 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
618
619 msg.append("tableId=");
620 msg.append(tableId);
621
622 msg.append(StringPool.CLOSE_CURLY_BRACE);
623
624 throw new NoSuchColumnException(msg.toString());
625 }
626 else {
627 return list.get(0);
628 }
629 }
630
631
645 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
646 long tableId, OrderByComparator orderByComparator)
647 throws NoSuchColumnException, SystemException {
648 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 ExpandoColumn[] array = new ExpandoColumnImpl[3];
656
657 array[0] = getByTableId_PrevAndNext(session, expandoColumn,
658 tableId, orderByComparator, true);
659
660 array[1] = expandoColumn;
661
662 array[2] = getByTableId_PrevAndNext(session, expandoColumn,
663 tableId, orderByComparator, false);
664
665 return array;
666 }
667 catch (Exception e) {
668 throw processException(e);
669 }
670 finally {
671 closeSession(session);
672 }
673 }
674
675 protected ExpandoColumn getByTableId_PrevAndNext(Session session,
676 ExpandoColumn expandoColumn, long tableId,
677 OrderByComparator orderByComparator, boolean previous) {
678 StringBundler query = null;
679
680 if (orderByComparator != null) {
681 query = new StringBundler(6 +
682 (orderByComparator.getOrderByFields().length * 6));
683 }
684 else {
685 query = new StringBundler(3);
686 }
687
688 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
689
690 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
691
692 if (orderByComparator != null) {
693 String[] orderByFields = orderByComparator.getOrderByFields();
694
695 if (orderByFields.length > 0) {
696 query.append(WHERE_AND);
697 }
698
699 for (int i = 0; i < orderByFields.length; i++) {
700 query.append(_ORDER_BY_ENTITY_ALIAS);
701 query.append(orderByFields[i]);
702
703 if ((i + 1) < orderByFields.length) {
704 if (orderByComparator.isAscending() ^ previous) {
705 query.append(WHERE_GREATER_THAN_HAS_NEXT);
706 }
707 else {
708 query.append(WHERE_LESSER_THAN_HAS_NEXT);
709 }
710 }
711 else {
712 if (orderByComparator.isAscending() ^ previous) {
713 query.append(WHERE_GREATER_THAN);
714 }
715 else {
716 query.append(WHERE_LESSER_THAN);
717 }
718 }
719 }
720
721 query.append(ORDER_BY_CLAUSE);
722
723 for (int i = 0; i < orderByFields.length; i++) {
724 query.append(_ORDER_BY_ENTITY_ALIAS);
725 query.append(orderByFields[i]);
726
727 if ((i + 1) < orderByFields.length) {
728 if (orderByComparator.isAscending() ^ previous) {
729 query.append(ORDER_BY_ASC_HAS_NEXT);
730 }
731 else {
732 query.append(ORDER_BY_DESC_HAS_NEXT);
733 }
734 }
735 else {
736 if (orderByComparator.isAscending() ^ previous) {
737 query.append(ORDER_BY_ASC);
738 }
739 else {
740 query.append(ORDER_BY_DESC);
741 }
742 }
743 }
744 }
745
746 else {
747 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
748 }
749
750 String sql = query.toString();
751
752 Query q = session.createQuery(sql);
753
754 q.setFirstResult(0);
755 q.setMaxResults(2);
756
757 QueryPos qPos = QueryPos.getInstance(q);
758
759 qPos.add(tableId);
760
761 if (orderByComparator != null) {
762 Object[] values = orderByComparator.getOrderByValues(expandoColumn);
763
764 for (Object value : values) {
765 qPos.add(value);
766 }
767 }
768
769 List<ExpandoColumn> list = q.list();
770
771 if (list.size() == 2) {
772 return list.get(1);
773 }
774 else {
775 return null;
776 }
777 }
778
779
786 public List<ExpandoColumn> filterFindByTableId(long tableId)
787 throws SystemException {
788 return filterFindByTableId(tableId, QueryUtil.ALL_POS,
789 QueryUtil.ALL_POS, null);
790 }
791
792
805 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
806 int end) throws SystemException {
807 return filterFindByTableId(tableId, start, end, null);
808 }
809
810
824 public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
825 int end, OrderByComparator orderByComparator) throws SystemException {
826 if (!InlineSQLHelperUtil.isEnabled()) {
827 return findByTableId(tableId, start, end, orderByComparator);
828 }
829
830 StringBundler query = null;
831
832 if (orderByComparator != null) {
833 query = new StringBundler(3 +
834 (orderByComparator.getOrderByFields().length * 3));
835 }
836 else {
837 query = new StringBundler(3);
838 }
839
840 if (getDB().isSupportsInlineDistinct()) {
841 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
842 }
843 else {
844 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
845 }
846
847 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
848
849 if (!getDB().isSupportsInlineDistinct()) {
850 query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
851 }
852
853 if (orderByComparator != null) {
854 if (getDB().isSupportsInlineDistinct()) {
855 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
856 orderByComparator);
857 }
858 else {
859 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
860 orderByComparator);
861 }
862 }
863
864 else {
865 if (getDB().isSupportsInlineDistinct()) {
866 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
867 }
868 else {
869 query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
870 }
871 }
872
873 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
874 ExpandoColumn.class.getName(), _FILTER_COLUMN_PK,
875 _FILTER_COLUMN_USERID);
876
877 Session session = null;
878
879 try {
880 session = openSession();
881
882 SQLQuery q = session.createSQLQuery(sql);
883
884 if (getDB().isSupportsInlineDistinct()) {
885 q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
886 }
887 else {
888 q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
889 }
890
891 QueryPos qPos = QueryPos.getInstance(q);
892
893 qPos.add(tableId);
894
895 return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
896 end);
897 }
898 catch (Exception e) {
899 throw processException(e);
900 }
901 finally {
902 closeSession(session);
903 }
904 }
905
906
915 public ExpandoColumn findByT_N(long tableId, String name)
916 throws NoSuchColumnException, SystemException {
917 ExpandoColumn expandoColumn = fetchByT_N(tableId, name);
918
919 if (expandoColumn == null) {
920 StringBundler msg = new StringBundler(6);
921
922 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
923
924 msg.append("tableId=");
925 msg.append(tableId);
926
927 msg.append(", name=");
928 msg.append(name);
929
930 msg.append(StringPool.CLOSE_CURLY_BRACE);
931
932 if (_log.isWarnEnabled()) {
933 _log.warn(msg.toString());
934 }
935
936 throw new NoSuchColumnException(msg.toString());
937 }
938
939 return expandoColumn;
940 }
941
942
950 public ExpandoColumn fetchByT_N(long tableId, String name)
951 throws SystemException {
952 return fetchByT_N(tableId, name, true);
953 }
954
955
963 public ExpandoColumn fetchByT_N(long tableId, String name,
964 boolean retrieveFromCache) throws SystemException {
965 Object[] finderArgs = new Object[] { tableId, name };
966
967 Object result = null;
968
969 if (retrieveFromCache) {
970 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_N,
971 finderArgs, this);
972 }
973
974 if (result == null) {
975 StringBundler query = new StringBundler(4);
976
977 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
978
979 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
980
981 if (name == null) {
982 query.append(_FINDER_COLUMN_T_N_NAME_1);
983 }
984 else {
985 if (name.equals(StringPool.BLANK)) {
986 query.append(_FINDER_COLUMN_T_N_NAME_3);
987 }
988 else {
989 query.append(_FINDER_COLUMN_T_N_NAME_2);
990 }
991 }
992
993 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
994
995 String sql = query.toString();
996
997 Session session = null;
998
999 try {
1000 session = openSession();
1001
1002 Query q = session.createQuery(sql);
1003
1004 QueryPos qPos = QueryPos.getInstance(q);
1005
1006 qPos.add(tableId);
1007
1008 if (name != null) {
1009 qPos.add(name);
1010 }
1011
1012 List<ExpandoColumn> list = q.list();
1013
1014 result = list;
1015
1016 ExpandoColumn expandoColumn = null;
1017
1018 if (list.isEmpty()) {
1019 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
1020 finderArgs, list);
1021 }
1022 else {
1023 expandoColumn = list.get(0);
1024
1025 cacheResult(expandoColumn);
1026
1027 if ((expandoColumn.getTableId() != tableId) ||
1028 (expandoColumn.getName() == null) ||
1029 !expandoColumn.getName().equals(name)) {
1030 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
1031 finderArgs, expandoColumn);
1032 }
1033 }
1034
1035 return expandoColumn;
1036 }
1037 catch (Exception e) {
1038 throw processException(e);
1039 }
1040 finally {
1041 if (result == null) {
1042 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
1043 finderArgs);
1044 }
1045
1046 closeSession(session);
1047 }
1048 }
1049 else {
1050 if (result instanceof List<?>) {
1051 return null;
1052 }
1053 else {
1054 return (ExpandoColumn)result;
1055 }
1056 }
1057 }
1058
1059
1065 public List<ExpandoColumn> findAll() throws SystemException {
1066 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1067 }
1068
1069
1081 public List<ExpandoColumn> findAll(int start, int end)
1082 throws SystemException {
1083 return findAll(start, end, null);
1084 }
1085
1086
1099 public List<ExpandoColumn> findAll(int start, int end,
1100 OrderByComparator orderByComparator) throws SystemException {
1101 Object[] finderArgs = new Object[] {
1102 String.valueOf(start), String.valueOf(end),
1103 String.valueOf(orderByComparator)
1104 };
1105
1106 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1107 finderArgs, this);
1108
1109 if (list == null) {
1110 StringBundler query = null;
1111 String sql = null;
1112
1113 if (orderByComparator != null) {
1114 query = new StringBundler(2 +
1115 (orderByComparator.getOrderByFields().length * 3));
1116
1117 query.append(_SQL_SELECT_EXPANDOCOLUMN);
1118
1119 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1120 orderByComparator);
1121
1122 sql = query.toString();
1123 }
1124 else {
1125 sql = _SQL_SELECT_EXPANDOCOLUMN.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1126 }
1127
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 Query q = session.createQuery(sql);
1134
1135 if (orderByComparator == null) {
1136 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1137 start, end, false);
1138
1139 Collections.sort(list);
1140 }
1141 else {
1142 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1143 start, end);
1144 }
1145 }
1146 catch (Exception e) {
1147 throw processException(e);
1148 }
1149 finally {
1150 if (list == null) {
1151 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1152 finderArgs);
1153 }
1154 else {
1155 cacheResult(list);
1156
1157 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1158 list);
1159 }
1160
1161 closeSession(session);
1162 }
1163 }
1164
1165 return list;
1166 }
1167
1168
1174 public void removeByTableId(long tableId) throws SystemException {
1175 for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
1176 remove(expandoColumn);
1177 }
1178 }
1179
1180
1187 public void removeByT_N(long tableId, String name)
1188 throws NoSuchColumnException, SystemException {
1189 ExpandoColumn expandoColumn = findByT_N(tableId, name);
1190
1191 remove(expandoColumn);
1192 }
1193
1194
1199 public void removeAll() throws SystemException {
1200 for (ExpandoColumn expandoColumn : findAll()) {
1201 remove(expandoColumn);
1202 }
1203 }
1204
1205
1212 public int countByTableId(long tableId) throws SystemException {
1213 Object[] finderArgs = new Object[] { tableId };
1214
1215 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
1216 finderArgs, this);
1217
1218 if (count == null) {
1219 StringBundler query = new StringBundler(2);
1220
1221 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1222
1223 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1224
1225 String sql = query.toString();
1226
1227 Session session = null;
1228
1229 try {
1230 session = openSession();
1231
1232 Query q = session.createQuery(sql);
1233
1234 QueryPos qPos = QueryPos.getInstance(q);
1235
1236 qPos.add(tableId);
1237
1238 count = (Long)q.uniqueResult();
1239 }
1240 catch (Exception e) {
1241 throw processException(e);
1242 }
1243 finally {
1244 if (count == null) {
1245 count = Long.valueOf(0);
1246 }
1247
1248 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
1249 finderArgs, count);
1250
1251 closeSession(session);
1252 }
1253 }
1254
1255 return count.intValue();
1256 }
1257
1258
1265 public int filterCountByTableId(long tableId) throws SystemException {
1266 if (!InlineSQLHelperUtil.isEnabled()) {
1267 return countByTableId(tableId);
1268 }
1269
1270 StringBundler query = new StringBundler(2);
1271
1272 query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1273
1274 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1275
1276 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1277 ExpandoColumn.class.getName(), _FILTER_COLUMN_PK,
1278 _FILTER_COLUMN_USERID);
1279
1280 Session session = null;
1281
1282 try {
1283 session = openSession();
1284
1285 SQLQuery q = session.createSQLQuery(sql);
1286
1287 q.addScalar(COUNT_COLUMN_NAME,
1288 com.liferay.portal.kernel.dao.orm.Type.LONG);
1289
1290 QueryPos qPos = QueryPos.getInstance(q);
1291
1292 qPos.add(tableId);
1293
1294 Long count = (Long)q.uniqueResult();
1295
1296 return count.intValue();
1297 }
1298 catch (Exception e) {
1299 throw processException(e);
1300 }
1301 finally {
1302 closeSession(session);
1303 }
1304 }
1305
1306
1314 public int countByT_N(long tableId, String name) throws SystemException {
1315 Object[] finderArgs = new Object[] { tableId, name };
1316
1317 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
1318 finderArgs, this);
1319
1320 if (count == null) {
1321 StringBundler query = new StringBundler(3);
1322
1323 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1324
1325 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1326
1327 if (name == null) {
1328 query.append(_FINDER_COLUMN_T_N_NAME_1);
1329 }
1330 else {
1331 if (name.equals(StringPool.BLANK)) {
1332 query.append(_FINDER_COLUMN_T_N_NAME_3);
1333 }
1334 else {
1335 query.append(_FINDER_COLUMN_T_N_NAME_2);
1336 }
1337 }
1338
1339 String sql = query.toString();
1340
1341 Session session = null;
1342
1343 try {
1344 session = openSession();
1345
1346 Query q = session.createQuery(sql);
1347
1348 QueryPos qPos = QueryPos.getInstance(q);
1349
1350 qPos.add(tableId);
1351
1352 if (name != null) {
1353 qPos.add(name);
1354 }
1355
1356 count = (Long)q.uniqueResult();
1357 }
1358 catch (Exception e) {
1359 throw processException(e);
1360 }
1361 finally {
1362 if (count == null) {
1363 count = Long.valueOf(0);
1364 }
1365
1366 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
1367 count);
1368
1369 closeSession(session);
1370 }
1371 }
1372
1373 return count.intValue();
1374 }
1375
1376
1382 public int countAll() throws SystemException {
1383 Object[] finderArgs = new Object[0];
1384
1385 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1386 finderArgs, this);
1387
1388 if (count == null) {
1389 Session session = null;
1390
1391 try {
1392 session = openSession();
1393
1394 Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
1395
1396 count = (Long)q.uniqueResult();
1397 }
1398 catch (Exception e) {
1399 throw processException(e);
1400 }
1401 finally {
1402 if (count == null) {
1403 count = Long.valueOf(0);
1404 }
1405
1406 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1407 count);
1408
1409 closeSession(session);
1410 }
1411 }
1412
1413 return count.intValue();
1414 }
1415
1416
1419 public void afterPropertiesSet() {
1420 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1421 com.liferay.portal.util.PropsUtil.get(
1422 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
1423
1424 if (listenerClassNames.length > 0) {
1425 try {
1426 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
1427
1428 for (String listenerClassName : listenerClassNames) {
1429 listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
1430 listenerClassName));
1431 }
1432
1433 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1434 }
1435 catch (Exception e) {
1436 _log.error(e);
1437 }
1438 }
1439 }
1440
1441 public void destroy() {
1442 EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
1443 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1444 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1445 }
1446
1447 @BeanReference(type = ExpandoColumnPersistence.class)
1448 protected ExpandoColumnPersistence expandoColumnPersistence;
1449 @BeanReference(type = ExpandoRowPersistence.class)
1450 protected ExpandoRowPersistence expandoRowPersistence;
1451 @BeanReference(type = ExpandoTablePersistence.class)
1452 protected ExpandoTablePersistence expandoTablePersistence;
1453 @BeanReference(type = ExpandoValuePersistence.class)
1454 protected ExpandoValuePersistence expandoValuePersistence;
1455 @BeanReference(type = ResourcePersistence.class)
1456 protected ResourcePersistence resourcePersistence;
1457 @BeanReference(type = UserPersistence.class)
1458 protected UserPersistence userPersistence;
1459 private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
1460 private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
1461 private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
1462 private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
1463 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
1464 private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
1465 private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
1466 private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
1467 private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = ?)";
1468 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
1469 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
1470 "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
1471 private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
1472 ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
1473 private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
1474 private static final String _FILTER_COLUMN_PK = "expandoColumn.columnId";
1475 private static final String _FILTER_COLUMN_USERID = null;
1476 private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
1477 private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
1478 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
1479 private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
1480 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
1481 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
1482 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
1483 }