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