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