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.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.expando.NoSuchColumnException;
044 import com.liferay.portlet.expando.model.ExpandoColumn;
045 import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
046 import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
070 public class ExpandoColumnPersistenceImpl extends BasePersistenceImpl<ExpandoColumn>
071 implements ExpandoColumnPersistence {
072 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoColumnImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
074 ".List";
075 public static final FinderPath FINDER_PATH_FIND_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
076 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
077 FINDER_CLASS_NAME_LIST, "findByTableId",
078 new String[] {
079 Long.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
085 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
086 FINDER_CLASS_NAME_LIST, "countByTableId",
087 new String[] { Long.class.getName() });
088 public static final FinderPath FINDER_PATH_FETCH_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
089 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
090 FINDER_CLASS_NAME_ENTITY, "fetchByT_N",
091 new String[] { Long.class.getName(), String.class.getName() });
092 public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
093 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
094 FINDER_CLASS_NAME_LIST, "countByT_N",
095 new String[] { Long.class.getName(), String.class.getName() });
096 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
097 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
098 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
099 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
100 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
101 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
102
103
108 public void cacheResult(ExpandoColumn expandoColumn) {
109 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
110 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
111 expandoColumn);
112
113 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
114 new Object[] {
115 new Long(expandoColumn.getTableId()),
116
117 expandoColumn.getName()
118 }, expandoColumn);
119 }
120
121
126 public void cacheResult(List<ExpandoColumn> expandoColumns) {
127 for (ExpandoColumn expandoColumn : expandoColumns) {
128 if (EntityCacheUtil.getResult(
129 ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
130 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
131 this) == null) {
132 cacheResult(expandoColumn);
133 }
134 }
135 }
136
137
144 public void clearCache() {
145 CacheRegistryUtil.clear(ExpandoColumnImpl.class.getName());
146 EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
147 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
149 }
150
151
158 public void clearCache(ExpandoColumn expandoColumn) {
159 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
160 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
161
162 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
163 new Object[] {
164 new Long(expandoColumn.getTableId()),
165
166 expandoColumn.getName()
167 });
168 }
169
170
176 public ExpandoColumn create(long columnId) {
177 ExpandoColumn expandoColumn = new ExpandoColumnImpl();
178
179 expandoColumn.setNew(true);
180 expandoColumn.setPrimaryKey(columnId);
181
182 return expandoColumn;
183 }
184
185
193 public ExpandoColumn remove(Serializable primaryKey)
194 throws NoSuchModelException, SystemException {
195 return remove(((Long)primaryKey).longValue());
196 }
197
198
206 public ExpandoColumn remove(long columnId)
207 throws NoSuchColumnException, SystemException {
208 Session session = null;
209
210 try {
211 session = openSession();
212
213 ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
214 new Long(columnId));
215
216 if (expandoColumn == null) {
217 if (_log.isWarnEnabled()) {
218 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
219 }
220
221 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
222 columnId);
223 }
224
225 return remove(expandoColumn);
226 }
227 catch (NoSuchColumnException nsee) {
228 throw nsee;
229 }
230 catch (Exception e) {
231 throw processException(e);
232 }
233 finally {
234 closeSession(session);
235 }
236 }
237
238 protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
239 throws SystemException {
240 expandoColumn = toUnwrappedModel(expandoColumn);
241
242 Session session = null;
243
244 try {
245 session = openSession();
246
247 BatchSessionUtil.delete(session, expandoColumn);
248 }
249 catch (Exception e) {
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255
256 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
257
258 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
259
260 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
261 new Object[] {
262 new Long(expandoColumnModelImpl.getOriginalTableId()),
263
264 expandoColumnModelImpl.getOriginalName()
265 });
266
267 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
268 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
269
270 return expandoColumn;
271 }
272
273 public ExpandoColumn updateImpl(
274 com.liferay.portlet.expando.model.ExpandoColumn expandoColumn,
275 boolean merge) throws SystemException {
276 expandoColumn = toUnwrappedModel(expandoColumn);
277
278 boolean isNew = expandoColumn.isNew();
279
280 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
281
282 Session session = null;
283
284 try {
285 session = openSession();
286
287 BatchSessionUtil.update(session, expandoColumn, merge);
288
289 expandoColumn.setNew(false);
290 }
291 catch (Exception e) {
292 throw processException(e);
293 }
294 finally {
295 closeSession(session);
296 }
297
298 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
299
300 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
301 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
302 expandoColumn);
303
304 if (!isNew &&
305 ((expandoColumn.getTableId() != expandoColumnModelImpl.getOriginalTableId()) ||
306 !Validator.equals(expandoColumn.getName(),
307 expandoColumnModelImpl.getOriginalName()))) {
308 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
309 new Object[] {
310 new Long(expandoColumnModelImpl.getOriginalTableId()),
311
312 expandoColumnModelImpl.getOriginalName()
313 });
314 }
315
316 if (isNew ||
317 ((expandoColumn.getTableId() != expandoColumnModelImpl.getOriginalTableId()) ||
318 !Validator.equals(expandoColumn.getName(),
319 expandoColumnModelImpl.getOriginalName()))) {
320 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
321 new Object[] {
322 new Long(expandoColumn.getTableId()),
323
324 expandoColumn.getName()
325 }, expandoColumn);
326 }
327
328 return expandoColumn;
329 }
330
331 protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
332 if (expandoColumn instanceof ExpandoColumnImpl) {
333 return expandoColumn;
334 }
335
336 ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
337
338 expandoColumnImpl.setNew(expandoColumn.isNew());
339 expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
340
341 expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
342 expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
343 expandoColumnImpl.setTableId(expandoColumn.getTableId());
344 expandoColumnImpl.setName(expandoColumn.getName());
345 expandoColumnImpl.setType(expandoColumn.getType());
346 expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
347 expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
348
349 return expandoColumnImpl;
350 }
351
352
360 public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
361 throws NoSuchModelException, SystemException {
362 return findByPrimaryKey(((Long)primaryKey).longValue());
363 }
364
365
373 public ExpandoColumn findByPrimaryKey(long columnId)
374 throws NoSuchColumnException, SystemException {
375 ExpandoColumn expandoColumn = fetchByPrimaryKey(columnId);
376
377 if (expandoColumn == null) {
378 if (_log.isWarnEnabled()) {
379 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
380 }
381
382 throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
383 columnId);
384 }
385
386 return expandoColumn;
387 }
388
389
396 public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey)
397 throws SystemException {
398 return fetchByPrimaryKey(((Long)primaryKey).longValue());
399 }
400
401
408 public ExpandoColumn fetchByPrimaryKey(long columnId)
409 throws SystemException {
410 ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
411 ExpandoColumnImpl.class, columnId, this);
412
413 if (expandoColumn == null) {
414 Session session = null;
415
416 try {
417 session = openSession();
418
419 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
420 new Long(columnId));
421 }
422 catch (Exception e) {
423 throw processException(e);
424 }
425 finally {
426 if (expandoColumn != null) {
427 cacheResult(expandoColumn);
428 }
429
430 closeSession(session);
431 }
432 }
433
434 return expandoColumn;
435 }
436
437
444 public List<ExpandoColumn> findByTableId(long tableId)
445 throws SystemException {
446 return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
447 }
448
449
462 public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
463 throws SystemException {
464 return findByTableId(tableId, start, end, null);
465 }
466
467
481 public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
482 OrderByComparator orderByComparator) throws SystemException {
483 Object[] finderArgs = new Object[] {
484 tableId,
485
486 String.valueOf(start), String.valueOf(end),
487 String.valueOf(orderByComparator)
488 };
489
490 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TABLEID,
491 finderArgs, this);
492
493 if (list == null) {
494 Session session = null;
495
496 try {
497 session = openSession();
498
499 StringBundler query = null;
500
501 if (orderByComparator != null) {
502 query = new StringBundler(3 +
503 (orderByComparator.getOrderByFields().length * 3));
504 }
505 else {
506 query = new StringBundler(3);
507 }
508
509 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
510
511 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
512
513 if (orderByComparator != null) {
514 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
515 orderByComparator);
516 }
517
518 else {
519 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
520 }
521
522 String sql = query.toString();
523
524 Query q = session.createQuery(sql);
525
526 QueryPos qPos = QueryPos.getInstance(q);
527
528 qPos.add(tableId);
529
530 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
531 start, end);
532 }
533 catch (Exception e) {
534 throw processException(e);
535 }
536 finally {
537 if (list == null) {
538 list = new ArrayList<ExpandoColumn>();
539 }
540
541 cacheResult(list);
542
543 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TABLEID,
544 finderArgs, list);
545
546 closeSession(session);
547 }
548 }
549
550 return list;
551 }
552
553
566 public ExpandoColumn findByTableId_First(long tableId,
567 OrderByComparator orderByComparator)
568 throws NoSuchColumnException, SystemException {
569 List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
570 orderByComparator);
571
572 if (list.isEmpty()) {
573 StringBundler msg = new StringBundler(4);
574
575 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
576
577 msg.append("tableId=");
578 msg.append(tableId);
579
580 msg.append(StringPool.CLOSE_CURLY_BRACE);
581
582 throw new NoSuchColumnException(msg.toString());
583 }
584 else {
585 return list.get(0);
586 }
587 }
588
589
602 public ExpandoColumn findByTableId_Last(long tableId,
603 OrderByComparator orderByComparator)
604 throws NoSuchColumnException, SystemException {
605 int count = countByTableId(tableId);
606
607 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
608 orderByComparator);
609
610 if (list.isEmpty()) {
611 StringBundler msg = new StringBundler(4);
612
613 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
614
615 msg.append("tableId=");
616 msg.append(tableId);
617
618 msg.append(StringPool.CLOSE_CURLY_BRACE);
619
620 throw new NoSuchColumnException(msg.toString());
621 }
622 else {
623 return list.get(0);
624 }
625 }
626
627
641 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
642 long tableId, OrderByComparator orderByComparator)
643 throws NoSuchColumnException, SystemException {
644 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
645
646 Session session = null;
647
648 try {
649 session = openSession();
650
651 ExpandoColumn[] array = new ExpandoColumnImpl[3];
652
653 array[0] = getByTableId_PrevAndNext(session, expandoColumn,
654 tableId, orderByComparator, true);
655
656 array[1] = expandoColumn;
657
658 array[2] = getByTableId_PrevAndNext(session, expandoColumn,
659 tableId, orderByComparator, false);
660
661 return array;
662 }
663 catch (Exception e) {
664 throw processException(e);
665 }
666 finally {
667 closeSession(session);
668 }
669 }
670
671 protected ExpandoColumn getByTableId_PrevAndNext(Session session,
672 ExpandoColumn expandoColumn, long tableId,
673 OrderByComparator orderByComparator, boolean previous) {
674 StringBundler query = null;
675
676 if (orderByComparator != null) {
677 query = new StringBundler(6 +
678 (orderByComparator.getOrderByFields().length * 6));
679 }
680 else {
681 query = new StringBundler(3);
682 }
683
684 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
685
686 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
687
688 if (orderByComparator != null) {
689 String[] orderByFields = orderByComparator.getOrderByFields();
690
691 if (orderByFields.length > 0) {
692 query.append(WHERE_AND);
693 }
694
695 for (int i = 0; i < orderByFields.length; i++) {
696 query.append(_ORDER_BY_ENTITY_ALIAS);
697 query.append(orderByFields[i]);
698
699 if ((i + 1) < orderByFields.length) {
700 if (orderByComparator.isAscending() ^ previous) {
701 query.append(WHERE_GREATER_THAN_HAS_NEXT);
702 }
703 else {
704 query.append(WHERE_LESSER_THAN_HAS_NEXT);
705 }
706 }
707 else {
708 if (orderByComparator.isAscending() ^ previous) {
709 query.append(WHERE_GREATER_THAN);
710 }
711 else {
712 query.append(WHERE_LESSER_THAN);
713 }
714 }
715 }
716
717 query.append(ORDER_BY_CLAUSE);
718
719 for (int i = 0; i < orderByFields.length; i++) {
720 query.append(_ORDER_BY_ENTITY_ALIAS);
721 query.append(orderByFields[i]);
722
723 if ((i + 1) < orderByFields.length) {
724 if (orderByComparator.isAscending() ^ previous) {
725 query.append(ORDER_BY_ASC_HAS_NEXT);
726 }
727 else {
728 query.append(ORDER_BY_DESC_HAS_NEXT);
729 }
730 }
731 else {
732 if (orderByComparator.isAscending() ^ previous) {
733 query.append(ORDER_BY_ASC);
734 }
735 else {
736 query.append(ORDER_BY_DESC);
737 }
738 }
739 }
740 }
741
742 else {
743 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
744 }
745
746 String sql = query.toString();
747
748 Query q = session.createQuery(sql);
749
750 q.setFirstResult(0);
751 q.setMaxResults(2);
752
753 QueryPos qPos = QueryPos.getInstance(q);
754
755 qPos.add(tableId);
756
757 if (orderByComparator != null) {
758 Object[] values = orderByComparator.getOrderByValues(expandoColumn);
759
760 for (Object value : values) {
761 qPos.add(value);
762 }
763 }
764
765 List<ExpandoColumn> list = q.list();
766
767 if (list.size() == 2) {
768 return list.get(1);
769 }
770 else {
771 return null;
772 }
773 }
774
775
784 public ExpandoColumn findByT_N(long tableId, String name)
785 throws NoSuchColumnException, SystemException {
786 ExpandoColumn expandoColumn = fetchByT_N(tableId, name);
787
788 if (expandoColumn == null) {
789 StringBundler msg = new StringBundler(6);
790
791 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
792
793 msg.append("tableId=");
794 msg.append(tableId);
795
796 msg.append(", name=");
797 msg.append(name);
798
799 msg.append(StringPool.CLOSE_CURLY_BRACE);
800
801 if (_log.isWarnEnabled()) {
802 _log.warn(msg.toString());
803 }
804
805 throw new NoSuchColumnException(msg.toString());
806 }
807
808 return expandoColumn;
809 }
810
811
819 public ExpandoColumn fetchByT_N(long tableId, String name)
820 throws SystemException {
821 return fetchByT_N(tableId, name, true);
822 }
823
824
832 public ExpandoColumn fetchByT_N(long tableId, String name,
833 boolean retrieveFromCache) throws SystemException {
834 Object[] finderArgs = new Object[] { tableId, name };
835
836 Object result = null;
837
838 if (retrieveFromCache) {
839 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_N,
840 finderArgs, this);
841 }
842
843 if (result == null) {
844 Session session = null;
845
846 try {
847 session = openSession();
848
849 StringBundler query = new StringBundler(4);
850
851 query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
852
853 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
854
855 if (name == null) {
856 query.append(_FINDER_COLUMN_T_N_NAME_1);
857 }
858 else {
859 if (name.equals(StringPool.BLANK)) {
860 query.append(_FINDER_COLUMN_T_N_NAME_3);
861 }
862 else {
863 query.append(_FINDER_COLUMN_T_N_NAME_2);
864 }
865 }
866
867 query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
868
869 String sql = query.toString();
870
871 Query q = session.createQuery(sql);
872
873 QueryPos qPos = QueryPos.getInstance(q);
874
875 qPos.add(tableId);
876
877 if (name != null) {
878 qPos.add(name);
879 }
880
881 List<ExpandoColumn> list = q.list();
882
883 result = list;
884
885 ExpandoColumn expandoColumn = null;
886
887 if (list.isEmpty()) {
888 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
889 finderArgs, list);
890 }
891 else {
892 expandoColumn = list.get(0);
893
894 cacheResult(expandoColumn);
895
896 if ((expandoColumn.getTableId() != tableId) ||
897 (expandoColumn.getName() == null) ||
898 !expandoColumn.getName().equals(name)) {
899 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
900 finderArgs, expandoColumn);
901 }
902 }
903
904 return expandoColumn;
905 }
906 catch (Exception e) {
907 throw processException(e);
908 }
909 finally {
910 if (result == null) {
911 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
912 finderArgs, new ArrayList<ExpandoColumn>());
913 }
914
915 closeSession(session);
916 }
917 }
918 else {
919 if (result instanceof List<?>) {
920 return null;
921 }
922 else {
923 return (ExpandoColumn)result;
924 }
925 }
926 }
927
928
934 public List<ExpandoColumn> findAll() throws SystemException {
935 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
936 }
937
938
950 public List<ExpandoColumn> findAll(int start, int end)
951 throws SystemException {
952 return findAll(start, end, null);
953 }
954
955
968 public List<ExpandoColumn> findAll(int start, int end,
969 OrderByComparator orderByComparator) throws SystemException {
970 Object[] finderArgs = new Object[] {
971 String.valueOf(start), String.valueOf(end),
972 String.valueOf(orderByComparator)
973 };
974
975 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
976 finderArgs, this);
977
978 if (list == null) {
979 Session session = null;
980
981 try {
982 session = openSession();
983
984 StringBundler query = null;
985 String sql = null;
986
987 if (orderByComparator != null) {
988 query = new StringBundler(2 +
989 (orderByComparator.getOrderByFields().length * 3));
990
991 query.append(_SQL_SELECT_EXPANDOCOLUMN);
992
993 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
994 orderByComparator);
995
996 sql = query.toString();
997 }
998 else {
999 sql = _SQL_SELECT_EXPANDOCOLUMN.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1000 }
1001
1002 Query q = session.createQuery(sql);
1003
1004 if (orderByComparator == null) {
1005 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1006 start, end, false);
1007
1008 Collections.sort(list);
1009 }
1010 else {
1011 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1012 start, end);
1013 }
1014 }
1015 catch (Exception e) {
1016 throw processException(e);
1017 }
1018 finally {
1019 if (list == null) {
1020 list = new ArrayList<ExpandoColumn>();
1021 }
1022
1023 cacheResult(list);
1024
1025 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1026
1027 closeSession(session);
1028 }
1029 }
1030
1031 return list;
1032 }
1033
1034
1040 public void removeByTableId(long tableId) throws SystemException {
1041 for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
1042 remove(expandoColumn);
1043 }
1044 }
1045
1046
1053 public void removeByT_N(long tableId, String name)
1054 throws NoSuchColumnException, SystemException {
1055 ExpandoColumn expandoColumn = findByT_N(tableId, name);
1056
1057 remove(expandoColumn);
1058 }
1059
1060
1065 public void removeAll() throws SystemException {
1066 for (ExpandoColumn expandoColumn : findAll()) {
1067 remove(expandoColumn);
1068 }
1069 }
1070
1071
1078 public int countByTableId(long tableId) throws SystemException {
1079 Object[] finderArgs = new Object[] { tableId };
1080
1081 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
1082 finderArgs, this);
1083
1084 if (count == null) {
1085 Session session = null;
1086
1087 try {
1088 session = openSession();
1089
1090 StringBundler query = new StringBundler(2);
1091
1092 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1093
1094 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1095
1096 String sql = query.toString();
1097
1098 Query q = session.createQuery(sql);
1099
1100 QueryPos qPos = QueryPos.getInstance(q);
1101
1102 qPos.add(tableId);
1103
1104 count = (Long)q.uniqueResult();
1105 }
1106 catch (Exception e) {
1107 throw processException(e);
1108 }
1109 finally {
1110 if (count == null) {
1111 count = Long.valueOf(0);
1112 }
1113
1114 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
1115 finderArgs, count);
1116
1117 closeSession(session);
1118 }
1119 }
1120
1121 return count.intValue();
1122 }
1123
1124
1132 public int countByT_N(long tableId, String name) throws SystemException {
1133 Object[] finderArgs = new Object[] { tableId, name };
1134
1135 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
1136 finderArgs, this);
1137
1138 if (count == null) {
1139 Session session = null;
1140
1141 try {
1142 session = openSession();
1143
1144 StringBundler query = new StringBundler(3);
1145
1146 query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1147
1148 query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1149
1150 if (name == null) {
1151 query.append(_FINDER_COLUMN_T_N_NAME_1);
1152 }
1153 else {
1154 if (name.equals(StringPool.BLANK)) {
1155 query.append(_FINDER_COLUMN_T_N_NAME_3);
1156 }
1157 else {
1158 query.append(_FINDER_COLUMN_T_N_NAME_2);
1159 }
1160 }
1161
1162 String sql = query.toString();
1163
1164 Query q = session.createQuery(sql);
1165
1166 QueryPos qPos = QueryPos.getInstance(q);
1167
1168 qPos.add(tableId);
1169
1170 if (name != null) {
1171 qPos.add(name);
1172 }
1173
1174 count = (Long)q.uniqueResult();
1175 }
1176 catch (Exception e) {
1177 throw processException(e);
1178 }
1179 finally {
1180 if (count == null) {
1181 count = Long.valueOf(0);
1182 }
1183
1184 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
1185 count);
1186
1187 closeSession(session);
1188 }
1189 }
1190
1191 return count.intValue();
1192 }
1193
1194
1200 public int countAll() throws SystemException {
1201 Object[] finderArgs = new Object[0];
1202
1203 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1204 finderArgs, this);
1205
1206 if (count == null) {
1207 Session session = null;
1208
1209 try {
1210 session = openSession();
1211
1212 Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
1213
1214 count = (Long)q.uniqueResult();
1215 }
1216 catch (Exception e) {
1217 throw processException(e);
1218 }
1219 finally {
1220 if (count == null) {
1221 count = Long.valueOf(0);
1222 }
1223
1224 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1225 count);
1226
1227 closeSession(session);
1228 }
1229 }
1230
1231 return count.intValue();
1232 }
1233
1234
1237 public void afterPropertiesSet() {
1238 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1239 com.liferay.portal.util.PropsUtil.get(
1240 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
1241
1242 if (listenerClassNames.length > 0) {
1243 try {
1244 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
1245
1246 for (String listenerClassName : listenerClassNames) {
1247 listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
1248 listenerClassName));
1249 }
1250
1251 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1252 }
1253 catch (Exception e) {
1254 _log.error(e);
1255 }
1256 }
1257 }
1258
1259 public void destroy() {
1260 EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
1261 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1262 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1263 }
1264
1265 @BeanReference(type = ExpandoColumnPersistence.class)
1266 protected ExpandoColumnPersistence expandoColumnPersistence;
1267 @BeanReference(type = ExpandoRowPersistence.class)
1268 protected ExpandoRowPersistence expandoRowPersistence;
1269 @BeanReference(type = ExpandoTablePersistence.class)
1270 protected ExpandoTablePersistence expandoTablePersistence;
1271 @BeanReference(type = ExpandoValuePersistence.class)
1272 protected ExpandoValuePersistence expandoValuePersistence;
1273 @BeanReference(type = ResourcePersistence.class)
1274 protected ResourcePersistence resourcePersistence;
1275 @BeanReference(type = UserPersistence.class)
1276 protected UserPersistence userPersistence;
1277 private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
1278 private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
1279 private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
1280 private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
1281 private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
1282 private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
1283 private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
1284 private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
1285 private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = ?)";
1286 private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
1287 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
1288 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
1289 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
1290 }