001
014
015 package com.liferay.portlet.dynamicdatamapping.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.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.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.dynamicdatamapping.NoSuchContentException;
046 import com.liferay.portlet.dynamicdatamapping.model.DDMContent;
047 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentImpl;
048 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class DDMContentPersistenceImpl extends BasePersistenceImpl<DDMContent>
069 implements DDMContentPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = DDMContentImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
081 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
083 new String[] {
084 String.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
090 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092 new String[] { String.class.getName() },
093 DDMContentModelImpl.UUID_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
095 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097 new String[] { String.class.getName() });
098 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
099 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
100 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
101 new String[] { String.class.getName(), Long.class.getName() },
102 DDMContentModelImpl.UUID_COLUMN_BITMASK |
103 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
105 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
107 new String[] { String.class.getName(), Long.class.getName() });
108 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
109 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
110 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
111 new String[] {
112 Long.class.getName(),
113
114 "java.lang.Integer", "java.lang.Integer",
115 "com.liferay.portal.kernel.util.OrderByComparator"
116 });
117 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
118 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
119 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
121 new String[] { Long.class.getName() },
122 DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
123 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
124 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
126 new String[] { Long.class.getName() });
127 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
128 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
129 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
130 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
131 new String[] {
132 Long.class.getName(),
133
134 "java.lang.Integer", "java.lang.Integer",
135 "com.liferay.portal.kernel.util.OrderByComparator"
136 });
137 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
138 new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
139 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
140 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
141 new String[] { Long.class.getName() },
142 DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
143 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
144 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
145 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
146 new String[] { Long.class.getName() });
147 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
148 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
149 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
150 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
151 DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
152 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
153 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
154 DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
155 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
156
157
162 public void cacheResult(DDMContent ddmContent) {
163 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
164 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
165
166 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
167 new Object[] {
168 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
169 }, ddmContent);
170
171 ddmContent.resetOriginalValues();
172 }
173
174
179 public void cacheResult(List<DDMContent> ddmContents) {
180 for (DDMContent ddmContent : ddmContents) {
181 if (EntityCacheUtil.getResult(
182 DDMContentModelImpl.ENTITY_CACHE_ENABLED,
183 DDMContentImpl.class, ddmContent.getPrimaryKey()) == null) {
184 cacheResult(ddmContent);
185 }
186 else {
187 ddmContent.resetOriginalValues();
188 }
189 }
190 }
191
192
199 @Override
200 public void clearCache() {
201 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
202 CacheRegistryUtil.clear(DDMContentImpl.class.getName());
203 }
204
205 EntityCacheUtil.clearCache(DDMContentImpl.class.getName());
206
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
209 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
210 }
211
212
219 @Override
220 public void clearCache(DDMContent ddmContent) {
221 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
222 DDMContentImpl.class, ddmContent.getPrimaryKey());
223
224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
226
227 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
228 new Object[] {
229 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
230 });
231 }
232
233
239 public DDMContent create(long contentId) {
240 DDMContent ddmContent = new DDMContentImpl();
241
242 ddmContent.setNew(true);
243 ddmContent.setPrimaryKey(contentId);
244
245 String uuid = PortalUUIDUtil.generate();
246
247 ddmContent.setUuid(uuid);
248
249 return ddmContent;
250 }
251
252
260 @Override
261 public DDMContent remove(Serializable primaryKey)
262 throws NoSuchModelException, SystemException {
263 return remove(((Long)primaryKey).longValue());
264 }
265
266
274 public DDMContent remove(long contentId)
275 throws NoSuchContentException, SystemException {
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 DDMContent ddmContent = (DDMContent)session.get(DDMContentImpl.class,
282 Long.valueOf(contentId));
283
284 if (ddmContent == null) {
285 if (_log.isWarnEnabled()) {
286 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
287 }
288
289 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
290 contentId);
291 }
292
293 return ddmContentPersistence.remove(ddmContent);
294 }
295 catch (NoSuchContentException nsee) {
296 throw nsee;
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304 }
305
306
313 @Override
314 public DDMContent remove(DDMContent ddmContent) throws SystemException {
315 return super.remove(ddmContent);
316 }
317
318 @Override
319 protected DDMContent removeImpl(DDMContent ddmContent)
320 throws SystemException {
321 ddmContent = toUnwrappedModel(ddmContent);
322
323 Session session = null;
324
325 try {
326 session = openSession();
327
328 BatchSessionUtil.delete(session, ddmContent);
329 }
330 catch (Exception e) {
331 throw processException(e);
332 }
333 finally {
334 closeSession(session);
335 }
336
337 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
338 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
339
340 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
341
342 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
343 new Object[] {
344 ddmContentModelImpl.getUuid(),
345 Long.valueOf(ddmContentModelImpl.getGroupId())
346 });
347
348 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
349 DDMContentImpl.class, ddmContent.getPrimaryKey());
350
351 return ddmContent;
352 }
353
354 @Override
355 public DDMContent updateImpl(
356 com.liferay.portlet.dynamicdatamapping.model.DDMContent ddmContent,
357 boolean merge) throws SystemException {
358 ddmContent = toUnwrappedModel(ddmContent);
359
360 boolean isNew = ddmContent.isNew();
361
362 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
363
364 if (Validator.isNull(ddmContent.getUuid())) {
365 String uuid = PortalUUIDUtil.generate();
366
367 ddmContent.setUuid(uuid);
368 }
369
370 Session session = null;
371
372 try {
373 session = openSession();
374
375 BatchSessionUtil.update(session, ddmContent, merge);
376
377 ddmContent.setNew(false);
378 }
379 catch (Exception e) {
380 throw processException(e);
381 }
382 finally {
383 closeSession(session);
384 }
385
386 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
387
388 if (isNew || !DDMContentModelImpl.COLUMN_BITMASK_ENABLED) {
389 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
390 }
391
392 else {
393 if ((ddmContentModelImpl.getColumnBitmask() &
394 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
395 Object[] args = new Object[] {
396 ddmContentModelImpl.getOriginalUuid()
397 };
398
399 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
400 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
401 args);
402
403 args = new Object[] { ddmContentModelImpl.getUuid() };
404
405 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
406 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
407 args);
408 }
409
410 if ((ddmContentModelImpl.getColumnBitmask() &
411 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
412 Object[] args = new Object[] {
413 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
414 };
415
416 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
417 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
418 args);
419
420 args = new Object[] {
421 Long.valueOf(ddmContentModelImpl.getGroupId())
422 };
423
424 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
425 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
426 args);
427 }
428
429 if ((ddmContentModelImpl.getColumnBitmask() &
430 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
431 Object[] args = new Object[] {
432 Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
433 };
434
435 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
436 args);
437 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
438 args);
439
440 args = new Object[] {
441 Long.valueOf(ddmContentModelImpl.getCompanyId())
442 };
443
444 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
445 args);
446 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
447 args);
448 }
449 }
450
451 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
452 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
453
454 if (isNew) {
455 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
456 new Object[] {
457 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
458 }, ddmContent);
459 }
460 else {
461 if ((ddmContentModelImpl.getColumnBitmask() &
462 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
463 Object[] args = new Object[] {
464 ddmContentModelImpl.getOriginalUuid(),
465 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
466 };
467
468 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
469 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
470
471 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
472 new Object[] {
473 ddmContent.getUuid(),
474 Long.valueOf(ddmContent.getGroupId())
475 }, ddmContent);
476 }
477 }
478
479 return ddmContent;
480 }
481
482 protected DDMContent toUnwrappedModel(DDMContent ddmContent) {
483 if (ddmContent instanceof DDMContentImpl) {
484 return ddmContent;
485 }
486
487 DDMContentImpl ddmContentImpl = new DDMContentImpl();
488
489 ddmContentImpl.setNew(ddmContent.isNew());
490 ddmContentImpl.setPrimaryKey(ddmContent.getPrimaryKey());
491
492 ddmContentImpl.setUuid(ddmContent.getUuid());
493 ddmContentImpl.setContentId(ddmContent.getContentId());
494 ddmContentImpl.setGroupId(ddmContent.getGroupId());
495 ddmContentImpl.setCompanyId(ddmContent.getCompanyId());
496 ddmContentImpl.setUserId(ddmContent.getUserId());
497 ddmContentImpl.setUserName(ddmContent.getUserName());
498 ddmContentImpl.setCreateDate(ddmContent.getCreateDate());
499 ddmContentImpl.setModifiedDate(ddmContent.getModifiedDate());
500 ddmContentImpl.setName(ddmContent.getName());
501 ddmContentImpl.setDescription(ddmContent.getDescription());
502 ddmContentImpl.setXml(ddmContent.getXml());
503
504 return ddmContentImpl;
505 }
506
507
515 @Override
516 public DDMContent findByPrimaryKey(Serializable primaryKey)
517 throws NoSuchModelException, SystemException {
518 return findByPrimaryKey(((Long)primaryKey).longValue());
519 }
520
521
529 public DDMContent findByPrimaryKey(long contentId)
530 throws NoSuchContentException, SystemException {
531 DDMContent ddmContent = fetchByPrimaryKey(contentId);
532
533 if (ddmContent == null) {
534 if (_log.isWarnEnabled()) {
535 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
536 }
537
538 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
539 contentId);
540 }
541
542 return ddmContent;
543 }
544
545
552 @Override
553 public DDMContent fetchByPrimaryKey(Serializable primaryKey)
554 throws SystemException {
555 return fetchByPrimaryKey(((Long)primaryKey).longValue());
556 }
557
558
565 public DDMContent fetchByPrimaryKey(long contentId)
566 throws SystemException {
567 DDMContent ddmContent = (DDMContent)EntityCacheUtil.getResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
568 DDMContentImpl.class, contentId);
569
570 if (ddmContent == _nullDDMContent) {
571 return null;
572 }
573
574 if (ddmContent == null) {
575 Session session = null;
576
577 boolean hasException = false;
578
579 try {
580 session = openSession();
581
582 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
583 Long.valueOf(contentId));
584 }
585 catch (Exception e) {
586 hasException = true;
587
588 throw processException(e);
589 }
590 finally {
591 if (ddmContent != null) {
592 cacheResult(ddmContent);
593 }
594 else if (!hasException) {
595 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
596 DDMContentImpl.class, contentId, _nullDDMContent);
597 }
598
599 closeSession(session);
600 }
601 }
602
603 return ddmContent;
604 }
605
606
613 public List<DDMContent> findByUuid(String uuid) throws SystemException {
614 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
615 }
616
617
630 public List<DDMContent> findByUuid(String uuid, int start, int end)
631 throws SystemException {
632 return findByUuid(uuid, start, end, null);
633 }
634
635
649 public List<DDMContent> findByUuid(String uuid, int start, int end,
650 OrderByComparator orderByComparator) throws SystemException {
651 FinderPath finderPath = null;
652 Object[] finderArgs = null;
653
654 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
655 (orderByComparator == null)) {
656 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
657 finderArgs = new Object[] { uuid };
658 }
659 else {
660 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
661 finderArgs = new Object[] { uuid, start, end, orderByComparator };
662 }
663
664 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
665 finderArgs, this);
666
667 if (list == null) {
668 StringBundler query = null;
669
670 if (orderByComparator != null) {
671 query = new StringBundler(3 +
672 (orderByComparator.getOrderByFields().length * 3));
673 }
674 else {
675 query = new StringBundler(2);
676 }
677
678 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
679
680 if (uuid == null) {
681 query.append(_FINDER_COLUMN_UUID_UUID_1);
682 }
683 else {
684 if (uuid.equals(StringPool.BLANK)) {
685 query.append(_FINDER_COLUMN_UUID_UUID_3);
686 }
687 else {
688 query.append(_FINDER_COLUMN_UUID_UUID_2);
689 }
690 }
691
692 if (orderByComparator != null) {
693 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
694 orderByComparator);
695 }
696
697 String sql = query.toString();
698
699 Session session = null;
700
701 try {
702 session = openSession();
703
704 Query q = session.createQuery(sql);
705
706 QueryPos qPos = QueryPos.getInstance(q);
707
708 if (uuid != null) {
709 qPos.add(uuid);
710 }
711
712 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
713 end);
714 }
715 catch (Exception e) {
716 throw processException(e);
717 }
718 finally {
719 if (list == null) {
720 FinderCacheUtil.removeResult(finderPath, finderArgs);
721 }
722 else {
723 cacheResult(list);
724
725 FinderCacheUtil.putResult(finderPath, finderArgs, list);
726 }
727
728 closeSession(session);
729 }
730 }
731
732 return list;
733 }
734
735
748 public DDMContent findByUuid_First(String uuid,
749 OrderByComparator orderByComparator)
750 throws NoSuchContentException, SystemException {
751 List<DDMContent> list = findByUuid(uuid, 0, 1, orderByComparator);
752
753 if (list.isEmpty()) {
754 StringBundler msg = new StringBundler(4);
755
756 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
757
758 msg.append("uuid=");
759 msg.append(uuid);
760
761 msg.append(StringPool.CLOSE_CURLY_BRACE);
762
763 throw new NoSuchContentException(msg.toString());
764 }
765 else {
766 return list.get(0);
767 }
768 }
769
770
783 public DDMContent findByUuid_Last(String uuid,
784 OrderByComparator orderByComparator)
785 throws NoSuchContentException, SystemException {
786 int count = countByUuid(uuid);
787
788 List<DDMContent> list = findByUuid(uuid, count - 1, count,
789 orderByComparator);
790
791 if (list.isEmpty()) {
792 StringBundler msg = new StringBundler(4);
793
794 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
795
796 msg.append("uuid=");
797 msg.append(uuid);
798
799 msg.append(StringPool.CLOSE_CURLY_BRACE);
800
801 throw new NoSuchContentException(msg.toString());
802 }
803 else {
804 return list.get(0);
805 }
806 }
807
808
822 public DDMContent[] findByUuid_PrevAndNext(long contentId, String uuid,
823 OrderByComparator orderByComparator)
824 throws NoSuchContentException, SystemException {
825 DDMContent ddmContent = findByPrimaryKey(contentId);
826
827 Session session = null;
828
829 try {
830 session = openSession();
831
832 DDMContent[] array = new DDMContentImpl[3];
833
834 array[0] = getByUuid_PrevAndNext(session, ddmContent, uuid,
835 orderByComparator, true);
836
837 array[1] = ddmContent;
838
839 array[2] = getByUuid_PrevAndNext(session, ddmContent, uuid,
840 orderByComparator, false);
841
842 return array;
843 }
844 catch (Exception e) {
845 throw processException(e);
846 }
847 finally {
848 closeSession(session);
849 }
850 }
851
852 protected DDMContent getByUuid_PrevAndNext(Session session,
853 DDMContent ddmContent, String uuid,
854 OrderByComparator orderByComparator, boolean previous) {
855 StringBundler query = null;
856
857 if (orderByComparator != null) {
858 query = new StringBundler(6 +
859 (orderByComparator.getOrderByFields().length * 6));
860 }
861 else {
862 query = new StringBundler(3);
863 }
864
865 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
866
867 if (uuid == null) {
868 query.append(_FINDER_COLUMN_UUID_UUID_1);
869 }
870 else {
871 if (uuid.equals(StringPool.BLANK)) {
872 query.append(_FINDER_COLUMN_UUID_UUID_3);
873 }
874 else {
875 query.append(_FINDER_COLUMN_UUID_UUID_2);
876 }
877 }
878
879 if (orderByComparator != null) {
880 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
881
882 if (orderByConditionFields.length > 0) {
883 query.append(WHERE_AND);
884 }
885
886 for (int i = 0; i < orderByConditionFields.length; i++) {
887 query.append(_ORDER_BY_ENTITY_ALIAS);
888 query.append(orderByConditionFields[i]);
889
890 if ((i + 1) < orderByConditionFields.length) {
891 if (orderByComparator.isAscending() ^ previous) {
892 query.append(WHERE_GREATER_THAN_HAS_NEXT);
893 }
894 else {
895 query.append(WHERE_LESSER_THAN_HAS_NEXT);
896 }
897 }
898 else {
899 if (orderByComparator.isAscending() ^ previous) {
900 query.append(WHERE_GREATER_THAN);
901 }
902 else {
903 query.append(WHERE_LESSER_THAN);
904 }
905 }
906 }
907
908 query.append(ORDER_BY_CLAUSE);
909
910 String[] orderByFields = orderByComparator.getOrderByFields();
911
912 for (int i = 0; i < orderByFields.length; i++) {
913 query.append(_ORDER_BY_ENTITY_ALIAS);
914 query.append(orderByFields[i]);
915
916 if ((i + 1) < orderByFields.length) {
917 if (orderByComparator.isAscending() ^ previous) {
918 query.append(ORDER_BY_ASC_HAS_NEXT);
919 }
920 else {
921 query.append(ORDER_BY_DESC_HAS_NEXT);
922 }
923 }
924 else {
925 if (orderByComparator.isAscending() ^ previous) {
926 query.append(ORDER_BY_ASC);
927 }
928 else {
929 query.append(ORDER_BY_DESC);
930 }
931 }
932 }
933 }
934
935 String sql = query.toString();
936
937 Query q = session.createQuery(sql);
938
939 q.setFirstResult(0);
940 q.setMaxResults(2);
941
942 QueryPos qPos = QueryPos.getInstance(q);
943
944 if (uuid != null) {
945 qPos.add(uuid);
946 }
947
948 if (orderByComparator != null) {
949 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
950
951 for (Object value : values) {
952 qPos.add(value);
953 }
954 }
955
956 List<DDMContent> list = q.list();
957
958 if (list.size() == 2) {
959 return list.get(1);
960 }
961 else {
962 return null;
963 }
964 }
965
966
975 public DDMContent findByUUID_G(String uuid, long groupId)
976 throws NoSuchContentException, SystemException {
977 DDMContent ddmContent = fetchByUUID_G(uuid, groupId);
978
979 if (ddmContent == null) {
980 StringBundler msg = new StringBundler(6);
981
982 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
983
984 msg.append("uuid=");
985 msg.append(uuid);
986
987 msg.append(", groupId=");
988 msg.append(groupId);
989
990 msg.append(StringPool.CLOSE_CURLY_BRACE);
991
992 if (_log.isWarnEnabled()) {
993 _log.warn(msg.toString());
994 }
995
996 throw new NoSuchContentException(msg.toString());
997 }
998
999 return ddmContent;
1000 }
1001
1002
1010 public DDMContent fetchByUUID_G(String uuid, long groupId)
1011 throws SystemException {
1012 return fetchByUUID_G(uuid, groupId, true);
1013 }
1014
1015
1024 public DDMContent fetchByUUID_G(String uuid, long groupId,
1025 boolean retrieveFromCache) throws SystemException {
1026 Object[] finderArgs = new Object[] { uuid, groupId };
1027
1028 Object result = null;
1029
1030 if (retrieveFromCache) {
1031 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1032 finderArgs, this);
1033 }
1034
1035 if (result == null) {
1036 StringBundler query = new StringBundler(3);
1037
1038 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1039
1040 if (uuid == null) {
1041 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1042 }
1043 else {
1044 if (uuid.equals(StringPool.BLANK)) {
1045 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1046 }
1047 else {
1048 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1049 }
1050 }
1051
1052 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1053
1054 String sql = query.toString();
1055
1056 Session session = null;
1057
1058 try {
1059 session = openSession();
1060
1061 Query q = session.createQuery(sql);
1062
1063 QueryPos qPos = QueryPos.getInstance(q);
1064
1065 if (uuid != null) {
1066 qPos.add(uuid);
1067 }
1068
1069 qPos.add(groupId);
1070
1071 List<DDMContent> list = q.list();
1072
1073 result = list;
1074
1075 DDMContent ddmContent = null;
1076
1077 if (list.isEmpty()) {
1078 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1079 finderArgs, list);
1080 }
1081 else {
1082 ddmContent = list.get(0);
1083
1084 cacheResult(ddmContent);
1085
1086 if ((ddmContent.getUuid() == null) ||
1087 !ddmContent.getUuid().equals(uuid) ||
1088 (ddmContent.getGroupId() != groupId)) {
1089 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1090 finderArgs, ddmContent);
1091 }
1092 }
1093
1094 return ddmContent;
1095 }
1096 catch (Exception e) {
1097 throw processException(e);
1098 }
1099 finally {
1100 if (result == null) {
1101 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1102 finderArgs);
1103 }
1104
1105 closeSession(session);
1106 }
1107 }
1108 else {
1109 if (result instanceof List<?>) {
1110 return null;
1111 }
1112 else {
1113 return (DDMContent)result;
1114 }
1115 }
1116 }
1117
1118
1125 public List<DDMContent> findByGroupId(long groupId)
1126 throws SystemException {
1127 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1128 }
1129
1130
1143 public List<DDMContent> findByGroupId(long groupId, int start, int end)
1144 throws SystemException {
1145 return findByGroupId(groupId, start, end, null);
1146 }
1147
1148
1162 public List<DDMContent> findByGroupId(long groupId, int start, int end,
1163 OrderByComparator orderByComparator) throws SystemException {
1164 FinderPath finderPath = null;
1165 Object[] finderArgs = null;
1166
1167 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1168 (orderByComparator == null)) {
1169 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1170 finderArgs = new Object[] { groupId };
1171 }
1172 else {
1173 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1174 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1175 }
1176
1177 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1178 finderArgs, this);
1179
1180 if (list == null) {
1181 StringBundler query = null;
1182
1183 if (orderByComparator != null) {
1184 query = new StringBundler(3 +
1185 (orderByComparator.getOrderByFields().length * 3));
1186 }
1187 else {
1188 query = new StringBundler(2);
1189 }
1190
1191 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1192
1193 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1194
1195 if (orderByComparator != null) {
1196 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1197 orderByComparator);
1198 }
1199
1200 String sql = query.toString();
1201
1202 Session session = null;
1203
1204 try {
1205 session = openSession();
1206
1207 Query q = session.createQuery(sql);
1208
1209 QueryPos qPos = QueryPos.getInstance(q);
1210
1211 qPos.add(groupId);
1212
1213 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1214 end);
1215 }
1216 catch (Exception e) {
1217 throw processException(e);
1218 }
1219 finally {
1220 if (list == null) {
1221 FinderCacheUtil.removeResult(finderPath, finderArgs);
1222 }
1223 else {
1224 cacheResult(list);
1225
1226 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1227 }
1228
1229 closeSession(session);
1230 }
1231 }
1232
1233 return list;
1234 }
1235
1236
1249 public DDMContent findByGroupId_First(long groupId,
1250 OrderByComparator orderByComparator)
1251 throws NoSuchContentException, SystemException {
1252 List<DDMContent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1253
1254 if (list.isEmpty()) {
1255 StringBundler msg = new StringBundler(4);
1256
1257 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1258
1259 msg.append("groupId=");
1260 msg.append(groupId);
1261
1262 msg.append(StringPool.CLOSE_CURLY_BRACE);
1263
1264 throw new NoSuchContentException(msg.toString());
1265 }
1266 else {
1267 return list.get(0);
1268 }
1269 }
1270
1271
1284 public DDMContent findByGroupId_Last(long groupId,
1285 OrderByComparator orderByComparator)
1286 throws NoSuchContentException, SystemException {
1287 int count = countByGroupId(groupId);
1288
1289 List<DDMContent> list = findByGroupId(groupId, count - 1, count,
1290 orderByComparator);
1291
1292 if (list.isEmpty()) {
1293 StringBundler msg = new StringBundler(4);
1294
1295 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1296
1297 msg.append("groupId=");
1298 msg.append(groupId);
1299
1300 msg.append(StringPool.CLOSE_CURLY_BRACE);
1301
1302 throw new NoSuchContentException(msg.toString());
1303 }
1304 else {
1305 return list.get(0);
1306 }
1307 }
1308
1309
1323 public DDMContent[] findByGroupId_PrevAndNext(long contentId, long groupId,
1324 OrderByComparator orderByComparator)
1325 throws NoSuchContentException, SystemException {
1326 DDMContent ddmContent = findByPrimaryKey(contentId);
1327
1328 Session session = null;
1329
1330 try {
1331 session = openSession();
1332
1333 DDMContent[] array = new DDMContentImpl[3];
1334
1335 array[0] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1336 orderByComparator, true);
1337
1338 array[1] = ddmContent;
1339
1340 array[2] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1341 orderByComparator, false);
1342
1343 return array;
1344 }
1345 catch (Exception e) {
1346 throw processException(e);
1347 }
1348 finally {
1349 closeSession(session);
1350 }
1351 }
1352
1353 protected DDMContent getByGroupId_PrevAndNext(Session session,
1354 DDMContent ddmContent, long groupId,
1355 OrderByComparator orderByComparator, boolean previous) {
1356 StringBundler query = null;
1357
1358 if (orderByComparator != null) {
1359 query = new StringBundler(6 +
1360 (orderByComparator.getOrderByFields().length * 6));
1361 }
1362 else {
1363 query = new StringBundler(3);
1364 }
1365
1366 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1367
1368 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1369
1370 if (orderByComparator != null) {
1371 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1372
1373 if (orderByConditionFields.length > 0) {
1374 query.append(WHERE_AND);
1375 }
1376
1377 for (int i = 0; i < orderByConditionFields.length; i++) {
1378 query.append(_ORDER_BY_ENTITY_ALIAS);
1379 query.append(orderByConditionFields[i]);
1380
1381 if ((i + 1) < orderByConditionFields.length) {
1382 if (orderByComparator.isAscending() ^ previous) {
1383 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1384 }
1385 else {
1386 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1387 }
1388 }
1389 else {
1390 if (orderByComparator.isAscending() ^ previous) {
1391 query.append(WHERE_GREATER_THAN);
1392 }
1393 else {
1394 query.append(WHERE_LESSER_THAN);
1395 }
1396 }
1397 }
1398
1399 query.append(ORDER_BY_CLAUSE);
1400
1401 String[] orderByFields = orderByComparator.getOrderByFields();
1402
1403 for (int i = 0; i < orderByFields.length; i++) {
1404 query.append(_ORDER_BY_ENTITY_ALIAS);
1405 query.append(orderByFields[i]);
1406
1407 if ((i + 1) < orderByFields.length) {
1408 if (orderByComparator.isAscending() ^ previous) {
1409 query.append(ORDER_BY_ASC_HAS_NEXT);
1410 }
1411 else {
1412 query.append(ORDER_BY_DESC_HAS_NEXT);
1413 }
1414 }
1415 else {
1416 if (orderByComparator.isAscending() ^ previous) {
1417 query.append(ORDER_BY_ASC);
1418 }
1419 else {
1420 query.append(ORDER_BY_DESC);
1421 }
1422 }
1423 }
1424 }
1425
1426 String sql = query.toString();
1427
1428 Query q = session.createQuery(sql);
1429
1430 q.setFirstResult(0);
1431 q.setMaxResults(2);
1432
1433 QueryPos qPos = QueryPos.getInstance(q);
1434
1435 qPos.add(groupId);
1436
1437 if (orderByComparator != null) {
1438 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1439
1440 for (Object value : values) {
1441 qPos.add(value);
1442 }
1443 }
1444
1445 List<DDMContent> list = q.list();
1446
1447 if (list.size() == 2) {
1448 return list.get(1);
1449 }
1450 else {
1451 return null;
1452 }
1453 }
1454
1455
1462 public List<DDMContent> findByCompanyId(long companyId)
1463 throws SystemException {
1464 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1465 null);
1466 }
1467
1468
1481 public List<DDMContent> findByCompanyId(long companyId, int start, int end)
1482 throws SystemException {
1483 return findByCompanyId(companyId, start, end, null);
1484 }
1485
1486
1500 public List<DDMContent> findByCompanyId(long companyId, int start, int end,
1501 OrderByComparator orderByComparator) throws SystemException {
1502 FinderPath finderPath = null;
1503 Object[] finderArgs = null;
1504
1505 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1506 (orderByComparator == null)) {
1507 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1508 finderArgs = new Object[] { companyId };
1509 }
1510 else {
1511 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1512 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1513 }
1514
1515 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1516 finderArgs, this);
1517
1518 if (list == null) {
1519 StringBundler query = null;
1520
1521 if (orderByComparator != null) {
1522 query = new StringBundler(3 +
1523 (orderByComparator.getOrderByFields().length * 3));
1524 }
1525 else {
1526 query = new StringBundler(2);
1527 }
1528
1529 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1530
1531 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1532
1533 if (orderByComparator != null) {
1534 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1535 orderByComparator);
1536 }
1537
1538 String sql = query.toString();
1539
1540 Session session = null;
1541
1542 try {
1543 session = openSession();
1544
1545 Query q = session.createQuery(sql);
1546
1547 QueryPos qPos = QueryPos.getInstance(q);
1548
1549 qPos.add(companyId);
1550
1551 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1552 end);
1553 }
1554 catch (Exception e) {
1555 throw processException(e);
1556 }
1557 finally {
1558 if (list == null) {
1559 FinderCacheUtil.removeResult(finderPath, finderArgs);
1560 }
1561 else {
1562 cacheResult(list);
1563
1564 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1565 }
1566
1567 closeSession(session);
1568 }
1569 }
1570
1571 return list;
1572 }
1573
1574
1587 public DDMContent findByCompanyId_First(long companyId,
1588 OrderByComparator orderByComparator)
1589 throws NoSuchContentException, SystemException {
1590 List<DDMContent> list = findByCompanyId(companyId, 0, 1,
1591 orderByComparator);
1592
1593 if (list.isEmpty()) {
1594 StringBundler msg = new StringBundler(4);
1595
1596 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1597
1598 msg.append("companyId=");
1599 msg.append(companyId);
1600
1601 msg.append(StringPool.CLOSE_CURLY_BRACE);
1602
1603 throw new NoSuchContentException(msg.toString());
1604 }
1605 else {
1606 return list.get(0);
1607 }
1608 }
1609
1610
1623 public DDMContent findByCompanyId_Last(long companyId,
1624 OrderByComparator orderByComparator)
1625 throws NoSuchContentException, SystemException {
1626 int count = countByCompanyId(companyId);
1627
1628 List<DDMContent> list = findByCompanyId(companyId, count - 1, count,
1629 orderByComparator);
1630
1631 if (list.isEmpty()) {
1632 StringBundler msg = new StringBundler(4);
1633
1634 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1635
1636 msg.append("companyId=");
1637 msg.append(companyId);
1638
1639 msg.append(StringPool.CLOSE_CURLY_BRACE);
1640
1641 throw new NoSuchContentException(msg.toString());
1642 }
1643 else {
1644 return list.get(0);
1645 }
1646 }
1647
1648
1662 public DDMContent[] findByCompanyId_PrevAndNext(long contentId,
1663 long companyId, OrderByComparator orderByComparator)
1664 throws NoSuchContentException, SystemException {
1665 DDMContent ddmContent = findByPrimaryKey(contentId);
1666
1667 Session session = null;
1668
1669 try {
1670 session = openSession();
1671
1672 DDMContent[] array = new DDMContentImpl[3];
1673
1674 array[0] = getByCompanyId_PrevAndNext(session, ddmContent,
1675 companyId, orderByComparator, true);
1676
1677 array[1] = ddmContent;
1678
1679 array[2] = getByCompanyId_PrevAndNext(session, ddmContent,
1680 companyId, orderByComparator, false);
1681
1682 return array;
1683 }
1684 catch (Exception e) {
1685 throw processException(e);
1686 }
1687 finally {
1688 closeSession(session);
1689 }
1690 }
1691
1692 protected DDMContent getByCompanyId_PrevAndNext(Session session,
1693 DDMContent ddmContent, long companyId,
1694 OrderByComparator orderByComparator, boolean previous) {
1695 StringBundler query = null;
1696
1697 if (orderByComparator != null) {
1698 query = new StringBundler(6 +
1699 (orderByComparator.getOrderByFields().length * 6));
1700 }
1701 else {
1702 query = new StringBundler(3);
1703 }
1704
1705 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1706
1707 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1708
1709 if (orderByComparator != null) {
1710 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1711
1712 if (orderByConditionFields.length > 0) {
1713 query.append(WHERE_AND);
1714 }
1715
1716 for (int i = 0; i < orderByConditionFields.length; i++) {
1717 query.append(_ORDER_BY_ENTITY_ALIAS);
1718 query.append(orderByConditionFields[i]);
1719
1720 if ((i + 1) < orderByConditionFields.length) {
1721 if (orderByComparator.isAscending() ^ previous) {
1722 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1723 }
1724 else {
1725 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1726 }
1727 }
1728 else {
1729 if (orderByComparator.isAscending() ^ previous) {
1730 query.append(WHERE_GREATER_THAN);
1731 }
1732 else {
1733 query.append(WHERE_LESSER_THAN);
1734 }
1735 }
1736 }
1737
1738 query.append(ORDER_BY_CLAUSE);
1739
1740 String[] orderByFields = orderByComparator.getOrderByFields();
1741
1742 for (int i = 0; i < orderByFields.length; i++) {
1743 query.append(_ORDER_BY_ENTITY_ALIAS);
1744 query.append(orderByFields[i]);
1745
1746 if ((i + 1) < orderByFields.length) {
1747 if (orderByComparator.isAscending() ^ previous) {
1748 query.append(ORDER_BY_ASC_HAS_NEXT);
1749 }
1750 else {
1751 query.append(ORDER_BY_DESC_HAS_NEXT);
1752 }
1753 }
1754 else {
1755 if (orderByComparator.isAscending() ^ previous) {
1756 query.append(ORDER_BY_ASC);
1757 }
1758 else {
1759 query.append(ORDER_BY_DESC);
1760 }
1761 }
1762 }
1763 }
1764
1765 String sql = query.toString();
1766
1767 Query q = session.createQuery(sql);
1768
1769 q.setFirstResult(0);
1770 q.setMaxResults(2);
1771
1772 QueryPos qPos = QueryPos.getInstance(q);
1773
1774 qPos.add(companyId);
1775
1776 if (orderByComparator != null) {
1777 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1778
1779 for (Object value : values) {
1780 qPos.add(value);
1781 }
1782 }
1783
1784 List<DDMContent> list = q.list();
1785
1786 if (list.size() == 2) {
1787 return list.get(1);
1788 }
1789 else {
1790 return null;
1791 }
1792 }
1793
1794
1800 public List<DDMContent> findAll() throws SystemException {
1801 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1802 }
1803
1804
1816 public List<DDMContent> findAll(int start, int end)
1817 throws SystemException {
1818 return findAll(start, end, null);
1819 }
1820
1821
1834 public List<DDMContent> findAll(int start, int end,
1835 OrderByComparator orderByComparator) throws SystemException {
1836 FinderPath finderPath = null;
1837 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1838
1839 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1840 (orderByComparator == null)) {
1841 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1842 finderArgs = FINDER_ARGS_EMPTY;
1843 }
1844 else {
1845 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1846 finderArgs = new Object[] { start, end, orderByComparator };
1847 }
1848
1849 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1850 finderArgs, this);
1851
1852 if (list == null) {
1853 StringBundler query = null;
1854 String sql = null;
1855
1856 if (orderByComparator != null) {
1857 query = new StringBundler(2 +
1858 (orderByComparator.getOrderByFields().length * 3));
1859
1860 query.append(_SQL_SELECT_DDMCONTENT);
1861
1862 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1863 orderByComparator);
1864
1865 sql = query.toString();
1866 }
1867 else {
1868 sql = _SQL_SELECT_DDMCONTENT;
1869 }
1870
1871 Session session = null;
1872
1873 try {
1874 session = openSession();
1875
1876 Query q = session.createQuery(sql);
1877
1878 if (orderByComparator == null) {
1879 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1880 start, end, false);
1881
1882 Collections.sort(list);
1883 }
1884 else {
1885 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1886 start, end);
1887 }
1888 }
1889 catch (Exception e) {
1890 throw processException(e);
1891 }
1892 finally {
1893 if (list == null) {
1894 FinderCacheUtil.removeResult(finderPath, finderArgs);
1895 }
1896 else {
1897 cacheResult(list);
1898
1899 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1900 }
1901
1902 closeSession(session);
1903 }
1904 }
1905
1906 return list;
1907 }
1908
1909
1915 public void removeByUuid(String uuid) throws SystemException {
1916 for (DDMContent ddmContent : findByUuid(uuid)) {
1917 ddmContentPersistence.remove(ddmContent);
1918 }
1919 }
1920
1921
1928 public void removeByUUID_G(String uuid, long groupId)
1929 throws NoSuchContentException, SystemException {
1930 DDMContent ddmContent = findByUUID_G(uuid, groupId);
1931
1932 ddmContentPersistence.remove(ddmContent);
1933 }
1934
1935
1941 public void removeByGroupId(long groupId) throws SystemException {
1942 for (DDMContent ddmContent : findByGroupId(groupId)) {
1943 ddmContentPersistence.remove(ddmContent);
1944 }
1945 }
1946
1947
1953 public void removeByCompanyId(long companyId) throws SystemException {
1954 for (DDMContent ddmContent : findByCompanyId(companyId)) {
1955 ddmContentPersistence.remove(ddmContent);
1956 }
1957 }
1958
1959
1964 public void removeAll() throws SystemException {
1965 for (DDMContent ddmContent : findAll()) {
1966 ddmContentPersistence.remove(ddmContent);
1967 }
1968 }
1969
1970
1977 public int countByUuid(String uuid) throws SystemException {
1978 Object[] finderArgs = new Object[] { uuid };
1979
1980 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1981 finderArgs, this);
1982
1983 if (count == null) {
1984 StringBundler query = new StringBundler(2);
1985
1986 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
1987
1988 if (uuid == null) {
1989 query.append(_FINDER_COLUMN_UUID_UUID_1);
1990 }
1991 else {
1992 if (uuid.equals(StringPool.BLANK)) {
1993 query.append(_FINDER_COLUMN_UUID_UUID_3);
1994 }
1995 else {
1996 query.append(_FINDER_COLUMN_UUID_UUID_2);
1997 }
1998 }
1999
2000 String sql = query.toString();
2001
2002 Session session = null;
2003
2004 try {
2005 session = openSession();
2006
2007 Query q = session.createQuery(sql);
2008
2009 QueryPos qPos = QueryPos.getInstance(q);
2010
2011 if (uuid != null) {
2012 qPos.add(uuid);
2013 }
2014
2015 count = (Long)q.uniqueResult();
2016 }
2017 catch (Exception e) {
2018 throw processException(e);
2019 }
2020 finally {
2021 if (count == null) {
2022 count = Long.valueOf(0);
2023 }
2024
2025 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2026 finderArgs, count);
2027
2028 closeSession(session);
2029 }
2030 }
2031
2032 return count.intValue();
2033 }
2034
2035
2043 public int countByUUID_G(String uuid, long groupId)
2044 throws SystemException {
2045 Object[] finderArgs = new Object[] { uuid, groupId };
2046
2047 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2048 finderArgs, this);
2049
2050 if (count == null) {
2051 StringBundler query = new StringBundler(3);
2052
2053 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2054
2055 if (uuid == null) {
2056 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2057 }
2058 else {
2059 if (uuid.equals(StringPool.BLANK)) {
2060 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2061 }
2062 else {
2063 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2064 }
2065 }
2066
2067 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2068
2069 String sql = query.toString();
2070
2071 Session session = null;
2072
2073 try {
2074 session = openSession();
2075
2076 Query q = session.createQuery(sql);
2077
2078 QueryPos qPos = QueryPos.getInstance(q);
2079
2080 if (uuid != null) {
2081 qPos.add(uuid);
2082 }
2083
2084 qPos.add(groupId);
2085
2086 count = (Long)q.uniqueResult();
2087 }
2088 catch (Exception e) {
2089 throw processException(e);
2090 }
2091 finally {
2092 if (count == null) {
2093 count = Long.valueOf(0);
2094 }
2095
2096 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2097 finderArgs, count);
2098
2099 closeSession(session);
2100 }
2101 }
2102
2103 return count.intValue();
2104 }
2105
2106
2113 public int countByGroupId(long groupId) throws SystemException {
2114 Object[] finderArgs = new Object[] { groupId };
2115
2116 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2117 finderArgs, this);
2118
2119 if (count == null) {
2120 StringBundler query = new StringBundler(2);
2121
2122 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2123
2124 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2125
2126 String sql = query.toString();
2127
2128 Session session = null;
2129
2130 try {
2131 session = openSession();
2132
2133 Query q = session.createQuery(sql);
2134
2135 QueryPos qPos = QueryPos.getInstance(q);
2136
2137 qPos.add(groupId);
2138
2139 count = (Long)q.uniqueResult();
2140 }
2141 catch (Exception e) {
2142 throw processException(e);
2143 }
2144 finally {
2145 if (count == null) {
2146 count = Long.valueOf(0);
2147 }
2148
2149 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2150 finderArgs, count);
2151
2152 closeSession(session);
2153 }
2154 }
2155
2156 return count.intValue();
2157 }
2158
2159
2166 public int countByCompanyId(long companyId) throws SystemException {
2167 Object[] finderArgs = new Object[] { companyId };
2168
2169 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2170 finderArgs, this);
2171
2172 if (count == null) {
2173 StringBundler query = new StringBundler(2);
2174
2175 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2176
2177 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2178
2179 String sql = query.toString();
2180
2181 Session session = null;
2182
2183 try {
2184 session = openSession();
2185
2186 Query q = session.createQuery(sql);
2187
2188 QueryPos qPos = QueryPos.getInstance(q);
2189
2190 qPos.add(companyId);
2191
2192 count = (Long)q.uniqueResult();
2193 }
2194 catch (Exception e) {
2195 throw processException(e);
2196 }
2197 finally {
2198 if (count == null) {
2199 count = Long.valueOf(0);
2200 }
2201
2202 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2203 finderArgs, count);
2204
2205 closeSession(session);
2206 }
2207 }
2208
2209 return count.intValue();
2210 }
2211
2212
2218 public int countAll() throws SystemException {
2219 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2220 FINDER_ARGS_EMPTY, this);
2221
2222 if (count == null) {
2223 Session session = null;
2224
2225 try {
2226 session = openSession();
2227
2228 Query q = session.createQuery(_SQL_COUNT_DDMCONTENT);
2229
2230 count = (Long)q.uniqueResult();
2231 }
2232 catch (Exception e) {
2233 throw processException(e);
2234 }
2235 finally {
2236 if (count == null) {
2237 count = Long.valueOf(0);
2238 }
2239
2240 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2241 FINDER_ARGS_EMPTY, count);
2242
2243 closeSession(session);
2244 }
2245 }
2246
2247 return count.intValue();
2248 }
2249
2250
2253 public void afterPropertiesSet() {
2254 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2255 com.liferay.portal.util.PropsUtil.get(
2256 "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMContent")));
2257
2258 if (listenerClassNames.length > 0) {
2259 try {
2260 List<ModelListener<DDMContent>> listenersList = new ArrayList<ModelListener<DDMContent>>();
2261
2262 for (String listenerClassName : listenerClassNames) {
2263 listenersList.add((ModelListener<DDMContent>)InstanceFactory.newInstance(
2264 listenerClassName));
2265 }
2266
2267 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2268 }
2269 catch (Exception e) {
2270 _log.error(e);
2271 }
2272 }
2273 }
2274
2275 public void destroy() {
2276 EntityCacheUtil.removeCache(DDMContentImpl.class.getName());
2277 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2278 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2279 }
2280
2281 @BeanReference(type = DDMContentPersistence.class)
2282 protected DDMContentPersistence ddmContentPersistence;
2283 @BeanReference(type = DDMStorageLinkPersistence.class)
2284 protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
2285 @BeanReference(type = DDMStructurePersistence.class)
2286 protected DDMStructurePersistence ddmStructurePersistence;
2287 @BeanReference(type = DDMStructureLinkPersistence.class)
2288 protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
2289 @BeanReference(type = DDMTemplatePersistence.class)
2290 protected DDMTemplatePersistence ddmTemplatePersistence;
2291 @BeanReference(type = ResourcePersistence.class)
2292 protected ResourcePersistence resourcePersistence;
2293 @BeanReference(type = UserPersistence.class)
2294 protected UserPersistence userPersistence;
2295 private static final String _SQL_SELECT_DDMCONTENT = "SELECT ddmContent FROM DDMContent ddmContent";
2296 private static final String _SQL_SELECT_DDMCONTENT_WHERE = "SELECT ddmContent FROM DDMContent ddmContent WHERE ";
2297 private static final String _SQL_COUNT_DDMCONTENT = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent";
2298 private static final String _SQL_COUNT_DDMCONTENT_WHERE = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent WHERE ";
2299 private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmContent.uuid IS NULL";
2300 private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmContent.uuid = ?";
2301 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?)";
2302 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmContent.uuid IS NULL AND ";
2303 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmContent.uuid = ? AND ";
2304 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
2305 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmContent.groupId = ?";
2306 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmContent.groupId = ?";
2307 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddmContent.companyId = ?";
2308 private static final String _ORDER_BY_ENTITY_ALIAS = "ddmContent.";
2309 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMContent exists with the primary key ";
2310 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMContent exists with the key {";
2311 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2312 private static Log _log = LogFactoryUtil.getLog(DDMContentPersistenceImpl.class);
2313 private static DDMContent _nullDDMContent = new DDMContentImpl() {
2314 @Override
2315 public Object clone() {
2316 return this;
2317 }
2318
2319 @Override
2320 public CacheModel<DDMContent> toCacheModel() {
2321 return _nullDDMContentCacheModel;
2322 }
2323 };
2324
2325 private static CacheModel<DDMContent> _nullDDMContentCacheModel = new CacheModel<DDMContent>() {
2326 public DDMContent toEntityModel() {
2327 return _nullDDMContent;
2328 }
2329 };
2330 }