001
014
015 package com.liferay.portlet.journal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.BatchSessionUtil;
042 import com.liferay.portal.service.persistence.ResourcePersistence;
043 import com.liferay.portal.service.persistence.UserPersistence;
044 import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
045 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046
047 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
048 import com.liferay.portlet.journal.NoSuchStructureException;
049 import com.liferay.portlet.journal.model.JournalStructure;
050 import com.liferay.portlet.journal.model.impl.JournalStructureImpl;
051 import com.liferay.portlet.journal.model.impl.JournalStructureModelImpl;
052
053 import java.io.Serializable;
054
055 import java.util.ArrayList;
056 import java.util.Collections;
057 import java.util.List;
058
059
075 public class JournalStructurePersistenceImpl extends BasePersistenceImpl<JournalStructure>
076 implements JournalStructurePersistence {
077 public static final String FINDER_CLASS_NAME_ENTITY = JournalStructureImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
079 ".List";
080 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
081 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
082 FINDER_CLASS_NAME_LIST, "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_COUNT_BY_UUID = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
090 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
091 FINDER_CLASS_NAME_LIST, "countByUuid",
092 new String[] { String.class.getName() });
093 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
094 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
095 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
096 new String[] { String.class.getName(), Long.class.getName() });
097 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
098 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
099 FINDER_CLASS_NAME_LIST, "countByUUID_G",
100 new String[] { String.class.getName(), Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
102 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_LIST, "findByGroupId",
104 new String[] {
105 Long.class.getName(),
106
107 "java.lang.Integer", "java.lang.Integer",
108 "com.liferay.portal.kernel.util.OrderByComparator"
109 });
110 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
111 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
112 FINDER_CLASS_NAME_LIST, "countByGroupId",
113 new String[] { Long.class.getName() });
114 public static final FinderPath FINDER_PATH_FIND_BY_STRUCTUREID = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
115 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
116 FINDER_CLASS_NAME_LIST, "findByStructureId",
117 new String[] {
118 String.class.getName(),
119
120 "java.lang.Integer", "java.lang.Integer",
121 "com.liferay.portal.kernel.util.OrderByComparator"
122 });
123 public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
124 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
125 FINDER_CLASS_NAME_LIST, "countByStructureId",
126 new String[] { String.class.getName() });
127 public static final FinderPath FINDER_PATH_FETCH_BY_G_S = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
128 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
129 FINDER_CLASS_NAME_ENTITY, "fetchByG_S",
130 new String[] { Long.class.getName(), String.class.getName() });
131 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
132 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
133 FINDER_CLASS_NAME_LIST, "countByG_S",
134 new String[] { Long.class.getName(), String.class.getName() });
135 public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
136 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
137 FINDER_CLASS_NAME_LIST, "findByG_P",
138 new String[] {
139 Long.class.getName(), String.class.getName(),
140
141 "java.lang.Integer", "java.lang.Integer",
142 "com.liferay.portal.kernel.util.OrderByComparator"
143 });
144 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
145 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
146 FINDER_CLASS_NAME_LIST, "countByG_P",
147 new String[] { Long.class.getName(), String.class.getName() });
148 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
149 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
150 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
151 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
152 JournalStructureModelImpl.FINDER_CACHE_ENABLED,
153 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
154
155
160 public void cacheResult(JournalStructure journalStructure) {
161 EntityCacheUtil.putResult(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
162 JournalStructureImpl.class, journalStructure.getPrimaryKey(),
163 journalStructure);
164
165 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
166 new Object[] {
167 journalStructure.getUuid(),
168 new Long(journalStructure.getGroupId())
169 }, journalStructure);
170
171 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
172 new Object[] {
173 new Long(journalStructure.getGroupId()),
174
175 journalStructure.getStructureId()
176 }, journalStructure);
177 }
178
179
184 public void cacheResult(List<JournalStructure> journalStructures) {
185 for (JournalStructure journalStructure : journalStructures) {
186 if (EntityCacheUtil.getResult(
187 JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
188 JournalStructureImpl.class,
189 journalStructure.getPrimaryKey(), this) == null) {
190 cacheResult(journalStructure);
191 }
192 }
193 }
194
195
202 public void clearCache() {
203 CacheRegistryUtil.clear(JournalStructureImpl.class.getName());
204 EntityCacheUtil.clearCache(JournalStructureImpl.class.getName());
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
207 }
208
209
216 public void clearCache(JournalStructure journalStructure) {
217 EntityCacheUtil.removeResult(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
218 JournalStructureImpl.class, journalStructure.getPrimaryKey());
219
220 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
221 new Object[] {
222 journalStructure.getUuid(),
223 new Long(journalStructure.getGroupId())
224 });
225
226 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_S,
227 new Object[] {
228 new Long(journalStructure.getGroupId()),
229
230 journalStructure.getStructureId()
231 });
232 }
233
234
240 public JournalStructure create(long id) {
241 JournalStructure journalStructure = new JournalStructureImpl();
242
243 journalStructure.setNew(true);
244 journalStructure.setPrimaryKey(id);
245
246 String uuid = PortalUUIDUtil.generate();
247
248 journalStructure.setUuid(uuid);
249
250 return journalStructure;
251 }
252
253
261 public JournalStructure remove(Serializable primaryKey)
262 throws NoSuchModelException, SystemException {
263 return remove(((Long)primaryKey).longValue());
264 }
265
266
274 public JournalStructure remove(long id)
275 throws NoSuchStructureException, SystemException {
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 JournalStructure journalStructure = (JournalStructure)session.get(JournalStructureImpl.class,
282 new Long(id));
283
284 if (journalStructure == null) {
285 if (_log.isWarnEnabled()) {
286 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
287 }
288
289 throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
290 id);
291 }
292
293 return remove(journalStructure);
294 }
295 catch (NoSuchStructureException nsee) {
296 throw nsee;
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304 }
305
306 protected JournalStructure removeImpl(JournalStructure journalStructure)
307 throws SystemException {
308 journalStructure = toUnwrappedModel(journalStructure);
309
310 Session session = null;
311
312 try {
313 session = openSession();
314
315 BatchSessionUtil.delete(session, journalStructure);
316 }
317 catch (Exception e) {
318 throw processException(e);
319 }
320 finally {
321 closeSession(session);
322 }
323
324 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
325
326 JournalStructureModelImpl journalStructureModelImpl = (JournalStructureModelImpl)journalStructure;
327
328 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
329 new Object[] {
330 journalStructureModelImpl.getOriginalUuid(),
331 new Long(journalStructureModelImpl.getOriginalGroupId())
332 });
333
334 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_S,
335 new Object[] {
336 new Long(journalStructureModelImpl.getOriginalGroupId()),
337
338 journalStructureModelImpl.getOriginalStructureId()
339 });
340
341 EntityCacheUtil.removeResult(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
342 JournalStructureImpl.class, journalStructure.getPrimaryKey());
343
344 return journalStructure;
345 }
346
347 public JournalStructure updateImpl(
348 com.liferay.portlet.journal.model.JournalStructure journalStructure,
349 boolean merge) throws SystemException {
350 journalStructure = toUnwrappedModel(journalStructure);
351
352 boolean isNew = journalStructure.isNew();
353
354 JournalStructureModelImpl journalStructureModelImpl = (JournalStructureModelImpl)journalStructure;
355
356 if (Validator.isNull(journalStructure.getUuid())) {
357 String uuid = PortalUUIDUtil.generate();
358
359 journalStructure.setUuid(uuid);
360 }
361
362 Session session = null;
363
364 try {
365 session = openSession();
366
367 BatchSessionUtil.update(session, journalStructure, merge);
368
369 journalStructure.setNew(false);
370 }
371 catch (Exception e) {
372 throw processException(e);
373 }
374 finally {
375 closeSession(session);
376 }
377
378 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
379
380 EntityCacheUtil.putResult(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
381 JournalStructureImpl.class, journalStructure.getPrimaryKey(),
382 journalStructure);
383
384 if (!isNew &&
385 (!Validator.equals(journalStructure.getUuid(),
386 journalStructureModelImpl.getOriginalUuid()) ||
387 (journalStructure.getGroupId() != journalStructureModelImpl.getOriginalGroupId()))) {
388 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
389 new Object[] {
390 journalStructureModelImpl.getOriginalUuid(),
391 new Long(journalStructureModelImpl.getOriginalGroupId())
392 });
393 }
394
395 if (isNew ||
396 (!Validator.equals(journalStructure.getUuid(),
397 journalStructureModelImpl.getOriginalUuid()) ||
398 (journalStructure.getGroupId() != journalStructureModelImpl.getOriginalGroupId()))) {
399 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
400 new Object[] {
401 journalStructure.getUuid(),
402 new Long(journalStructure.getGroupId())
403 }, journalStructure);
404 }
405
406 if (!isNew &&
407 ((journalStructure.getGroupId() != journalStructureModelImpl.getOriginalGroupId()) ||
408 !Validator.equals(journalStructure.getStructureId(),
409 journalStructureModelImpl.getOriginalStructureId()))) {
410 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_S,
411 new Object[] {
412 new Long(journalStructureModelImpl.getOriginalGroupId()),
413
414 journalStructureModelImpl.getOriginalStructureId()
415 });
416 }
417
418 if (isNew ||
419 ((journalStructure.getGroupId() != journalStructureModelImpl.getOriginalGroupId()) ||
420 !Validator.equals(journalStructure.getStructureId(),
421 journalStructureModelImpl.getOriginalStructureId()))) {
422 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
423 new Object[] {
424 new Long(journalStructure.getGroupId()),
425
426 journalStructure.getStructureId()
427 }, journalStructure);
428 }
429
430 return journalStructure;
431 }
432
433 protected JournalStructure toUnwrappedModel(
434 JournalStructure journalStructure) {
435 if (journalStructure instanceof JournalStructureImpl) {
436 return journalStructure;
437 }
438
439 JournalStructureImpl journalStructureImpl = new JournalStructureImpl();
440
441 journalStructureImpl.setNew(journalStructure.isNew());
442 journalStructureImpl.setPrimaryKey(journalStructure.getPrimaryKey());
443
444 journalStructureImpl.setUuid(journalStructure.getUuid());
445 journalStructureImpl.setId(journalStructure.getId());
446 journalStructureImpl.setGroupId(journalStructure.getGroupId());
447 journalStructureImpl.setCompanyId(journalStructure.getCompanyId());
448 journalStructureImpl.setUserId(journalStructure.getUserId());
449 journalStructureImpl.setUserName(journalStructure.getUserName());
450 journalStructureImpl.setCreateDate(journalStructure.getCreateDate());
451 journalStructureImpl.setModifiedDate(journalStructure.getModifiedDate());
452 journalStructureImpl.setStructureId(journalStructure.getStructureId());
453 journalStructureImpl.setParentStructureId(journalStructure.getParentStructureId());
454 journalStructureImpl.setName(journalStructure.getName());
455 journalStructureImpl.setDescription(journalStructure.getDescription());
456 journalStructureImpl.setXsd(journalStructure.getXsd());
457
458 return journalStructureImpl;
459 }
460
461
469 public JournalStructure findByPrimaryKey(Serializable primaryKey)
470 throws NoSuchModelException, SystemException {
471 return findByPrimaryKey(((Long)primaryKey).longValue());
472 }
473
474
482 public JournalStructure findByPrimaryKey(long id)
483 throws NoSuchStructureException, SystemException {
484 JournalStructure journalStructure = fetchByPrimaryKey(id);
485
486 if (journalStructure == null) {
487 if (_log.isWarnEnabled()) {
488 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
489 }
490
491 throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
492 id);
493 }
494
495 return journalStructure;
496 }
497
498
505 public JournalStructure fetchByPrimaryKey(Serializable primaryKey)
506 throws SystemException {
507 return fetchByPrimaryKey(((Long)primaryKey).longValue());
508 }
509
510
517 public JournalStructure fetchByPrimaryKey(long id)
518 throws SystemException {
519 JournalStructure journalStructure = (JournalStructure)EntityCacheUtil.getResult(JournalStructureModelImpl.ENTITY_CACHE_ENABLED,
520 JournalStructureImpl.class, id, this);
521
522 if (journalStructure == null) {
523 Session session = null;
524
525 try {
526 session = openSession();
527
528 journalStructure = (JournalStructure)session.get(JournalStructureImpl.class,
529 new Long(id));
530 }
531 catch (Exception e) {
532 throw processException(e);
533 }
534 finally {
535 if (journalStructure != null) {
536 cacheResult(journalStructure);
537 }
538
539 closeSession(session);
540 }
541 }
542
543 return journalStructure;
544 }
545
546
553 public List<JournalStructure> findByUuid(String uuid)
554 throws SystemException {
555 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
556 }
557
558
571 public List<JournalStructure> findByUuid(String uuid, int start, int end)
572 throws SystemException {
573 return findByUuid(uuid, start, end, null);
574 }
575
576
590 public List<JournalStructure> findByUuid(String uuid, int start, int end,
591 OrderByComparator orderByComparator) throws SystemException {
592 Object[] finderArgs = new Object[] {
593 uuid,
594
595 String.valueOf(start), String.valueOf(end),
596 String.valueOf(orderByComparator)
597 };
598
599 List<JournalStructure> list = (List<JournalStructure>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
600 finderArgs, this);
601
602 if (list == null) {
603 Session session = null;
604
605 try {
606 session = openSession();
607
608 StringBundler query = null;
609
610 if (orderByComparator != null) {
611 query = new StringBundler(3 +
612 (orderByComparator.getOrderByFields().length * 3));
613 }
614 else {
615 query = new StringBundler(3);
616 }
617
618 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
619
620 if (uuid == null) {
621 query.append(_FINDER_COLUMN_UUID_UUID_1);
622 }
623 else {
624 if (uuid.equals(StringPool.BLANK)) {
625 query.append(_FINDER_COLUMN_UUID_UUID_3);
626 }
627 else {
628 query.append(_FINDER_COLUMN_UUID_UUID_2);
629 }
630 }
631
632 if (orderByComparator != null) {
633 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
634 orderByComparator);
635 }
636
637 else {
638 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
639 }
640
641 String sql = query.toString();
642
643 Query q = session.createQuery(sql);
644
645 QueryPos qPos = QueryPos.getInstance(q);
646
647 if (uuid != null) {
648 qPos.add(uuid);
649 }
650
651 list = (List<JournalStructure>)QueryUtil.list(q, getDialect(),
652 start, end);
653 }
654 catch (Exception e) {
655 throw processException(e);
656 }
657 finally {
658 if (list == null) {
659 list = new ArrayList<JournalStructure>();
660 }
661
662 cacheResult(list);
663
664 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
665 list);
666
667 closeSession(session);
668 }
669 }
670
671 return list;
672 }
673
674
687 public JournalStructure findByUuid_First(String uuid,
688 OrderByComparator orderByComparator)
689 throws NoSuchStructureException, SystemException {
690 List<JournalStructure> list = findByUuid(uuid, 0, 1, orderByComparator);
691
692 if (list.isEmpty()) {
693 StringBundler msg = new StringBundler(4);
694
695 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
696
697 msg.append("uuid=");
698 msg.append(uuid);
699
700 msg.append(StringPool.CLOSE_CURLY_BRACE);
701
702 throw new NoSuchStructureException(msg.toString());
703 }
704 else {
705 return list.get(0);
706 }
707 }
708
709
722 public JournalStructure findByUuid_Last(String uuid,
723 OrderByComparator orderByComparator)
724 throws NoSuchStructureException, SystemException {
725 int count = countByUuid(uuid);
726
727 List<JournalStructure> list = findByUuid(uuid, count - 1, count,
728 orderByComparator);
729
730 if (list.isEmpty()) {
731 StringBundler msg = new StringBundler(4);
732
733 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
734
735 msg.append("uuid=");
736 msg.append(uuid);
737
738 msg.append(StringPool.CLOSE_CURLY_BRACE);
739
740 throw new NoSuchStructureException(msg.toString());
741 }
742 else {
743 return list.get(0);
744 }
745 }
746
747
761 public JournalStructure[] findByUuid_PrevAndNext(long id, String uuid,
762 OrderByComparator orderByComparator)
763 throws NoSuchStructureException, SystemException {
764 JournalStructure journalStructure = findByPrimaryKey(id);
765
766 Session session = null;
767
768 try {
769 session = openSession();
770
771 JournalStructure[] array = new JournalStructureImpl[3];
772
773 array[0] = getByUuid_PrevAndNext(session, journalStructure, uuid,
774 orderByComparator, true);
775
776 array[1] = journalStructure;
777
778 array[2] = getByUuid_PrevAndNext(session, journalStructure, uuid,
779 orderByComparator, false);
780
781 return array;
782 }
783 catch (Exception e) {
784 throw processException(e);
785 }
786 finally {
787 closeSession(session);
788 }
789 }
790
791 protected JournalStructure getByUuid_PrevAndNext(Session session,
792 JournalStructure journalStructure, String uuid,
793 OrderByComparator orderByComparator, boolean previous) {
794 StringBundler query = null;
795
796 if (orderByComparator != null) {
797 query = new StringBundler(6 +
798 (orderByComparator.getOrderByFields().length * 6));
799 }
800 else {
801 query = new StringBundler(3);
802 }
803
804 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
805
806 if (uuid == null) {
807 query.append(_FINDER_COLUMN_UUID_UUID_1);
808 }
809 else {
810 if (uuid.equals(StringPool.BLANK)) {
811 query.append(_FINDER_COLUMN_UUID_UUID_3);
812 }
813 else {
814 query.append(_FINDER_COLUMN_UUID_UUID_2);
815 }
816 }
817
818 if (orderByComparator != null) {
819 String[] orderByFields = orderByComparator.getOrderByFields();
820
821 if (orderByFields.length > 0) {
822 query.append(WHERE_AND);
823 }
824
825 for (int i = 0; i < orderByFields.length; i++) {
826 query.append(_ORDER_BY_ENTITY_ALIAS);
827 query.append(orderByFields[i]);
828
829 if ((i + 1) < orderByFields.length) {
830 if (orderByComparator.isAscending() ^ previous) {
831 query.append(WHERE_GREATER_THAN_HAS_NEXT);
832 }
833 else {
834 query.append(WHERE_LESSER_THAN_HAS_NEXT);
835 }
836 }
837 else {
838 if (orderByComparator.isAscending() ^ previous) {
839 query.append(WHERE_GREATER_THAN);
840 }
841 else {
842 query.append(WHERE_LESSER_THAN);
843 }
844 }
845 }
846
847 query.append(ORDER_BY_CLAUSE);
848
849 for (int i = 0; i < orderByFields.length; i++) {
850 query.append(_ORDER_BY_ENTITY_ALIAS);
851 query.append(orderByFields[i]);
852
853 if ((i + 1) < orderByFields.length) {
854 if (orderByComparator.isAscending() ^ previous) {
855 query.append(ORDER_BY_ASC_HAS_NEXT);
856 }
857 else {
858 query.append(ORDER_BY_DESC_HAS_NEXT);
859 }
860 }
861 else {
862 if (orderByComparator.isAscending() ^ previous) {
863 query.append(ORDER_BY_ASC);
864 }
865 else {
866 query.append(ORDER_BY_DESC);
867 }
868 }
869 }
870 }
871
872 else {
873 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
874 }
875
876 String sql = query.toString();
877
878 Query q = session.createQuery(sql);
879
880 q.setFirstResult(0);
881 q.setMaxResults(2);
882
883 QueryPos qPos = QueryPos.getInstance(q);
884
885 if (uuid != null) {
886 qPos.add(uuid);
887 }
888
889 if (orderByComparator != null) {
890 Object[] values = orderByComparator.getOrderByValues(journalStructure);
891
892 for (Object value : values) {
893 qPos.add(value);
894 }
895 }
896
897 List<JournalStructure> list = q.list();
898
899 if (list.size() == 2) {
900 return list.get(1);
901 }
902 else {
903 return null;
904 }
905 }
906
907
916 public JournalStructure findByUUID_G(String uuid, long groupId)
917 throws NoSuchStructureException, SystemException {
918 JournalStructure journalStructure = fetchByUUID_G(uuid, groupId);
919
920 if (journalStructure == null) {
921 StringBundler msg = new StringBundler(6);
922
923 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
924
925 msg.append("uuid=");
926 msg.append(uuid);
927
928 msg.append(", groupId=");
929 msg.append(groupId);
930
931 msg.append(StringPool.CLOSE_CURLY_BRACE);
932
933 if (_log.isWarnEnabled()) {
934 _log.warn(msg.toString());
935 }
936
937 throw new NoSuchStructureException(msg.toString());
938 }
939
940 return journalStructure;
941 }
942
943
951 public JournalStructure fetchByUUID_G(String uuid, long groupId)
952 throws SystemException {
953 return fetchByUUID_G(uuid, groupId, true);
954 }
955
956
964 public JournalStructure fetchByUUID_G(String uuid, long groupId,
965 boolean retrieveFromCache) throws SystemException {
966 Object[] finderArgs = new Object[] { uuid, groupId };
967
968 Object result = null;
969
970 if (retrieveFromCache) {
971 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
972 finderArgs, this);
973 }
974
975 if (result == null) {
976 Session session = null;
977
978 try {
979 session = openSession();
980
981 StringBundler query = new StringBundler(4);
982
983 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
984
985 if (uuid == null) {
986 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
987 }
988 else {
989 if (uuid.equals(StringPool.BLANK)) {
990 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
991 }
992 else {
993 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
994 }
995 }
996
997 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
998
999 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
1000
1001 String sql = query.toString();
1002
1003 Query q = session.createQuery(sql);
1004
1005 QueryPos qPos = QueryPos.getInstance(q);
1006
1007 if (uuid != null) {
1008 qPos.add(uuid);
1009 }
1010
1011 qPos.add(groupId);
1012
1013 List<JournalStructure> list = q.list();
1014
1015 result = list;
1016
1017 JournalStructure journalStructure = null;
1018
1019 if (list.isEmpty()) {
1020 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1021 finderArgs, list);
1022 }
1023 else {
1024 journalStructure = list.get(0);
1025
1026 cacheResult(journalStructure);
1027
1028 if ((journalStructure.getUuid() == null) ||
1029 !journalStructure.getUuid().equals(uuid) ||
1030 (journalStructure.getGroupId() != groupId)) {
1031 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1032 finderArgs, journalStructure);
1033 }
1034 }
1035
1036 return journalStructure;
1037 }
1038 catch (Exception e) {
1039 throw processException(e);
1040 }
1041 finally {
1042 if (result == null) {
1043 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1044 finderArgs, new ArrayList<JournalStructure>());
1045 }
1046
1047 closeSession(session);
1048 }
1049 }
1050 else {
1051 if (result instanceof List<?>) {
1052 return null;
1053 }
1054 else {
1055 return (JournalStructure)result;
1056 }
1057 }
1058 }
1059
1060
1067 public List<JournalStructure> findByGroupId(long groupId)
1068 throws SystemException {
1069 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1070 }
1071
1072
1085 public List<JournalStructure> findByGroupId(long groupId, int start, int end)
1086 throws SystemException {
1087 return findByGroupId(groupId, start, end, null);
1088 }
1089
1090
1104 public List<JournalStructure> findByGroupId(long groupId, int start,
1105 int end, OrderByComparator orderByComparator) throws SystemException {
1106 Object[] finderArgs = new Object[] {
1107 groupId,
1108
1109 String.valueOf(start), String.valueOf(end),
1110 String.valueOf(orderByComparator)
1111 };
1112
1113 List<JournalStructure> list = (List<JournalStructure>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1114 finderArgs, this);
1115
1116 if (list == null) {
1117 Session session = null;
1118
1119 try {
1120 session = openSession();
1121
1122 StringBundler query = null;
1123
1124 if (orderByComparator != null) {
1125 query = new StringBundler(3 +
1126 (orderByComparator.getOrderByFields().length * 3));
1127 }
1128 else {
1129 query = new StringBundler(3);
1130 }
1131
1132 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
1133
1134 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1135
1136 if (orderByComparator != null) {
1137 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1138 orderByComparator);
1139 }
1140
1141 else {
1142 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
1143 }
1144
1145 String sql = query.toString();
1146
1147 Query q = session.createQuery(sql);
1148
1149 QueryPos qPos = QueryPos.getInstance(q);
1150
1151 qPos.add(groupId);
1152
1153 list = (List<JournalStructure>)QueryUtil.list(q, getDialect(),
1154 start, end);
1155 }
1156 catch (Exception e) {
1157 throw processException(e);
1158 }
1159 finally {
1160 if (list == null) {
1161 list = new ArrayList<JournalStructure>();
1162 }
1163
1164 cacheResult(list);
1165
1166 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1167 finderArgs, list);
1168
1169 closeSession(session);
1170 }
1171 }
1172
1173 return list;
1174 }
1175
1176
1189 public JournalStructure findByGroupId_First(long groupId,
1190 OrderByComparator orderByComparator)
1191 throws NoSuchStructureException, SystemException {
1192 List<JournalStructure> list = findByGroupId(groupId, 0, 1,
1193 orderByComparator);
1194
1195 if (list.isEmpty()) {
1196 StringBundler msg = new StringBundler(4);
1197
1198 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1199
1200 msg.append("groupId=");
1201 msg.append(groupId);
1202
1203 msg.append(StringPool.CLOSE_CURLY_BRACE);
1204
1205 throw new NoSuchStructureException(msg.toString());
1206 }
1207 else {
1208 return list.get(0);
1209 }
1210 }
1211
1212
1225 public JournalStructure findByGroupId_Last(long groupId,
1226 OrderByComparator orderByComparator)
1227 throws NoSuchStructureException, SystemException {
1228 int count = countByGroupId(groupId);
1229
1230 List<JournalStructure> list = findByGroupId(groupId, count - 1, count,
1231 orderByComparator);
1232
1233 if (list.isEmpty()) {
1234 StringBundler msg = new StringBundler(4);
1235
1236 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1237
1238 msg.append("groupId=");
1239 msg.append(groupId);
1240
1241 msg.append(StringPool.CLOSE_CURLY_BRACE);
1242
1243 throw new NoSuchStructureException(msg.toString());
1244 }
1245 else {
1246 return list.get(0);
1247 }
1248 }
1249
1250
1264 public JournalStructure[] findByGroupId_PrevAndNext(long id, long groupId,
1265 OrderByComparator orderByComparator)
1266 throws NoSuchStructureException, SystemException {
1267 JournalStructure journalStructure = findByPrimaryKey(id);
1268
1269 Session session = null;
1270
1271 try {
1272 session = openSession();
1273
1274 JournalStructure[] array = new JournalStructureImpl[3];
1275
1276 array[0] = getByGroupId_PrevAndNext(session, journalStructure,
1277 groupId, orderByComparator, true);
1278
1279 array[1] = journalStructure;
1280
1281 array[2] = getByGroupId_PrevAndNext(session, journalStructure,
1282 groupId, orderByComparator, false);
1283
1284 return array;
1285 }
1286 catch (Exception e) {
1287 throw processException(e);
1288 }
1289 finally {
1290 closeSession(session);
1291 }
1292 }
1293
1294 protected JournalStructure getByGroupId_PrevAndNext(Session session,
1295 JournalStructure journalStructure, long groupId,
1296 OrderByComparator orderByComparator, boolean previous) {
1297 StringBundler query = null;
1298
1299 if (orderByComparator != null) {
1300 query = new StringBundler(6 +
1301 (orderByComparator.getOrderByFields().length * 6));
1302 }
1303 else {
1304 query = new StringBundler(3);
1305 }
1306
1307 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
1308
1309 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1310
1311 if (orderByComparator != null) {
1312 String[] orderByFields = orderByComparator.getOrderByFields();
1313
1314 if (orderByFields.length > 0) {
1315 query.append(WHERE_AND);
1316 }
1317
1318 for (int i = 0; i < orderByFields.length; i++) {
1319 query.append(_ORDER_BY_ENTITY_ALIAS);
1320 query.append(orderByFields[i]);
1321
1322 if ((i + 1) < orderByFields.length) {
1323 if (orderByComparator.isAscending() ^ previous) {
1324 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1325 }
1326 else {
1327 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1328 }
1329 }
1330 else {
1331 if (orderByComparator.isAscending() ^ previous) {
1332 query.append(WHERE_GREATER_THAN);
1333 }
1334 else {
1335 query.append(WHERE_LESSER_THAN);
1336 }
1337 }
1338 }
1339
1340 query.append(ORDER_BY_CLAUSE);
1341
1342 for (int i = 0; i < orderByFields.length; i++) {
1343 query.append(_ORDER_BY_ENTITY_ALIAS);
1344 query.append(orderByFields[i]);
1345
1346 if ((i + 1) < orderByFields.length) {
1347 if (orderByComparator.isAscending() ^ previous) {
1348 query.append(ORDER_BY_ASC_HAS_NEXT);
1349 }
1350 else {
1351 query.append(ORDER_BY_DESC_HAS_NEXT);
1352 }
1353 }
1354 else {
1355 if (orderByComparator.isAscending() ^ previous) {
1356 query.append(ORDER_BY_ASC);
1357 }
1358 else {
1359 query.append(ORDER_BY_DESC);
1360 }
1361 }
1362 }
1363 }
1364
1365 else {
1366 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
1367 }
1368
1369 String sql = query.toString();
1370
1371 Query q = session.createQuery(sql);
1372
1373 q.setFirstResult(0);
1374 q.setMaxResults(2);
1375
1376 QueryPos qPos = QueryPos.getInstance(q);
1377
1378 qPos.add(groupId);
1379
1380 if (orderByComparator != null) {
1381 Object[] values = orderByComparator.getOrderByValues(journalStructure);
1382
1383 for (Object value : values) {
1384 qPos.add(value);
1385 }
1386 }
1387
1388 List<JournalStructure> list = q.list();
1389
1390 if (list.size() == 2) {
1391 return list.get(1);
1392 }
1393 else {
1394 return null;
1395 }
1396 }
1397
1398
1405 public List<JournalStructure> filterFindByGroupId(long groupId)
1406 throws SystemException {
1407 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1408 QueryUtil.ALL_POS, null);
1409 }
1410
1411
1424 public List<JournalStructure> filterFindByGroupId(long groupId, int start,
1425 int end) throws SystemException {
1426 return filterFindByGroupId(groupId, start, end, null);
1427 }
1428
1429
1443 public List<JournalStructure> filterFindByGroupId(long groupId, int start,
1444 int end, OrderByComparator orderByComparator) throws SystemException {
1445 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1446 return findByGroupId(groupId, start, end, orderByComparator);
1447 }
1448
1449 Session session = null;
1450
1451 try {
1452 session = openSession();
1453
1454 StringBundler query = null;
1455
1456 if (orderByComparator != null) {
1457 query = new StringBundler(3 +
1458 (orderByComparator.getOrderByFields().length * 3));
1459 }
1460 else {
1461 query = new StringBundler(3);
1462 }
1463
1464 if (getDB().isSupportsInlineDistinct()) {
1465 query.append(_FILTER_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
1466 }
1467 else {
1468 query.append(_FILTER_SQL_SELECT_JOURNALSTRUCTURE_NO_INLINE_DISTINCT_WHERE);
1469 }
1470
1471 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1472
1473 if (orderByComparator != null) {
1474 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1475 orderByComparator);
1476 }
1477
1478 else {
1479 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
1480 }
1481
1482 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1483 JournalStructure.class.getName(), _FILTER_COLUMN_PK,
1484 _FILTER_COLUMN_USERID, groupId);
1485
1486 SQLQuery q = session.createSQLQuery(sql);
1487
1488 q.addEntity(_FILTER_ENTITY_ALIAS, JournalStructureImpl.class);
1489
1490 QueryPos qPos = QueryPos.getInstance(q);
1491
1492 qPos.add(groupId);
1493
1494 return (List<JournalStructure>)QueryUtil.list(q, getDialect(),
1495 start, end);
1496 }
1497 catch (Exception e) {
1498 throw processException(e);
1499 }
1500 finally {
1501 closeSession(session);
1502 }
1503 }
1504
1505
1512 public List<JournalStructure> findByStructureId(String structureId)
1513 throws SystemException {
1514 return findByStructureId(structureId, QueryUtil.ALL_POS,
1515 QueryUtil.ALL_POS, null);
1516 }
1517
1518
1531 public List<JournalStructure> findByStructureId(String structureId,
1532 int start, int end) throws SystemException {
1533 return findByStructureId(structureId, start, end, null);
1534 }
1535
1536
1550 public List<JournalStructure> findByStructureId(String structureId,
1551 int start, int end, OrderByComparator orderByComparator)
1552 throws SystemException {
1553 Object[] finderArgs = new Object[] {
1554 structureId,
1555
1556 String.valueOf(start), String.valueOf(end),
1557 String.valueOf(orderByComparator)
1558 };
1559
1560 List<JournalStructure> list = (List<JournalStructure>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_STRUCTUREID,
1561 finderArgs, this);
1562
1563 if (list == null) {
1564 Session session = null;
1565
1566 try {
1567 session = openSession();
1568
1569 StringBundler query = null;
1570
1571 if (orderByComparator != null) {
1572 query = new StringBundler(3 +
1573 (orderByComparator.getOrderByFields().length * 3));
1574 }
1575 else {
1576 query = new StringBundler(3);
1577 }
1578
1579 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
1580
1581 if (structureId == null) {
1582 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
1583 }
1584 else {
1585 if (structureId.equals(StringPool.BLANK)) {
1586 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
1587 }
1588 else {
1589 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1590 }
1591 }
1592
1593 if (orderByComparator != null) {
1594 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1595 orderByComparator);
1596 }
1597
1598 else {
1599 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
1600 }
1601
1602 String sql = query.toString();
1603
1604 Query q = session.createQuery(sql);
1605
1606 QueryPos qPos = QueryPos.getInstance(q);
1607
1608 if (structureId != null) {
1609 qPos.add(structureId);
1610 }
1611
1612 list = (List<JournalStructure>)QueryUtil.list(q, getDialect(),
1613 start, end);
1614 }
1615 catch (Exception e) {
1616 throw processException(e);
1617 }
1618 finally {
1619 if (list == null) {
1620 list = new ArrayList<JournalStructure>();
1621 }
1622
1623 cacheResult(list);
1624
1625 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_STRUCTUREID,
1626 finderArgs, list);
1627
1628 closeSession(session);
1629 }
1630 }
1631
1632 return list;
1633 }
1634
1635
1648 public JournalStructure findByStructureId_First(String structureId,
1649 OrderByComparator orderByComparator)
1650 throws NoSuchStructureException, SystemException {
1651 List<JournalStructure> list = findByStructureId(structureId, 0, 1,
1652 orderByComparator);
1653
1654 if (list.isEmpty()) {
1655 StringBundler msg = new StringBundler(4);
1656
1657 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1658
1659 msg.append("structureId=");
1660 msg.append(structureId);
1661
1662 msg.append(StringPool.CLOSE_CURLY_BRACE);
1663
1664 throw new NoSuchStructureException(msg.toString());
1665 }
1666 else {
1667 return list.get(0);
1668 }
1669 }
1670
1671
1684 public JournalStructure findByStructureId_Last(String structureId,
1685 OrderByComparator orderByComparator)
1686 throws NoSuchStructureException, SystemException {
1687 int count = countByStructureId(structureId);
1688
1689 List<JournalStructure> list = findByStructureId(structureId, count - 1,
1690 count, orderByComparator);
1691
1692 if (list.isEmpty()) {
1693 StringBundler msg = new StringBundler(4);
1694
1695 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1696
1697 msg.append("structureId=");
1698 msg.append(structureId);
1699
1700 msg.append(StringPool.CLOSE_CURLY_BRACE);
1701
1702 throw new NoSuchStructureException(msg.toString());
1703 }
1704 else {
1705 return list.get(0);
1706 }
1707 }
1708
1709
1723 public JournalStructure[] findByStructureId_PrevAndNext(long id,
1724 String structureId, OrderByComparator orderByComparator)
1725 throws NoSuchStructureException, SystemException {
1726 JournalStructure journalStructure = findByPrimaryKey(id);
1727
1728 Session session = null;
1729
1730 try {
1731 session = openSession();
1732
1733 JournalStructure[] array = new JournalStructureImpl[3];
1734
1735 array[0] = getByStructureId_PrevAndNext(session, journalStructure,
1736 structureId, orderByComparator, true);
1737
1738 array[1] = journalStructure;
1739
1740 array[2] = getByStructureId_PrevAndNext(session, journalStructure,
1741 structureId, orderByComparator, false);
1742
1743 return array;
1744 }
1745 catch (Exception e) {
1746 throw processException(e);
1747 }
1748 finally {
1749 closeSession(session);
1750 }
1751 }
1752
1753 protected JournalStructure getByStructureId_PrevAndNext(Session session,
1754 JournalStructure journalStructure, String structureId,
1755 OrderByComparator orderByComparator, boolean previous) {
1756 StringBundler query = null;
1757
1758 if (orderByComparator != null) {
1759 query = new StringBundler(6 +
1760 (orderByComparator.getOrderByFields().length * 6));
1761 }
1762 else {
1763 query = new StringBundler(3);
1764 }
1765
1766 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
1767
1768 if (structureId == null) {
1769 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
1770 }
1771 else {
1772 if (structureId.equals(StringPool.BLANK)) {
1773 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
1774 }
1775 else {
1776 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1777 }
1778 }
1779
1780 if (orderByComparator != null) {
1781 String[] orderByFields = orderByComparator.getOrderByFields();
1782
1783 if (orderByFields.length > 0) {
1784 query.append(WHERE_AND);
1785 }
1786
1787 for (int i = 0; i < orderByFields.length; i++) {
1788 query.append(_ORDER_BY_ENTITY_ALIAS);
1789 query.append(orderByFields[i]);
1790
1791 if ((i + 1) < orderByFields.length) {
1792 if (orderByComparator.isAscending() ^ previous) {
1793 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1794 }
1795 else {
1796 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1797 }
1798 }
1799 else {
1800 if (orderByComparator.isAscending() ^ previous) {
1801 query.append(WHERE_GREATER_THAN);
1802 }
1803 else {
1804 query.append(WHERE_LESSER_THAN);
1805 }
1806 }
1807 }
1808
1809 query.append(ORDER_BY_CLAUSE);
1810
1811 for (int i = 0; i < orderByFields.length; i++) {
1812 query.append(_ORDER_BY_ENTITY_ALIAS);
1813 query.append(orderByFields[i]);
1814
1815 if ((i + 1) < orderByFields.length) {
1816 if (orderByComparator.isAscending() ^ previous) {
1817 query.append(ORDER_BY_ASC_HAS_NEXT);
1818 }
1819 else {
1820 query.append(ORDER_BY_DESC_HAS_NEXT);
1821 }
1822 }
1823 else {
1824 if (orderByComparator.isAscending() ^ previous) {
1825 query.append(ORDER_BY_ASC);
1826 }
1827 else {
1828 query.append(ORDER_BY_DESC);
1829 }
1830 }
1831 }
1832 }
1833
1834 else {
1835 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
1836 }
1837
1838 String sql = query.toString();
1839
1840 Query q = session.createQuery(sql);
1841
1842 q.setFirstResult(0);
1843 q.setMaxResults(2);
1844
1845 QueryPos qPos = QueryPos.getInstance(q);
1846
1847 if (structureId != null) {
1848 qPos.add(structureId);
1849 }
1850
1851 if (orderByComparator != null) {
1852 Object[] values = orderByComparator.getOrderByValues(journalStructure);
1853
1854 for (Object value : values) {
1855 qPos.add(value);
1856 }
1857 }
1858
1859 List<JournalStructure> list = q.list();
1860
1861 if (list.size() == 2) {
1862 return list.get(1);
1863 }
1864 else {
1865 return null;
1866 }
1867 }
1868
1869
1878 public JournalStructure findByG_S(long groupId, String structureId)
1879 throws NoSuchStructureException, SystemException {
1880 JournalStructure journalStructure = fetchByG_S(groupId, structureId);
1881
1882 if (journalStructure == null) {
1883 StringBundler msg = new StringBundler(6);
1884
1885 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1886
1887 msg.append("groupId=");
1888 msg.append(groupId);
1889
1890 msg.append(", structureId=");
1891 msg.append(structureId);
1892
1893 msg.append(StringPool.CLOSE_CURLY_BRACE);
1894
1895 if (_log.isWarnEnabled()) {
1896 _log.warn(msg.toString());
1897 }
1898
1899 throw new NoSuchStructureException(msg.toString());
1900 }
1901
1902 return journalStructure;
1903 }
1904
1905
1913 public JournalStructure fetchByG_S(long groupId, String structureId)
1914 throws SystemException {
1915 return fetchByG_S(groupId, structureId, true);
1916 }
1917
1918
1926 public JournalStructure fetchByG_S(long groupId, String structureId,
1927 boolean retrieveFromCache) throws SystemException {
1928 Object[] finderArgs = new Object[] { groupId, structureId };
1929
1930 Object result = null;
1931
1932 if (retrieveFromCache) {
1933 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_S,
1934 finderArgs, this);
1935 }
1936
1937 if (result == null) {
1938 Session session = null;
1939
1940 try {
1941 session = openSession();
1942
1943 StringBundler query = new StringBundler(4);
1944
1945 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
1946
1947 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1948
1949 if (structureId == null) {
1950 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
1951 }
1952 else {
1953 if (structureId.equals(StringPool.BLANK)) {
1954 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
1955 }
1956 else {
1957 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
1958 }
1959 }
1960
1961 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
1962
1963 String sql = query.toString();
1964
1965 Query q = session.createQuery(sql);
1966
1967 QueryPos qPos = QueryPos.getInstance(q);
1968
1969 qPos.add(groupId);
1970
1971 if (structureId != null) {
1972 qPos.add(structureId);
1973 }
1974
1975 List<JournalStructure> list = q.list();
1976
1977 result = list;
1978
1979 JournalStructure journalStructure = null;
1980
1981 if (list.isEmpty()) {
1982 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
1983 finderArgs, list);
1984 }
1985 else {
1986 journalStructure = list.get(0);
1987
1988 cacheResult(journalStructure);
1989
1990 if ((journalStructure.getGroupId() != groupId) ||
1991 (journalStructure.getStructureId() == null) ||
1992 !journalStructure.getStructureId()
1993 .equals(structureId)) {
1994 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
1995 finderArgs, journalStructure);
1996 }
1997 }
1998
1999 return journalStructure;
2000 }
2001 catch (Exception e) {
2002 throw processException(e);
2003 }
2004 finally {
2005 if (result == null) {
2006 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
2007 finderArgs, new ArrayList<JournalStructure>());
2008 }
2009
2010 closeSession(session);
2011 }
2012 }
2013 else {
2014 if (result instanceof List<?>) {
2015 return null;
2016 }
2017 else {
2018 return (JournalStructure)result;
2019 }
2020 }
2021 }
2022
2023
2031 public List<JournalStructure> findByG_P(long groupId,
2032 String parentStructureId) throws SystemException {
2033 return findByG_P(groupId, parentStructureId, QueryUtil.ALL_POS,
2034 QueryUtil.ALL_POS, null);
2035 }
2036
2037
2051 public List<JournalStructure> findByG_P(long groupId,
2052 String parentStructureId, int start, int end) throws SystemException {
2053 return findByG_P(groupId, parentStructureId, start, end, null);
2054 }
2055
2056
2071 public List<JournalStructure> findByG_P(long groupId,
2072 String parentStructureId, int start, int end,
2073 OrderByComparator orderByComparator) throws SystemException {
2074 Object[] finderArgs = new Object[] {
2075 groupId, parentStructureId,
2076
2077 String.valueOf(start), String.valueOf(end),
2078 String.valueOf(orderByComparator)
2079 };
2080
2081 List<JournalStructure> list = (List<JournalStructure>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
2082 finderArgs, this);
2083
2084 if (list == null) {
2085 Session session = null;
2086
2087 try {
2088 session = openSession();
2089
2090 StringBundler query = null;
2091
2092 if (orderByComparator != null) {
2093 query = new StringBundler(4 +
2094 (orderByComparator.getOrderByFields().length * 3));
2095 }
2096 else {
2097 query = new StringBundler(4);
2098 }
2099
2100 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
2101
2102 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2103
2104 if (parentStructureId == null) {
2105 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_1);
2106 }
2107 else {
2108 if (parentStructureId.equals(StringPool.BLANK)) {
2109 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_3);
2110 }
2111 else {
2112 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
2113 }
2114 }
2115
2116 if (orderByComparator != null) {
2117 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2118 orderByComparator);
2119 }
2120
2121 else {
2122 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
2123 }
2124
2125 String sql = query.toString();
2126
2127 Query q = session.createQuery(sql);
2128
2129 QueryPos qPos = QueryPos.getInstance(q);
2130
2131 qPos.add(groupId);
2132
2133 if (parentStructureId != null) {
2134 qPos.add(parentStructureId);
2135 }
2136
2137 list = (List<JournalStructure>)QueryUtil.list(q, getDialect(),
2138 start, end);
2139 }
2140 catch (Exception e) {
2141 throw processException(e);
2142 }
2143 finally {
2144 if (list == null) {
2145 list = new ArrayList<JournalStructure>();
2146 }
2147
2148 cacheResult(list);
2149
2150 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
2151 list);
2152
2153 closeSession(session);
2154 }
2155 }
2156
2157 return list;
2158 }
2159
2160
2174 public JournalStructure findByG_P_First(long groupId,
2175 String parentStructureId, OrderByComparator orderByComparator)
2176 throws NoSuchStructureException, SystemException {
2177 List<JournalStructure> list = findByG_P(groupId, parentStructureId, 0,
2178 1, orderByComparator);
2179
2180 if (list.isEmpty()) {
2181 StringBundler msg = new StringBundler(6);
2182
2183 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2184
2185 msg.append("groupId=");
2186 msg.append(groupId);
2187
2188 msg.append(", parentStructureId=");
2189 msg.append(parentStructureId);
2190
2191 msg.append(StringPool.CLOSE_CURLY_BRACE);
2192
2193 throw new NoSuchStructureException(msg.toString());
2194 }
2195 else {
2196 return list.get(0);
2197 }
2198 }
2199
2200
2214 public JournalStructure findByG_P_Last(long groupId,
2215 String parentStructureId, OrderByComparator orderByComparator)
2216 throws NoSuchStructureException, SystemException {
2217 int count = countByG_P(groupId, parentStructureId);
2218
2219 List<JournalStructure> list = findByG_P(groupId, parentStructureId,
2220 count - 1, count, orderByComparator);
2221
2222 if (list.isEmpty()) {
2223 StringBundler msg = new StringBundler(6);
2224
2225 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2226
2227 msg.append("groupId=");
2228 msg.append(groupId);
2229
2230 msg.append(", parentStructureId=");
2231 msg.append(parentStructureId);
2232
2233 msg.append(StringPool.CLOSE_CURLY_BRACE);
2234
2235 throw new NoSuchStructureException(msg.toString());
2236 }
2237 else {
2238 return list.get(0);
2239 }
2240 }
2241
2242
2257 public JournalStructure[] findByG_P_PrevAndNext(long id, long groupId,
2258 String parentStructureId, OrderByComparator orderByComparator)
2259 throws NoSuchStructureException, SystemException {
2260 JournalStructure journalStructure = findByPrimaryKey(id);
2261
2262 Session session = null;
2263
2264 try {
2265 session = openSession();
2266
2267 JournalStructure[] array = new JournalStructureImpl[3];
2268
2269 array[0] = getByG_P_PrevAndNext(session, journalStructure, groupId,
2270 parentStructureId, orderByComparator, true);
2271
2272 array[1] = journalStructure;
2273
2274 array[2] = getByG_P_PrevAndNext(session, journalStructure, groupId,
2275 parentStructureId, orderByComparator, false);
2276
2277 return array;
2278 }
2279 catch (Exception e) {
2280 throw processException(e);
2281 }
2282 finally {
2283 closeSession(session);
2284 }
2285 }
2286
2287 protected JournalStructure getByG_P_PrevAndNext(Session session,
2288 JournalStructure journalStructure, long groupId,
2289 String parentStructureId, OrderByComparator orderByComparator,
2290 boolean previous) {
2291 StringBundler query = null;
2292
2293 if (orderByComparator != null) {
2294 query = new StringBundler(6 +
2295 (orderByComparator.getOrderByFields().length * 6));
2296 }
2297 else {
2298 query = new StringBundler(3);
2299 }
2300
2301 query.append(_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
2302
2303 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2304
2305 if (parentStructureId == null) {
2306 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_1);
2307 }
2308 else {
2309 if (parentStructureId.equals(StringPool.BLANK)) {
2310 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_3);
2311 }
2312 else {
2313 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
2314 }
2315 }
2316
2317 if (orderByComparator != null) {
2318 String[] orderByFields = orderByComparator.getOrderByFields();
2319
2320 if (orderByFields.length > 0) {
2321 query.append(WHERE_AND);
2322 }
2323
2324 for (int i = 0; i < orderByFields.length; i++) {
2325 query.append(_ORDER_BY_ENTITY_ALIAS);
2326 query.append(orderByFields[i]);
2327
2328 if ((i + 1) < orderByFields.length) {
2329 if (orderByComparator.isAscending() ^ previous) {
2330 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2331 }
2332 else {
2333 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2334 }
2335 }
2336 else {
2337 if (orderByComparator.isAscending() ^ previous) {
2338 query.append(WHERE_GREATER_THAN);
2339 }
2340 else {
2341 query.append(WHERE_LESSER_THAN);
2342 }
2343 }
2344 }
2345
2346 query.append(ORDER_BY_CLAUSE);
2347
2348 for (int i = 0; i < orderByFields.length; i++) {
2349 query.append(_ORDER_BY_ENTITY_ALIAS);
2350 query.append(orderByFields[i]);
2351
2352 if ((i + 1) < orderByFields.length) {
2353 if (orderByComparator.isAscending() ^ previous) {
2354 query.append(ORDER_BY_ASC_HAS_NEXT);
2355 }
2356 else {
2357 query.append(ORDER_BY_DESC_HAS_NEXT);
2358 }
2359 }
2360 else {
2361 if (orderByComparator.isAscending() ^ previous) {
2362 query.append(ORDER_BY_ASC);
2363 }
2364 else {
2365 query.append(ORDER_BY_DESC);
2366 }
2367 }
2368 }
2369 }
2370
2371 else {
2372 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
2373 }
2374
2375 String sql = query.toString();
2376
2377 Query q = session.createQuery(sql);
2378
2379 q.setFirstResult(0);
2380 q.setMaxResults(2);
2381
2382 QueryPos qPos = QueryPos.getInstance(q);
2383
2384 qPos.add(groupId);
2385
2386 if (parentStructureId != null) {
2387 qPos.add(parentStructureId);
2388 }
2389
2390 if (orderByComparator != null) {
2391 Object[] values = orderByComparator.getOrderByValues(journalStructure);
2392
2393 for (Object value : values) {
2394 qPos.add(value);
2395 }
2396 }
2397
2398 List<JournalStructure> list = q.list();
2399
2400 if (list.size() == 2) {
2401 return list.get(1);
2402 }
2403 else {
2404 return null;
2405 }
2406 }
2407
2408
2416 public List<JournalStructure> filterFindByG_P(long groupId,
2417 String parentStructureId) throws SystemException {
2418 return filterFindByG_P(groupId, parentStructureId, QueryUtil.ALL_POS,
2419 QueryUtil.ALL_POS, null);
2420 }
2421
2422
2436 public List<JournalStructure> filterFindByG_P(long groupId,
2437 String parentStructureId, int start, int end) throws SystemException {
2438 return filterFindByG_P(groupId, parentStructureId, start, end, null);
2439 }
2440
2441
2456 public List<JournalStructure> filterFindByG_P(long groupId,
2457 String parentStructureId, int start, int end,
2458 OrderByComparator orderByComparator) throws SystemException {
2459 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2460 return findByG_P(groupId, parentStructureId, start, end,
2461 orderByComparator);
2462 }
2463
2464 Session session = null;
2465
2466 try {
2467 session = openSession();
2468
2469 StringBundler query = null;
2470
2471 if (orderByComparator != null) {
2472 query = new StringBundler(4 +
2473 (orderByComparator.getOrderByFields().length * 3));
2474 }
2475 else {
2476 query = new StringBundler(4);
2477 }
2478
2479 if (getDB().isSupportsInlineDistinct()) {
2480 query.append(_FILTER_SQL_SELECT_JOURNALSTRUCTURE_WHERE);
2481 }
2482 else {
2483 query.append(_FILTER_SQL_SELECT_JOURNALSTRUCTURE_NO_INLINE_DISTINCT_WHERE);
2484 }
2485
2486 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2487
2488 if (parentStructureId == null) {
2489 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_1);
2490 }
2491 else {
2492 if (parentStructureId.equals(StringPool.BLANK)) {
2493 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_3);
2494 }
2495 else {
2496 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
2497 }
2498 }
2499
2500 if (orderByComparator != null) {
2501 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2502 orderByComparator);
2503 }
2504
2505 else {
2506 query.append(JournalStructureModelImpl.ORDER_BY_JPQL);
2507 }
2508
2509 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2510 JournalStructure.class.getName(), _FILTER_COLUMN_PK,
2511 _FILTER_COLUMN_USERID, groupId);
2512
2513 SQLQuery q = session.createSQLQuery(sql);
2514
2515 q.addEntity(_FILTER_ENTITY_ALIAS, JournalStructureImpl.class);
2516
2517 QueryPos qPos = QueryPos.getInstance(q);
2518
2519 qPos.add(groupId);
2520
2521 if (parentStructureId != null) {
2522 qPos.add(parentStructureId);
2523 }
2524
2525 return (List<JournalStructure>)QueryUtil.list(q, getDialect(),
2526 start, end);
2527 }
2528 catch (Exception e) {
2529 throw processException(e);
2530 }
2531 finally {
2532 closeSession(session);
2533 }
2534 }
2535
2536
2542 public List<JournalStructure> findAll() throws SystemException {
2543 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2544 }
2545
2546
2558 public List<JournalStructure> findAll(int start, int end)
2559 throws SystemException {
2560 return findAll(start, end, null);
2561 }
2562
2563
2576 public List<JournalStructure> findAll(int start, int end,
2577 OrderByComparator orderByComparator) throws SystemException {
2578 Object[] finderArgs = new Object[] {
2579 String.valueOf(start), String.valueOf(end),
2580 String.valueOf(orderByComparator)
2581 };
2582
2583 List<JournalStructure> list = (List<JournalStructure>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2584 finderArgs, this);
2585
2586 if (list == null) {
2587 Session session = null;
2588
2589 try {
2590 session = openSession();
2591
2592 StringBundler query = null;
2593 String sql = null;
2594
2595 if (orderByComparator != null) {
2596 query = new StringBundler(2 +
2597 (orderByComparator.getOrderByFields().length * 3));
2598
2599 query.append(_SQL_SELECT_JOURNALSTRUCTURE);
2600
2601 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2602 orderByComparator);
2603
2604 sql = query.toString();
2605 }
2606 else {
2607 sql = _SQL_SELECT_JOURNALSTRUCTURE.concat(JournalStructureModelImpl.ORDER_BY_JPQL);
2608 }
2609
2610 Query q = session.createQuery(sql);
2611
2612 if (orderByComparator == null) {
2613 list = (List<JournalStructure>)QueryUtil.list(q,
2614 getDialect(), start, end, false);
2615
2616 Collections.sort(list);
2617 }
2618 else {
2619 list = (List<JournalStructure>)QueryUtil.list(q,
2620 getDialect(), start, end);
2621 }
2622 }
2623 catch (Exception e) {
2624 throw processException(e);
2625 }
2626 finally {
2627 if (list == null) {
2628 list = new ArrayList<JournalStructure>();
2629 }
2630
2631 cacheResult(list);
2632
2633 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2634
2635 closeSession(session);
2636 }
2637 }
2638
2639 return list;
2640 }
2641
2642
2648 public void removeByUuid(String uuid) throws SystemException {
2649 for (JournalStructure journalStructure : findByUuid(uuid)) {
2650 remove(journalStructure);
2651 }
2652 }
2653
2654
2661 public void removeByUUID_G(String uuid, long groupId)
2662 throws NoSuchStructureException, SystemException {
2663 JournalStructure journalStructure = findByUUID_G(uuid, groupId);
2664
2665 remove(journalStructure);
2666 }
2667
2668
2674 public void removeByGroupId(long groupId) throws SystemException {
2675 for (JournalStructure journalStructure : findByGroupId(groupId)) {
2676 remove(journalStructure);
2677 }
2678 }
2679
2680
2686 public void removeByStructureId(String structureId)
2687 throws SystemException {
2688 for (JournalStructure journalStructure : findByStructureId(structureId)) {
2689 remove(journalStructure);
2690 }
2691 }
2692
2693
2700 public void removeByG_S(long groupId, String structureId)
2701 throws NoSuchStructureException, SystemException {
2702 JournalStructure journalStructure = findByG_S(groupId, structureId);
2703
2704 remove(journalStructure);
2705 }
2706
2707
2714 public void removeByG_P(long groupId, String parentStructureId)
2715 throws SystemException {
2716 for (JournalStructure journalStructure : findByG_P(groupId,
2717 parentStructureId)) {
2718 remove(journalStructure);
2719 }
2720 }
2721
2722
2727 public void removeAll() throws SystemException {
2728 for (JournalStructure journalStructure : findAll()) {
2729 remove(journalStructure);
2730 }
2731 }
2732
2733
2740 public int countByUuid(String uuid) throws SystemException {
2741 Object[] finderArgs = new Object[] { uuid };
2742
2743 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2744 finderArgs, this);
2745
2746 if (count == null) {
2747 Session session = null;
2748
2749 try {
2750 session = openSession();
2751
2752 StringBundler query = new StringBundler(2);
2753
2754 query.append(_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
2755
2756 if (uuid == null) {
2757 query.append(_FINDER_COLUMN_UUID_UUID_1);
2758 }
2759 else {
2760 if (uuid.equals(StringPool.BLANK)) {
2761 query.append(_FINDER_COLUMN_UUID_UUID_3);
2762 }
2763 else {
2764 query.append(_FINDER_COLUMN_UUID_UUID_2);
2765 }
2766 }
2767
2768 String sql = query.toString();
2769
2770 Query q = session.createQuery(sql);
2771
2772 QueryPos qPos = QueryPos.getInstance(q);
2773
2774 if (uuid != null) {
2775 qPos.add(uuid);
2776 }
2777
2778 count = (Long)q.uniqueResult();
2779 }
2780 catch (Exception e) {
2781 throw processException(e);
2782 }
2783 finally {
2784 if (count == null) {
2785 count = Long.valueOf(0);
2786 }
2787
2788 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2789 finderArgs, count);
2790
2791 closeSession(session);
2792 }
2793 }
2794
2795 return count.intValue();
2796 }
2797
2798
2806 public int countByUUID_G(String uuid, long groupId)
2807 throws SystemException {
2808 Object[] finderArgs = new Object[] { uuid, groupId };
2809
2810 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2811 finderArgs, this);
2812
2813 if (count == null) {
2814 Session session = null;
2815
2816 try {
2817 session = openSession();
2818
2819 StringBundler query = new StringBundler(3);
2820
2821 query.append(_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
2822
2823 if (uuid == null) {
2824 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2825 }
2826 else {
2827 if (uuid.equals(StringPool.BLANK)) {
2828 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2829 }
2830 else {
2831 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2832 }
2833 }
2834
2835 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2836
2837 String sql = query.toString();
2838
2839 Query q = session.createQuery(sql);
2840
2841 QueryPos qPos = QueryPos.getInstance(q);
2842
2843 if (uuid != null) {
2844 qPos.add(uuid);
2845 }
2846
2847 qPos.add(groupId);
2848
2849 count = (Long)q.uniqueResult();
2850 }
2851 catch (Exception e) {
2852 throw processException(e);
2853 }
2854 finally {
2855 if (count == null) {
2856 count = Long.valueOf(0);
2857 }
2858
2859 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2860 finderArgs, count);
2861
2862 closeSession(session);
2863 }
2864 }
2865
2866 return count.intValue();
2867 }
2868
2869
2876 public int countByGroupId(long groupId) throws SystemException {
2877 Object[] finderArgs = new Object[] { groupId };
2878
2879 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2880 finderArgs, this);
2881
2882 if (count == null) {
2883 Session session = null;
2884
2885 try {
2886 session = openSession();
2887
2888 StringBundler query = new StringBundler(2);
2889
2890 query.append(_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
2891
2892 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2893
2894 String sql = query.toString();
2895
2896 Query q = session.createQuery(sql);
2897
2898 QueryPos qPos = QueryPos.getInstance(q);
2899
2900 qPos.add(groupId);
2901
2902 count = (Long)q.uniqueResult();
2903 }
2904 catch (Exception e) {
2905 throw processException(e);
2906 }
2907 finally {
2908 if (count == null) {
2909 count = Long.valueOf(0);
2910 }
2911
2912 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2913 finderArgs, count);
2914
2915 closeSession(session);
2916 }
2917 }
2918
2919 return count.intValue();
2920 }
2921
2922
2929 public int filterCountByGroupId(long groupId) throws SystemException {
2930 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2931 return countByGroupId(groupId);
2932 }
2933
2934 Session session = null;
2935
2936 try {
2937 session = openSession();
2938
2939 StringBundler query = new StringBundler(2);
2940
2941 query.append(_FILTER_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
2942
2943 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2944
2945 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2946 JournalStructure.class.getName(), _FILTER_COLUMN_PK,
2947 _FILTER_COLUMN_USERID, groupId);
2948
2949 SQLQuery q = session.createSQLQuery(sql);
2950
2951 q.addScalar(COUNT_COLUMN_NAME,
2952 com.liferay.portal.kernel.dao.orm.Type.LONG);
2953
2954 QueryPos qPos = QueryPos.getInstance(q);
2955
2956 qPos.add(groupId);
2957
2958 Long count = (Long)q.uniqueResult();
2959
2960 return count.intValue();
2961 }
2962 catch (Exception e) {
2963 throw processException(e);
2964 }
2965 finally {
2966 closeSession(session);
2967 }
2968 }
2969
2970
2977 public int countByStructureId(String structureId) throws SystemException {
2978 Object[] finderArgs = new Object[] { structureId };
2979
2980 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
2981 finderArgs, this);
2982
2983 if (count == null) {
2984 Session session = null;
2985
2986 try {
2987 session = openSession();
2988
2989 StringBundler query = new StringBundler(2);
2990
2991 query.append(_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
2992
2993 if (structureId == null) {
2994 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
2995 }
2996 else {
2997 if (structureId.equals(StringPool.BLANK)) {
2998 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
2999 }
3000 else {
3001 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3002 }
3003 }
3004
3005 String sql = query.toString();
3006
3007 Query q = session.createQuery(sql);
3008
3009 QueryPos qPos = QueryPos.getInstance(q);
3010
3011 if (structureId != null) {
3012 qPos.add(structureId);
3013 }
3014
3015 count = (Long)q.uniqueResult();
3016 }
3017 catch (Exception e) {
3018 throw processException(e);
3019 }
3020 finally {
3021 if (count == null) {
3022 count = Long.valueOf(0);
3023 }
3024
3025 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
3026 finderArgs, count);
3027
3028 closeSession(session);
3029 }
3030 }
3031
3032 return count.intValue();
3033 }
3034
3035
3043 public int countByG_S(long groupId, String structureId)
3044 throws SystemException {
3045 Object[] finderArgs = new Object[] { groupId, structureId };
3046
3047 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
3048 finderArgs, this);
3049
3050 if (count == null) {
3051 Session session = null;
3052
3053 try {
3054 session = openSession();
3055
3056 StringBundler query = new StringBundler(3);
3057
3058 query.append(_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
3059
3060 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3061
3062 if (structureId == null) {
3063 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
3064 }
3065 else {
3066 if (structureId.equals(StringPool.BLANK)) {
3067 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
3068 }
3069 else {
3070 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
3071 }
3072 }
3073
3074 String sql = query.toString();
3075
3076 Query q = session.createQuery(sql);
3077
3078 QueryPos qPos = QueryPos.getInstance(q);
3079
3080 qPos.add(groupId);
3081
3082 if (structureId != null) {
3083 qPos.add(structureId);
3084 }
3085
3086 count = (Long)q.uniqueResult();
3087 }
3088 catch (Exception e) {
3089 throw processException(e);
3090 }
3091 finally {
3092 if (count == null) {
3093 count = Long.valueOf(0);
3094 }
3095
3096 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
3097 count);
3098
3099 closeSession(session);
3100 }
3101 }
3102
3103 return count.intValue();
3104 }
3105
3106
3114 public int filterCountByG_S(long groupId, String structureId)
3115 throws SystemException {
3116 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3117 return countByG_S(groupId, structureId);
3118 }
3119
3120 Session session = null;
3121
3122 try {
3123 session = openSession();
3124
3125 StringBundler query = new StringBundler(3);
3126
3127 query.append(_FILTER_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
3128
3129 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3130
3131 if (structureId == null) {
3132 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
3133 }
3134 else {
3135 if (structureId.equals(StringPool.BLANK)) {
3136 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
3137 }
3138 else {
3139 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
3140 }
3141 }
3142
3143 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3144 JournalStructure.class.getName(), _FILTER_COLUMN_PK,
3145 _FILTER_COLUMN_USERID, groupId);
3146
3147 SQLQuery q = session.createSQLQuery(sql);
3148
3149 q.addScalar(COUNT_COLUMN_NAME,
3150 com.liferay.portal.kernel.dao.orm.Type.LONG);
3151
3152 QueryPos qPos = QueryPos.getInstance(q);
3153
3154 qPos.add(groupId);
3155
3156 if (structureId != null) {
3157 qPos.add(structureId);
3158 }
3159
3160 Long count = (Long)q.uniqueResult();
3161
3162 return count.intValue();
3163 }
3164 catch (Exception e) {
3165 throw processException(e);
3166 }
3167 finally {
3168 closeSession(session);
3169 }
3170 }
3171
3172
3180 public int countByG_P(long groupId, String parentStructureId)
3181 throws SystemException {
3182 Object[] finderArgs = new Object[] { groupId, parentStructureId };
3183
3184 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3185 finderArgs, this);
3186
3187 if (count == null) {
3188 Session session = null;
3189
3190 try {
3191 session = openSession();
3192
3193 StringBundler query = new StringBundler(3);
3194
3195 query.append(_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
3196
3197 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3198
3199 if (parentStructureId == null) {
3200 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_1);
3201 }
3202 else {
3203 if (parentStructureId.equals(StringPool.BLANK)) {
3204 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_3);
3205 }
3206 else {
3207 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
3208 }
3209 }
3210
3211 String sql = query.toString();
3212
3213 Query q = session.createQuery(sql);
3214
3215 QueryPos qPos = QueryPos.getInstance(q);
3216
3217 qPos.add(groupId);
3218
3219 if (parentStructureId != null) {
3220 qPos.add(parentStructureId);
3221 }
3222
3223 count = (Long)q.uniqueResult();
3224 }
3225 catch (Exception e) {
3226 throw processException(e);
3227 }
3228 finally {
3229 if (count == null) {
3230 count = Long.valueOf(0);
3231 }
3232
3233 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3234 count);
3235
3236 closeSession(session);
3237 }
3238 }
3239
3240 return count.intValue();
3241 }
3242
3243
3251 public int filterCountByG_P(long groupId, String parentStructureId)
3252 throws SystemException {
3253 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3254 return countByG_P(groupId, parentStructureId);
3255 }
3256
3257 Session session = null;
3258
3259 try {
3260 session = openSession();
3261
3262 StringBundler query = new StringBundler(3);
3263
3264 query.append(_FILTER_SQL_COUNT_JOURNALSTRUCTURE_WHERE);
3265
3266 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3267
3268 if (parentStructureId == null) {
3269 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_1);
3270 }
3271 else {
3272 if (parentStructureId.equals(StringPool.BLANK)) {
3273 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_3);
3274 }
3275 else {
3276 query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
3277 }
3278 }
3279
3280 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3281 JournalStructure.class.getName(), _FILTER_COLUMN_PK,
3282 _FILTER_COLUMN_USERID, groupId);
3283
3284 SQLQuery q = session.createSQLQuery(sql);
3285
3286 q.addScalar(COUNT_COLUMN_NAME,
3287 com.liferay.portal.kernel.dao.orm.Type.LONG);
3288
3289 QueryPos qPos = QueryPos.getInstance(q);
3290
3291 qPos.add(groupId);
3292
3293 if (parentStructureId != null) {
3294 qPos.add(parentStructureId);
3295 }
3296
3297 Long count = (Long)q.uniqueResult();
3298
3299 return count.intValue();
3300 }
3301 catch (Exception e) {
3302 throw processException(e);
3303 }
3304 finally {
3305 closeSession(session);
3306 }
3307 }
3308
3309
3315 public int countAll() throws SystemException {
3316 Object[] finderArgs = new Object[0];
3317
3318 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3319 finderArgs, this);
3320
3321 if (count == null) {
3322 Session session = null;
3323
3324 try {
3325 session = openSession();
3326
3327 Query q = session.createQuery(_SQL_COUNT_JOURNALSTRUCTURE);
3328
3329 count = (Long)q.uniqueResult();
3330 }
3331 catch (Exception e) {
3332 throw processException(e);
3333 }
3334 finally {
3335 if (count == null) {
3336 count = Long.valueOf(0);
3337 }
3338
3339 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3340 count);
3341
3342 closeSession(session);
3343 }
3344 }
3345
3346 return count.intValue();
3347 }
3348
3349
3352 public void afterPropertiesSet() {
3353 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3354 com.liferay.portal.util.PropsUtil.get(
3355 "value.object.listener.com.liferay.portlet.journal.model.JournalStructure")));
3356
3357 if (listenerClassNames.length > 0) {
3358 try {
3359 List<ModelListener<JournalStructure>> listenersList = new ArrayList<ModelListener<JournalStructure>>();
3360
3361 for (String listenerClassName : listenerClassNames) {
3362 listenersList.add((ModelListener<JournalStructure>)InstanceFactory.newInstance(
3363 listenerClassName));
3364 }
3365
3366 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3367 }
3368 catch (Exception e) {
3369 _log.error(e);
3370 }
3371 }
3372 }
3373
3374 public void destroy() {
3375 EntityCacheUtil.removeCache(JournalStructureImpl.class.getName());
3376 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3377 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3378 }
3379
3380 @BeanReference(type = JournalArticlePersistence.class)
3381 protected JournalArticlePersistence journalArticlePersistence;
3382 @BeanReference(type = JournalArticleImagePersistence.class)
3383 protected JournalArticleImagePersistence journalArticleImagePersistence;
3384 @BeanReference(type = JournalArticleResourcePersistence.class)
3385 protected JournalArticleResourcePersistence journalArticleResourcePersistence;
3386 @BeanReference(type = JournalContentSearchPersistence.class)
3387 protected JournalContentSearchPersistence journalContentSearchPersistence;
3388 @BeanReference(type = JournalFeedPersistence.class)
3389 protected JournalFeedPersistence journalFeedPersistence;
3390 @BeanReference(type = JournalStructurePersistence.class)
3391 protected JournalStructurePersistence journalStructurePersistence;
3392 @BeanReference(type = JournalTemplatePersistence.class)
3393 protected JournalTemplatePersistence journalTemplatePersistence;
3394 @BeanReference(type = ResourcePersistence.class)
3395 protected ResourcePersistence resourcePersistence;
3396 @BeanReference(type = UserPersistence.class)
3397 protected UserPersistence userPersistence;
3398 @BeanReference(type = WebDAVPropsPersistence.class)
3399 protected WebDAVPropsPersistence webDAVPropsPersistence;
3400 @BeanReference(type = ExpandoValuePersistence.class)
3401 protected ExpandoValuePersistence expandoValuePersistence;
3402 private static final String _SQL_SELECT_JOURNALSTRUCTURE = "SELECT journalStructure FROM JournalStructure journalStructure";
3403 private static final String _SQL_SELECT_JOURNALSTRUCTURE_WHERE = "SELECT journalStructure FROM JournalStructure journalStructure WHERE ";
3404 private static final String _SQL_COUNT_JOURNALSTRUCTURE = "SELECT COUNT(journalStructure) FROM JournalStructure journalStructure";
3405 private static final String _SQL_COUNT_JOURNALSTRUCTURE_WHERE = "SELECT COUNT(journalStructure) FROM JournalStructure journalStructure WHERE ";
3406 private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalStructure.uuid IS NULL";
3407 private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalStructure.uuid = ?";
3408 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalStructure.uuid IS NULL OR journalStructure.uuid = ?)";
3409 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalStructure.uuid IS NULL AND ";
3410 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalStructure.uuid = ? AND ";
3411 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalStructure.uuid IS NULL OR journalStructure.uuid = ?) AND ";
3412 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalStructure.groupId = ?";
3413 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalStructure.groupId = ?";
3414 private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1 = "journalStructure.structureId IS NULL";
3415 private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "journalStructure.structureId = ?";
3416 private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3 = "(journalStructure.structureId IS NULL OR journalStructure.structureId = ?)";
3417 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "journalStructure.groupId = ? AND ";
3418 private static final String _FINDER_COLUMN_G_S_STRUCTUREID_1 = "journalStructure.structureId IS NULL";
3419 private static final String _FINDER_COLUMN_G_S_STRUCTUREID_2 = "journalStructure.structureId = ?";
3420 private static final String _FINDER_COLUMN_G_S_STRUCTUREID_3 = "(journalStructure.structureId IS NULL OR journalStructure.structureId = ?)";
3421 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "journalStructure.groupId = ? AND ";
3422 private static final String _FINDER_COLUMN_G_P_PARENTSTRUCTUREID_1 = "journalStructure.parentStructureId IS NULL";
3423 private static final String _FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2 = "journalStructure.parentStructureId = ?";
3424 private static final String _FINDER_COLUMN_G_P_PARENTSTRUCTUREID_3 = "(journalStructure.parentStructureId IS NULL OR journalStructure.parentStructureId = ?)";
3425 private static final String _FILTER_SQL_SELECT_JOURNALSTRUCTURE_WHERE = "SELECT DISTINCT {journalStructure.*} FROM JournalStructure journalStructure WHERE ";
3426 private static final String _FILTER_SQL_SELECT_JOURNALSTRUCTURE_NO_INLINE_DISTINCT_WHERE =
3427 "SELECT {journalStructure.*} FROM (SELECT DISTINCT id FROM JournalStructure) journalStructure2 INNER JOIN JournalStructure journalStructure ON (journalStructure2.id = journalStructure.id) WHERE ";
3428 private static final String _FILTER_SQL_COUNT_JOURNALSTRUCTURE_WHERE = "SELECT COUNT(DISTINCT journalStructure.id) AS COUNT_VALUE FROM JournalStructure journalStructure WHERE ";
3429 private static final String _FILTER_COLUMN_PK = "journalStructure.id";
3430 private static final String _FILTER_COLUMN_USERID = "journalStructure.userId";
3431 private static final String _FILTER_ENTITY_ALIAS = "journalStructure";
3432 private static final String _ORDER_BY_ENTITY_ALIAS = "journalStructure.";
3433 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalStructure exists with the primary key ";
3434 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalStructure exists with the key {";
3435 private static Log _log = LogFactoryUtil.getLog(JournalStructurePersistenceImpl.class);
3436 }