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