1
19
20 package com.liferay.portlet.expando.service.persistence;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.annotation.BeanReference;
24 import com.liferay.portal.kernel.cache.CacheRegistry;
25 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
26 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
27 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28 import com.liferay.portal.kernel.dao.orm.FinderPath;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.log.Log;
34 import com.liferay.portal.kernel.log.LogFactoryUtil;
35 import com.liferay.portal.kernel.util.GetterUtil;
36 import com.liferay.portal.kernel.util.OrderByComparator;
37 import com.liferay.portal.kernel.util.StringPool;
38 import com.liferay.portal.kernel.util.StringUtil;
39 import com.liferay.portal.model.ModelListener;
40 import com.liferay.portal.service.persistence.BatchSessionUtil;
41 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42
43 import com.liferay.portlet.expando.NoSuchColumnException;
44 import com.liferay.portlet.expando.model.ExpandoColumn;
45 import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
46 import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
47
48 import java.util.ArrayList;
49 import java.util.Collections;
50 import java.util.List;
51
52
58 public class ExpandoColumnPersistenceImpl extends BasePersistenceImpl
59 implements ExpandoColumnPersistence {
60 public static final String FINDER_CLASS_NAME_ENTITY = ExpandoColumnImpl.class.getName();
61 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
62 ".List";
63 public static final FinderPath FINDER_PATH_FIND_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
64 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
65 FINDER_CLASS_NAME_LIST, "findByTableId",
66 new String[] { Long.class.getName() });
67 public static final FinderPath FINDER_PATH_FIND_BY_OBC_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
68 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
69 FINDER_CLASS_NAME_LIST, "findByTableId",
70 new String[] {
71 Long.class.getName(),
72
73 "java.lang.Integer", "java.lang.Integer",
74 "com.liferay.portal.kernel.util.OrderByComparator"
75 });
76 public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
77 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
78 FINDER_CLASS_NAME_LIST, "countByTableId",
79 new String[] { Long.class.getName() });
80 public static final FinderPath FINDER_PATH_FETCH_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
81 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
82 FINDER_CLASS_NAME_ENTITY, "fetchByT_N",
83 new String[] { Long.class.getName(), String.class.getName() });
84 public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
85 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
86 FINDER_CLASS_NAME_LIST, "countByT_N",
87 new String[] { Long.class.getName(), String.class.getName() });
88 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
89 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
90 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
91 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
92 ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
93 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
94
95 public void cacheResult(ExpandoColumn expandoColumn) {
96 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
97 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
98 expandoColumn);
99
100 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
101 new Object[] {
102 new Long(expandoColumn.getTableId()),
103
104 expandoColumn.getName()
105 }, expandoColumn);
106 }
107
108 public void cacheResult(List<ExpandoColumn> expandoColumns) {
109 for (ExpandoColumn expandoColumn : expandoColumns) {
110 if (EntityCacheUtil.getResult(
111 ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
112 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
113 this) == null) {
114 cacheResult(expandoColumn);
115 }
116 }
117 }
118
119 public void clearCache() {
120 CacheRegistry.clear(ExpandoColumnImpl.class.getName());
121 EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
122 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
123 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
124 }
125
126 public ExpandoColumn create(long columnId) {
127 ExpandoColumn expandoColumn = new ExpandoColumnImpl();
128
129 expandoColumn.setNew(true);
130 expandoColumn.setPrimaryKey(columnId);
131
132 return expandoColumn;
133 }
134
135 public ExpandoColumn remove(long columnId)
136 throws NoSuchColumnException, SystemException {
137 Session session = null;
138
139 try {
140 session = openSession();
141
142 ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
143 new Long(columnId));
144
145 if (expandoColumn == null) {
146 if (_log.isWarnEnabled()) {
147 _log.warn("No ExpandoColumn exists with the primary key " +
148 columnId);
149 }
150
151 throw new NoSuchColumnException(
152 "No ExpandoColumn exists with the primary key " + columnId);
153 }
154
155 return remove(expandoColumn);
156 }
157 catch (NoSuchColumnException nsee) {
158 throw nsee;
159 }
160 catch (Exception e) {
161 throw processException(e);
162 }
163 finally {
164 closeSession(session);
165 }
166 }
167
168 public ExpandoColumn remove(ExpandoColumn expandoColumn)
169 throws SystemException {
170 for (ModelListener<ExpandoColumn> listener : listeners) {
171 listener.onBeforeRemove(expandoColumn);
172 }
173
174 expandoColumn = removeImpl(expandoColumn);
175
176 for (ModelListener<ExpandoColumn> listener : listeners) {
177 listener.onAfterRemove(expandoColumn);
178 }
179
180 return expandoColumn;
181 }
182
183 protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
184 throws SystemException {
185 Session session = null;
186
187 try {
188 session = openSession();
189
190 if (expandoColumn.isCachedModel() || BatchSessionUtil.isEnabled()) {
191 Object staleObject = session.get(ExpandoColumnImpl.class,
192 expandoColumn.getPrimaryKeyObj());
193
194 if (staleObject != null) {
195 session.evict(staleObject);
196 }
197 }
198
199 session.delete(expandoColumn);
200
201 session.flush();
202 }
203 catch (Exception e) {
204 throw processException(e);
205 }
206 finally {
207 closeSession(session);
208 }
209
210 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
211
212 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
213
214 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
215 new Object[] {
216 new Long(expandoColumnModelImpl.getOriginalTableId()),
217
218 expandoColumnModelImpl.getOriginalName()
219 });
220
221 EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
222 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
223
224 return expandoColumn;
225 }
226
227
230 public ExpandoColumn update(ExpandoColumn expandoColumn)
231 throws SystemException {
232 if (_log.isWarnEnabled()) {
233 _log.warn(
234 "Using the deprecated update(ExpandoColumn expandoColumn) method. Use update(ExpandoColumn expandoColumn, boolean merge) instead.");
235 }
236
237 return update(expandoColumn, false);
238 }
239
240
253 public ExpandoColumn update(ExpandoColumn expandoColumn, boolean merge)
254 throws SystemException {
255 boolean isNew = expandoColumn.isNew();
256
257 for (ModelListener<ExpandoColumn> listener : listeners) {
258 if (isNew) {
259 listener.onBeforeCreate(expandoColumn);
260 }
261 else {
262 listener.onBeforeUpdate(expandoColumn);
263 }
264 }
265
266 expandoColumn = updateImpl(expandoColumn, merge);
267
268 for (ModelListener<ExpandoColumn> listener : listeners) {
269 if (isNew) {
270 listener.onAfterCreate(expandoColumn);
271 }
272 else {
273 listener.onAfterUpdate(expandoColumn);
274 }
275 }
276
277 return expandoColumn;
278 }
279
280 public ExpandoColumn updateImpl(
281 com.liferay.portlet.expando.model.ExpandoColumn expandoColumn,
282 boolean merge) throws SystemException {
283 boolean isNew = expandoColumn.isNew();
284
285 ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
286
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 BatchSessionUtil.update(session, expandoColumn, merge);
293
294 expandoColumn.setNew(false);
295 }
296 catch (Exception e) {
297 throw processException(e);
298 }
299 finally {
300 closeSession(session);
301 }
302
303 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
304
305 EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
306 ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
307 expandoColumn);
308
309 if (!isNew &&
310 ((expandoColumn.getTableId() != expandoColumnModelImpl.getOriginalTableId()) ||
311 !expandoColumn.getName()
312 .equals(expandoColumnModelImpl.getOriginalName()))) {
313 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_N,
314 new Object[] {
315 new Long(expandoColumnModelImpl.getOriginalTableId()),
316
317 expandoColumnModelImpl.getOriginalName()
318 });
319 }
320
321 if (isNew ||
322 ((expandoColumn.getTableId() != expandoColumnModelImpl.getOriginalTableId()) ||
323 !expandoColumn.getName()
324 .equals(expandoColumnModelImpl.getOriginalName()))) {
325 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
326 new Object[] {
327 new Long(expandoColumn.getTableId()),
328
329 expandoColumn.getName()
330 }, expandoColumn);
331 }
332
333 return expandoColumn;
334 }
335
336 public ExpandoColumn findByPrimaryKey(long columnId)
337 throws NoSuchColumnException, SystemException {
338 ExpandoColumn expandoColumn = fetchByPrimaryKey(columnId);
339
340 if (expandoColumn == null) {
341 if (_log.isWarnEnabled()) {
342 _log.warn("No ExpandoColumn exists with the primary key " +
343 columnId);
344 }
345
346 throw new NoSuchColumnException(
347 "No ExpandoColumn exists with the primary key " + columnId);
348 }
349
350 return expandoColumn;
351 }
352
353 public ExpandoColumn fetchByPrimaryKey(long columnId)
354 throws SystemException {
355 ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
356 ExpandoColumnImpl.class, columnId, this);
357
358 if (expandoColumn == null) {
359 Session session = null;
360
361 try {
362 session = openSession();
363
364 expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
365 new Long(columnId));
366 }
367 catch (Exception e) {
368 throw processException(e);
369 }
370 finally {
371 if (expandoColumn != null) {
372 cacheResult(expandoColumn);
373 }
374
375 closeSession(session);
376 }
377 }
378
379 return expandoColumn;
380 }
381
382 public List<ExpandoColumn> findByTableId(long tableId)
383 throws SystemException {
384 Object[] finderArgs = new Object[] { new Long(tableId) };
385
386 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TABLEID,
387 finderArgs, this);
388
389 if (list == null) {
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 StringBuilder query = new StringBuilder();
396
397 query.append(
398 "FROM com.liferay.portlet.expando.model.ExpandoColumn WHERE ");
399
400 query.append("tableId = ?");
401
402 query.append(" ");
403
404 Query q = session.createQuery(query.toString());
405
406 QueryPos qPos = QueryPos.getInstance(q);
407
408 qPos.add(tableId);
409
410 list = q.list();
411 }
412 catch (Exception e) {
413 throw processException(e);
414 }
415 finally {
416 if (list == null) {
417 list = new ArrayList<ExpandoColumn>();
418 }
419
420 cacheResult(list);
421
422 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TABLEID,
423 finderArgs, list);
424
425 closeSession(session);
426 }
427 }
428
429 return list;
430 }
431
432 public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
433 throws SystemException {
434 return findByTableId(tableId, start, end, null);
435 }
436
437 public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
438 OrderByComparator obc) throws SystemException {
439 Object[] finderArgs = new Object[] {
440 new Long(tableId),
441
442 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
443 };
444
445 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_TABLEID,
446 finderArgs, this);
447
448 if (list == null) {
449 Session session = null;
450
451 try {
452 session = openSession();
453
454 StringBuilder query = new StringBuilder();
455
456 query.append(
457 "FROM com.liferay.portlet.expando.model.ExpandoColumn WHERE ");
458
459 query.append("tableId = ?");
460
461 query.append(" ");
462
463 if (obc != null) {
464 query.append("ORDER BY ");
465 query.append(obc.getOrderBy());
466 }
467
468 Query q = session.createQuery(query.toString());
469
470 QueryPos qPos = QueryPos.getInstance(q);
471
472 qPos.add(tableId);
473
474 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
475 start, end);
476 }
477 catch (Exception e) {
478 throw processException(e);
479 }
480 finally {
481 if (list == null) {
482 list = new ArrayList<ExpandoColumn>();
483 }
484
485 cacheResult(list);
486
487 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_TABLEID,
488 finderArgs, list);
489
490 closeSession(session);
491 }
492 }
493
494 return list;
495 }
496
497 public ExpandoColumn findByTableId_First(long tableId, OrderByComparator obc)
498 throws NoSuchColumnException, SystemException {
499 List<ExpandoColumn> list = findByTableId(tableId, 0, 1, obc);
500
501 if (list.isEmpty()) {
502 StringBuilder msg = new StringBuilder();
503
504 msg.append("No ExpandoColumn exists with the key {");
505
506 msg.append("tableId=" + tableId);
507
508 msg.append(StringPool.CLOSE_CURLY_BRACE);
509
510 throw new NoSuchColumnException(msg.toString());
511 }
512 else {
513 return list.get(0);
514 }
515 }
516
517 public ExpandoColumn findByTableId_Last(long tableId, OrderByComparator obc)
518 throws NoSuchColumnException, SystemException {
519 int count = countByTableId(tableId);
520
521 List<ExpandoColumn> list = findByTableId(tableId, count - 1, count, obc);
522
523 if (list.isEmpty()) {
524 StringBuilder msg = new StringBuilder();
525
526 msg.append("No ExpandoColumn exists with the key {");
527
528 msg.append("tableId=" + tableId);
529
530 msg.append(StringPool.CLOSE_CURLY_BRACE);
531
532 throw new NoSuchColumnException(msg.toString());
533 }
534 else {
535 return list.get(0);
536 }
537 }
538
539 public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
540 long tableId, OrderByComparator obc)
541 throws NoSuchColumnException, SystemException {
542 ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
543
544 int count = countByTableId(tableId);
545
546 Session session = null;
547
548 try {
549 session = openSession();
550
551 StringBuilder query = new StringBuilder();
552
553 query.append(
554 "FROM com.liferay.portlet.expando.model.ExpandoColumn WHERE ");
555
556 query.append("tableId = ?");
557
558 query.append(" ");
559
560 if (obc != null) {
561 query.append("ORDER BY ");
562 query.append(obc.getOrderBy());
563 }
564
565 Query q = session.createQuery(query.toString());
566
567 QueryPos qPos = QueryPos.getInstance(q);
568
569 qPos.add(tableId);
570
571 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
572 expandoColumn);
573
574 ExpandoColumn[] array = new ExpandoColumnImpl[3];
575
576 array[0] = (ExpandoColumn)objArray[0];
577 array[1] = (ExpandoColumn)objArray[1];
578 array[2] = (ExpandoColumn)objArray[2];
579
580 return array;
581 }
582 catch (Exception e) {
583 throw processException(e);
584 }
585 finally {
586 closeSession(session);
587 }
588 }
589
590 public ExpandoColumn findByT_N(long tableId, String name)
591 throws NoSuchColumnException, SystemException {
592 ExpandoColumn expandoColumn = fetchByT_N(tableId, name);
593
594 if (expandoColumn == null) {
595 StringBuilder msg = new StringBuilder();
596
597 msg.append("No ExpandoColumn exists with the key {");
598
599 msg.append("tableId=" + tableId);
600
601 msg.append(", ");
602 msg.append("name=" + name);
603
604 msg.append(StringPool.CLOSE_CURLY_BRACE);
605
606 if (_log.isWarnEnabled()) {
607 _log.warn(msg.toString());
608 }
609
610 throw new NoSuchColumnException(msg.toString());
611 }
612
613 return expandoColumn;
614 }
615
616 public ExpandoColumn fetchByT_N(long tableId, String name)
617 throws SystemException {
618 return fetchByT_N(tableId, name, true);
619 }
620
621 public ExpandoColumn fetchByT_N(long tableId, String name,
622 boolean retrieveFromCache) throws SystemException {
623 Object[] finderArgs = new Object[] { new Long(tableId), name };
624
625 Object result = null;
626
627 if (retrieveFromCache) {
628 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_N,
629 finderArgs, this);
630 }
631
632 if (result == null) {
633 Session session = null;
634
635 try {
636 session = openSession();
637
638 StringBuilder query = new StringBuilder();
639
640 query.append(
641 "FROM com.liferay.portlet.expando.model.ExpandoColumn WHERE ");
642
643 query.append("tableId = ?");
644
645 query.append(" AND ");
646
647 if (name == null) {
648 query.append("name IS NULL");
649 }
650 else {
651 query.append("name = ?");
652 }
653
654 query.append(" ");
655
656 Query q = session.createQuery(query.toString());
657
658 QueryPos qPos = QueryPos.getInstance(q);
659
660 qPos.add(tableId);
661
662 if (name != null) {
663 qPos.add(name);
664 }
665
666 List<ExpandoColumn> list = q.list();
667
668 result = list;
669
670 ExpandoColumn expandoColumn = null;
671
672 if (list.isEmpty()) {
673 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
674 finderArgs, list);
675 }
676 else {
677 expandoColumn = list.get(0);
678
679 cacheResult(expandoColumn);
680
681 if ((expandoColumn.getTableId() != tableId) ||
682 (expandoColumn.getName() == null) ||
683 !expandoColumn.getName().equals(name)) {
684 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
685 finderArgs, list);
686 }
687 }
688
689 return expandoColumn;
690 }
691 catch (Exception e) {
692 throw processException(e);
693 }
694 finally {
695 if (result == null) {
696 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_N,
697 finderArgs, new ArrayList<ExpandoColumn>());
698 }
699
700 closeSession(session);
701 }
702 }
703 else {
704 if (result instanceof List) {
705 return null;
706 }
707 else {
708 return (ExpandoColumn)result;
709 }
710 }
711 }
712
713 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
714 throws SystemException {
715 Session session = null;
716
717 try {
718 session = openSession();
719
720 dynamicQuery.compile(session);
721
722 return dynamicQuery.list();
723 }
724 catch (Exception e) {
725 throw processException(e);
726 }
727 finally {
728 closeSession(session);
729 }
730 }
731
732 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
733 int start, int end) throws SystemException {
734 Session session = null;
735
736 try {
737 session = openSession();
738
739 dynamicQuery.setLimit(start, end);
740
741 dynamicQuery.compile(session);
742
743 return dynamicQuery.list();
744 }
745 catch (Exception e) {
746 throw processException(e);
747 }
748 finally {
749 closeSession(session);
750 }
751 }
752
753 public List<ExpandoColumn> findAll() throws SystemException {
754 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
755 }
756
757 public List<ExpandoColumn> findAll(int start, int end)
758 throws SystemException {
759 return findAll(start, end, null);
760 }
761
762 public List<ExpandoColumn> findAll(int start, int end, OrderByComparator obc)
763 throws SystemException {
764 Object[] finderArgs = new Object[] {
765 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
766 };
767
768 List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
769 finderArgs, this);
770
771 if (list == null) {
772 Session session = null;
773
774 try {
775 session = openSession();
776
777 StringBuilder query = new StringBuilder();
778
779 query.append(
780 "FROM com.liferay.portlet.expando.model.ExpandoColumn ");
781
782 if (obc != null) {
783 query.append("ORDER BY ");
784 query.append(obc.getOrderBy());
785 }
786
787 Query q = session.createQuery(query.toString());
788
789 if (obc == null) {
790 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
791 start, end, false);
792
793 Collections.sort(list);
794 }
795 else {
796 list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
797 start, end);
798 }
799 }
800 catch (Exception e) {
801 throw processException(e);
802 }
803 finally {
804 if (list == null) {
805 list = new ArrayList<ExpandoColumn>();
806 }
807
808 cacheResult(list);
809
810 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
811
812 closeSession(session);
813 }
814 }
815
816 return list;
817 }
818
819 public void removeByTableId(long tableId) throws SystemException {
820 for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
821 remove(expandoColumn);
822 }
823 }
824
825 public void removeByT_N(long tableId, String name)
826 throws NoSuchColumnException, SystemException {
827 ExpandoColumn expandoColumn = findByT_N(tableId, name);
828
829 remove(expandoColumn);
830 }
831
832 public void removeAll() throws SystemException {
833 for (ExpandoColumn expandoColumn : findAll()) {
834 remove(expandoColumn);
835 }
836 }
837
838 public int countByTableId(long tableId) throws SystemException {
839 Object[] finderArgs = new Object[] { new Long(tableId) };
840
841 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
842 finderArgs, this);
843
844 if (count == null) {
845 Session session = null;
846
847 try {
848 session = openSession();
849
850 StringBuilder query = new StringBuilder();
851
852 query.append("SELECT COUNT(*) ");
853 query.append(
854 "FROM com.liferay.portlet.expando.model.ExpandoColumn WHERE ");
855
856 query.append("tableId = ?");
857
858 query.append(" ");
859
860 Query q = session.createQuery(query.toString());
861
862 QueryPos qPos = QueryPos.getInstance(q);
863
864 qPos.add(tableId);
865
866 count = (Long)q.uniqueResult();
867 }
868 catch (Exception e) {
869 throw processException(e);
870 }
871 finally {
872 if (count == null) {
873 count = Long.valueOf(0);
874 }
875
876 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
877 finderArgs, count);
878
879 closeSession(session);
880 }
881 }
882
883 return count.intValue();
884 }
885
886 public int countByT_N(long tableId, String name) throws SystemException {
887 Object[] finderArgs = new Object[] { new Long(tableId), name };
888
889 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
890 finderArgs, this);
891
892 if (count == null) {
893 Session session = null;
894
895 try {
896 session = openSession();
897
898 StringBuilder query = new StringBuilder();
899
900 query.append("SELECT COUNT(*) ");
901 query.append(
902 "FROM com.liferay.portlet.expando.model.ExpandoColumn WHERE ");
903
904 query.append("tableId = ?");
905
906 query.append(" AND ");
907
908 if (name == null) {
909 query.append("name IS NULL");
910 }
911 else {
912 query.append("name = ?");
913 }
914
915 query.append(" ");
916
917 Query q = session.createQuery(query.toString());
918
919 QueryPos qPos = QueryPos.getInstance(q);
920
921 qPos.add(tableId);
922
923 if (name != null) {
924 qPos.add(name);
925 }
926
927 count = (Long)q.uniqueResult();
928 }
929 catch (Exception e) {
930 throw processException(e);
931 }
932 finally {
933 if (count == null) {
934 count = Long.valueOf(0);
935 }
936
937 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
938 count);
939
940 closeSession(session);
941 }
942 }
943
944 return count.intValue();
945 }
946
947 public int countAll() throws SystemException {
948 Object[] finderArgs = new Object[0];
949
950 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
951 finderArgs, this);
952
953 if (count == null) {
954 Session session = null;
955
956 try {
957 session = openSession();
958
959 Query q = session.createQuery(
960 "SELECT COUNT(*) FROM com.liferay.portlet.expando.model.ExpandoColumn");
961
962 count = (Long)q.uniqueResult();
963 }
964 catch (Exception e) {
965 throw processException(e);
966 }
967 finally {
968 if (count == null) {
969 count = Long.valueOf(0);
970 }
971
972 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
973 count);
974
975 closeSession(session);
976 }
977 }
978
979 return count.intValue();
980 }
981
982 public void afterPropertiesSet() {
983 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
984 com.liferay.portal.util.PropsUtil.get(
985 "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
986
987 if (listenerClassNames.length > 0) {
988 try {
989 List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
990
991 for (String listenerClassName : listenerClassNames) {
992 listenersList.add((ModelListener<ExpandoColumn>)Class.forName(
993 listenerClassName).newInstance());
994 }
995
996 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
997 }
998 catch (Exception e) {
999 _log.error(e);
1000 }
1001 }
1002 }
1003
1004 @BeanReference(name = "com.liferay.portlet.expando.service.persistence.ExpandoColumnPersistence.impl")
1005 protected com.liferay.portlet.expando.service.persistence.ExpandoColumnPersistence expandoColumnPersistence;
1006 @BeanReference(name = "com.liferay.portlet.expando.service.persistence.ExpandoRowPersistence.impl")
1007 protected com.liferay.portlet.expando.service.persistence.ExpandoRowPersistence expandoRowPersistence;
1008 @BeanReference(name = "com.liferay.portlet.expando.service.persistence.ExpandoTablePersistence.impl")
1009 protected com.liferay.portlet.expando.service.persistence.ExpandoTablePersistence expandoTablePersistence;
1010 @BeanReference(name = "com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence.impl")
1011 protected com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence expandoValuePersistence;
1012 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
1013}