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_WITH_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_WITHOUT_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 clearUniqueFindersCache(ddmContent);
228 }
229
230 @Override
231 public void clearCache(List<DDMContent> ddmContents) {
232 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
233 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
234
235 for (DDMContent ddmContent : ddmContents) {
236 EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
237 DDMContentImpl.class, ddmContent.getPrimaryKey());
238
239 clearUniqueFindersCache(ddmContent);
240 }
241 }
242
243 protected void cacheUniqueFindersCache(DDMContent ddmContent) {
244 if (ddmContent.isNew()) {
245 Object[] args = new Object[] {
246 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
247 };
248
249 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
250 Long.valueOf(1));
251 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
252 ddmContent);
253 }
254 else {
255 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
256
257 if ((ddmContentModelImpl.getColumnBitmask() &
258 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
259 Object[] args = new Object[] {
260 ddmContent.getUuid(),
261 Long.valueOf(ddmContent.getGroupId())
262 };
263
264 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
265 Long.valueOf(1));
266 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
267 ddmContent);
268 }
269 }
270 }
271
272 protected void clearUniqueFindersCache(DDMContent ddmContent) {
273 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
274
275 Object[] args = new Object[] {
276 ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
277 };
278
279 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
280 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
281
282 if ((ddmContentModelImpl.getColumnBitmask() &
283 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
284 args = new Object[] {
285 ddmContentModelImpl.getOriginalUuid(),
286 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
287 };
288
289 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
290 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
291 }
292 }
293
294
300 public DDMContent create(long contentId) {
301 DDMContent ddmContent = new DDMContentImpl();
302
303 ddmContent.setNew(true);
304 ddmContent.setPrimaryKey(contentId);
305
306 String uuid = PortalUUIDUtil.generate();
307
308 ddmContent.setUuid(uuid);
309
310 return ddmContent;
311 }
312
313
321 public DDMContent remove(long contentId)
322 throws NoSuchContentException, SystemException {
323 return remove(Long.valueOf(contentId));
324 }
325
326
334 @Override
335 public DDMContent remove(Serializable primaryKey)
336 throws NoSuchContentException, SystemException {
337 Session session = null;
338
339 try {
340 session = openSession();
341
342 DDMContent ddmContent = (DDMContent)session.get(DDMContentImpl.class,
343 primaryKey);
344
345 if (ddmContent == null) {
346 if (_log.isWarnEnabled()) {
347 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
348 }
349
350 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
351 primaryKey);
352 }
353
354 return remove(ddmContent);
355 }
356 catch (NoSuchContentException nsee) {
357 throw nsee;
358 }
359 catch (Exception e) {
360 throw processException(e);
361 }
362 finally {
363 closeSession(session);
364 }
365 }
366
367 @Override
368 protected DDMContent removeImpl(DDMContent ddmContent)
369 throws SystemException {
370 ddmContent = toUnwrappedModel(ddmContent);
371
372 Session session = null;
373
374 try {
375 session = openSession();
376
377 BatchSessionUtil.delete(session, ddmContent);
378 }
379 catch (Exception e) {
380 throw processException(e);
381 }
382 finally {
383 closeSession(session);
384 }
385
386 clearCache(ddmContent);
387
388 return ddmContent;
389 }
390
391 @Override
392 public DDMContent updateImpl(
393 com.liferay.portlet.dynamicdatamapping.model.DDMContent ddmContent,
394 boolean merge) throws SystemException {
395 ddmContent = toUnwrappedModel(ddmContent);
396
397 boolean isNew = ddmContent.isNew();
398
399 DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
400
401 if (Validator.isNull(ddmContent.getUuid())) {
402 String uuid = PortalUUIDUtil.generate();
403
404 ddmContent.setUuid(uuid);
405 }
406
407 Session session = null;
408
409 try {
410 session = openSession();
411
412 BatchSessionUtil.update(session, ddmContent, merge);
413
414 ddmContent.setNew(false);
415 }
416 catch (Exception e) {
417 throw processException(e);
418 }
419 finally {
420 closeSession(session);
421 }
422
423 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
424
425 if (isNew || !DDMContentModelImpl.COLUMN_BITMASK_ENABLED) {
426 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
427 }
428
429 else {
430 if ((ddmContentModelImpl.getColumnBitmask() &
431 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
432 Object[] args = new Object[] {
433 ddmContentModelImpl.getOriginalUuid()
434 };
435
436 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
437 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
438 args);
439
440 args = new Object[] { ddmContentModelImpl.getUuid() };
441
442 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
443 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
444 args);
445 }
446
447 if ((ddmContentModelImpl.getColumnBitmask() &
448 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
449 Object[] args = new Object[] {
450 Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
451 };
452
453 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
454 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
455 args);
456
457 args = new Object[] {
458 Long.valueOf(ddmContentModelImpl.getGroupId())
459 };
460
461 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
462 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
463 args);
464 }
465
466 if ((ddmContentModelImpl.getColumnBitmask() &
467 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
468 Object[] args = new Object[] {
469 Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
470 };
471
472 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
473 args);
474 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
475 args);
476
477 args = new Object[] {
478 Long.valueOf(ddmContentModelImpl.getCompanyId())
479 };
480
481 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
482 args);
483 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
484 args);
485 }
486 }
487
488 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
489 DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
490
491 clearUniqueFindersCache(ddmContent);
492 cacheUniqueFindersCache(ddmContent);
493
494 return ddmContent;
495 }
496
497 protected DDMContent toUnwrappedModel(DDMContent ddmContent) {
498 if (ddmContent instanceof DDMContentImpl) {
499 return ddmContent;
500 }
501
502 DDMContentImpl ddmContentImpl = new DDMContentImpl();
503
504 ddmContentImpl.setNew(ddmContent.isNew());
505 ddmContentImpl.setPrimaryKey(ddmContent.getPrimaryKey());
506
507 ddmContentImpl.setUuid(ddmContent.getUuid());
508 ddmContentImpl.setContentId(ddmContent.getContentId());
509 ddmContentImpl.setGroupId(ddmContent.getGroupId());
510 ddmContentImpl.setCompanyId(ddmContent.getCompanyId());
511 ddmContentImpl.setUserId(ddmContent.getUserId());
512 ddmContentImpl.setUserName(ddmContent.getUserName());
513 ddmContentImpl.setCreateDate(ddmContent.getCreateDate());
514 ddmContentImpl.setModifiedDate(ddmContent.getModifiedDate());
515 ddmContentImpl.setName(ddmContent.getName());
516 ddmContentImpl.setDescription(ddmContent.getDescription());
517 ddmContentImpl.setXml(ddmContent.getXml());
518
519 return ddmContentImpl;
520 }
521
522
530 @Override
531 public DDMContent findByPrimaryKey(Serializable primaryKey)
532 throws NoSuchModelException, SystemException {
533 return findByPrimaryKey(((Long)primaryKey).longValue());
534 }
535
536
544 public DDMContent findByPrimaryKey(long contentId)
545 throws NoSuchContentException, SystemException {
546 DDMContent ddmContent = fetchByPrimaryKey(contentId);
547
548 if (ddmContent == null) {
549 if (_log.isWarnEnabled()) {
550 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
551 }
552
553 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
554 contentId);
555 }
556
557 return ddmContent;
558 }
559
560
567 @Override
568 public DDMContent fetchByPrimaryKey(Serializable primaryKey)
569 throws SystemException {
570 return fetchByPrimaryKey(((Long)primaryKey).longValue());
571 }
572
573
580 public DDMContent fetchByPrimaryKey(long contentId)
581 throws SystemException {
582 DDMContent ddmContent = (DDMContent)EntityCacheUtil.getResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
583 DDMContentImpl.class, contentId);
584
585 if (ddmContent == _nullDDMContent) {
586 return null;
587 }
588
589 if (ddmContent == null) {
590 Session session = null;
591
592 boolean hasException = false;
593
594 try {
595 session = openSession();
596
597 ddmContent = (DDMContent)session.get(DDMContentImpl.class,
598 Long.valueOf(contentId));
599 }
600 catch (Exception e) {
601 hasException = true;
602
603 throw processException(e);
604 }
605 finally {
606 if (ddmContent != null) {
607 cacheResult(ddmContent);
608 }
609 else if (!hasException) {
610 EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
611 DDMContentImpl.class, contentId, _nullDDMContent);
612 }
613
614 closeSession(session);
615 }
616 }
617
618 return ddmContent;
619 }
620
621
628 public List<DDMContent> findByUuid(String uuid) throws SystemException {
629 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
630 }
631
632
645 public List<DDMContent> findByUuid(String uuid, int start, int end)
646 throws SystemException {
647 return findByUuid(uuid, start, end, null);
648 }
649
650
664 public List<DDMContent> findByUuid(String uuid, int start, int end,
665 OrderByComparator orderByComparator) throws SystemException {
666 FinderPath finderPath = null;
667 Object[] finderArgs = null;
668
669 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
670 (orderByComparator == null)) {
671 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
672 finderArgs = new Object[] { uuid };
673 }
674 else {
675 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
676 finderArgs = new Object[] { uuid, start, end, orderByComparator };
677 }
678
679 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
680 finderArgs, this);
681
682 if ((list != null) && !list.isEmpty()) {
683 for (DDMContent ddmContent : list) {
684 if (!Validator.equals(uuid, ddmContent.getUuid())) {
685 list = null;
686
687 break;
688 }
689 }
690 }
691
692 if (list == null) {
693 StringBundler query = null;
694
695 if (orderByComparator != null) {
696 query = new StringBundler(3 +
697 (orderByComparator.getOrderByFields().length * 3));
698 }
699 else {
700 query = new StringBundler(2);
701 }
702
703 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
704
705 if (uuid == null) {
706 query.append(_FINDER_COLUMN_UUID_UUID_1);
707 }
708 else {
709 if (uuid.equals(StringPool.BLANK)) {
710 query.append(_FINDER_COLUMN_UUID_UUID_3);
711 }
712 else {
713 query.append(_FINDER_COLUMN_UUID_UUID_2);
714 }
715 }
716
717 if (orderByComparator != null) {
718 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
719 orderByComparator);
720 }
721
722 String sql = query.toString();
723
724 Session session = null;
725
726 try {
727 session = openSession();
728
729 Query q = session.createQuery(sql);
730
731 QueryPos qPos = QueryPos.getInstance(q);
732
733 if (uuid != null) {
734 qPos.add(uuid);
735 }
736
737 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
738 end);
739 }
740 catch (Exception e) {
741 throw processException(e);
742 }
743 finally {
744 if (list == null) {
745 FinderCacheUtil.removeResult(finderPath, finderArgs);
746 }
747 else {
748 cacheResult(list);
749
750 FinderCacheUtil.putResult(finderPath, finderArgs, list);
751 }
752
753 closeSession(session);
754 }
755 }
756
757 return list;
758 }
759
760
769 public DDMContent findByUuid_First(String uuid,
770 OrderByComparator orderByComparator)
771 throws NoSuchContentException, SystemException {
772 DDMContent ddmContent = fetchByUuid_First(uuid, orderByComparator);
773
774 if (ddmContent != null) {
775 return ddmContent;
776 }
777
778 StringBundler msg = new StringBundler(4);
779
780 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
781
782 msg.append("uuid=");
783 msg.append(uuid);
784
785 msg.append(StringPool.CLOSE_CURLY_BRACE);
786
787 throw new NoSuchContentException(msg.toString());
788 }
789
790
798 public DDMContent fetchByUuid_First(String uuid,
799 OrderByComparator orderByComparator) throws SystemException {
800 List<DDMContent> list = findByUuid(uuid, 0, 1, orderByComparator);
801
802 if (!list.isEmpty()) {
803 return list.get(0);
804 }
805
806 return null;
807 }
808
809
818 public DDMContent findByUuid_Last(String uuid,
819 OrderByComparator orderByComparator)
820 throws NoSuchContentException, SystemException {
821 DDMContent ddmContent = fetchByUuid_Last(uuid, orderByComparator);
822
823 if (ddmContent != null) {
824 return ddmContent;
825 }
826
827 StringBundler msg = new StringBundler(4);
828
829 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
830
831 msg.append("uuid=");
832 msg.append(uuid);
833
834 msg.append(StringPool.CLOSE_CURLY_BRACE);
835
836 throw new NoSuchContentException(msg.toString());
837 }
838
839
847 public DDMContent fetchByUuid_Last(String uuid,
848 OrderByComparator orderByComparator) throws SystemException {
849 int count = countByUuid(uuid);
850
851 List<DDMContent> list = findByUuid(uuid, count - 1, count,
852 orderByComparator);
853
854 if (!list.isEmpty()) {
855 return list.get(0);
856 }
857
858 return null;
859 }
860
861
871 public DDMContent[] findByUuid_PrevAndNext(long contentId, String uuid,
872 OrderByComparator orderByComparator)
873 throws NoSuchContentException, SystemException {
874 DDMContent ddmContent = findByPrimaryKey(contentId);
875
876 Session session = null;
877
878 try {
879 session = openSession();
880
881 DDMContent[] array = new DDMContentImpl[3];
882
883 array[0] = getByUuid_PrevAndNext(session, ddmContent, uuid,
884 orderByComparator, true);
885
886 array[1] = ddmContent;
887
888 array[2] = getByUuid_PrevAndNext(session, ddmContent, uuid,
889 orderByComparator, false);
890
891 return array;
892 }
893 catch (Exception e) {
894 throw processException(e);
895 }
896 finally {
897 closeSession(session);
898 }
899 }
900
901 protected DDMContent getByUuid_PrevAndNext(Session session,
902 DDMContent ddmContent, String uuid,
903 OrderByComparator orderByComparator, boolean previous) {
904 StringBundler query = null;
905
906 if (orderByComparator != null) {
907 query = new StringBundler(6 +
908 (orderByComparator.getOrderByFields().length * 6));
909 }
910 else {
911 query = new StringBundler(3);
912 }
913
914 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
915
916 if (uuid == null) {
917 query.append(_FINDER_COLUMN_UUID_UUID_1);
918 }
919 else {
920 if (uuid.equals(StringPool.BLANK)) {
921 query.append(_FINDER_COLUMN_UUID_UUID_3);
922 }
923 else {
924 query.append(_FINDER_COLUMN_UUID_UUID_2);
925 }
926 }
927
928 if (orderByComparator != null) {
929 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
930
931 if (orderByConditionFields.length > 0) {
932 query.append(WHERE_AND);
933 }
934
935 for (int i = 0; i < orderByConditionFields.length; i++) {
936 query.append(_ORDER_BY_ENTITY_ALIAS);
937 query.append(orderByConditionFields[i]);
938
939 if ((i + 1) < orderByConditionFields.length) {
940 if (orderByComparator.isAscending() ^ previous) {
941 query.append(WHERE_GREATER_THAN_HAS_NEXT);
942 }
943 else {
944 query.append(WHERE_LESSER_THAN_HAS_NEXT);
945 }
946 }
947 else {
948 if (orderByComparator.isAscending() ^ previous) {
949 query.append(WHERE_GREATER_THAN);
950 }
951 else {
952 query.append(WHERE_LESSER_THAN);
953 }
954 }
955 }
956
957 query.append(ORDER_BY_CLAUSE);
958
959 String[] orderByFields = orderByComparator.getOrderByFields();
960
961 for (int i = 0; i < orderByFields.length; i++) {
962 query.append(_ORDER_BY_ENTITY_ALIAS);
963 query.append(orderByFields[i]);
964
965 if ((i + 1) < orderByFields.length) {
966 if (orderByComparator.isAscending() ^ previous) {
967 query.append(ORDER_BY_ASC_HAS_NEXT);
968 }
969 else {
970 query.append(ORDER_BY_DESC_HAS_NEXT);
971 }
972 }
973 else {
974 if (orderByComparator.isAscending() ^ previous) {
975 query.append(ORDER_BY_ASC);
976 }
977 else {
978 query.append(ORDER_BY_DESC);
979 }
980 }
981 }
982 }
983
984 String sql = query.toString();
985
986 Query q = session.createQuery(sql);
987
988 q.setFirstResult(0);
989 q.setMaxResults(2);
990
991 QueryPos qPos = QueryPos.getInstance(q);
992
993 if (uuid != null) {
994 qPos.add(uuid);
995 }
996
997 if (orderByComparator != null) {
998 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
999
1000 for (Object value : values) {
1001 qPos.add(value);
1002 }
1003 }
1004
1005 List<DDMContent> list = q.list();
1006
1007 if (list.size() == 2) {
1008 return list.get(1);
1009 }
1010 else {
1011 return null;
1012 }
1013 }
1014
1015
1024 public DDMContent findByUUID_G(String uuid, long groupId)
1025 throws NoSuchContentException, SystemException {
1026 DDMContent ddmContent = fetchByUUID_G(uuid, groupId);
1027
1028 if (ddmContent == null) {
1029 StringBundler msg = new StringBundler(6);
1030
1031 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1032
1033 msg.append("uuid=");
1034 msg.append(uuid);
1035
1036 msg.append(", groupId=");
1037 msg.append(groupId);
1038
1039 msg.append(StringPool.CLOSE_CURLY_BRACE);
1040
1041 if (_log.isWarnEnabled()) {
1042 _log.warn(msg.toString());
1043 }
1044
1045 throw new NoSuchContentException(msg.toString());
1046 }
1047
1048 return ddmContent;
1049 }
1050
1051
1059 public DDMContent fetchByUUID_G(String uuid, long groupId)
1060 throws SystemException {
1061 return fetchByUUID_G(uuid, groupId, true);
1062 }
1063
1064
1073 public DDMContent fetchByUUID_G(String uuid, long groupId,
1074 boolean retrieveFromCache) throws SystemException {
1075 Object[] finderArgs = new Object[] { uuid, groupId };
1076
1077 Object result = null;
1078
1079 if (retrieveFromCache) {
1080 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1081 finderArgs, this);
1082 }
1083
1084 if (result instanceof DDMContent) {
1085 DDMContent ddmContent = (DDMContent)result;
1086
1087 if (!Validator.equals(uuid, ddmContent.getUuid()) ||
1088 (groupId != ddmContent.getGroupId())) {
1089 result = null;
1090 }
1091 }
1092
1093 if (result == null) {
1094 StringBundler query = new StringBundler(3);
1095
1096 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1097
1098 if (uuid == null) {
1099 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1100 }
1101 else {
1102 if (uuid.equals(StringPool.BLANK)) {
1103 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1104 }
1105 else {
1106 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1107 }
1108 }
1109
1110 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1111
1112 String sql = query.toString();
1113
1114 Session session = null;
1115
1116 try {
1117 session = openSession();
1118
1119 Query q = session.createQuery(sql);
1120
1121 QueryPos qPos = QueryPos.getInstance(q);
1122
1123 if (uuid != null) {
1124 qPos.add(uuid);
1125 }
1126
1127 qPos.add(groupId);
1128
1129 List<DDMContent> list = q.list();
1130
1131 result = list;
1132
1133 DDMContent ddmContent = null;
1134
1135 if (list.isEmpty()) {
1136 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1137 finderArgs, list);
1138 }
1139 else {
1140 ddmContent = list.get(0);
1141
1142 cacheResult(ddmContent);
1143
1144 if ((ddmContent.getUuid() == null) ||
1145 !ddmContent.getUuid().equals(uuid) ||
1146 (ddmContent.getGroupId() != groupId)) {
1147 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1148 finderArgs, ddmContent);
1149 }
1150 }
1151
1152 return ddmContent;
1153 }
1154 catch (Exception e) {
1155 throw processException(e);
1156 }
1157 finally {
1158 if (result == null) {
1159 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1160 finderArgs);
1161 }
1162
1163 closeSession(session);
1164 }
1165 }
1166 else {
1167 if (result instanceof List<?>) {
1168 return null;
1169 }
1170 else {
1171 return (DDMContent)result;
1172 }
1173 }
1174 }
1175
1176
1183 public List<DDMContent> findByGroupId(long groupId)
1184 throws SystemException {
1185 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1186 }
1187
1188
1201 public List<DDMContent> findByGroupId(long groupId, int start, int end)
1202 throws SystemException {
1203 return findByGroupId(groupId, start, end, null);
1204 }
1205
1206
1220 public List<DDMContent> findByGroupId(long groupId, int start, int end,
1221 OrderByComparator orderByComparator) throws SystemException {
1222 FinderPath finderPath = null;
1223 Object[] finderArgs = null;
1224
1225 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1226 (orderByComparator == null)) {
1227 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1228 finderArgs = new Object[] { groupId };
1229 }
1230 else {
1231 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1232 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1233 }
1234
1235 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1236 finderArgs, this);
1237
1238 if ((list != null) && !list.isEmpty()) {
1239 for (DDMContent ddmContent : list) {
1240 if ((groupId != ddmContent.getGroupId())) {
1241 list = null;
1242
1243 break;
1244 }
1245 }
1246 }
1247
1248 if (list == null) {
1249 StringBundler query = null;
1250
1251 if (orderByComparator != null) {
1252 query = new StringBundler(3 +
1253 (orderByComparator.getOrderByFields().length * 3));
1254 }
1255 else {
1256 query = new StringBundler(2);
1257 }
1258
1259 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1260
1261 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1262
1263 if (orderByComparator != null) {
1264 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1265 orderByComparator);
1266 }
1267
1268 String sql = query.toString();
1269
1270 Session session = null;
1271
1272 try {
1273 session = openSession();
1274
1275 Query q = session.createQuery(sql);
1276
1277 QueryPos qPos = QueryPos.getInstance(q);
1278
1279 qPos.add(groupId);
1280
1281 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1282 end);
1283 }
1284 catch (Exception e) {
1285 throw processException(e);
1286 }
1287 finally {
1288 if (list == null) {
1289 FinderCacheUtil.removeResult(finderPath, finderArgs);
1290 }
1291 else {
1292 cacheResult(list);
1293
1294 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1295 }
1296
1297 closeSession(session);
1298 }
1299 }
1300
1301 return list;
1302 }
1303
1304
1313 public DDMContent findByGroupId_First(long groupId,
1314 OrderByComparator orderByComparator)
1315 throws NoSuchContentException, SystemException {
1316 DDMContent ddmContent = fetchByGroupId_First(groupId, orderByComparator);
1317
1318 if (ddmContent != null) {
1319 return ddmContent;
1320 }
1321
1322 StringBundler msg = new StringBundler(4);
1323
1324 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1325
1326 msg.append("groupId=");
1327 msg.append(groupId);
1328
1329 msg.append(StringPool.CLOSE_CURLY_BRACE);
1330
1331 throw new NoSuchContentException(msg.toString());
1332 }
1333
1334
1342 public DDMContent fetchByGroupId_First(long groupId,
1343 OrderByComparator orderByComparator) throws SystemException {
1344 List<DDMContent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1345
1346 if (!list.isEmpty()) {
1347 return list.get(0);
1348 }
1349
1350 return null;
1351 }
1352
1353
1362 public DDMContent findByGroupId_Last(long groupId,
1363 OrderByComparator orderByComparator)
1364 throws NoSuchContentException, SystemException {
1365 DDMContent ddmContent = fetchByGroupId_Last(groupId, orderByComparator);
1366
1367 if (ddmContent != null) {
1368 return ddmContent;
1369 }
1370
1371 StringBundler msg = new StringBundler(4);
1372
1373 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1374
1375 msg.append("groupId=");
1376 msg.append(groupId);
1377
1378 msg.append(StringPool.CLOSE_CURLY_BRACE);
1379
1380 throw new NoSuchContentException(msg.toString());
1381 }
1382
1383
1391 public DDMContent fetchByGroupId_Last(long groupId,
1392 OrderByComparator orderByComparator) throws SystemException {
1393 int count = countByGroupId(groupId);
1394
1395 List<DDMContent> list = findByGroupId(groupId, count - 1, count,
1396 orderByComparator);
1397
1398 if (!list.isEmpty()) {
1399 return list.get(0);
1400 }
1401
1402 return null;
1403 }
1404
1405
1415 public DDMContent[] findByGroupId_PrevAndNext(long contentId, long groupId,
1416 OrderByComparator orderByComparator)
1417 throws NoSuchContentException, SystemException {
1418 DDMContent ddmContent = findByPrimaryKey(contentId);
1419
1420 Session session = null;
1421
1422 try {
1423 session = openSession();
1424
1425 DDMContent[] array = new DDMContentImpl[3];
1426
1427 array[0] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1428 orderByComparator, true);
1429
1430 array[1] = ddmContent;
1431
1432 array[2] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1433 orderByComparator, false);
1434
1435 return array;
1436 }
1437 catch (Exception e) {
1438 throw processException(e);
1439 }
1440 finally {
1441 closeSession(session);
1442 }
1443 }
1444
1445 protected DDMContent getByGroupId_PrevAndNext(Session session,
1446 DDMContent ddmContent, long groupId,
1447 OrderByComparator orderByComparator, boolean previous) {
1448 StringBundler query = null;
1449
1450 if (orderByComparator != null) {
1451 query = new StringBundler(6 +
1452 (orderByComparator.getOrderByFields().length * 6));
1453 }
1454 else {
1455 query = new StringBundler(3);
1456 }
1457
1458 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1459
1460 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1461
1462 if (orderByComparator != null) {
1463 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1464
1465 if (orderByConditionFields.length > 0) {
1466 query.append(WHERE_AND);
1467 }
1468
1469 for (int i = 0; i < orderByConditionFields.length; i++) {
1470 query.append(_ORDER_BY_ENTITY_ALIAS);
1471 query.append(orderByConditionFields[i]);
1472
1473 if ((i + 1) < orderByConditionFields.length) {
1474 if (orderByComparator.isAscending() ^ previous) {
1475 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1476 }
1477 else {
1478 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1479 }
1480 }
1481 else {
1482 if (orderByComparator.isAscending() ^ previous) {
1483 query.append(WHERE_GREATER_THAN);
1484 }
1485 else {
1486 query.append(WHERE_LESSER_THAN);
1487 }
1488 }
1489 }
1490
1491 query.append(ORDER_BY_CLAUSE);
1492
1493 String[] orderByFields = orderByComparator.getOrderByFields();
1494
1495 for (int i = 0; i < orderByFields.length; i++) {
1496 query.append(_ORDER_BY_ENTITY_ALIAS);
1497 query.append(orderByFields[i]);
1498
1499 if ((i + 1) < orderByFields.length) {
1500 if (orderByComparator.isAscending() ^ previous) {
1501 query.append(ORDER_BY_ASC_HAS_NEXT);
1502 }
1503 else {
1504 query.append(ORDER_BY_DESC_HAS_NEXT);
1505 }
1506 }
1507 else {
1508 if (orderByComparator.isAscending() ^ previous) {
1509 query.append(ORDER_BY_ASC);
1510 }
1511 else {
1512 query.append(ORDER_BY_DESC);
1513 }
1514 }
1515 }
1516 }
1517
1518 String sql = query.toString();
1519
1520 Query q = session.createQuery(sql);
1521
1522 q.setFirstResult(0);
1523 q.setMaxResults(2);
1524
1525 QueryPos qPos = QueryPos.getInstance(q);
1526
1527 qPos.add(groupId);
1528
1529 if (orderByComparator != null) {
1530 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1531
1532 for (Object value : values) {
1533 qPos.add(value);
1534 }
1535 }
1536
1537 List<DDMContent> list = q.list();
1538
1539 if (list.size() == 2) {
1540 return list.get(1);
1541 }
1542 else {
1543 return null;
1544 }
1545 }
1546
1547
1554 public List<DDMContent> findByCompanyId(long companyId)
1555 throws SystemException {
1556 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1557 null);
1558 }
1559
1560
1573 public List<DDMContent> findByCompanyId(long companyId, int start, int end)
1574 throws SystemException {
1575 return findByCompanyId(companyId, start, end, null);
1576 }
1577
1578
1592 public List<DDMContent> findByCompanyId(long companyId, int start, int end,
1593 OrderByComparator orderByComparator) throws SystemException {
1594 FinderPath finderPath = null;
1595 Object[] finderArgs = null;
1596
1597 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1598 (orderByComparator == null)) {
1599 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1600 finderArgs = new Object[] { companyId };
1601 }
1602 else {
1603 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1604 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1605 }
1606
1607 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1608 finderArgs, this);
1609
1610 if ((list != null) && !list.isEmpty()) {
1611 for (DDMContent ddmContent : list) {
1612 if ((companyId != ddmContent.getCompanyId())) {
1613 list = null;
1614
1615 break;
1616 }
1617 }
1618 }
1619
1620 if (list == null) {
1621 StringBundler query = null;
1622
1623 if (orderByComparator != null) {
1624 query = new StringBundler(3 +
1625 (orderByComparator.getOrderByFields().length * 3));
1626 }
1627 else {
1628 query = new StringBundler(2);
1629 }
1630
1631 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1632
1633 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1634
1635 if (orderByComparator != null) {
1636 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1637 orderByComparator);
1638 }
1639
1640 String sql = query.toString();
1641
1642 Session session = null;
1643
1644 try {
1645 session = openSession();
1646
1647 Query q = session.createQuery(sql);
1648
1649 QueryPos qPos = QueryPos.getInstance(q);
1650
1651 qPos.add(companyId);
1652
1653 list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1654 end);
1655 }
1656 catch (Exception e) {
1657 throw processException(e);
1658 }
1659 finally {
1660 if (list == null) {
1661 FinderCacheUtil.removeResult(finderPath, finderArgs);
1662 }
1663 else {
1664 cacheResult(list);
1665
1666 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1667 }
1668
1669 closeSession(session);
1670 }
1671 }
1672
1673 return list;
1674 }
1675
1676
1685 public DDMContent findByCompanyId_First(long companyId,
1686 OrderByComparator orderByComparator)
1687 throws NoSuchContentException, SystemException {
1688 DDMContent ddmContent = fetchByCompanyId_First(companyId,
1689 orderByComparator);
1690
1691 if (ddmContent != null) {
1692 return ddmContent;
1693 }
1694
1695 StringBundler msg = new StringBundler(4);
1696
1697 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1698
1699 msg.append("companyId=");
1700 msg.append(companyId);
1701
1702 msg.append(StringPool.CLOSE_CURLY_BRACE);
1703
1704 throw new NoSuchContentException(msg.toString());
1705 }
1706
1707
1715 public DDMContent fetchByCompanyId_First(long companyId,
1716 OrderByComparator orderByComparator) throws SystemException {
1717 List<DDMContent> list = findByCompanyId(companyId, 0, 1,
1718 orderByComparator);
1719
1720 if (!list.isEmpty()) {
1721 return list.get(0);
1722 }
1723
1724 return null;
1725 }
1726
1727
1736 public DDMContent findByCompanyId_Last(long companyId,
1737 OrderByComparator orderByComparator)
1738 throws NoSuchContentException, SystemException {
1739 DDMContent ddmContent = fetchByCompanyId_Last(companyId,
1740 orderByComparator);
1741
1742 if (ddmContent != null) {
1743 return ddmContent;
1744 }
1745
1746 StringBundler msg = new StringBundler(4);
1747
1748 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1749
1750 msg.append("companyId=");
1751 msg.append(companyId);
1752
1753 msg.append(StringPool.CLOSE_CURLY_BRACE);
1754
1755 throw new NoSuchContentException(msg.toString());
1756 }
1757
1758
1766 public DDMContent fetchByCompanyId_Last(long companyId,
1767 OrderByComparator orderByComparator) throws SystemException {
1768 int count = countByCompanyId(companyId);
1769
1770 List<DDMContent> list = findByCompanyId(companyId, count - 1, count,
1771 orderByComparator);
1772
1773 if (!list.isEmpty()) {
1774 return list.get(0);
1775 }
1776
1777 return null;
1778 }
1779
1780
1790 public DDMContent[] findByCompanyId_PrevAndNext(long contentId,
1791 long companyId, OrderByComparator orderByComparator)
1792 throws NoSuchContentException, SystemException {
1793 DDMContent ddmContent = findByPrimaryKey(contentId);
1794
1795 Session session = null;
1796
1797 try {
1798 session = openSession();
1799
1800 DDMContent[] array = new DDMContentImpl[3];
1801
1802 array[0] = getByCompanyId_PrevAndNext(session, ddmContent,
1803 companyId, orderByComparator, true);
1804
1805 array[1] = ddmContent;
1806
1807 array[2] = getByCompanyId_PrevAndNext(session, ddmContent,
1808 companyId, orderByComparator, false);
1809
1810 return array;
1811 }
1812 catch (Exception e) {
1813 throw processException(e);
1814 }
1815 finally {
1816 closeSession(session);
1817 }
1818 }
1819
1820 protected DDMContent getByCompanyId_PrevAndNext(Session session,
1821 DDMContent ddmContent, long companyId,
1822 OrderByComparator orderByComparator, boolean previous) {
1823 StringBundler query = null;
1824
1825 if (orderByComparator != null) {
1826 query = new StringBundler(6 +
1827 (orderByComparator.getOrderByFields().length * 6));
1828 }
1829 else {
1830 query = new StringBundler(3);
1831 }
1832
1833 query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1834
1835 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1836
1837 if (orderByComparator != null) {
1838 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1839
1840 if (orderByConditionFields.length > 0) {
1841 query.append(WHERE_AND);
1842 }
1843
1844 for (int i = 0; i < orderByConditionFields.length; i++) {
1845 query.append(_ORDER_BY_ENTITY_ALIAS);
1846 query.append(orderByConditionFields[i]);
1847
1848 if ((i + 1) < orderByConditionFields.length) {
1849 if (orderByComparator.isAscending() ^ previous) {
1850 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1851 }
1852 else {
1853 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1854 }
1855 }
1856 else {
1857 if (orderByComparator.isAscending() ^ previous) {
1858 query.append(WHERE_GREATER_THAN);
1859 }
1860 else {
1861 query.append(WHERE_LESSER_THAN);
1862 }
1863 }
1864 }
1865
1866 query.append(ORDER_BY_CLAUSE);
1867
1868 String[] orderByFields = orderByComparator.getOrderByFields();
1869
1870 for (int i = 0; i < orderByFields.length; i++) {
1871 query.append(_ORDER_BY_ENTITY_ALIAS);
1872 query.append(orderByFields[i]);
1873
1874 if ((i + 1) < orderByFields.length) {
1875 if (orderByComparator.isAscending() ^ previous) {
1876 query.append(ORDER_BY_ASC_HAS_NEXT);
1877 }
1878 else {
1879 query.append(ORDER_BY_DESC_HAS_NEXT);
1880 }
1881 }
1882 else {
1883 if (orderByComparator.isAscending() ^ previous) {
1884 query.append(ORDER_BY_ASC);
1885 }
1886 else {
1887 query.append(ORDER_BY_DESC);
1888 }
1889 }
1890 }
1891 }
1892
1893 String sql = query.toString();
1894
1895 Query q = session.createQuery(sql);
1896
1897 q.setFirstResult(0);
1898 q.setMaxResults(2);
1899
1900 QueryPos qPos = QueryPos.getInstance(q);
1901
1902 qPos.add(companyId);
1903
1904 if (orderByComparator != null) {
1905 Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1906
1907 for (Object value : values) {
1908 qPos.add(value);
1909 }
1910 }
1911
1912 List<DDMContent> list = q.list();
1913
1914 if (list.size() == 2) {
1915 return list.get(1);
1916 }
1917 else {
1918 return null;
1919 }
1920 }
1921
1922
1928 public List<DDMContent> findAll() throws SystemException {
1929 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1930 }
1931
1932
1944 public List<DDMContent> findAll(int start, int end)
1945 throws SystemException {
1946 return findAll(start, end, null);
1947 }
1948
1949
1962 public List<DDMContent> findAll(int start, int end,
1963 OrderByComparator orderByComparator) throws SystemException {
1964 FinderPath finderPath = null;
1965 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1966
1967 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1968 (orderByComparator == null)) {
1969 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1970 finderArgs = FINDER_ARGS_EMPTY;
1971 }
1972 else {
1973 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1974 finderArgs = new Object[] { start, end, orderByComparator };
1975 }
1976
1977 List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1978 finderArgs, this);
1979
1980 if (list == null) {
1981 StringBundler query = null;
1982 String sql = null;
1983
1984 if (orderByComparator != null) {
1985 query = new StringBundler(2 +
1986 (orderByComparator.getOrderByFields().length * 3));
1987
1988 query.append(_SQL_SELECT_DDMCONTENT);
1989
1990 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1991 orderByComparator);
1992
1993 sql = query.toString();
1994 }
1995 else {
1996 sql = _SQL_SELECT_DDMCONTENT;
1997 }
1998
1999 Session session = null;
2000
2001 try {
2002 session = openSession();
2003
2004 Query q = session.createQuery(sql);
2005
2006 if (orderByComparator == null) {
2007 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2008 start, end, false);
2009
2010 Collections.sort(list);
2011 }
2012 else {
2013 list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
2014 start, end);
2015 }
2016 }
2017 catch (Exception e) {
2018 throw processException(e);
2019 }
2020 finally {
2021 if (list == null) {
2022 FinderCacheUtil.removeResult(finderPath, finderArgs);
2023 }
2024 else {
2025 cacheResult(list);
2026
2027 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2028 }
2029
2030 closeSession(session);
2031 }
2032 }
2033
2034 return list;
2035 }
2036
2037
2043 public void removeByUuid(String uuid) throws SystemException {
2044 for (DDMContent ddmContent : findByUuid(uuid)) {
2045 remove(ddmContent);
2046 }
2047 }
2048
2049
2057 public DDMContent removeByUUID_G(String uuid, long groupId)
2058 throws NoSuchContentException, SystemException {
2059 DDMContent ddmContent = findByUUID_G(uuid, groupId);
2060
2061 return remove(ddmContent);
2062 }
2063
2064
2070 public void removeByGroupId(long groupId) throws SystemException {
2071 for (DDMContent ddmContent : findByGroupId(groupId)) {
2072 remove(ddmContent);
2073 }
2074 }
2075
2076
2082 public void removeByCompanyId(long companyId) throws SystemException {
2083 for (DDMContent ddmContent : findByCompanyId(companyId)) {
2084 remove(ddmContent);
2085 }
2086 }
2087
2088
2093 public void removeAll() throws SystemException {
2094 for (DDMContent ddmContent : findAll()) {
2095 remove(ddmContent);
2096 }
2097 }
2098
2099
2106 public int countByUuid(String uuid) throws SystemException {
2107 Object[] finderArgs = new Object[] { uuid };
2108
2109 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2110 finderArgs, this);
2111
2112 if (count == null) {
2113 StringBundler query = new StringBundler(2);
2114
2115 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2116
2117 if (uuid == null) {
2118 query.append(_FINDER_COLUMN_UUID_UUID_1);
2119 }
2120 else {
2121 if (uuid.equals(StringPool.BLANK)) {
2122 query.append(_FINDER_COLUMN_UUID_UUID_3);
2123 }
2124 else {
2125 query.append(_FINDER_COLUMN_UUID_UUID_2);
2126 }
2127 }
2128
2129 String sql = query.toString();
2130
2131 Session session = null;
2132
2133 try {
2134 session = openSession();
2135
2136 Query q = session.createQuery(sql);
2137
2138 QueryPos qPos = QueryPos.getInstance(q);
2139
2140 if (uuid != null) {
2141 qPos.add(uuid);
2142 }
2143
2144 count = (Long)q.uniqueResult();
2145 }
2146 catch (Exception e) {
2147 throw processException(e);
2148 }
2149 finally {
2150 if (count == null) {
2151 count = Long.valueOf(0);
2152 }
2153
2154 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2155 finderArgs, count);
2156
2157 closeSession(session);
2158 }
2159 }
2160
2161 return count.intValue();
2162 }
2163
2164
2172 public int countByUUID_G(String uuid, long groupId)
2173 throws SystemException {
2174 Object[] finderArgs = new Object[] { uuid, groupId };
2175
2176 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2177 finderArgs, this);
2178
2179 if (count == null) {
2180 StringBundler query = new StringBundler(3);
2181
2182 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2183
2184 if (uuid == null) {
2185 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2186 }
2187 else {
2188 if (uuid.equals(StringPool.BLANK)) {
2189 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2190 }
2191 else {
2192 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2193 }
2194 }
2195
2196 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2197
2198 String sql = query.toString();
2199
2200 Session session = null;
2201
2202 try {
2203 session = openSession();
2204
2205 Query q = session.createQuery(sql);
2206
2207 QueryPos qPos = QueryPos.getInstance(q);
2208
2209 if (uuid != null) {
2210 qPos.add(uuid);
2211 }
2212
2213 qPos.add(groupId);
2214
2215 count = (Long)q.uniqueResult();
2216 }
2217 catch (Exception e) {
2218 throw processException(e);
2219 }
2220 finally {
2221 if (count == null) {
2222 count = Long.valueOf(0);
2223 }
2224
2225 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2226 finderArgs, count);
2227
2228 closeSession(session);
2229 }
2230 }
2231
2232 return count.intValue();
2233 }
2234
2235
2242 public int countByGroupId(long groupId) throws SystemException {
2243 Object[] finderArgs = new Object[] { groupId };
2244
2245 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2246 finderArgs, this);
2247
2248 if (count == null) {
2249 StringBundler query = new StringBundler(2);
2250
2251 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2252
2253 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2254
2255 String sql = query.toString();
2256
2257 Session session = null;
2258
2259 try {
2260 session = openSession();
2261
2262 Query q = session.createQuery(sql);
2263
2264 QueryPos qPos = QueryPos.getInstance(q);
2265
2266 qPos.add(groupId);
2267
2268 count = (Long)q.uniqueResult();
2269 }
2270 catch (Exception e) {
2271 throw processException(e);
2272 }
2273 finally {
2274 if (count == null) {
2275 count = Long.valueOf(0);
2276 }
2277
2278 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2279 finderArgs, count);
2280
2281 closeSession(session);
2282 }
2283 }
2284
2285 return count.intValue();
2286 }
2287
2288
2295 public int countByCompanyId(long companyId) throws SystemException {
2296 Object[] finderArgs = new Object[] { companyId };
2297
2298 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2299 finderArgs, this);
2300
2301 if (count == null) {
2302 StringBundler query = new StringBundler(2);
2303
2304 query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2305
2306 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2307
2308 String sql = query.toString();
2309
2310 Session session = null;
2311
2312 try {
2313 session = openSession();
2314
2315 Query q = session.createQuery(sql);
2316
2317 QueryPos qPos = QueryPos.getInstance(q);
2318
2319 qPos.add(companyId);
2320
2321 count = (Long)q.uniqueResult();
2322 }
2323 catch (Exception e) {
2324 throw processException(e);
2325 }
2326 finally {
2327 if (count == null) {
2328 count = Long.valueOf(0);
2329 }
2330
2331 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2332 finderArgs, count);
2333
2334 closeSession(session);
2335 }
2336 }
2337
2338 return count.intValue();
2339 }
2340
2341
2347 public int countAll() throws SystemException {
2348 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2349 FINDER_ARGS_EMPTY, this);
2350
2351 if (count == null) {
2352 Session session = null;
2353
2354 try {
2355 session = openSession();
2356
2357 Query q = session.createQuery(_SQL_COUNT_DDMCONTENT);
2358
2359 count = (Long)q.uniqueResult();
2360 }
2361 catch (Exception e) {
2362 throw processException(e);
2363 }
2364 finally {
2365 if (count == null) {
2366 count = Long.valueOf(0);
2367 }
2368
2369 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2370 FINDER_ARGS_EMPTY, count);
2371
2372 closeSession(session);
2373 }
2374 }
2375
2376 return count.intValue();
2377 }
2378
2379
2382 public void afterPropertiesSet() {
2383 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2384 com.liferay.portal.util.PropsUtil.get(
2385 "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMContent")));
2386
2387 if (listenerClassNames.length > 0) {
2388 try {
2389 List<ModelListener<DDMContent>> listenersList = new ArrayList<ModelListener<DDMContent>>();
2390
2391 for (String listenerClassName : listenerClassNames) {
2392 Class<?> clazz = getClass();
2393
2394 listenersList.add((ModelListener<DDMContent>)InstanceFactory.newInstance(
2395 clazz.getClassLoader(), listenerClassName));
2396 }
2397
2398 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2399 }
2400 catch (Exception e) {
2401 _log.error(e);
2402 }
2403 }
2404 }
2405
2406 public void destroy() {
2407 EntityCacheUtil.removeCache(DDMContentImpl.class.getName());
2408 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2409 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2410 }
2411
2412 @BeanReference(type = DDMContentPersistence.class)
2413 protected DDMContentPersistence ddmContentPersistence;
2414 @BeanReference(type = DDMStorageLinkPersistence.class)
2415 protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
2416 @BeanReference(type = DDMStructurePersistence.class)
2417 protected DDMStructurePersistence ddmStructurePersistence;
2418 @BeanReference(type = DDMStructureLinkPersistence.class)
2419 protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
2420 @BeanReference(type = DDMTemplatePersistence.class)
2421 protected DDMTemplatePersistence ddmTemplatePersistence;
2422 @BeanReference(type = ResourcePersistence.class)
2423 protected ResourcePersistence resourcePersistence;
2424 @BeanReference(type = UserPersistence.class)
2425 protected UserPersistence userPersistence;
2426 private static final String _SQL_SELECT_DDMCONTENT = "SELECT ddmContent FROM DDMContent ddmContent";
2427 private static final String _SQL_SELECT_DDMCONTENT_WHERE = "SELECT ddmContent FROM DDMContent ddmContent WHERE ";
2428 private static final String _SQL_COUNT_DDMCONTENT = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent";
2429 private static final String _SQL_COUNT_DDMCONTENT_WHERE = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent WHERE ";
2430 private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmContent.uuid IS NULL";
2431 private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmContent.uuid = ?";
2432 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?)";
2433 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmContent.uuid IS NULL AND ";
2434 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmContent.uuid = ? AND ";
2435 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
2436 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmContent.groupId = ?";
2437 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmContent.groupId = ?";
2438 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddmContent.companyId = ?";
2439 private static final String _ORDER_BY_ENTITY_ALIAS = "ddmContent.";
2440 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMContent exists with the primary key ";
2441 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMContent exists with the key {";
2442 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2443 private static Log _log = LogFactoryUtil.getLog(DDMContentPersistenceImpl.class);
2444 private static DDMContent _nullDDMContent = new DDMContentImpl() {
2445 @Override
2446 public Object clone() {
2447 return this;
2448 }
2449
2450 @Override
2451 public CacheModel<DDMContent> toCacheModel() {
2452 return _nullDDMContentCacheModel;
2453 }
2454 };
2455
2456 private static CacheModel<DDMContent> _nullDDMContentCacheModel = new CacheModel<DDMContent>() {
2457 public DDMContent toEntityModel() {
2458 return _nullDDMContent;
2459 }
2460 };
2461 }