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