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